Skip to content

Commit d07107b

Browse files
committed
Update module behavior to add a JIT Init and Shutdown step
1 parent 1c8a1e6 commit d07107b

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

composer.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/JIT/Context.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPCfg\Operand;
1313
use PHPCompiler\Runtime;
1414
use PHPCompiler\Block;
15+
use PHPCompiler\Module;
1516
use PHPCompiler\VM\Variable as VMVariable;
1617
use PHPTypes\Type;
1718

@@ -43,6 +44,7 @@ class Context {
4344
private array $stringConstant = [];
4445
private array $builtins;
4546
private array $stringConstantMap = [];
47+
private array $modules = [];
4648

4749
private ?Result $result = null;
4850
public Builtin\MemoryManager $memory;
@@ -117,6 +119,11 @@ public function popScope(): void {
117119
$this->scope = array_pop($this->scopeStack);
118120
}
119121

122+
public function registerModule(Module $module): void {
123+
$this->modules[] = $module;
124+
$module->jitInit($this);
125+
}
126+
120127
public function registerBuiltin(Builtin $builtin): void {
121128
$this->builtins[] = $builtin;
122129
}
@@ -196,6 +203,9 @@ public function compileInPlace() {
196203
}
197204

198205
private function compileCommon() {
206+
foreach ($this->modules as $module) {
207+
$module->jitShutdown($this);
208+
}
199209
foreach ($this->builtins as $builtin) {
200210
$builtin->shutdown();
201211
}

lib/Module.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ public function getFunctions(): array;
1919

2020
public function init(Runtime $runtime): void;
2121

22+
public function jitInit(JIT\Context $context): void;
23+
24+
public function jitShutdown(JIT\Context $context): void;
25+
2226
public function shutdown(): void;
2327
}

lib/ModuleAbstract.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public function shutdown(): void {
3030

3131
}
3232

33+
public function jitInit(JIT\Context $context): void {
34+
35+
}
36+
37+
public function jitShutdown(JIT\Context $context): void {
38+
39+
}
40+
3341
protected function parseAndCompileFunction(string $name, string $filename): Func {
3442
$script = $this->runtime->parse(file_get_contents($filename), $filename);
3543
$func = $this->findFunction($name, $script);

lib/Runtime.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ public function loadJitContext(): JITContext {
107107
if (!is_null($this->debugFile)) {
108108
$this->jitContext->setDebugFile($this->debugFile);
109109
}
110+
foreach ($this->modules as $module) {
111+
$this->jitContext->registerModule($module);
112+
}
110113
}
111114
return $this->jitContext;
112115
}

0 commit comments

Comments
 (0)