diff options
Diffstat (limited to 'cl-forth.lisp')
-rw-r--r-- | cl-forth.lisp | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/cl-forth.lisp b/cl-forth.lisp index 66327e5..88019ce 100644 --- a/cl-forth.lisp +++ b/cl-forth.lisp @@ -188,35 +188,11 @@ (defmethod write-program ((target (eql :c)) program out &key (mem-cap 640000)) (declare (ignore mem-cap)) - (format out - "#include <stdio.h> - -struct Stack { - int content[100]; - int i; -}; - -typedef struct Stack Stack; - -void push(Stack* stack, int val){ - stack->content[stack->i] = val; - stack->i += 1; -} - -int pop(Stack* stack){ - stack->i -= 1; - return stack->content[stack->i]; -} - -Stack stack; -int rax, rbx; - -int main(void){ - stack.i = 0; -") - (iter (for op in-sequence program) - (write-op target out (car op) (cdr op))) - (format out " return 0;~%}~%")) + (gen-c-stack out) + (with-c-fn (:int main) () out + (iter (for op in-sequence program) + (write-op target out (car op) (cdr op))) + (format out "~% return 0;~%"))) (defun generate-program (program &key (path "output.asm") (compile nil) @@ -238,7 +214,9 @@ int main(void){ :output t :silence silence))) (defmethod compile-program ((target (eql :c)) path silence) - (run `("gcc" ,path) :output t :silence silence)) + (let ((name (first (uiop:split-string path :separator '(#\.))))) + (run `("gcc" ,path "-o" ,name) + :output t :silence silence))) |