starting to implement first macros

Another commit, another bugfix.

Some snippets from my currently exploding todo list:

- always investigate lookup errors immediately. Beyond the root cause, they should never happen at the moment, while we aren't reclaiming memory.
  we should always return a more precise error message. Usually involving null pointer checks.

- on abort, print out stack trace
  - emit mapping of labels to addresses during survey
  - store a mapping of symbols somewhere in the code image

- stop allocating 1KB per token; expand space for tokens as needed
This commit is contained in:
Kartik K. Agaram 2021-05-07 09:49:16 -07:00
parent 7105b73fd3
commit 74be534e2b
4 changed files with 20 additions and 0 deletions

View File

@ -1,5 +1,9 @@
(
(globals . (
(mac . [(def mac (litmac litfn () (name params . body)
`(def ,name (litmac litfn () ,params ,@body))))])
(when . [(mac when (cond body)
`(if ,cond ,body ()))])
(hline . [(def hline (fn (screen y color)
(hline1 screen y 0 (width screen) color)))])
(hline1 . [(def hline1 (fn (screen y lo hi color)

View File

@ -472,6 +472,15 @@ fn evaluate _in-ah: (addr handle cell), _out-ah: (addr handle cell), env-h: (han
increment call-number
evaluate left-ah, left-out-ah, env-h, globals, trace, screen-cell, keyboard-cell, call-number
debug-print "B", 4/fg, 0xc5/bg=blue-bg
# a trip wire in case we're running without a trace (e.g. when loading the initial state from disk)
{
var left-out/eax: (addr cell) <- lookup *left-out-ah
compare left-out, 0
{
break-if-!=
abort "unknown variable"
}
}
#
curr-out-ah <- get curr-out, right
var right-ah/eax: (addr handle cell) <- get curr, right

View File

@ -63,6 +63,7 @@ fn initialize-globals _self: (addr global-table) {
}
fn load-globals in: (addr handle cell), self: (addr global-table) {
#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "a", 2/fg 0/bg
var remaining-ah/esi: (addr handle cell) <- copy in
{
var _remaining/eax: (addr cell) <- lookup *remaining-ah
@ -70,6 +71,7 @@ fn load-globals in: (addr handle cell), self: (addr global-table) {
var done?/eax: boolean <- nil? remaining
compare done?, 0/false
break-if-!=
#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "b", 2/fg 0/bg
var curr-ah/eax: (addr handle cell) <- get remaining, left
var curr/eax: (addr cell) <- lookup *curr-ah
remaining-ah <- get remaining, right
@ -83,10 +85,14 @@ fn load-globals in: (addr handle cell), self: (addr global-table) {
allocate value-gap-buffer-ah
var value-gap-buffer/eax: (addr gap-buffer) <- lookup *value-gap-buffer-ah
initialize-gap-buffer value-gap-buffer, 0x1000/4KB
#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "w", 2/fg 0/bg
load-gap-buffer-from-stream value-gap-buffer, value-data
#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "x", 2/fg 0/bg
read-evaluate-and-move-to-globals value-gap-buffer-ah, self
#? draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "y", 2/fg 0/bg
loop
}
#? abort "zz"
}
fn write-globals out: (addr stream byte), _self: (addr global-table) {

View File

@ -639,6 +639,7 @@ fn read-evaluate-and-move-to-globals _in-ah: (addr handle gap-buffer), globals:
var read-result-h: (handle cell)
var read-result-ah/esi: (addr handle cell) <- address read-result-h
read-cell in, read-result-ah, 0/no-trace
macroexpand read-result-ah, globals, 0/no-trace
var nil-storage: (handle cell)
var nil-ah/eax: (addr handle cell) <- address nil-storage
allocate-pair nil-ah