summaryrefslogtreecommitdiff
path: root/src/engine/entities/FunctionApplication.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/entities/FunctionApplication.ts')
-rw-r--r--src/engine/entities/FunctionApplication.ts16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/engine/entities/FunctionApplication.ts b/src/engine/entities/FunctionApplication.ts
index d907eca..175534c 100644
--- a/src/engine/entities/FunctionApplication.ts
+++ b/src/engine/entities/FunctionApplication.ts
@@ -34,6 +34,10 @@ import {
interpret,
} from "../../interpreter";
+const APPLICATION_RESULTS: Record<string, (gridPosition: Coord2D) => Entity> = {
+ _KEY: (gridPosition: Coord2D) => new Key(gridPosition),
+};
+
export class FunctionApplication extends Entity {
private static spriteSpec = SPRITE_SPECS.get(Sprites.BUBBLE) as SpriteSpec;
@@ -43,7 +47,9 @@ export class FunctionApplication extends Entity {
super(EntityNames.FunctionApplication);
this.symbolTable = new SymbolTable();
- this.symbolTable.add("key");
+ Object.keys(APPLICATION_RESULTS).forEach((key) => {
+ this.symbolTable.add(key);
+ });
const dimension = {
width: FunctionApplication.spriteSpec.width,
@@ -109,9 +115,10 @@ export class FunctionApplication extends Entity {
ComponentNames.LambdaTerm
);
const newCode = applicationTerm.code.replace("_INPUT", functionTerm.code);
+
let result: DebrujinifiedLambdaTerm | null = null;
try {
- result = interpret(newCode, this.symbolTable);
+ result = interpret(newCode, this.symbolTable, true);
} catch (e) {
console.error(e);
fail();
@@ -131,8 +138,9 @@ export class FunctionApplication extends Entity {
applicationResultingEntity = new FunctionBox(grid.gridPosition, code);
} else if ("name" in result) {
const { name } = result;
- if (name === "key") {
- applicationResultingEntity = new Key(grid.gridPosition);
+ const entityFactory = APPLICATION_RESULTS[name];
+ if (entityFactory) {
+ game.addEntity(entityFactory(nextPosition));
}
} else {
fail();