separate coreLibs and userLibs for LispFactory

This commit is contained in:
Pekka Laiho 2020-06-17 18:31:13 +07:00
parent 90a9b3aa53
commit 871df1f691

View File

@ -3,7 +3,7 @@ namespace MadLisp;
class LispFactory class LispFactory
{ {
public function make(array $libraries = []): Lisp public function make(array $coreLibs = [], array $userLibs = []): Lisp
{ {
$tokenizer = new Tokenizer(); $tokenizer = new Tokenizer();
$reader = new Reader(); $reader = new Reader();
@ -50,14 +50,19 @@ class LispFactory
(new Lib\Time())->register($env); (new Lib\Time())->register($env);
(new Lib\Types())->register($env); (new Lib\Types())->register($env);
// Register additional libraries // Register additional libs for root env
foreach ($libraries as $lib) { foreach ($coreLibs as $lib) {
$lib->register($env); $lib->register($env);
} }
// User environment // User environment
$env = new Env('user', $env); $env = new Env('user', $env);
// Register additional libs for user env
foreach ($userLibs as $lib) {
$lib->register($env);
}
return new Lisp($tokenizer, $reader, $eval, $printer, $env); return new Lisp($tokenizer, $reader, $eval, $printer, $env);
} }
} }