1
1
mirror of https://github.com/kanaka/mal.git synced 2024-08-17 09:40:21 +03:00

ps: prevent defmacro! from mutating functions

This commit is contained in:
Nicolas Boulenguez 2021-08-15 20:06:25 +02:00 committed by Joel Martin
parent 1bbf5a027d
commit cd09dfbac5
4 changed files with 22 additions and 15 deletions

View File

@ -160,11 +160,10 @@ end } def
env
/loop? true def % loop
}{ /defmacro! a0 eq { %if defmacro!
/a1 ast 1 _nth def
/a2 ast 2 _nth def
a2 env EVAL
dup /macro? true put % set macro flag
env exch a1 exch env_set % def! it
env
ast 1 _nth
ast 2 _nth env EVAL _macro
env_set
}{ /macroexpand a0 eq { %if defmacro!
ast 1 _nth env macroexpand
}{ /do a0 eq { %if do

View File

@ -160,11 +160,10 @@ end } def
env
/loop? true def % loop
}{ /defmacro! a0 eq { %if defmacro!
/a1 ast 1 _nth def
/a2 ast 2 _nth def
a2 env EVAL
dup /macro? true put % set macro flag
env exch a1 exch env_set % def! it
env
ast 1 _nth
ast 2 _nth env EVAL _macro
env_set
}{ /macroexpand a0 eq { %if defmacro!
ast 1 _nth env macroexpand
}{ /do a0 eq { %if do

View File

@ -160,11 +160,10 @@ end } def
env
/loop? true def % loop
}{ /defmacro! a0 eq { %if defmacro!
/a1 ast 1 _nth def
/a2 ast 2 _nth def
a2 env EVAL
dup /macro? true put % set macro flag
env exch a1 exch env_set % def! it
env
ast 1 _nth
ast 2 _nth env EVAL _macro
env_set
}{ /macroexpand a0 eq { %if defmacro!
ast 1 _nth env macroexpand
}{ /ps* a0 eq { %if ps*

View File

@ -291,6 +291,16 @@ end } def
put % stack: mal_fn
} def
% fn -> _defmacro -> macro
/_macro {
dup /ast get exch
dup /env get exch
/params get
_mal_function
dup
/macro? true put
} def
/_function? {
dup type /dicttype eq {
/_maltype_ get /function eq