From 5bdcb85f67c295c6967d8e1931d1cef95b29fab9 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 20 Oct 2020 09:33:13 -0700 Subject: 7081 Defining new functions seems to be working. _However_, we aren't yet detecting duplicates. `x x *` leads to a declaration of `x x f`. --- apps/tile/environment.mu | 24 ++++++++++++++++-------- apps/tile/word.mu | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 8 deletions(-) (limited to 'apps/tile') diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index 53e7bc63..b5cacb86 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -599,6 +599,8 @@ $process-sandbox-define:body: { # copy-unbound-words-to-args functions # + var empty-word: (handle word) + copy-handle empty-word, final-line-contents construct-call functions, final-line-contents # clear partial-name-for-function var empty-word: (handle word) @@ -698,19 +700,25 @@ fn bound? w: (addr word), functions-ah: (addr handle function) -> result/ebx: bo } # construct a call to `f` with copies of exactly its args -fn construct-call _f-ah: (addr handle function), out: (addr handle word) { +fn construct-call _f-ah: (addr handle function), _dest-ah: (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 + # append args in reverse + var args-ah/eax: (addr handle word) <- get f, args + var dest-ah/edi: (addr handle word) <- copy _dest-ah + copy-words-in-reverse args-ah, dest-ah + # append name + { + var dest/eax: (addr word) <- lookup *dest-ah + compare dest, 0 + break-if-= + dest-ah <- get dest, next + loop + } 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 + allocate-word-with dest-ah, name } fn word-index _words: (addr handle word), _n: int, out: (addr handle word) { diff --git a/apps/tile/word.mu b/apps/tile/word.mu index e6167820..80fd6f3e 100644 --- a/apps/tile/word.mu +++ b/apps/tile/word.mu @@ -279,6 +279,27 @@ fn copy-words _src-ah: (addr handle word), _dest-ah: (addr handle word) { copy-words next-src-ah, next-dest-ah } +fn copy-words-in-reverse _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 + var src-a/esi: (addr word) <- copy _src-a + compare src-a, 0 + break-if-= + # recurse + var next-src-ah/ecx: (addr handle word) <- get src-a, next + var dest-ah/edi: (addr handle word) <- copy _dest-ah + copy-words-in-reverse next-src-ah, dest-ah + # copy at end + { + var dest-a/eax: (addr word) <- lookup *dest-ah + compare dest-a, 0 + break-if-= + dest-ah <- get dest-a, next + loop + } + copy-word src-a, 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 -- cgit 1.4.1-2-gfad0