mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 21:35:03 +00:00
debugging support for eval
This commit is contained in:
parent
01d429324e
commit
aa71b4da36
@ -5,8 +5,8 @@ function ml_get_lisp(): array
|
|||||||
{
|
{
|
||||||
$tokenizer = new MadLisp\Tokenizer();
|
$tokenizer = new MadLisp\Tokenizer();
|
||||||
$reader = new MadLisp\Reader();
|
$reader = new MadLisp\Reader();
|
||||||
$eval = new MadLisp\Evaller($tokenizer, $reader);
|
|
||||||
$printer = new MadLisp\Printer();
|
$printer = new MadLisp\Printer();
|
||||||
|
$eval = new MadLisp\Evaller($tokenizer, $reader, $printer);
|
||||||
|
|
||||||
$lisp = new MadLisp\Lisp($tokenizer, $reader, $eval, $printer);
|
$lisp = new MadLisp\Lisp($tokenizer, $reader, $eval, $printer);
|
||||||
|
|
||||||
|
@ -5,17 +5,36 @@ class Evaller
|
|||||||
{
|
{
|
||||||
protected Tokenizer $tokenizer;
|
protected Tokenizer $tokenizer;
|
||||||
protected Reader $reader;
|
protected Reader $reader;
|
||||||
|
protected Printer $printer;
|
||||||
|
|
||||||
public function __construct(Tokenizer $tokenizer, Reader $reader)
|
private const DEBUG = true;
|
||||||
|
|
||||||
|
public function __construct(Tokenizer $tokenizer, Reader $reader, Printer $printer)
|
||||||
{
|
{
|
||||||
$this->tokenizer = $tokenizer;
|
$this->tokenizer = $tokenizer;
|
||||||
$this->reader = $reader;
|
$this->reader = $reader;
|
||||||
|
$this->printer = $printer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function eval($ast, Env $env)
|
public function eval($ast, Env $env)
|
||||||
{
|
{
|
||||||
|
if (self::DEBUG) {
|
||||||
|
print("eval: ");
|
||||||
|
$this->printer->print($ast);
|
||||||
|
print("\n");
|
||||||
|
$loops = 0;
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
|
if (self::DEBUG) {
|
||||||
|
if ($loops++ > 0) {
|
||||||
|
print("eval loop: ");
|
||||||
|
$this->printer->print($ast);
|
||||||
|
print("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Not list or empty list
|
// Not list or empty list
|
||||||
if (!($ast instanceof MList)) {
|
if (!($ast instanceof MList)) {
|
||||||
return $this->evalAst($ast, $env);
|
return $this->evalAst($ast, $env);
|
||||||
|
Loading…
Reference in New Issue
Block a user