2020-06-17 10:24:15 +00:00
|
|
|
<?php
|
|
|
|
namespace MadLisp;
|
|
|
|
|
|
|
|
class LispFactory
|
|
|
|
{
|
2020-06-17 11:31:13 +00:00
|
|
|
public function make(array $coreLibs = [], array $userLibs = []): Lisp
|
2020-06-17 10:24:15 +00:00
|
|
|
{
|
|
|
|
$tokenizer = new Tokenizer();
|
|
|
|
$reader = new Reader();
|
|
|
|
$printer = new Printer();
|
|
|
|
$eval = new Evaller($tokenizer, $reader, $printer);
|
|
|
|
|
|
|
|
// Root environment
|
|
|
|
$env = new Env('root');
|
|
|
|
|
|
|
|
// Register core functions
|
2020-12-05 02:41:27 +00:00
|
|
|
(new Lib\Core($tokenizer, $reader, $printer, $eval))->register($env);
|
2020-10-17 07:47:30 +00:00
|
|
|
|
2020-06-17 10:24:15 +00:00
|
|
|
// Register core libraries
|
|
|
|
(new Lib\Collections())->register($env);
|
|
|
|
(new Lib\Compare())->register($env);
|
2020-06-19 12:09:07 +00:00
|
|
|
(new Lib\Database())->register($env);
|
2020-06-20 03:33:15 +00:00
|
|
|
(new Lib\Http())->register($env);
|
2020-06-17 10:24:15 +00:00
|
|
|
(new Lib\IO())->register($env);
|
2020-06-19 03:50:44 +00:00
|
|
|
(new Lib\Json())->register($env);
|
2020-06-17 10:24:15 +00:00
|
|
|
(new Lib\Math())->register($env);
|
2020-10-18 07:33:27 +00:00
|
|
|
(new Lib\Regex())->register($env);
|
2020-06-17 10:24:15 +00:00
|
|
|
(new Lib\Strings())->register($env);
|
|
|
|
(new Lib\Time())->register($env);
|
|
|
|
(new Lib\Types())->register($env);
|
|
|
|
|
2020-06-17 11:31:13 +00:00
|
|
|
// Register additional libs for root env
|
|
|
|
foreach ($coreLibs as $lib) {
|
2020-06-17 10:24:15 +00:00
|
|
|
$lib->register($env);
|
|
|
|
}
|
|
|
|
|
|
|
|
// User environment
|
|
|
|
$env = new Env('user', $env);
|
|
|
|
|
2020-06-17 11:31:13 +00:00
|
|
|
// Register additional libs for user env
|
|
|
|
foreach ($userLibs as $lib) {
|
|
|
|
$lib->register($env);
|
|
|
|
}
|
|
|
|
|
2020-06-17 10:24:15 +00:00
|
|
|
return new Lisp($tokenizer, $reader, $eval, $printer, $env);
|
|
|
|
}
|
|
|
|
}
|