diff options
author | mRnea <akannemre@gmail.com> | 2024-07-27 16:42:24 +0300 |
---|---|---|
committer | mRnea <akannemre@gmail.com> | 2024-07-27 16:42:24 +0300 |
commit | d1481f2770f363aa436db853a7c4f7616de80e50 (patch) | |
tree | 33eb9616d2d96f08aaff329be9a8f9aee65e939b /cl-forth.lisp | |
parent | 2d94db09901c346d1ac7f5787f89609b6ecf38dd (diff) |
added memory manipulation and syscalls
Diffstat (limited to 'cl-forth.lisp')
-rw-r--r-- | cl-forth.lisp | 21 |
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 '(#\.))))) |