diff options
author | Lizzy Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-11 16:22:06 -0600 |
---|---|---|
committer | Lizzy Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-11 16:22:06 -0600 |
commit | 32879581e53fae5e684c24b44433172d8375d69e (patch) | |
tree | 307551e59409c2f01168e5fabeff200319c18aa7 /src/engine/entities/FunctionApplication.ts | |
parent | 4da17f6dedb4475c7730bdeab9ad3e339f0bfdee (diff) | |
download | the-abstraction-engine-32879581e53fae5e684c24b44433172d8375d69e.tar.gz the-abstraction-engine-32879581e53fae5e684c24b44433172d8375d69e.zip |
support underscores in function application, add sign entity
Diffstat (limited to 'src/engine/entities/FunctionApplication.ts')
-rw-r--r-- | src/engine/entities/FunctionApplication.ts | 16 |
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(); |