summaryrefslogtreecommitdiff
path: root/util.lisp
blob: 813f55b4db0a4b116f1ab0bfe226a149de7cb75b (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
(in-package :cl-forth)

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defmacro eval-always (&body body)
    `(eval-when (:compile-toplevel :load-toplevel :execute)
       ,@body)))

(eval-always 
 (defmacro with-gensyms (syms &body body)
   `(let ,(mapcar (lambda (sym) `(,sym (gensym ,(string sym)))) syms)
      ,@body)))

(defmacro init-hash (&body body)
  (with-gensyms (table)
    `(let ((,table (make-hash-table)))
       ,@(iter (for (k v) in body)
               (collect `(setf (gethash ',k ,table) ,v)))
       ,table)))

(defun mklist (form)
  (if (listp form) form (list form)))

;; (defmacro run (args)
;;   (let ((sym (gensym)))
;;     `(let ((,sym ,args))
;;        (format t "~{~a~^ ~}~%" ,sym)
;;        (uiop:run-program ,sym))))

(defun run (args)
  (format t "~{~a~^ ~}~%" args)
  (uiop:run-program args :output *standard-output*))

;; ,(file-namestring
;;   (make-pathname :name (pathname-name path)
;;                  :type "o"))

(defparameter *test-program*
  '((push 34)
    (push 35)
    (plus)
    (dump)
    (push 500)
    (push 80)
    (minus)
    (dump)))