aboutsummaryrefslogtreecommitdiff
path: root/forth/types.fs
diff options
context:
space:
mode:
authorChouser <chouser@n01se.net>2015-02-17 18:47:23 -0500
committerChouser <chouser@n01se.net>2015-02-21 13:22:44 -0500
commit580c4eef9d61f39264813b662fe5335c3c3c4ee5 (patch)
tree0ab0a822f737e307084f8c4b391c3ac9abf44da9 /forth/types.fs
parente82947d00f700558500e85e22aaf187544769a2e (diff)
downloadmal-580c4eef9d61f39264813b662fe5335c3c3c4ee5.tar.gz
mal-580c4eef9d61f39264813b662fe5335c3c3c4ee5.zip
forth: Add step 9, just try*/throw
- Moved some stuff out of printer into str, to support throwing strings in types.fs - Fixed an apparently completely broken 'nth' - Still failing 120 step9 tests
Diffstat (limited to 'forth/types.fs')
-rw-r--r--forth/types.fs19
1 files changed, 8 insertions, 11 deletions
diff --git a/forth/types.fs b/forth/types.fs
index 07eca02..d238001 100644
--- a/forth/types.fs
+++ b/forth/types.fs
@@ -1,3 +1,5 @@
+require str.fs
+
\ === sorted-array === /
\ Here are a few utility functions useful for creating and maintaining
\ the deftype* method tables. The keys array is kept in sorted order,
@@ -131,10 +133,8 @@ MalType% deftype MalFalse MalFalse new constant mal-false
\ themselves for the given object, and then execute that implementation.
: execute-method { obj pxt -- }
obj not-object? if
- ." Refusing to invoke protocol fn '"
- pxt >name name>string type
- ." ' on non-object: " obj .
- 1 throw
+ 0 0 obj int>str s" ' on non-object: " pxt >name name>string
+ s" Refusing to invoke protocol fn '" ...throw-str
endif
obj mal-type @ dup MalTypeType-methods 2@ swap ( type methods method-keys )
dup 0= if \ No protocols extended to this type; check for a default
@@ -148,12 +148,8 @@ MalType% deftype MalFalse MalFalse new constant mal-false
endif
0= if ( type idx )
2drop
- ." No protocol fn '"
- pxt >name name>string type
- ." ' extended to type '"
- obj mal-type @ type-name type
- ." '" cr
- 1 throw
+ 0 0 s" '" obj mal-type @ type-name s" ' extended to type '"
+ pxt >name name>string s" No protocol fn '" ...throw-str
endif
trace if ." Calling '" pxt >name name>string type ." ' on " obj mal-type @ type-name type cr endif
@@ -449,11 +445,12 @@ MalType%
cell% field MalString/str-len
deftype MalString
-: MalString. { str-addr str-len -- mal-str }
+: MalString.0 { str-addr str-len -- mal-str }
MalString new { str }
str-addr str MalString/str-addr !
str-len str MalString/str-len !
str ;
+' MalString.0 is MalString.
: unpack-str ( mal-string -- addr len )
dup MalString/str-addr @