From 970db3294fef0560d5af3225e80fc5f9b9c0b9f3 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sat, 8 Apr 2023 22:24:49 +0200 Subject: [PATCH] Class FuelCell was a bit silly --- src/cat.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/cat.ts b/src/cat.ts index 2b9feec..20e6346 100644 --- a/src/cat.ts +++ b/src/cat.ts @@ -20,10 +20,6 @@ export type EnvironmentChain> = null | { rib: Environment, ne export type Environment> = { [key: string]: Value }; export type Frame> = Closure & { 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): Token { export class VM> { stack: Value[] = []; rstack: Frame[] = []; - fuel = new FuelCell(); + fuel = 10000; debug = false; static parse(program: string): Token[] { @@ -132,8 +128,8 @@ export class VM> { 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++];