-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.lisp
42 lines (39 loc) · 1.19 KB
/
main.lisp
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
(defpackage #:paras
(:nicknames #:paras/main)
(:use #:cl
#:paras/types)
(:import-from #:paras/parser
#:parse
#:parse-string)
(:import-from #:paras/compiler
#:compile-code
#:recompile-form
#:compiled-form
#:compiled-form-body)
(:import-from #:paras/errors
#:execution-error)
(:shadowing-import-from #:paras/builtin
#:use
#:require
#:*modules*)
(:export #:execute-form
#:compile-code
#:recompile-form
#:parse
#:parse-string
#:execute-string
#:use
#:require
#:*modules*))
(in-package #:paras)
(defun execute-form (form)
(check-type form compiled-form)
(let ((code (compiled-form-body form)))
(handler-case
(etypecase code
(paras-form-type (eval code))
(paras-variable-type (symbol-value code))
(paras-constant-type code))
(error (e) (error 'execution-error :internal-error e)))))
(defun execute-string (string)
(execute-form (compile-code (parse-string string))))