diff options
| author | Chouser <chouser@n01se.net> | 2015-02-15 17:44:52 -0500 |
|---|---|---|
| committer | Chouser <chouser@n01se.net> | 2015-02-21 13:22:44 -0500 |
| commit | 785786c6033c97a70e78fb6b684d58aea18df4ae (patch) | |
| tree | 705ee89c9b7fd82aee10b70c15e285c38c388f86 /forth/printer.fs | |
| parent | c4403c179e732a50e2b21a01469f0a38ea2d0187 (diff) | |
| download | mal-785786c6033c97a70e78fb6b684d58aea18df4ae.tar.gz mal-785786c6033c97a70e78fb6b684d58aea18df4ae.zip | |
forth: Finish step 4
Diffstat (limited to 'forth/printer.fs')
| -rw-r--r-- | forth/printer.fs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/forth/printer.fs b/forth/printer.fs index 0474944..6152993 100644 --- a/forth/printer.fs +++ b/forth/printer.fs @@ -51,12 +51,12 @@ here constant space-str \ === printer protocol and implementations === / -def-protocol-method pr-buf ( str-addr str-len this -- str-addr str-len ) -def-protocol-method pr-seq-buf ( str-addr str-len this -- str-addr str-len ) -def-protocol-method pr-pairs-buf ( str-addr str-len this -- str-addr str-len ) +def-protocol-method pr-buf ( readably? str-addr str-len this -- str-addr str-len ) +def-protocol-method pr-seq-buf ( readably? str-addr str-len this -- str-addr str-len ) +def-protocol-method pr-pairs-buf ( readably? str-addr str-len this -- str-addr str-len ) : pr-str { obj } - new-str obj pr-buf ; + true new-str obj pr-buf rot drop ; \ Examples of extending existing protocol methods to existing type MalDefault @@ -138,12 +138,7 @@ drop addr len ; -MalString - extend pr-buf - dup MalString/str-addr @ - swap MalString/str-len @ - { addr len } - +: escape-str { addr len } s\" \"" str-append 0 ( i ) begin @@ -169,5 +164,15 @@ MalString 1+ repeat drop addr len str-append - s\" \"" str-append ;; + s\" \"" str-append ; + +MalString + extend pr-buf + dup MalString/str-addr @ + swap MalString/str-len @ + 4 pick if + escape-str + else + str-append + endif ;; drop |
