From 785786c6033c97a70e78fb6b684d58aea18df4ae Mon Sep 17 00:00:00 2001 From: Chouser Date: Sun, 15 Feb 2015 17:44:52 -0500 Subject: forth: Finish step 4 --- forth/printer.fs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'forth/printer.fs') 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 -- cgit v1.2.3