Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
winston-h-zhang committed Oct 30, 2024
1 parent 793d188 commit 34b411c
Show file tree
Hide file tree
Showing 4 changed files with 466 additions and 0 deletions.
1 change: 1 addition & 0 deletions loam.asd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
(:file "lattice")
(:file "datalog")
(:file "allocation")
(:file "evaluation")
(:file "data")
)))

Expand Down
19 changes: 19 additions & 0 deletions loam/datalog.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ and a list of free variables in FORM."
(let :rule-binding)
(when :restriction)
(case :case)
(cond :cond)
(if :if)
(t :predicate)))

Expand All @@ -743,6 +744,19 @@ and a list of free variables in FORM."
(nconc (aux if-branch `(when ,condition))
(aux else-branch `(when (not ,condition)))))))

;; Synthesizes a segment that starts with a case statement.
;; Errors if the first segment is not a case segment.
(defun synthesize-cond-segment (case-segment curr-rhs end-handle)
(destructuring-bind (head &rest branches)
case-segment
(assert (eql head 'cond))
(loop for (test branch-segments) in branches
for test-segment = `(when ,test)
for curr-rhs-tail = (append curr-rhs (list test-segment))
append (synthesize-segments branch-segments (copy-list curr-rhs-tail) end-handle)
into output-rules
finally (return output-rules))))

;; Synthesizes a segment that starts with a case statement.
;; Errors if the first segment is not a case segment.
(defun synthesize-case-segment (case-segment curr-rhs end-handle)
Expand Down Expand Up @@ -776,6 +790,11 @@ and a list of free variables in FORM."
do (assert (eql rest nil))
and append (synthesize-case-segment segment (copy-list curr-rhs-tail) end-handle) into output-rules
and do (return output-rules)
when (eql kind :cond)
;; Ditto the above for if statements.
do (assert (eql rest nil))
and append (synthesize-cond-segment segment (copy-list curr-rhs-tail) end-handle) into output-rules
and do (return output-rules)
when (eql kind :if)
;; Ditto the above for if statements.
do (assert (eql rest nil))
Expand Down
Loading

0 comments on commit 34b411c

Please sign in to comment.