2020-05-31 10:50:29 +00:00
|
|
|
<?php
|
|
|
|
namespace MadLisp;
|
|
|
|
|
2020-06-05 08:33:52 +00:00
|
|
|
use Closure;
|
|
|
|
|
2020-05-31 10:50:29 +00:00
|
|
|
class UserFunc extends Func
|
|
|
|
{
|
2020-06-05 08:33:52 +00:00
|
|
|
protected $ast;
|
|
|
|
protected Env $tempEnv;
|
|
|
|
protected array $bindings;
|
|
|
|
|
|
|
|
public function __construct(Closure $closure, $ast, Env $tempEnv, array $bindings)
|
|
|
|
{
|
|
|
|
parent::__construct($closure, null);
|
|
|
|
|
|
|
|
$this->ast = $ast;
|
|
|
|
$this->tempEnv = $tempEnv;
|
|
|
|
$this->bindings = $bindings;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAst()
|
|
|
|
{
|
|
|
|
return $this->ast;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEnv(array $args)
|
|
|
|
{
|
2020-06-06 08:31:09 +00:00
|
|
|
$newEnv = new Env('apply', $this->tempEnv);
|
2020-06-05 08:33:52 +00:00
|
|
|
|
|
|
|
for ($i = 0; $i < count($this->bindings); $i++) {
|
|
|
|
$newEnv->set($this->bindings[$i]->getName(), $args[$i] ?? null);
|
|
|
|
}
|
2020-05-31 10:50:29 +00:00
|
|
|
|
2020-06-05 08:33:52 +00:00
|
|
|
return $newEnv;
|
|
|
|
}
|
2020-05-31 10:50:29 +00:00
|
|
|
}
|