aboutsummaryrefslogtreecommitdiff
path: root/ps/printer.ps
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-14 22:46:54 -0500
committerJoel Martin <github@martintribe.org>2014-04-14 22:46:54 -0500
commit0027e8fed423a24ec93234a6bf0fb701c233d583 (patch)
treec1c447a16958fc174f15af15c181b1582506d9ed /ps/printer.ps
parent8adb082743f12402d0817018ab1e8ff0c0e4729e (diff)
downloadmal-0027e8fed423a24ec93234a6bf0fb701c233d583.tar.gz
mal-0027e8fed423a24ec93234a6bf0fb701c233d583.zip
PS: fix function closures. Self-hosted up to step7.
Diffstat (limited to 'ps/printer.ps')
-rw-r--r--ps/printer.ps37
1 files changed, 29 insertions, 8 deletions
diff --git a/ps/printer.ps b/ps/printer.ps
index 1be0963..de91d80 100644
--- a/ps/printer.ps
+++ b/ps/printer.ps
@@ -5,9 +5,8 @@
% ast print_readably -> _pr_str -> string
/_pr_str { 4 dict begin
/print_readably exch def
- dup
- /func? exch xcheck def % executable function
- /obj exch cvlit def
+ dup xcheck { (Cannot print proc: ) print dup == quit } if % assert
+ /obj exch def
obj _sequential? {
obj _list? { (\() (\)) }{ ([) (]) } ifelse
obj /data get ( ) print_readably _pr_str_args
@@ -19,7 +18,13 @@
( ) print_readably _pr_str_args
concatenate
(}) concatenate
- }{ obj _mal_function? { % if user defined function
+ }{ obj _function? { % if builtin function
+ (<\(builtin_fn* {)
+ obj /data get dup length array copy cvlit
+ ( ) print_readably _pr_str_args
+ (}>)
+ concatenate concatenate
+ }{ obj _mal_function? { % if user defined mal_function
(<\(fn* )
obj /params get print_readably _pr_str
( )
@@ -33,10 +38,10 @@
concatenate concatenate
}{ /arraytype obj type eq { % if list or code block
% accumulate an array of strings
- func? { (<builtin_fn* { ) }{ (\() } ifelse
+ (\()
obj ( ) print_readably _pr_str_args
concatenate
- func? { ( } >) }{ (\)) } ifelse
+ (\))
concatenate
}{ /integertype obj type eq { % if number
/slen obj 10 add log ceiling cvi def
@@ -60,7 +65,7 @@
obj dup length string cvs
}{
(<unknown>)
- } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse
+ } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse
end } def
% array delim print_readably -> _pr_str_args -> new_string
@@ -72,10 +77,26 @@ end } def
args length 0 gt { %if any elements
[
args { %foreach argument in array
- print_readably _pr_str
+ dup xcheck { %if executable
+ 255 string cvs
+ }{
+ print_readably _pr_str
+ } ifelse
} forall
]
{ concatenate delim concatenate } forall
dup length delim length sub 0 exch getinterval % strip off final delim
} if
end } def
+
+% utility function
+/print_dict {
+ (DICT contents:\n) print
+ {
+ ( - ) print
+ exch dup length string cvs print % key
+ (: ) print
+ ==
+ } forall
+} def
+