Skip to content

Commit

Permalink
Implement case and if segments, memory macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
winston-h-zhang committed Oct 29, 2024
1 parent 683f6eb commit 0a3b98d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 4 additions & 5 deletions loam/allocation.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@

(defun ptr-wide-tag (ptr) (widen (ptr-tag ptr)))

(defun concat-sym (root suf)
(intern (format nil "~A~A" root suf)))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defun concat-sym (root suf)
(intern (format nil "~A~A" root suf))))

(defmacro mem-constructor (name (tag initial-addr hasher) &body args)
(multiple-value-bind
Expand Down Expand Up @@ -547,9 +548,7 @@
always (= next-addr (1+ addr)))))

(test mem-constructor-spec
(let ((unnamed-spec (cddr (spec (find-prototype 'cons-mem)))) ; Strip off the program name.
(unnamed-syn-spec (cddr (spec (find-prototype 'syn-cons-mem)))))
(is (equal unnamed-spec unnamed-syn-spec))))
(is (compare-spec 'syn-cons-mem 'cons-mem)))

(test allocation
(let* ((program (make-program-instance 'map-double))
Expand Down
4 changes: 1 addition & 3 deletions loam/datalog.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ and a list of free variables in FORM."
(defun synthesize-if-segment (if-segment curr-rhs end-handle)
(destructuring-bind (head if-form &rest branches)
if-segment
(display head)
(assert (eql head 'if))
(assert (= (length branches) 2)) ; Must only have then and else branches.
(loop with first = t
Expand All @@ -754,7 +753,6 @@ and a list of free variables in FORM."
(defun synthesize-case-segment (case-segment curr-rhs end-handle)
(destructuring-bind (head case-form &rest branches)
case-segment
(display head)
(assert (eql head 'case))
(loop for (test branch-segments) in branches
for test-segment = `(when (eql ,case-form ,test))
Expand Down Expand Up @@ -791,7 +789,7 @@ and a list of free variables in FORM."
finally
;; If we don't hit a case statement, then after we process all segments,
;; we must finish with an final rule.
(let ((final-rule (display (make-rule `(,end-handle <-- ,@curr-rhs-tail)))))
(let ((final-rule (make-rule `(,end-handle <-- ,@curr-rhs-tail))))
(return `(,@output-rules ,final-rule)))))

;; This function takes a unsynthesized rule and synthesizes it.
Expand Down

0 comments on commit 0a3b98d

Please sign in to comment.