-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompile.php
32 lines (25 loc) · 1.03 KB
/
compile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require_once __DIR__ . '/vendor/autoload.php';
use IsaEken\BrickEngine\BrickEngine;
use IsaEken\BrickEngine\Enums\ValueType;
use IsaEken\BrickEngine\Runtime\Context;
use IsaEken\BrickEngine\Value;
$contents = file_get_contents(__DIR__ . '/examples/code.txt');
$engine = new BrickEngine();
$engine->context = new Context(functions: [
'asd' => function (Context $context) use ($engine): Value {
$arguments = array_map(function ($argument) use ($context) {
return $context->value($argument)->data;
}, $context->arguments);
$value = array_reduce($arguments, fn ($a, $b) => $a + $b, 0);
return new Value($context, ValueType::Numeric, $value);
},
'echo' => function (Context $context) use ($engine): Value {
foreach ($context->arguments as $argument) {
print(sprintf("%s\n", $engine->context->value($argument)->data));
}
return new Value($context, ValueType::Void);
},
]);
$engine->context->setVariable('asd', 123);
dd($engine->compile($contents));