mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-26 15:14:12 +00:00
Optimization: remove extra function call from macroexpand
This commit is contained in:
parent
dae6c8aed2
commit
304e112f37
@ -358,26 +358,18 @@ class Evaller
|
|||||||
return $ast;
|
return $ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getMacroFn($ast, Env $env): ?Func
|
private function macroexpand($ast, Env $env)
|
||||||
{
|
{
|
||||||
if ($ast instanceof MList) {
|
while ($ast instanceof MList) {
|
||||||
$data = $ast->getData();
|
$data = $ast->getData();
|
||||||
if (count($data) > 0 && $data[0] instanceof Symbol) {
|
if (count($data) > 0 && $data[0] instanceof Symbol) {
|
||||||
$fn = $env->get($data[0]->getName(), false);
|
$fn = $env->get($data[0]->getName(), false);
|
||||||
if ($fn && $fn instanceof Func && $fn->isMacro()) {
|
if ($fn && $fn instanceof Func && $fn->isMacro()) {
|
||||||
return $fn;
|
$ast = $fn->call(array_slice($data, 1));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function macroexpand($ast, Env $env)
|
|
||||||
{
|
|
||||||
while (($fn = $this->getMacroFn($ast, $env))) {
|
|
||||||
// We know ast is a list
|
|
||||||
$ast = $fn->call(array_slice($ast->getData(), 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ast;
|
return $ast;
|
||||||
|
Loading…
Reference in New Issue
Block a user