edtris/gneiss/example.fnl

35 lines
1.2 KiB
Fennel

(local Cpu (require :gneiss.cpu))
(local {: show} (require :inspector.debug))
(local sql (require :diet-sqlite))
(import-macros {: $ : query : specify} :sqlog.macros)
(sql.shutdown)
; (sql.register-logger #(print "SQL:" $2 $1))
(local cpu (Cpu))
(macro divisible-by [val denominator]
`($ (= (% ,val ,denominator) 0)))
(pp (divisible-by i 3))
(specify cpu.sqlog
(table fizzbuzz i fizzbuzz))
(let [pgid (cpu:insert-program ($
(do ; 1
(!+ [cpu.frame fp :i 1] [cpu.my-fp fp])) ; ideally: (!+ [cpu.frame-var :i 1])
(do ;2
(!+ [fizzbuzz i (case (when (and ,(divisible-by i 3) ,(divisible-by i 5)) :fizzbuzz)
(when ,(divisible-by i 3) :fizz)
(when ,(divisible-by i 5) :buzz)
(else i))] [cpu.frame-var :i i])
(!= [cpu.frame _ _ (+ i 1)] [cpu.frame fp :i i] [cpu.my-fp fp]) ; ideally: (!= [cpu.frame-var :i 1])?
(!= [cpu.frame _ _ 1] [cpu.frame fp :$ip _] [cpu.my-fp fp] [cpu.frame-var :i i] (< i 100))) ; if i < 100 goto 2
,cpu.ret))
pid (cpu:initialize-process pgid)]
(cpu:run)
(show (query cpu.sqlog [fizzbuzz i fizzbuzz])))
{}