Skip to content

Commit bf088ed

Browse files
committed
Refactor builtin handling.
1 parent 9466a23 commit bf088ed

File tree

3 files changed

+8
-48
lines changed

3 files changed

+8
-48
lines changed

loam/data.lisp

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
(eq (symbol-package s) builtin-package)))
1515

1616
;; Getting them via do-external-symbols doesn't preserve the order, so here we are...
17-
(defparameter *builtin-list*
17+
(deflexical +builtins+
1818
(list 'lurk.builtin:atom
1919
'lurk.builtin:apply
2020
'lurk.builtin:begin
@@ -57,51 +57,11 @@
5757
'lurk.builtin:breakpoint
5858
'lurk.builtin:fail))
5959

60+
(loop for sym in +builtins+ for i from 0
61+
do (setf (get sym 'idx) i))
62+
6063
;; Forgive the heresy.
61-
(defun builtin-idx (b)
62-
(case b
63-
(lurk.builtin:atom 0)
64-
(lurk.builtin:apply 1)
65-
(lurk.builtin:begin 2)
66-
(lurk.builtin:car 3)
67-
(lurk.builtin:cdr 4)
68-
(lurk.builtin:char 5)
69-
(lurk.builtin:commit 6)
70-
(lurk.builtin:comm 7)
71-
(lurk.builtin:bignum 8)
72-
(lurk.builtin:cons 9)
73-
(lurk.builtin:current-env 10)
74-
(lurk.builtin:emit 11)
75-
(lurk.builtin:empty-env 12)
76-
(lurk.builtin:eval 13)
77-
(lurk.builtin:eq 14)
78-
(lurk.builtin:eqq 15)
79-
(lurk.builtin:type-eq 16)
80-
(lurk.builtin:type-eqq 17)
81-
(lurk.builtin:hide 18)
82-
(lurk.builtin:if 19)
83-
(lurk.builtin:lambda 20)
84-
(lurk.builtin:let 21)
85-
(lurk.builtin:letrec 22)
86-
(lurk.builtin:u64 23)
87-
(lurk.builtin:open 24)
88-
(lurk.builtin:quote 25)
89-
(lurk.builtin:secret 26)
90-
(lurk.builtin:strcons 27)
91-
(lurk.builtin:list 28)
92-
(lurk.builtin:+ 29)
93-
(lurk.builtin:- 30)
94-
(lurk.builtin:* 31)
95-
(lurk.builtin:/ 32)
96-
(lurk.builtin:% 33)
97-
(lurk.builtin:= 34)
98-
(lurk.builtin:< 35)
99-
(lurk.builtin:> 36)
100-
(lurk.builtin:<= 37)
101-
(lurk.builtin:>= 38)
102-
(lurk.builtin:breakpoint 39)
103-
(lurk.builtin:fail 40)
104-
))
64+
(defun builtin-idx (b) (get b 'idx))
10565

10666
;; bignum is reserved.
10767
(deftype wide-num () '(unsigned-byte 256))

loam/evaluation.lisp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@
606606
collect (list sym-value (dual i))))
607607

608608
(defun initial-builtin-digest-mem ()
609-
(loop for b in *builtin-list*
609+
(loop for b in +builtins+
610610
for i from 0
611611
for builtin-value = (wide-ptr-value (intern-wide-ptr b))
612612
collect (list builtin-value (dual i))))

loam/package.lisp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
(:import-from #:allocation #:*program* #:lurk-allocation #:allocation-tag-names #:element #:wide #:wide-elements #:wide-nth
6262
#:make-wide #:widen #:wide-ptr #:make-wide-ptr #:wide-ptr-tag #:wide-ptr-value #:tag-name #:tag-value
6363
#:tag #:== #:hash-cache #:hash #:unhash #:+element-bits+ #:nth-tag)
64-
(:export #:builtin-idx #:*builtin-list* #:intern-wide-ptr #:num #:env #:thunk #:fun))
64+
(:export #:builtin-idx #:+builtins+ #:intern-wide-ptr #:num #:env #:thunk #:fun))
6565

6666
(defpackage evaluation
6767
(:use #:common-lisp)
@@ -77,7 +77,7 @@
7777
(:import-from #:allocation #:*program* #:element #:dual-element #:ptr #:make-ptr #:ptr-tag #:ptr-value #:wide-ptr #:make-wide-ptr #:wide-ptr-tag #:wide-ptr-value #:make-wide
7878
#:widen #:wide #:wide-elements #:wide-nth #:element #:tag #:tag-name #:tag-value #:tag-address #:nth-tag #:lurk-allocation
7979
#:allocation-tag-names #:alloc #:hash-cache #:hash #:unhash #:+element-bits+ #:is-tag-p #:has-tag-p)
80-
(:import-from #:data #:builtin-idx #:*builtin-list* #:intern-wide-ptr #:num #:env #:thunk #:fun))
80+
(:import-from #:data #:builtin-idx #:+builtins+ #:intern-wide-ptr #:num #:env #:thunk #:fun))
8181

8282
(defpackage loam
8383
(:use #:common-lisp)

0 commit comments

Comments
 (0)