mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 21:35:03 +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
|
||||
if (!($ast instanceof MList)) {
|
||||
return $this->evalAst($ast, $env);
|
||||
}
|
||||
// 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 Symbol || $ast instanceof Collection) {
|
||||
return $this->evalAst($ast, $env);
|
||||
} else {
|
||||
// This is not evaluated so we can just return it.
|
||||
return $ast;
|
||||
}
|
||||
}
|
||||
|
||||
// Perform macro expansion
|
||||
$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);
|
||||
// Perform macro expansion on first iteration
|
||||
if ($check == 0) {
|
||||
$ast = $this->macroexpand($ast, $env);
|
||||
}
|
||||
}
|
||||
|
||||
$astData = $ast->getData();
|
||||
$astLength = count($astData);
|
||||
|
||||
// Empty list
|
||||
// Empty list, return
|
||||
if ($astLength == 0) {
|
||||
return $ast;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user