Class FuelCell was a bit silly

This commit is contained in:
Tony Garnock-Jones 2023-04-08 22:24:49 +02:00
parent 7f5e4a2c73
commit 970db3294f
1 changed files with 3 additions and 7 deletions

View File

@ -20,10 +20,6 @@ export type EnvironmentChain<V extends VM<V>> = null | { rib: Environment<V>, ne
export type Environment<V extends VM<V>> = { [key: string]: Value<V> };
export type Frame<V extends VM<V>> = Closure<V> & { ip: number };
export class FuelCell {
fuel = 10000;
}
export class RuntimeError extends Error {}
export class FuelExhausted extends RuntimeError {}
export class StackUnderflow extends RuntimeError {}
@ -54,7 +50,7 @@ export function asToken(x: PreservesValue<unknown>): Token {
export class VM<Self extends VM<Self>> {
stack: Value<Self>[] = [];
rstack: Frame<Self>[] = [];
fuel = new FuelCell();
fuel = 10000;
debug = false;
static parse(program: string): Token[] {
@ -132,8 +128,8 @@ export class VM<Self extends VM<Self>> {
step(): boolean {
if (!this.popToPending()) return false;
if (this.fuel.fuel <= 0) throw new FuelExhausted("Fuel exhausted");
this.fuel.fuel--;
if (this.fuel <= 0) throw new FuelExhausted("Fuel exhausted");
this.fuel--;
const op = this.frame.code[this.frame.ip++];