aboutsummaryrefslogtreecommitdiff
path: root/forth/printer.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/printer.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/printer.fs')
-rw-r--r--forth/printer.fs50
1 files changed, 1 insertions, 49 deletions
diff --git a/forth/printer.fs b/forth/printer.fs
index 5309745..645e5da 100644
--- a/forth/printer.fs
+++ b/forth/printer.fs
@@ -1,54 +1,6 @@
+require str.fs
require types.fs
-: safe-type ( str-addr str-len -- )
- dup 256 > if
- drop 256 type ." ...<lots more>"
- else
- type
- endif ;
-
-\ === mutable string buffer === /
-\ string buffer that maintains an allocation larger than the current
-\ string size. When appending would cause the string size exceed the
-\ current allocation, resize is used to double the allocation. The
-\ current allocation is not stored anywhere, but computed based on
-\ current string size or str-base-size, whichever is larger.
-64 constant str-base-size
-
-: new-str ( -- addr length )
- str-base-size allocate throw 0 ;
-
-: round-up ( n -- n )
- 2
- begin
- 1 lshift 2dup <
- until
- nip ;
-
-: str-append { buf-addr buf-str-len str-addr str-len }
- buf-str-len str-len +
- { new-len }
- new-len str-base-size >= if
- buf-str-len new-len xor buf-str-len > if
- buf-addr new-len round-up resize throw
- to buf-addr
- endif
- endif
- str-addr buf-addr buf-str-len + str-len cmove
- buf-addr new-len ;
-
-\ define a-space, to append a space char to a string
-bl c,
-here constant space-str
-: a-space space-str 1 str-append ;
-
-: str-append-char ( buf-addr buf-str-len char -- buf-addr buf-str-len )
- pad ! pad 1 str-append ;
-
-: int>str ( num -- str-addr str-len )
- s>d <# #s #> ;
-
-
\ === printer protocol and implementations === /
def-protocol-method pr-buf ( readably? str-addr str-len this -- str-addr str-len )