Skip to content

Commit

Permalink
Refactor builtin handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
porcuquine committed Nov 5, 2024
1 parent 9466a23 commit bf088ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 48 deletions.
50 changes: 5 additions & 45 deletions loam/data.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
(eq (symbol-package s) builtin-package)))

;; Getting them via do-external-symbols doesn't preserve the order, so here we are...
(defparameter *builtin-list*
(deflexical +builtins+
(list 'lurk.builtin:atom
'lurk.builtin:apply
'lurk.builtin:begin
Expand Down Expand Up @@ -57,51 +57,11 @@
'lurk.builtin:breakpoint
'lurk.builtin:fail))

(loop for sym in +builtins+ for i from 0
do (setf (get sym 'idx) i))

;; Forgive the heresy.
(defun builtin-idx (b)
(case b
(lurk.builtin:atom 0)
(lurk.builtin:apply 1)
(lurk.builtin:begin 2)
(lurk.builtin:car 3)
(lurk.builtin:cdr 4)
(lurk.builtin:char 5)
(lurk.builtin:commit 6)
(lurk.builtin:comm 7)
(lurk.builtin:bignum 8)
(lurk.builtin:cons 9)
(lurk.builtin:current-env 10)
(lurk.builtin:emit 11)
(lurk.builtin:empty-env 12)
(lurk.builtin:eval 13)
(lurk.builtin:eq 14)
(lurk.builtin:eqq 15)
(lurk.builtin:type-eq 16)
(lurk.builtin:type-eqq 17)
(lurk.builtin:hide 18)
(lurk.builtin:if 19)
(lurk.builtin:lambda 20)
(lurk.builtin:let 21)
(lurk.builtin:letrec 22)
(lurk.builtin:u64 23)
(lurk.builtin:open 24)
(lurk.builtin:quote 25)
(lurk.builtin:secret 26)
(lurk.builtin:strcons 27)
(lurk.builtin:list 28)
(lurk.builtin:+ 29)
(lurk.builtin:- 30)
(lurk.builtin:* 31)
(lurk.builtin:/ 32)
(lurk.builtin:% 33)
(lurk.builtin:= 34)
(lurk.builtin:< 35)
(lurk.builtin:> 36)
(lurk.builtin:<= 37)
(lurk.builtin:>= 38)
(lurk.builtin:breakpoint 39)
(lurk.builtin:fail 40)
))
(defun builtin-idx (b) (get b 'idx))

;; bignum is reserved.
(deftype wide-num () '(unsigned-byte 256))
Expand Down
2 changes: 1 addition & 1 deletion loam/evaluation.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@
collect (list sym-value (dual i))))

(defun initial-builtin-digest-mem ()
(loop for b in *builtin-list*
(loop for b in +builtins+
for i from 0
for builtin-value = (wide-ptr-value (intern-wide-ptr b))
collect (list builtin-value (dual i))))
Expand Down
4 changes: 2 additions & 2 deletions loam/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
(:import-from #:allocation #:*program* #:lurk-allocation #:allocation-tag-names #:element #:wide #:wide-elements #:wide-nth
#:make-wide #:widen #:wide-ptr #:make-wide-ptr #:wide-ptr-tag #:wide-ptr-value #:tag-name #:tag-value
#:tag #:== #:hash-cache #:hash #:unhash #:+element-bits+ #:nth-tag)
(:export #:builtin-idx #:*builtin-list* #:intern-wide-ptr #:num #:env #:thunk #:fun))
(:export #:builtin-idx #:+builtins+ #:intern-wide-ptr #:num #:env #:thunk #:fun))

(defpackage evaluation
(:use #:common-lisp)
Expand All @@ -77,7 +77,7 @@
(: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
#:widen #:wide #:wide-elements #:wide-nth #:element #:tag #:tag-name #:tag-value #:tag-address #:nth-tag #:lurk-allocation
#:allocation-tag-names #:alloc #:hash-cache #:hash #:unhash #:+element-bits+ #:is-tag-p #:has-tag-p)
(:import-from #:data #:builtin-idx #:*builtin-list* #:intern-wide-ptr #:num #:env #:thunk #:fun))
(:import-from #:data #:builtin-idx #:+builtins+ #:intern-wide-ptr #:num #:env #:thunk #:fun))

(defpackage loam
(:use #:common-lisp)
Expand Down

0 comments on commit bf088ed

Please sign in to comment.