This commit is contained in:
Kartik Agaram 2020-10-19 23:53:45 -07:00
parent e28b949f18
commit 0cdbfff256
4 changed files with 96 additions and 1 deletions

View File

@ -637,10 +637,44 @@ $process-sandbox-define:body: {
# aren't defined in the rest of 'functions'. Append them in order.
# Assumes function body is a single line for now.
fn copy-unbound-words-to-args _functions: (addr handle function) {
# target
var target-ah/eax: (addr handle function) <- copy _functions
var _target/eax: (addr function) <- lookup *target-ah
var target/esi: (addr function) <- copy _target
var dest/edi: (addr handle word) <- get target, args
# next
var functions-ah/eax: (addr handle function) <- get target, next
var _functions/eax: (addr function) <- lookup *functions-ah
var functions/ecx: (addr function) <- copy _functions
# src
var line-ah/eax: (addr handle line) <- get target, body
var line/eax: (addr line) <- lookup *line-ah
var curr-ah/eax: (addr handle word) <- get line, data
var curr/eax: (addr word) <- lookup *curr-ah
{
compare curr, 0
break-if-=
# HERE
var next-ah/ecx: (addr handle word) <- get curr, next
curr <- lookup *next-ah
loop
}
}
# construct a call to `f` with copies of exactly its args
fn construct-call f: (addr handle function), out: (addr handle word) {
fn construct-call _f-ah: (addr handle function), out: (addr handle word) {
var f-ah/eax: (addr handle function) <- copy _f-ah
var _f/eax: (addr function) <- lookup *f-ah
var f/esi: (addr function) <- copy _f
var name-ah/eax: (addr handle array byte) <- get f, name
var name/eax: (addr array byte) <- lookup *name-ah
var dest/edi: (addr handle word) <- copy out
allocate-word-with dest, name
var tmp/eax: (addr word) <- lookup *dest
dest <- get tmp, next
var _args-ah/eax: (addr handle word) <- get f, args
var args-ah/esi: (addr handle word) <- copy _args-ah
copy-words args-ah, dest
}
fn word-index _words: (addr handle word), _n: int, out: (addr handle word) {

View File

@ -288,3 +288,21 @@ fn test-gap-buffer-equal-from-start? {
var result/eax: int <- copy _result
check-ints-equal result, 1, "F - test-gap-buffer-equal-from-start?"
}
fn copy-gap-buffer _src-ah: (addr handle gap-buffer), _dest-ah: (addr handle gap-buffer) {
# obtain src-a, dest-a
var src-ah/eax: (addr handle gap-buffer) <- copy _src-ah
var _src-a/eax: (addr gap-buffer) <- lookup *src-ah
var src-a/esi: (addr gap-buffer) <- copy _src-a
var dest-ah/eax: (addr handle gap-buffer) <- copy _dest-ah
var _dest-a/eax: (addr gap-buffer) <- lookup *dest-ah
var dest-a/edi: (addr gap-buffer) <- copy _dest-a
# copy left grapheme-stack
var src/ecx: (addr grapheme-stack) <- get src-a, left
var dest/edx: (addr grapheme-stack) <- get dest-a, left
copy-grapheme-stack src, dest
# copy right grapheme-stack
src <- get src-a, right
dest <- get dest-a, right
copy-grapheme-stack src, dest
}

View File

@ -62,6 +62,23 @@ $pop-grapheme-stack:body: {
}
}
fn copy-grapheme-stack _src: (addr grapheme-stack), dest: (addr grapheme-stack) {
var src/esi: (addr grapheme-stack) <- copy _src
var data-ah/edi: (addr handle array grapheme) <- get src, data
var _data/eax: (addr array grapheme) <- lookup *data-ah
var data/edi: (addr array grapheme) <- copy _data
var top-addr/ecx: (addr int) <- get src, top
var i/eax: int <- copy 0
{
compare i, *top-addr
break-if->=
var g/edx: (addr grapheme) <- index data, i
push-grapheme-stack dest, *g
i <- increment
loop
}
}
# dump stack to screen from bottom to top
# don't move the cursor or anything
fn render-stack-from-bottom _self: (addr grapheme-stack), screen: (addr screen) {

View File

@ -264,6 +264,32 @@ fn print-words-in-reverse screen: (addr screen), _words-ah: (addr handle word) {
print-string screen, " "
}
fn copy-words _src-ah: (addr handle word), _dest-ah: (addr handle word) {
var src-ah/eax: (addr handle word) <- copy _src-ah
var src-a/eax: (addr word) <- lookup *src-ah
compare src-a, 0
break-if-=
# copy
var dest-ah/edi: (addr handle word) <- copy _dest-ah
copy-word src-a, dest-ah
# recurse
var next-src-ah/esi: (addr handle word) <- get src-a, next
var dest-a/eax: (addr word) <- lookup *dest-ah
var next-dest-ah/eax: (addr handle word) <- get dest-a, next
copy-words next-src-ah, next-dest-ah
}
fn copy-word _src-a: (addr word), _dest-ah: (addr handle word) {
var dest-ah/eax: (addr handle word) <- copy _dest-ah
allocate dest-ah
var _dest-a/eax: (addr word) <- lookup *dest-ah
var dest-a/eax: (addr word) <- copy _dest-a
var dest/edi: (addr handle gap-buffer) <- get dest-a, scalar-data
var src-a/eax: (addr word) <- copy _src-a
var src/eax: (addr handle gap-buffer) <- get src-a, scalar-data
copy-gap-buffer src, dest
}
# one implication of handles: append must take a handle
fn append-word _self-ah: (addr handle word) {
var self-ah/esi: (addr handle word) <- copy _self-ah