summaryrefslogtreecommitdiff
path: root/cl-forth.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'cl-forth.lisp')
-rw-r--r--cl-forth.lisp21
1 files changed, 12 insertions, 9 deletions
diff --git a/cl-forth.lisp b/cl-forth.lisp
index a87d0eb..9d66532 100644
--- a/cl-forth.lisp
+++ b/cl-forth.lisp
@@ -2,7 +2,9 @@
(eval-always
(defparameter *identifiers*
- '(+ - dump = ise yoksa yap eş push değiş üst rot düş döngü iken < >))
+ '(+ - dump = ise yoksa yap eş push değiş üst rot düş döngü iken < >
+ syscall-1 syscall-2 syscall-3 syscall-4 syscall-5 syscall-6
+ bel oku yaz))
(defun is-identifier (sym)
(find sym *identifiers*)))
@@ -101,6 +103,9 @@
(assert (eq 'döngü (car top)))
(push (list 'iken i (cadr top)) stack)
(vector-push-extend (list 'iken nil) ops)))
+ ((search "syscall" (string-downcase (string op)))
+ (let ((syscall-num (parse-integer (subseq (string op) 8))))
+ (vector-push-extend (list 'syscall syscall-num) ops)))
(t (vector-push-extend (list op) ops))))
(finally (return ops))))
@@ -192,13 +197,8 @@
;;; COMPILER
-(defun gen-header (op str)
- (format str " ;; -- ~s --~%" op))
-
-;; (defun not-implemented (str)
-;; (format str " ;; -- TODO: not implemented --~%"))
-
-(defun generate-program (program &key (path "output.asm") (compile nil))
+(defun generate-program (program &key (path "output.asm") (compile nil)
+ (mem-cap 640000))
(with-open-file (out path :direction :output
:if-exists :supersede)
(format out "~a~%" "segment .text")
@@ -208,7 +208,10 @@
(iter (for op in-sequence program)
(gen-header op out)
(gen-code op out))
- (gen-code '(exit 0) out))
+ (gen-header '(exit 0) out)
+ (gen-code '(exit 0) out)
+ (format out "~a~%" "segment .bss")
+ (format out "~a ~a~%" "bel: resb" mem-cap))
(when compile
(run `("nasm" "-felf64" ,path))
(let ((name (first (uiop:split-string path :separator '(#\.)))))