madlisp/bootstrap.php

33 lines
716 B
PHP
Raw Normal View History

2020-05-28 04:55:58 +00:00
<?php
require('vendor/autoload.php');
2020-05-30 11:47:54 +00:00
function ml_get_lisp(): array
2020-05-28 04:55:58 +00:00
{
2020-05-30 11:47:54 +00:00
$tokenizer = new MadLisp\Tokenizer();
$reader = new MadLisp\Reader();
$eval = new MadLisp\Evaller();
$printer = new MadLisp\Printer();
$lisp = new MadLisp\Lisp($tokenizer, $reader, $eval, $printer);
// environment
2020-05-28 04:55:58 +00:00
$env = new MadLisp\Env();
(new MadLisp\Lib\Math())->register($env);
2020-05-28 04:55:58 +00:00
/*
2020-05-30 11:47:54 +00:00
$env->set('eval', function (...$args) use ($eval, $env) {
$results = $eval->eval($args, $env);
return $results[count($results) - 1];
});
2020-05-28 10:10:00 +00:00
2020-05-30 12:19:37 +00:00
$env->set('print', function (...$args) use ($printer) {
$printer->print($args);
return null;
});
*/
2020-05-30 12:19:37 +00:00
2020-05-30 11:47:54 +00:00
return [$lisp, $env];
2020-05-28 10:10:00 +00:00
}