From d00493a763a368825f17f2525c3f1c2cb23ad9de Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 13 Dec 2023 21:22:40 +0000 Subject: Add Shid local-drop instruction --- src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java | 6 ++++++ src/main/java/org/shedlang/compiler/shid/ShidSerializer.java | 6 ++++++ .../shedlang/compiler/shid/instructions/ShidInstruction.java | 2 +- .../org/shedlang/compiler/shid/instructions/ShidLocalDrop.java | 10 ++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalDrop.java (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java index a555d181..582d3959 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java @@ -467,6 +467,10 @@ public class PatioCodeGen { context ); + case ShidLocalDrop localDrop -> { + yield context; + } + case ShidLocalLoad localLoad -> { var local = context.shidLocalNameToLocal(localLoad.name()); @@ -989,6 +993,8 @@ public class PatioCodeGen { } case ShidIntSub intSubInstruction -> { } + case ShidLocalDrop localDropInstruction -> { + } case ShidLocalLoad localLoadInstruction -> { } case ShidLocalStore localStoreInstruction -> { diff --git a/src/main/java/org/shedlang/compiler/shid/ShidSerializer.java b/src/main/java/org/shedlang/compiler/shid/ShidSerializer.java index 58f49ed0..bd6971fd 100644 --- a/src/main/java/org/shedlang/compiler/shid/ShidSerializer.java +++ b/src/main/java/org/shedlang/compiler/shid/ShidSerializer.java @@ -155,6 +155,12 @@ public class ShidSerializer { case ShidIntSub intSub -> treeList(treeIdentifier("int-sub")); + case ShidLocalDrop localDrop -> + treeList( + treeIdentifier("local-drop"), + treeString(localDrop.name()) + ); + case ShidLocalLoad localLoadInstruction -> treeList( treeIdentifier("local-load"), diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java index 082c3de5..1c1afc3c 100644 --- a/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; public sealed interface ShidInstruction - permits ShidCall, ShidDefineEffect, ShidDefineFunction, ShidDefineStruct, ShidDiscard, ShidDuplicate, ShedEffectHandlerBreak, ShidFieldLoad, ShidIf, ShidIntAdd, ShidIntEquals, ShidIntNotEqual, ShidIntSub, ShidLocalLoad, ShidLocalStore, ShidLoop, ShidLoopBreak, ShidLoopContinue, ShidNamespaceFieldStore, ShidNamespaceImport, ShidPushBool, ShidPushInt, ShidPushString, ShidPushUnit, ShidResume, ShidReturn, ShidStringAdd, ShidSwitch, ShidTry, ShidTupleCreate, ShidTupleGet, ShidVarLoad, ShidVarStore { + permits ShedEffectHandlerBreak, ShidCall, ShidDefineEffect, ShidDefineFunction, ShidDefineStruct, ShidDiscard, ShidDuplicate, ShidFieldLoad, ShidIf, ShidIntAdd, ShidIntEquals, ShidIntNotEqual, ShidIntSub, ShidLocalDrop, ShidLocalLoad, ShidLocalStore, ShidLoop, ShidLoopBreak, ShidLoopContinue, ShidNamespaceFieldStore, ShidNamespaceImport, ShidPushBool, ShidPushInt, ShidPushString, ShidPushUnit, ShidResume, ShidReturn, ShidStringAdd, ShidSwitch, ShidTry, ShidTupleCreate, ShidTupleGet, ShidVarLoad, ShidVarStore { Source source(); } diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalDrop.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalDrop.java new file mode 100644 index 00000000..582de263 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalDrop.java @@ -0,0 +1,10 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Assert that the local with the given name will not be loaded until a store + * into that local. + */ +public record ShidLocalDrop(String name, Source source) implements ShidInstruction { +} -- cgit v1.2.3