Closed porky11 closed 8 years ago
The specific problem with arg-list-names
is that it's attempting to dereference last-node
when last-node
may be null, at least when I attempt to use it with a form like (defc eg' extern eg int ((a int) (b int)))
. I don't think walk-nodes
is appropriate in this case, because it's not clear that recursion is required. The following should work as expected:
(using-namespace std.macros
(def defc (macro extern (name linkage cname type args)
(let ((arg-list \ (nullptr DNode))
(arg-list' \ (nullptr DNode))
(args' \ (@:@ args list-node)))
(while (not (null args'))
(let ((name-node \ (copy mc false (@:@ args' list-node))))
(if (null arg-list')
(do (setv arg-list' name-node)
(setv arg-list arg-list'))
(do (setf (:@ arg-list' next-node) name-node)
(setv arg-list' (@:@ arg-list next-node))))
(setv args' (@:@ args' next-node))))
(let ((fdef \ (qq (uq cname) (uql arg-list))))
(print fdef) ;;debug, print the form
(printf "\n")
(qq do
(def (uq cname) (fn extern-c (uq type) (uq args)))
(def (uq name) (fn (uq linkage) (uq type) (uq args)
((uq cname) (uql arg-list))))))))))
The current DNode structure, where each node can potentially be a list node, appears to be confusing. Whether to change that to be more CL-like needs further thought; in the meantime, the documentation for qq
has been updated to be more accurate.
If you have any ideas around a set of macros for simplifying macro authorship, that would be much appreciated.
I think, I wrote this issue, before I really understood, how macros work. I first thought, the DNodes are similar to lists in lisp, but it's a bit different. So after understanding this, it should not be a problem
I wrote a macro for easier defining c-functions.
It contains a function, that convert a list like this
((a int) (b (p void)))
to a list like that(a b)
(so extracting the function names) I think I should usestd.macros.walk-nodes
, but I'm not sure, how to do it. I tried thiswhich causes segfault. I think, I have to link the nodes correctly, because when removing everything concerning
last-node
, i just get the first argument back. It seems weird to me, that DNodes, that are not lists, contain a next-node.Maybe the documentation on macros (i.e. walk-nodes and the DNode struct) should be improved, or macros added to simplify macro creation.