aboutsummaryrefslogtreecommitdiff
path: root/ps/types.ps
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-03-31 23:05:41 -0500
committerJoel Martin <github@martintribe.org>2014-03-31 23:05:41 -0500
commit3da90d39071ddd9a70c6adaf69fbc8f8b99346dd (patch)
treef6f0567ae30fbd54dda6d43e8336f56e35ed828f /ps/types.ps
parent8e7e339db8060f95d27694b93b8d4d648d13c083 (diff)
downloadmal-3da90d39071ddd9a70c6adaf69fbc8f8b99346dd.tar.gz
mal-3da90d39071ddd9a70c6adaf69fbc8f8b99346dd.zip
PS: add step8_macros.
Use dicts rather than array block for user defined mal function type. Add fload function to setup call from a mal_function dict.
Diffstat (limited to 'ps/types.ps')
-rw-r--r--ps/types.ps35
1 files changed, 32 insertions, 3 deletions
diff --git a/ps/types.ps b/ps/types.ps
index a830108..1eb2cf5 100644
--- a/ps/types.ps
+++ b/ps/types.ps
@@ -35,9 +35,16 @@
dup
/func? exch xcheck def % executable function
/obj exch cvlit def
- /arraytype obj type eq { % if list
+ obj _mal_function? { % if user defined function
+ (<\(fn* )
+ obj /params get print_readably _pr_str
+ ( )
+ obj /ast get print_readably _pr_str
+ (\)>)
+ concatenate concatenate concatenate concatenate
+ }{ /arraytype obj type eq { % if list or code block
% accumulate an array of strings
- func? { (<fn* { ) }{ (\() } ifelse
+ func? { (<builtin_fn* { ) }{ (\() } ifelse
obj ( ) print_readably _pr_str_args
concatenate
func? { ( } >) }{ (\)) } ifelse
@@ -61,7 +68,7 @@
obj dup length string cvs
}{
(<unknown>)
- } 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
@@ -120,6 +127,25 @@ end } def
type /nametype eq
} def
+%
+% Functions
+%
+/_mal_function? {
+ dup type /dicttype eq {
+ /type get /_maltype_function eq
+ }{
+ pop false
+ } ifelse
+} def
+
+% args mal_function -> fload -> ast new_env
+% fload: sets up arguments on the stack for an EVAL call
+/fload {
+ dup /ast get 3 1 roll % stack: ast args mal_function
+ dup /env get 3 1 roll % stack: ast env args mal_function
+ /params get exch % stack: ast env params args
+ env_new % stack: ast new_env
+} def
%
% Errors/Exceptions
@@ -274,4 +300,7 @@ end } def
(concat) { dup 0 get exch 1 get _concat }
(empty?) { 0 get length 0 eq }
(count) { 0 get length }
+ (nth) { dup 0 get exch 1 get _nth }
+ (first) { 0 get _first }
+ (rest) { 0 get _rest }
>> def