mu/mu.arc

55 lines
1.5 KiB
Plaintext
Raw Normal View History

2014-07-07 01:49:53 +00:00
; things that a future assembler will need separate memory for:
; code; types; args channel
2014-07-06 08:41:37 +00:00
(def clear ()
(= types* (obj
integer (obj size 1)
address (obj size 1)))
2014-07-06 08:41:37 +00:00
(= memory* (table))
(= function* (table)))
(clear)
(def add-fns (fns)
(each (name . body) fns
(= function*.name body)))
2014-07-06 07:07:03 +00:00
2014-07-06 09:19:32 +00:00
(def run (instrs (o fn-args) (o returned))
2014-07-06 07:07:03 +00:00
(each instr instrs
2014-07-06 08:57:47 +00:00
(unless returned
;? (prn instr)
;? (prn memory*)
2014-07-06 09:06:42 +00:00
(let delim (or (pos '<- instr) -1)
(with (oarg (if (>= delim 0)
(cut instr 0 delim))
2014-07-06 09:06:42 +00:00
op (instr (+ delim 1))
arg (cut instr (+ delim 2)))
;? (prn op " " oarg)
2014-07-06 09:06:42 +00:00
(case op
loadi
(= (memory* oarg.0.1) arg.0)
2014-07-06 09:06:42 +00:00
add
(= (memory* oarg.0.1)
(+ (memory* arg.0.1) (memory* arg.1.1)))
2014-07-06 09:19:32 +00:00
read
(= (memory* oarg.0.1)
2014-07-06 09:19:32 +00:00
; hardcoded channel for now
(memory* pop.fn-args.1))
2014-07-07 03:13:15 +00:00
reply
(= returned (annotate 'result arg))
2014-07-06 09:06:42 +00:00
; else user-defined function
(let results (run function*.op arg)
;? (prn "== " memory*)
(each o oarg
;? (prn o)
(= (memory* o.1) (memory* pop.results.1))))
2014-07-06 09:06:42 +00:00
)))))
2014-07-06 08:53:18 +00:00
;? (prn "return")
rep.returned)
2014-07-06 07:07:03 +00:00
2014-07-06 08:41:37 +00:00
(awhen cdr.argv
(each file it
2014-07-07 01:49:53 +00:00
;? (prn file)
2014-07-06 08:41:37 +00:00
(add-fns readfile.file))
2014-07-07 01:49:53 +00:00
;? (prn function*)
2014-07-06 08:41:37 +00:00
(run function*!main)
2014-07-06 07:07:03 +00:00
(prn memory*))