diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-26 22:50:00 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-26 22:50:00 +0000 |
| commit | 0f4259f445f66ab55d41f2b2139678b8dae15cdd (patch) | |
| tree | 905e73d66115586bd1aecb0e49c380478c76920d /src/main/java | |
| parent | b3efe37e3ee8ed6a7d044051f37faaea70f681fe (diff) | |
Store Patio local info in context
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java index bef80075..b14d7a35 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/PatioToWasm.java @@ -564,7 +564,7 @@ public class PatioToWasm { )); case PatioLocalRef patioLocalRef -> { - var wasmLocalIndex = context.patioLocalNameToWasmLocalIndex.get(patioLocalRef.name()); + var wasmLocalIndex = context.wasmLocalIndex(patioLocalRef); yield context.addInstruction(new WasmLocalGet(wasmLocalIndex)); } }; @@ -794,17 +794,21 @@ public class PatioToWasm { } private static class Context { + private record PatioLocalInfo(WasmLocalIndex wasmLocalIndex) {} + public static Context forFunction( WasmTarget platformTarget, WasmModule module, List<WasmLocal> locals ) { - var patioLocalNameToWasmLocalIndex = P.<String, WasmLocalIndex>map(); + var patioLocalNameToInfo = P.<String, PatioLocalInfo>map(); for (var local : locals) { - patioLocalNameToWasmLocalIndex = patioLocalNameToWasmLocalIndex.plus( + var wasmLocalIndex = new WasmLocalIndex(patioLocalNameToInfo.size()); + var localInfo = new PatioLocalInfo(wasmLocalIndex); + patioLocalNameToInfo = patioLocalNameToInfo.plus( local.name(), - new WasmLocalIndex(patioLocalNameToWasmLocalIndex.size()) + localInfo ); } @@ -813,7 +817,7 @@ public class PatioToWasm { module, P.vector(), P.stack(), - patioLocalNameToWasmLocalIndex, + patioLocalNameToInfo, new NullStructuredInstructionBuilder(), P.stack() ); @@ -823,7 +827,7 @@ public class PatioToWasm { private final WasmModule module; private final PVector<WasmInstruction> instructions; private final PStack<PVector<WasmInstruction>> instructionsStack; - private final PMap<String, WasmLocalIndex> patioLocalNameToWasmLocalIndex; + private final PMap<String, PatioLocalInfo> patioLocalNameToInfo; private final WasmStructuredInstructionBuilder structuredInstructionBuilder; private final PStack<WasmStructuredInstructionBuilder> structuredInstructionBuilderStack; @@ -832,7 +836,7 @@ public class PatioToWasm { WasmModule module, PVector<WasmInstruction> instructions, PStack<PVector<WasmInstruction>> instructionsStack, - PMap<String, WasmLocalIndex> patioLocalNameToWasmLocalIndex, + PMap<String, PatioLocalInfo> patioLocalNameToInfo, WasmStructuredInstructionBuilder structuredInstructionBuilder, PStack<WasmStructuredInstructionBuilder> structuredInstructionBuilderStack ) { @@ -840,7 +844,7 @@ public class PatioToWasm { this.module = module; this.instructions = instructions; this.instructionsStack = instructionsStack; - this.patioLocalNameToWasmLocalIndex = patioLocalNameToWasmLocalIndex; + this.patioLocalNameToInfo = patioLocalNameToInfo; this.structuredInstructionBuilder = structuredInstructionBuilder; this.structuredInstructionBuilderStack = structuredInstructionBuilderStack; } @@ -851,7 +855,7 @@ public class PatioToWasm { this.module.addType(type), this.instructions, this.instructionsStack, - this.patioLocalNameToWasmLocalIndex, + this.patioLocalNameToInfo, this.structuredInstructionBuilder, this.structuredInstructionBuilderStack ); @@ -863,14 +867,14 @@ public class PatioToWasm { this.module, this.instructions.plus(instruction), this.instructionsStack, - this.patioLocalNameToWasmLocalIndex, + this.patioLocalNameToInfo, this.structuredInstructionBuilder, this.structuredInstructionBuilderStack ); } private WasmLocalIndex wasmLocalIndex(PatioLocalRef patioLocalRef) { - return this.patioLocalNameToWasmLocalIndex.get(patioLocalRef.name()); + return this.patioLocalNameToInfo.get(patioLocalRef.name()).wasmLocalIndex; } public Context enterBlockInstruction() { @@ -879,7 +883,7 @@ public class PatioToWasm { this.module, P.vector(), this.instructionsStack.plus(this.instructions), - this.patioLocalNameToWasmLocalIndex, + this.patioLocalNameToInfo, new WasmBlockInstructionBuilder(), this.structuredInstructionBuilderStack.plus(this.structuredInstructionBuilder) ); @@ -900,7 +904,7 @@ public class PatioToWasm { this.module, P.vector(), this.instructionsStack.plus(this.instructions), - this.patioLocalNameToWasmLocalIndex, + this.patioLocalNameToInfo, new WasmLoopInstructionBuilder(), this.structuredInstructionBuilderStack.plus(this.structuredInstructionBuilder) ); @@ -921,7 +925,7 @@ public class PatioToWasm { this.module, P.vector(), this.instructionsStack.plus(this.instructions), - this.patioLocalNameToWasmLocalIndex, + this.patioLocalNameToInfo, new WasmIfInstructionBuilder(blockType), this.structuredInstructionBuilderStack.plus(this.structuredInstructionBuilder) ); @@ -933,7 +937,7 @@ public class PatioToWasm { this.module, P.vector(), this.instructionsStack, - this.patioLocalNameToWasmLocalIndex, + this.patioLocalNameToInfo, this.structuredInstructionBuilder.enterElse(this.instructions), this.structuredInstructionBuilderStack ); @@ -950,7 +954,7 @@ public class PatioToWasm { this.module, P.vector(), this.instructionsStack.plus(this.instructions), - this.patioLocalNameToWasmLocalIndex, + this.patioLocalNameToInfo, new WasmTryInstructionBuilder(blockType), this.structuredInstructionBuilderStack.plus(this.structuredInstructionBuilder) ); @@ -962,7 +966,7 @@ public class PatioToWasm { this.module, P.vector(), this.instructionsStack, - this.patioLocalNameToWasmLocalIndex, + this.patioLocalNameToInfo, this.structuredInstructionBuilder.enterCatch(tagName, this.instructions), this.structuredInstructionBuilderStack ); @@ -979,7 +983,7 @@ public class PatioToWasm { this.module, this.instructionsStack.get(0), this.instructionsStack.minus(0), - this.patioLocalNameToWasmLocalIndex, + this.patioLocalNameToInfo, this.structuredInstructionBuilderStack.get(0), this.structuredInstructionBuilderStack.minus(0) ); |
