mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-26 15:14:12 +00:00
small optimization for evaller
This commit is contained in:
parent
304e112f37
commit
16f2e615b1
@ -37,23 +37,28 @@ class Evaller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return fast for optimization if not list
|
// Return fast for optimization
|
||||||
|
// Check two times: before and after macro expansion
|
||||||
|
for ($check = 0; $check <= 1; $check++) {
|
||||||
if (!($ast instanceof MList)) {
|
if (!($ast instanceof MList)) {
|
||||||
|
if ($ast instanceof Symbol || $ast instanceof Collection) {
|
||||||
return $this->evalAst($ast, $env);
|
return $this->evalAst($ast, $env);
|
||||||
|
} else {
|
||||||
|
// This is not evaluated so we can just return it.
|
||||||
|
return $ast;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform macro expansion
|
// Perform macro expansion on first iteration
|
||||||
|
if ($check == 0) {
|
||||||
$ast = $this->macroexpand($ast, $env);
|
$ast = $this->macroexpand($ast, $env);
|
||||||
|
}
|
||||||
// After macro expansion we have to check for not-a-list again
|
|
||||||
if (!($ast instanceof MList)) {
|
|
||||||
return $this->evalAst($ast, $env);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$astData = $ast->getData();
|
$astData = $ast->getData();
|
||||||
$astLength = count($astData);
|
$astLength = count($astData);
|
||||||
|
|
||||||
// Empty list
|
// Empty list, return
|
||||||
if ($astLength == 0) {
|
if ($astLength == 0) {
|
||||||
return $ast;
|
return $ast;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user