blob: 578fa011dd6afddaa967d9b03bcc683c6283d6dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
(in-package :cl-forth)
(defun main ()
(let ((args (rest sb-ext:*posix-argv*)))
(let ((flag (first args)))
(cond ((string= flag "-c")
;; (iter (for (k v) in-hashtable *operations*)
;; (for i from 0)
;; (format t "~s: ~s~%" i k))
;; (let ((tokens (lex-file (second args))))
;; (format t "~s~%" tokens)
;; (let ((program (prog-from-tokens tokens)))
;; (format t "~s~%" program)
;; (generate-program program :compile t)))
(compile-program (second args)))
((string= flag "-i")
(interpret-program (make-program (second args))))
(t (format t "~a is not a valid flag~%" flag))))))
;; (defun make-exe ()
;; (sb-ext:save-lisp-and-die #P"cl-forth"
;; :toplevel #'main
;; :executable t))
(defparameter *example-path* (from-root "test/prog.lorth"))
(defun example-lex ()
(lex-file *example-path* t))
(defun example-prog ()
(make-program *example-path*))
(defun example-compile ()
(generate-program (make-program *example-path*) :path "test/output.asm"
:compile t))
(defun example-interpret ()
(interpret-program (make-program *example-path*)))
(defun example-run ()
(example-compile)
(run '("test/output")))
(defun start-forth-repl ()
(iter (for line = (progn (format t "~&> ") (read-line)))
(when (string= line "bye")
(finish))
(interpret-program (parse-tokens (lex-line line 0)))))
|