Skip to content

Commit 5abf8c3

Browse files
committed
improve krivine error handling
1 parent baf681a commit 5abf8c3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/krivine.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ function step()
129129

130130
$fn = [$this, $inst];
131131

132+
if (!is_callable($fn)) {
133+
throw new \RuntimeException("Invalid instruction '$inst'");
134+
}
135+
132136
return $fn($inst_arg, rest($this->code), $this->env, $this->stack);
133137
}
134138

@@ -151,6 +155,9 @@ function push($args, $code, $env, $stack)
151155
function grab($args, $code, $env, $stack)
152156
{
153157
list($code0, $env0) = first($stack);
158+
$code0 = $code0 ?: [['unclosed_term']];
159+
$env0 = $env0 ?: [];
160+
154161
array_unshift($env, [$code0, $env0]);
155162

156163
return new Machine($code, $env, rest($stack));

0 commit comments

Comments
 (0)