diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-02 19:47:35 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-02 19:47:35 +0000 |
| commit | 07d62885c5150fe6eadfa9372a190dd73fd754cc (patch) | |
| tree | 17959fa67c7ab5d375f3966003358afc0715b210 /src | |
| parent | 0ad5be30c1d301942f8cec567d0719fd9ff18f3f (diff) | |
Rename stack IR to Shid
Diffstat (limited to 'src')
121 files changed, 1320 insertions, 1320 deletions
diff --git a/src/main/java/org/shedlang/compiler/ShedCompiler.java b/src/main/java/org/shedlang/compiler/ShedCompiler.java index 325383ae..f07ead28 100644 --- a/src/main/java/org/shedlang/compiler/ShedCompiler.java +++ b/src/main/java/org/shedlang/compiler/ShedCompiler.java @@ -6,8 +6,8 @@ import org.shedlang.compiler.config.ConfigChecker; import org.shedlang.compiler.config.ProjectConfig; import org.shedlang.compiler.parser.Parser; import org.shedlang.compiler.sources.Sources; -import org.shedlang.compiler.stackir.StackCompiler; -import org.shedlang.compiler.stackir.StackIrNamespace; +import org.shedlang.compiler.shid.ShidCodeGen; +import org.shedlang.compiler.shid.ShidNamespace; import org.shedlang.compiler.typechecker.TypeChecker; import org.shedlang.compiler.typechecker.TypeCheckerContext; import org.shedlang.compiler.types.*; @@ -36,7 +36,7 @@ public class ShedCompiler { var untypedNamespaceNodes = parseSource(sourceRoot, sourceFilePaths); - var namespaces = new ArrayList<StackIrNamespace>(); + var namespaces = new ArrayList<ShidNamespace>(); var typeCheckerContext = TypeCheckerContext.EMPTY .addNamespaceTypeInfo( @@ -59,8 +59,8 @@ public class ShedCompiler { var typeCheckNamespaceResult = TypeChecker.typeCheckNamespace(untypedNamespaceNode, typeCheckerContext); typeCheckerContext = typeCheckNamespaceResult.context(); - var stackIrNamespace = StackCompiler.compileNamespace(typeCheckNamespaceResult.value()); - namespaces.add(stackIrNamespace); + var shidNamespace = ShidCodeGen.compileNamespace(typeCheckNamespaceResult.value()); + namespaces.add(shidNamespace); } var typeInfos = typeCheckerContext.toTypeInfos(); diff --git a/src/main/java/org/shedlang/compiler/backends/Backend.java b/src/main/java/org/shedlang/compiler/backends/Backend.java index 42938d34..40a00fbf 100644 --- a/src/main/java/org/shedlang/compiler/backends/Backend.java +++ b/src/main/java/org/shedlang/compiler/backends/Backend.java @@ -1,7 +1,7 @@ package org.shedlang.compiler.backends; import org.shedlang.compiler.config.ProjectConfig; -import org.shedlang.compiler.stackir.StackIrNamespace; +import org.shedlang.compiler.shid.ShidNamespace; import org.shedlang.compiler.typechecker.TypeInfos; import java.io.IOException; @@ -13,7 +13,7 @@ public interface Backend { void compile( ProjectConfig config, - List<StackIrNamespace> namespaces, + List<ShidNamespace> namespaces, TypeInfos typeInfos, Path targetDir ) throws IOException, InterruptedException; diff --git a/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java b/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java index dd33ae89..c2a6ea23 100644 --- a/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java +++ b/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java @@ -1,8 +1,8 @@ package org.shedlang.compiler.backends; import org.shedlang.compiler.config.ProjectConfig; -import org.shedlang.compiler.stackir.InstructionSerializer; -import org.shedlang.compiler.stackir.StackIrNamespace; +import org.shedlang.compiler.shid.InstructionSerializer; +import org.shedlang.compiler.shid.ShidNamespace; import org.shedlang.compiler.typechecker.TypeInfos; import java.nio.file.Path; @@ -11,7 +11,7 @@ import java.util.List; public class GenerateInstructionsBackend implements Backend { public void compile( ProjectConfig config, - List<StackIrNamespace> namespaces, + List<ShidNamespace> namespaces, TypeInfos typeInfos, Path targetDir ) { diff --git a/src/main/java/org/shedlang/compiler/backends/PatioBackend.java b/src/main/java/org/shedlang/compiler/backends/PatioBackend.java index 9e444cee..f9ae1695 100644 --- a/src/main/java/org/shedlang/compiler/backends/PatioBackend.java +++ b/src/main/java/org/shedlang/compiler/backends/PatioBackend.java @@ -4,7 +4,7 @@ import org.shedlang.compiler.config.ProjectConfig; import org.shedlang.compiler.patio.PatioCodeGen; import org.shedlang.compiler.patio.PatioCodeGenContext; import org.shedlang.compiler.patio.ast.PatioSerializer; -import org.shedlang.compiler.stackir.StackIrNamespace; +import org.shedlang.compiler.shid.ShidNamespace; import org.shedlang.compiler.typechecker.TypeInfos; import java.nio.file.Path; @@ -13,7 +13,7 @@ import java.util.List; public class PatioBackend implements Backend { public void compile( ProjectConfig config, - List<StackIrNamespace> namespaces, + List<ShidNamespace> namespaces, TypeInfos typeInfos, Path targetDir ) { diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java index c1575a31..97e1917f 100644 --- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java +++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java @@ -15,7 +15,7 @@ import org.shedlang.compiler.filesystem.ShedCompilerFiles; import org.shedlang.compiler.patio.PatioCodeGen; import org.shedlang.compiler.patio.PatioCodeGenContext; import org.shedlang.compiler.sources.Sources; -import org.shedlang.compiler.stackir.StackIrNamespace; +import org.shedlang.compiler.shid.ShidNamespace; import org.shedlang.compiler.typechecker.TypeInfos; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.util.processes.ProcessError; @@ -42,7 +42,7 @@ public class LlvmBackend implements Backend { @Override public void compile( ProjectConfig config, - List<StackIrNamespace> namespaces, + List<ShidNamespace> namespaces, TypeInfos typeInfos, Path targetDir ) throws IOException, InterruptedException { diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java b/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java index a0074d28..17b5c1ff 100644 --- a/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java +++ b/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java @@ -10,7 +10,7 @@ import org.shedlang.compiler.filesystem.ShedCompilerFiles; import org.shedlang.compiler.patio.PatioCodeGen; import org.shedlang.compiler.patio.PatioCodeGenContext; import org.shedlang.compiler.sources.Sources; -import org.shedlang.compiler.stackir.StackIrNamespace; +import org.shedlang.compiler.shid.ShidNamespace; import org.shedlang.compiler.typechecker.TypeInfos; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.util.processes.ProcessError; @@ -35,7 +35,7 @@ public class WasmBackend implements Backend { @Override public void compile( ProjectConfig config, - List<StackIrNamespace> namespaces, + List<ShidNamespace> namespaces, TypeInfos typeInfos, Path targetDir ) throws IOException, InterruptedException { diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java index e2f1b6ba..b5b3aa0b 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java @@ -13,8 +13,8 @@ import org.shedlang.compiler.patio.ast.types.PatioDataLayouts; import org.shedlang.compiler.patio.ast.types.PatioTypes; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; -import org.shedlang.compiler.stackir.StackIrNamespace; -import org.shedlang.compiler.stackir.instructions.*; +import org.shedlang.compiler.shid.ShidNamespace; +import org.shedlang.compiler.shid.instructions.*; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.util.P; @@ -100,19 +100,19 @@ public class PatioCodeGen { } public static PatioCompilationUnit generateNamespace( - StackIrNamespace stackIrNamespace, + ShidNamespace shidNamespace, PatioCodeGenContext context ) { context = PatioCodeGenNamespaces.define( - stackIrNamespace.namespaceName(), + shidNamespace.namespaceName(), initContext -> { - initContext = declareStackIrLocals( - stackIrNamespace.instructions(), + initContext = declareShidLocals( + shidNamespace.instructions(), FreeVariables.empty(), initContext ); - return generateInstructions(stackIrNamespace.instructions(), initContext); + return generateInstructions(shidNamespace.instructions(), initContext); }, context ); @@ -122,22 +122,22 @@ public class PatioCodeGen { } public static PatioCodeGenContext generateInstructions( - List<Instruction> stackIrInstructions, + List<ShidInstruction> shidInstructions, PatioCodeGenContext context ) { - for (var stackIrInstruction : stackIrInstructions) { - context = generateInstruction(stackIrInstruction, context); + for (var shidInstruction : shidInstructions) { + context = generateInstruction(shidInstruction, context); } return context; } public static PatioCodeGenContext generateInstruction( - Instruction stackIrInstruction, + ShidInstruction shidInstruction, PatioCodeGenContext context ) { - return switch (stackIrInstruction) { - case CallInstruction call -> { + return switch (shidInstruction) { + case ShidCall call -> { var namedArgsByName = new ArrayList<Map.Entry<String, PatioLocalRef>>(); for (var argName : call.namedArgNames().reversed()) { var argResult = context.allocateVal( @@ -150,7 +150,7 @@ public class PatioCodeGen { context = context.temporaryPopIntoLocal( arg, - stackIrInstruction.source() + shidInstruction.source() ); namedArgsByName.add(Map.entry(argName, arg)); @@ -168,7 +168,7 @@ public class PatioCodeGen { context = context.temporaryPopIntoLocal( arg, - stackIrInstruction.source() + shidInstruction.source() ); positionalArgs.add(arg); @@ -184,7 +184,7 @@ public class PatioCodeGen { context = context.temporaryPopIntoLocal( receiver, - stackIrInstruction.source() + shidInstruction.source() ); var targetResult = context.allocateVal( @@ -199,12 +199,12 @@ public class PatioCodeGen { receiver, positionalArgs, namedArgsByName, - stackIrInstruction.source(), + shidInstruction.source(), context ).temporaryPush(target); } - case DefineEffectInstruction defineEffect -> { + case ShidDefineEffect defineEffect -> { var targetResult = context.allocateVal( PatioCodeGenLocalSpace.USER_DEFINED_EFFECT, defineEffect.effect().name(), @@ -225,7 +225,7 @@ public class PatioCodeGen { yield context; } - case DefineFunctionInstruction defineFunction -> { + case ShidDefineFunction defineFunction -> { var targetResult = context.allocateVal( PatioCodeGenLocalSpace.CLOSURE, defineFunction.name(), @@ -243,7 +243,7 @@ public class PatioCodeGen { functionContext -> { // TODO: explicitly store locals on a function? - functionContext = declareStackIrLocals( + functionContext = declareShidLocals( defineFunction.body(), defineFunction.freeVariables(), functionContext @@ -260,7 +260,7 @@ public class PatioCodeGen { yield context; } - case DefineStructInstruction defineStruct -> { + case ShidDefineStruct defineStruct -> { var targetResult = context.allocateVal( PatioCodeGenLocalSpace.STRUCT_TYPE, defineStruct.type().name(), @@ -282,10 +282,10 @@ public class PatioCodeGen { yield context; } - case DiscardInstruction discard -> + case ShidDiscard discard -> context.temporaryPop().context(); - case DuplicateInstruction duplicate -> { + case ShidDuplicate duplicate -> { var valueResult = context.temporaryPop(); var value = valueResult.value(); context = valueResult.context(); @@ -293,7 +293,7 @@ public class PatioCodeGen { yield context.temporaryPush(value).temporaryPush(value); } - case FieldLoadInstruction fieldLoad -> { + case ShidFieldLoad fieldLoad -> { var receiverResult = context.temporaryPop(); var receiver = receiverResult.value(); context = receiverResult.context(); @@ -307,7 +307,7 @@ public class PatioCodeGen { context = targetResult.context(); switch (fieldLoad.receiver()) { - case FieldLoadInstruction.Receiver.Effect receiverEffect -> { + case ShidFieldLoad.Receiver.Effect receiverEffect -> { context = PatioCodeGenEffects.fieldLoad( target, receiver, @@ -318,7 +318,7 @@ public class PatioCodeGen { ); } - case FieldLoadInstruction.Receiver.Namespace receiverNamespace -> { + case ShidFieldLoad.Receiver.Namespace receiverNamespace -> { context = PatioCodeGenNamespaces.fieldLoad( target, receiver, @@ -329,7 +329,7 @@ public class PatioCodeGen { ); } - case FieldLoadInstruction.Receiver.Struct receiverStruct -> { + case ShidFieldLoad.Receiver.Struct receiverStruct -> { context = PatioCodeGenStructs.fieldLoad( target, receiver, @@ -346,7 +346,7 @@ public class PatioCodeGen { yield context; } - case IfInstruction if_ -> { + case ShidIf if_ -> { var conditionBoolResult = generateCondition(if_.source(), context); var conditionBool = conditionBoolResult.value(); context = conditionBoolResult.context(); @@ -387,7 +387,7 @@ public class PatioCodeGen { yield context; } - case IntAddInstruction intAdd -> + case ShidIntAdd intAdd -> generateBinaryOperation( (target, left, right, operationContext) -> operationContext.addInstruction(new PatioIntAdd( @@ -399,7 +399,7 @@ public class PatioCodeGen { context ); - case IntEqualsInstruction intEquals -> + case ShidIntEquals intEquals -> generateComparison( (target, left, right, operationContext) -> operationContext.addInstruction(new PatioIntEquals( @@ -412,7 +412,7 @@ public class PatioCodeGen { context ); - case IntNotEqualInstruction intNotEqual -> + case ShidIntNotEqual intNotEqual -> generateComparison( (target, left, right, operationContext) -> operationContext.addInstruction(new PatioIntNotEqual( @@ -425,7 +425,7 @@ public class PatioCodeGen { context ); - case IntSubInstruction intSub -> + case ShidIntSub intSub -> generateBinaryOperation( (target, left, right, operationContext) -> operationContext.addInstruction(new PatioIntSub( @@ -437,30 +437,30 @@ public class PatioCodeGen { context ); - case LocalLoadInstruction localLoad -> { - var local = context.stackIrLocalNameToLocal(localLoad.name()); + case ShidLocalLoad localLoad -> { + var local = context.shidLocalNameToLocal(localLoad.name()); yield context.temporaryPush(local); } - case LocalStoreInstruction localStore -> { + case ShidLocalStore localStore -> { context = context.temporaryPopIntoLocal( - context.stackIrLocalNameToLocal(localStore.name()), + context.shidLocalNameToLocal(localStore.name()), localStore.source() ); - context = context.initStackIrLocal(localStore.name()); + context = context.initShidLocal(localStore.name()); yield context; } - case LoopBreakInstruction loopBreak -> + case ShidLoopBreak loopBreak -> context.addInstruction(new PatioLoopBreak(loopBreak.source())); - case LoopContinueInstruction loopContinue -> + case ShidLoopContinue loopContinue -> context.addInstruction(new PatioLoopContinue(loopContinue.source())); - case LoopInstruction loop -> { + case ShidLoop loop -> { context = context.enterBlock(); context = generateInstructions(loop.body(), context); @@ -473,7 +473,7 @@ public class PatioCodeGen { yield context; } - case NamespaceFieldStoreInstruction namespaceFieldStore -> { + case ShidNamespaceFieldStore namespaceFieldStore -> { var fieldValueResult = context.temporaryPop(); var fieldValue = fieldValueResult.value(); context = fieldValueResult.context(); @@ -489,7 +489,7 @@ public class PatioCodeGen { yield context; } - case NamespaceImportInstruction namespaceImport -> { + case ShidNamespaceImport namespaceImport -> { var namespaceValueResult = context.allocateVal( PatioCodeGenLocalSpace.NAMESPACE_VALUE, PatioCodeGenNamespaces.NAMESPACE_VALUE_TYPE @@ -509,13 +509,13 @@ public class PatioCodeGen { yield context; } - case PushBoolInstruction pushBool -> + case ShidPushBool pushBool -> pushValue(pushBool.value() ? 1 : 0, pushBool.source(), context); - case PushIntInstruction pushInt -> + case ShidPushInt pushInt -> pushValue(pushInt.value().intValueExact(), pushInt.source(), context); - case PushStringInstruction pushString -> { + case ShidPushString pushString -> { var stringPtrOperandResult = PatioCodeGenStrings.define( pushString.value(), pushString.source(), @@ -542,10 +542,10 @@ public class PatioCodeGen { yield context; } - case PushUnitInstruction pushUnit -> + case ShidPushUnit pushUnit -> pushValue(0, pushUnit.source(), context); - case ResumeInstruction resume -> { + case ShidResume resume -> { var valueResult = context.temporaryPop(); var value = valueResult.value(); context = valueResult.context(); @@ -553,7 +553,7 @@ public class PatioCodeGen { yield context.addInstruction(new PatioResume(value, resume.source())); } - case ReturnInstruction return_ -> { + case ShidReturn return_ -> { var valueResult = context.temporaryPop(); var value = valueResult.value(); context = valueResult.context(); @@ -561,7 +561,7 @@ public class PatioCodeGen { yield context.addInstruction(new PatioReturn(value, return_.source())); } - case StringAddInstruction stringAdd -> + case ShidStringAdd stringAdd -> generateBinaryOperation( (target, left, right, operationContext) -> PatioCodeGenStrings.add( @@ -574,7 +574,7 @@ public class PatioCodeGen { context ); - case SwitchInstruction switch_ -> { + case ShidSwitch switch_ -> { var targetResult = context.allocateVal( PatioCodeGenLocalSpace.TEMPORARY, PatioCodeGenTypes.VALUE_TYPE @@ -602,20 +602,20 @@ public class PatioCodeGen { var cases = new ArrayList<PatioSwitch.Case>(); - for (var stackIrCase : switch_.cases()) { + for (var shidCase : switch_.cases()) { var bodyResult = generateBlock( 1, - stackIrCase.body(), - stackIrCase.source(), + shidCase.body(), + shidCase.source(), context ); var body = bodyResult.value(); context = bodyResult.context(); cases.add(new PatioSwitch.Case( - context.structTag(stackIrCase.caseType()), + context.structTag(shidCase.caseType()), body, - stackIrCase.source() + shidCase.source() )); } @@ -638,7 +638,7 @@ public class PatioCodeGen { yield context; } - case TryInstruction try_ -> { + case ShidTry try_ -> { var handlerMethodsByName = new HashMap<String, PatioOperand>(); for (var handlerMethodName : try_.handlerMethodNames().reversed()) { @@ -661,7 +661,7 @@ public class PatioCodeGen { yield context; } - case TupleCreateInstruction tupleCreate -> { + case ShidTupleCreate tupleCreate -> { var elements = new ArrayList<PatioOperand>(); for (var elementIndex = tupleCreate.elementCount(); elementIndex --> 0;) { @@ -687,7 +687,7 @@ public class PatioCodeGen { yield context.temporaryPush(tuple); } - case TupleGetInstruction tupleGet -> { + case ShidTupleGet tupleGet -> { var tupleResult = context.temporaryPop(); var tuple = tupleResult.value(); context = tupleResult.context(); @@ -705,7 +705,7 @@ public class PatioCodeGen { yield context.temporaryPush(target); } - case VarLoadInstruction varLoad -> { + case ShidVarLoad varLoad -> { var varValueResult = context.allocateVal( PatioCodeGenLocalSpace.VAR_VALUE, varLoad.name(), @@ -716,7 +716,7 @@ public class PatioCodeGen { context = context.addInstruction(new PatioMemoryLoad( varValue, - context.stackIrLocalNameToLocal(varLoad.name()), + context.shidLocalNameToLocal(varLoad.name()), PatioDataLayouts.fromType(PatioCodeGenTypes.VALUE_TYPE), List.of(), varLoad.source() @@ -727,13 +727,13 @@ public class PatioCodeGen { yield context; } - case VarStoreInstruction varStore -> { + case ShidVarStore varStore -> { var valueResult = context.temporaryPop(); var value = valueResult.value(); context = valueResult.context(); context = context.addInstruction(new PatioMemoryStore( - context.stackIrLocalNameToLocal(varStore.name()), + context.shidLocalNameToLocal(varStore.name()), PatioDataLayouts.fromType(PatioCodeGenTypes.VALUE_TYPE), List.of(), value, @@ -816,12 +816,12 @@ public class PatioCodeGen { private static PatioCodeGenResult<PatioBlock> generateBlock( int resultCount, - List<Instruction> stackIrInstructions, + List<ShidInstruction> shidInstructions, Source source, PatioCodeGenContext context ) { context = context.enterBlock(); - context = generateInstructions(stackIrInstructions, context); + context = generateInstructions(shidInstructions, context); var targets = new ArrayList<PatioOperand>(); for (var i = 0; i < resultCount; i++) { @@ -875,8 +875,8 @@ public class PatioCodeGen { return context.toResult(conditionBool); } - private static PatioCodeGenContext declareStackIrLocals( - List<Instruction> body, + private static PatioCodeGenContext declareShidLocals( + List<ShidInstruction> body, FreeVariables freeVariables, PatioCodeGenContext context ) { @@ -890,7 +890,7 @@ public class PatioCodeGen { if (freeVariableNames.contains(boundVariable.name())) { // This is a terrible hack. Another reason to collect variables up-front. } else if (boundVariable.isMutable()) { - var patioLocalResult = context.declareStackIrVal( + var patioLocalResult = context.declareShidVal( boundVariable.name(), PatioTypes.DATA_POINTER ); @@ -904,9 +904,9 @@ public class PatioCodeGen { Sources.NULL )); - context = context.initStackIrLocal(boundVariable.name()); + context = context.initShidLocal(boundVariable.name()); } else { - context = context.declareStackIrVal( + context = context.declareShidVal( boundVariable.name(), PatioCodeGenTypes.VALUE_TYPE ).context(); @@ -916,82 +916,82 @@ public class PatioCodeGen { } private static OrderedPSet<BoundVariable> findAssignedVariables( - List<Instruction> body, + List<ShidInstruction> body, OrderedPSet<BoundVariable> boundVariables ) { for (var bodyInstruction : body) { switch (bodyInstruction) { - case CallInstruction callInstruction -> { + case ShidCall callInstruction -> { } - case DefineEffectInstruction defineEffectInstruction -> { + case ShidDefineEffect defineEffectInstruction -> { } - case DefineFunctionInstruction defineFunctionInstruction -> { + case ShidDefineFunction defineFunctionInstruction -> { } - case DefineStructInstruction defineStructInstruction -> { + case ShidDefineStruct defineStructInstruction -> { } - case DiscardInstruction discardInstruction -> { + case ShidDiscard discardInstruction -> { } - case DuplicateInstruction duplicateInstruction -> { + case ShidDuplicate duplicateInstruction -> { } - case FieldLoadInstruction fieldLoadInstruction -> { + case ShidFieldLoad fieldLoadInstruction -> { } - case IfInstruction ifInstruction -> { + case ShidIf ifInstruction -> { boundVariables = findAssignedVariables(ifInstruction.trueBody(), boundVariables); boundVariables = findAssignedVariables(ifInstruction.falseBody(), boundVariables); } - case IntAddInstruction intAddInstruction -> { + case ShidIntAdd intAddInstruction -> { } - case IntEqualsInstruction intEqualsInstruction -> { + case ShidIntEquals intEqualsInstruction -> { } - case IntNotEqualInstruction intNotEqualInstruction -> { + case ShidIntNotEqual intNotEqualInstruction -> { } - case IntSubInstruction intSubInstruction -> { + case ShidIntSub intSubInstruction -> { } - case LocalLoadInstruction localLoadInstruction -> { + case ShidLocalLoad localLoadInstruction -> { } - case LocalStoreInstruction localStoreInstruction -> { + case ShidLocalStore localStoreInstruction -> { boundVariables = boundVariables.plus(BoundVariable.immutable(localStoreInstruction.name())); } - case LoopBreakInstruction loopBreakInstruction -> { + case ShidLoopBreak loopBreakInstruction -> { } - case LoopContinueInstruction loopContinueInstruction -> { + case ShidLoopContinue loopContinueInstruction -> { } - case LoopInstruction loopInstruction -> { + case ShidLoop loopInstruction -> { boundVariables = findAssignedVariables(loopInstruction.body(), boundVariables); } - case NamespaceFieldStoreInstruction namespaceFieldStoreInstruction -> { + case ShidNamespaceFieldStore namespaceFieldStoreInstruction -> { } - case NamespaceImportInstruction namespaceImportInstruction -> { + case ShidNamespaceImport namespaceImportInstruction -> { } - case PushBoolInstruction pushBoolInstruction -> { + case ShidPushBool pushBoolInstruction -> { } - case PushIntInstruction pushIntInstruction -> { + case ShidPushInt pushIntInstruction -> { } - case PushStringInstruction pushStringInstruction -> { + case ShidPushString pushStringInstruction -> { } - case PushUnitInstruction pushUnitInstruction -> { + case ShidPushUnit pushUnitInstruction -> { } - case ResumeInstruction resumeInstruction -> { + case ShidResume resumeInstruction -> { } - case ReturnInstruction returnInstruction -> { + case ShidReturn returnInstruction -> { } - case StringAddInstruction stringAddInstruction -> { + case ShidStringAdd stringAddInstruction -> { } - case SwitchInstruction switchInstruction -> { + case ShidSwitch switchInstruction -> { for (var switchCase : switchInstruction.cases()) { boundVariables = findAssignedVariables(switchCase.body(), boundVariables); } } - case TryInstruction tryInstruction -> { + case ShidTry tryInstruction -> { boundVariables = findAssignedVariables(tryInstruction.body(), boundVariables); } - case TupleCreateInstruction tupleCreateInstruction -> { + case ShidTupleCreate tupleCreateInstruction -> { } - case TupleGetInstruction tupleGetInstruction -> { + case ShidTupleGet tupleGetInstruction -> { } - case VarLoadInstruction varLoadInstruction -> { + case ShidVarLoad varLoadInstruction -> { } - case VarStoreInstruction varStoreInstruction -> { + case ShidVarStore varStoreInstruction -> { boundVariables = boundVariables.plus(BoundVariable.mutable(varStoreInstruction.name())); } } diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java index 961eeef0..abc89e10 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java @@ -9,7 +9,7 @@ import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; import org.shedlang.compiler.patio.ast.operands.PatioOperand; import org.shedlang.compiler.patio.ast.types.*; import org.shedlang.compiler.sources.Source; -import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; +import org.shedlang.compiler.shid.instructions.ShidDefineFunction; import java.util.ArrayList; import java.util.List; @@ -53,7 +53,7 @@ class PatioCodeGenClosures { FreeVariable freeVariable, PatioCodeGenContext context ) { - var local = context.stackIrLocalNameToLocal(freeVariable.name()); + var local = context.shidLocalNameToLocal(freeVariable.name()); return context.localType(local); } @@ -64,8 +64,8 @@ class PatioCodeGenClosures { public static PatioCodeGenContext create( PatioLocalRef target, String name, - List<DefineFunctionInstruction.Param> positionalParams, - List<DefineFunctionInstruction.Param> namedParams, + List<ShidDefineFunction.Param> positionalParams, + List<ShidDefineFunction.Param> namedParams, FreeVariables freeVariables, Function<PatioCodeGenContext, PatioCodeGenContext> generateBody, Source source, @@ -90,14 +90,14 @@ class PatioCodeGenClosures { bodyContext = closurePointerResult.context(); var orderedNamedParams = sortedBy(namedParams, param -> param.name()); - var stackIrParams = Stream.concat(positionalParams.stream(), orderedNamedParams.stream()).toList(); + var shidParams = Stream.concat(positionalParams.stream(), orderedNamedParams.stream()).toList(); - for (var stackIrParam : stackIrParams) { - bodyContext = bodyContext.defineStackIrParam(stackIrParam.name()); + for (var shidParam : shidParams) { + bodyContext = bodyContext.defineShidParam(shidParam.name()); } for (var freeVariable : freeVariables) { - var freeVariableLocalResult = bodyContext.declareStackIrVal( + var freeVariableLocalResult = bodyContext.declareShidVal( freeVariable.name(), freeVariableType(freeVariable, bodyContextParent) ); @@ -112,7 +112,7 @@ class PatioCodeGenClosures { source )); - bodyContext = bodyContext.initStackIrLocal(freeVariable.name()); + bodyContext = bodyContext.initShidLocal(freeVariable.name()); } bodyContext = generateBody.apply(bodyContext); @@ -145,13 +145,13 @@ class PatioCodeGenClosures { )); for (var freeVariable : freeVariables) { - context = context.onceStackIrLocalDefined( + context = context.onceShidLocalDefined( freeVariable.name(), c -> c.addInstruction(new PatioMemoryStore( closurePointer, layout, freeVariableOffset(freeVariable), - c.stackIrLocalNameToLocal(freeVariable.name()), + c.shidLocalNameToLocal(freeVariable.name()), source )) ); diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java index cfb075c3..545a198f 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java @@ -184,8 +184,8 @@ public record PatioCodeGenContext( PStack<PatioLocalRef> temporaryStack, PVector<PatioInstruction> instructions, OrderedPMap<String, PatioLocal> localsByName, - PMap<String, PatioLocalRef> stackIrNameToLocal, - PMap<String, PVector<Function<PatioCodeGenContext, PatioCodeGenContext>>> waitingForStackIrLocal + PMap<String, PatioLocalRef> shidNameToLocal, + PMap<String, PVector<Function<PatioCodeGenContext, PatioCodeGenContext>>> waitingForShidLocal ) { public static final FunctionContext EMPTY = new FunctionContext( P.stack(), @@ -201,8 +201,8 @@ public record PatioCodeGenContext( this.temporaryStack.minus(0), this.instructions, this.localsByName, - this.stackIrNameToLocal, - this.waitingForStackIrLocal + this.shidNameToLocal, + this.waitingForShidLocal ).toResult(this.temporaryStack.get(0)); } @@ -212,8 +212,8 @@ public record PatioCodeGenContext( this.temporaryStack.plus(value), this.instructions, this.localsByName, - this.stackIrNameToLocal, - this.waitingForStackIrLocal + this.shidNameToLocal, + this.waitingForShidLocal ); } @@ -223,8 +223,8 @@ public record PatioCodeGenContext( this.temporaryStack, this.instructions.plus(instruction), this.localsByName, - this.stackIrNameToLocal, - this.waitingForStackIrLocal + this.shidNameToLocal, + this.waitingForShidLocal ); } @@ -244,22 +244,22 @@ public record PatioCodeGenContext( this.temporaryStack, this.instructions, this.localsByName.plus(fullName, createLocal.apply(fullName)), - this.stackIrNameToLocal, - this.waitingForStackIrLocal + this.shidNameToLocal, + this.waitingForShidLocal ).toResult(new PatioLocalRef(fullName)); } @CheckReturnValue - public FunctionContext.Result<PatioLocalRef> declareStackIrLocal( + public FunctionContext.Result<PatioLocalRef> declareShidLocal( String name, PatioType type, PatioLocalType localType ) { var context = this; - if (this.stackIrNameToLocal.containsKey(name)) { + if (this.shidNameToLocal.containsKey(name)) { // TODO: better error - throw new RuntimeException("Stack IR local already exists: " + name); + throw new RuntimeException("Shid local already exists: " + name); } var fullName = NameAllocator.allocateFixedName( @@ -278,48 +278,48 @@ public record PatioCodeGenContext( new PatioLocal(fullName, type, localType) ), // TODO: the mapping is redundant given we fix the mapping - this.stackIrNameToLocal.plus(name, localRef), - this.waitingForStackIrLocal.plus(name, P.vector()) + this.shidNameToLocal.plus(name, localRef), + this.waitingForShidLocal.plus(name, P.vector()) ); return context.toResult(localRef); } @CheckReturnValue - public FunctionContext.Result<PVector<Function<PatioCodeGenContext, PatioCodeGenContext>>> initStackIrLocal(String name) { + public FunctionContext.Result<PVector<Function<PatioCodeGenContext, PatioCodeGenContext>>> initShidLocal(String name) { var context = new FunctionContext( this.temporaryStack, this.instructions, this.localsByName, - this.stackIrNameToLocal, - this.waitingForStackIrLocal.minus(name) + this.shidNameToLocal, + this.waitingForShidLocal.minus(name) ); - return context.toResult(this.waitingForStackIrLocal.getOrDefault(name, P.vector())); + return context.toResult(this.waitingForShidLocal.getOrDefault(name, P.vector())); } @CheckReturnValue - public PatioLocalRef stackIrLocalNameToLocal(String name) { - var local = this.stackIrNameToLocal.get(name); + public PatioLocalRef shidLocalNameToLocal(String name) { + var local = this.shidNameToLocal.get(name); if (local == null) { // TODO: better error - throw new RuntimeException("Unknown stack IR local: " + name); + throw new RuntimeException("Unknown Shid local: " + name); } return local; } @CheckReturnValue - public Optional<PatioLocalRef> stackIrLocalNameToLocalOrNone(String name) { - var local = this.stackIrNameToLocal.get(name); + public Optional<PatioLocalRef> shidLocalNameToLocalOrNone(String name) { + var local = this.shidNameToLocal.get(name); return Optional.ofNullable(local); } @CheckReturnValue - public boolean isStackIrLocalDefined(String name) { - return !this.waitingForStackIrLocal.containsKey(name); + public boolean isShidLocalDefined(String name) { + return !this.waitingForShidLocal.containsKey(name); } @CheckReturnValue @@ -329,7 +329,7 @@ public record PatioCodeGenContext( } @CheckReturnValue - public FunctionContext addWaitingForShedLocal( + public FunctionContext addWaitingForShidLocal( String name, Function<PatioCodeGenContext, PatioCodeGenContext> func ) { @@ -337,10 +337,10 @@ public record PatioCodeGenContext( this.temporaryStack, this.instructions, this.localsByName, - this.stackIrNameToLocal, - this.waitingForStackIrLocal.plus( + this.shidNameToLocal, + this.waitingForShidLocal.plus( name, - this.waitingForStackIrLocal.getOrDefault(name, P.vector()).plus(func) + this.waitingForShidLocal.getOrDefault(name, P.vector()).plus(func) ) ); } @@ -514,13 +514,13 @@ public record PatioCodeGenContext( } @CheckReturnValue - public PatioCodeGenContext defineStackIrParam(String name) { - return declareStackIrParam(name).initStackIrLocal(name); + public PatioCodeGenContext defineShidParam(String name) { + return declareShidParam(name).initShidLocal(name); } @CheckReturnValue - private PatioCodeGenContext declareStackIrParam(String name) { - return declareStackIrLocal( + private PatioCodeGenContext declareShidParam(String name) { + return declareShidLocal( name, PatioCodeGenTypes.VALUE_TYPE, PatioLocalType.PARAM @@ -528,8 +528,8 @@ public record PatioCodeGenContext( } @CheckReturnValue - public PatioCodeGenResult<PatioLocalRef> declareStackIrVal(String name, PatioType type) { - return declareStackIrLocal( + public PatioCodeGenResult<PatioLocalRef> declareShidVal(String name, PatioType type) { + return declareShidLocal( name, type, PatioLocalType.VAL @@ -537,12 +537,12 @@ public record PatioCodeGenContext( } @CheckReturnValue - public PatioCodeGenResult<PatioLocalRef> declareStackIrLocal( + public PatioCodeGenResult<PatioLocalRef> declareShidLocal( String name, PatioType type, PatioLocalType patioLocalType ) { - return withFunctionContextResult(this.functionContext.declareStackIrLocal( + return withFunctionContextResult(this.functionContext.declareShidLocal( name, type, patioLocalType @@ -550,8 +550,8 @@ public record PatioCodeGenContext( } @CheckReturnValue - public PatioCodeGenContext initStackIrLocal(String name) { - var result = this.functionContext.initStackIrLocal(name); + public PatioCodeGenContext initShidLocal(String name) { + var result = this.functionContext.initShidLocal(name); var context = withFunctionContext(result.context); for (var func : result.value) { @@ -562,18 +562,18 @@ public record PatioCodeGenContext( } @CheckReturnValue - public PatioCodeGenContext onceStackIrLocalDefined( + public PatioCodeGenContext onceShidLocalDefined( String name, Function<PatioCodeGenContext, PatioCodeGenContext> func ) { - var local = this.functionContext.stackIrLocalNameToLocalOrNone(name); + var local = this.functionContext.shidLocalNameToLocalOrNone(name); if (local.isEmpty()) { // TODO: better error - throw new RuntimeException("Unknown stack IR local: " + name); - } else if (!this.functionContext.isStackIrLocalDefined(name)) { + throw new RuntimeException("Unknown Shid local: " + name); + } else if (!this.functionContext.isShidLocalDefined(name)) { return withFunctionContext( - this.functionContext.addWaitingForShedLocal(name, func) + this.functionContext.addWaitingForShidLocal(name, func) ); } else { return func.apply(this); @@ -581,8 +581,8 @@ public record PatioCodeGenContext( } @CheckReturnValue - public PatioLocalRef stackIrLocalNameToLocal(String name) { - return this.functionContext.stackIrLocalNameToLocal(name); + public PatioLocalRef shidLocalNameToLocal(String name) { + return this.functionContext.shidLocalNameToLocal(name); } @CheckReturnValue @@ -634,8 +634,8 @@ public record PatioCodeGenContext( P.stack(), P.vector(), this.functionContext.localsByName, - this.functionContext.stackIrNameToLocal, - this.functionContext.waitingForStackIrLocal + this.functionContext.shidNameToLocal, + this.functionContext.waitingForShidLocal ) ); } @@ -654,8 +654,8 @@ public record PatioCodeGenContext( this.blockStack.get(0).temporaryStack, this.blockStack.get(0).instructions, this.functionContext.localsByName, - this.functionContext.stackIrNameToLocal, - this.functionContext.waitingForStackIrLocal + this.functionContext.shidNameToLocal, + this.functionContext.waitingForShidLocal ) ).toResult(this.functionContext.instructions); } diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java index 4eb842b2..5f32e90e 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java @@ -13,7 +13,7 @@ import org.shedlang.compiler.patio.ast.types.PatioType; import org.shedlang.compiler.patio.ast.types.PatioTypes; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.sources.Sources; -import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; +import org.shedlang.compiler.shid.instructions.ShidDefineFunction; import org.shedlang.compiler.types.UserDefinedEffect; import org.shedlang.compiler.util.Lists; @@ -104,7 +104,7 @@ public class PatioCodeGenEffects { var positionalParams = IntStream.range(0, method.type().positionalParams().size()) // TODO: ensure names of positional params doesn't clash with named params - .mapToObj(paramIndex -> new DefineFunctionInstruction.Param("arg" + paramIndex, source)) + .mapToObj(paramIndex -> new ShidDefineFunction.Param("arg" + paramIndex, source)) .toList(); context = PatioCodeGenClosures.create( @@ -112,7 +112,7 @@ public class PatioCodeGenEffects { method.name(), positionalParams, method.type().namedParams().stream() - .map(namedParam -> new DefineFunctionInstruction.Param(namedParam.name(), source)) + .map(namedParam -> new ShidDefineFunction.Param(namedParam.name(), source)) .toList(), FreeVariables.empty(), bodyContext -> { @@ -147,12 +147,12 @@ public class PatioCodeGenEffects { returnValue, handlerMethod, positionalParams.stream() - .map(param -> bodyContextArgs.stackIrLocalNameToLocal(param.name())) + .map(param -> bodyContextArgs.shidLocalNameToLocal(param.name())) .toList(), method.type().namedParams().stream() .map(param -> Map.entry( param.name(), - bodyContextArgs.stackIrLocalNameToLocal(param.name()) + bodyContextArgs.shidLocalNameToLocal(param.name()) )) .toList(), source, diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java index 92081325..6ef49080 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java @@ -8,8 +8,8 @@ import org.shedlang.compiler.patio.ast.types.PatioDataLayout; import org.shedlang.compiler.patio.ast.types.PatioDataLayouts; import org.shedlang.compiler.patio.ast.types.PatioTypes; import org.shedlang.compiler.sources.Source; -import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; -import org.shedlang.compiler.stackir.instructions.DefineStructInstruction; +import org.shedlang.compiler.shid.instructions.ShidDefineFunction; +import org.shedlang.compiler.shid.instructions.ShidDefineStruct; import org.shedlang.compiler.types.StructType; import org.shedlang.compiler.util.Lists; @@ -22,7 +22,7 @@ public class PatioCodeGenStructs { public static PatioCodeGenContext createType( PatioLocalRef target, StructType type, - List<DefineStructInstruction.Field> fields, + List<ShidDefineStruct.Field> fields, Source source, PatioCodeGenContext context ) { @@ -31,7 +31,7 @@ public class PatioCodeGenStructs { type.name(), List.of(), fields.stream() - .map(field -> new DefineFunctionInstruction.Param(field.name(), field.source())) + .map(field -> new ShidDefineFunction.Param(field.name(), field.source())) .toList(), FreeVariables.empty(), bodyContext -> { @@ -67,7 +67,7 @@ public class PatioCodeGenStructs { valuePointer, structDataLayout, List.of(1, fieldIndex), - bodyContext.stackIrLocalNameToLocal(field.name()), + bodyContext.shidLocalNameToLocal(field.name()), source )); } diff --git a/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java b/src/main/java/org/shedlang/compiler/shid/InstructionSerializer.java index 2cf812c4..afbccf6c 100644 --- a/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java +++ b/src/main/java/org/shedlang/compiler/shid/InstructionSerializer.java @@ -1,6 +1,6 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; -import org.shedlang.compiler.stackir.instructions.*; +import org.shedlang.compiler.shid.instructions.*; import org.shedlang.compiler.treetext.Tree; import org.shedlang.compiler.types.StructType; import org.shedlang.compiler.types.UserDefinedEffect; @@ -14,17 +14,17 @@ public class InstructionSerializer { private InstructionSerializer() { } - public static void serializeInstructions(List<Instruction> instructions, StringBuilder builder) { + public static void serializeInstructions(List<ShidInstruction> instructions, StringBuilder builder) { var tree = instructionsToTree(instructions); serializeTree(tree, builder, 0); } - public static void serializeInstruction(Instruction instruction, StringBuilder builder) { + public static void serializeInstruction(ShidInstruction instruction, StringBuilder builder) { var tree = instructionToTree(instruction); serializeTree(tree, builder, 0); } - private static Tree instructionsToTree(List<? extends Instruction> instructions) { + private static Tree instructionsToTree(List<? extends ShidInstruction> instructions) { return treeListIndented( instructions.stream() .map(instruction -> instructionToTree(instruction)) @@ -32,9 +32,9 @@ public class InstructionSerializer { ); } - private static Tree instructionToTree(Instruction instruction) { + private static Tree instructionToTree(ShidInstruction instruction) { return switch (instruction) { - case CallInstruction callInstruction -> + case ShidCall callInstruction -> treeList( treeIdentifier("call"), treeNamed( @@ -51,13 +51,13 @@ public class InstructionSerializer { ) ); - case DefineEffectInstruction defineEffectInstruction -> + case ShidDefineEffect defineEffectInstruction -> treeList( treeIdentifier("define-effect"), userDefinedEffectToTree(defineEffectInstruction.effect()) ); - case DefineFunctionInstruction defineFunctionInstruction -> + case ShidDefineFunction defineFunctionInstruction -> treeListIndented( treeIdentifier("define-function"), treeNamed("name", treeString(defineFunctionInstruction.name())), @@ -79,7 +79,7 @@ public class InstructionSerializer { treeNamed("body", instructionsToTree(defineFunctionInstruction.body())) ); - case DefineStructInstruction defineStructInstruction -> + case ShidDefineStruct defineStructInstruction -> treeListIndented( treeIdentifier("define-struct"), treeNamed("type", structTypeToTree(defineStructInstruction.type())), @@ -90,33 +90,33 @@ public class InstructionSerializer { )) ); - case DiscardInstruction discardInstruction -> + case ShidDiscard discardInstruction -> treeList( treeIdentifier("discard") ); - case DuplicateInstruction duplicate -> + case ShidDuplicate duplicate -> treeList( treeIdentifier("duplicate") ); - case FieldLoadInstruction fieldLoad -> + case ShidFieldLoad fieldLoad -> treeList( treeIdentifier("field-load"), switch (fieldLoad.receiver()) { - case FieldLoadInstruction.Receiver.Effect effect -> + case ShidFieldLoad.Receiver.Effect effect -> treeList( treeIdentifier("effect"), userDefinedEffectToTree(effect.effect()) ); - case FieldLoadInstruction.Receiver.Namespace namespace -> + case ShidFieldLoad.Receiver.Namespace namespace -> treeList( treeIdentifier("namespace"), treeString(namespace.name().toString()) ); - case FieldLoadInstruction.Receiver.Struct struct -> + case ShidFieldLoad.Receiver.Struct struct -> treeList( treeIdentifier("struct"), structTypeToTree(struct.type()) @@ -125,7 +125,7 @@ public class InstructionSerializer { treeString(fieldLoad.fieldName()) ); - case IfInstruction if_ -> + case ShidIf if_ -> treeListIndented( treeIdentifier("if"), treeNamed("result-count", treeInt(if_.resultCount())), @@ -133,92 +133,92 @@ public class InstructionSerializer { instructionsToTree(if_.falseBody()) ); - case IntAddInstruction intAdd -> + case ShidIntAdd intAdd -> treeList(treeIdentifier("int-add")); - case IntEqualsInstruction intEquals -> + case ShidIntEquals intEquals -> treeList(treeIdentifier("int-eq")); - case IntNotEqualInstruction intNotEqual -> + case ShidIntNotEqual intNotEqual -> treeList(treeIdentifier("int-ne")); - case IntSubInstruction intSub -> + case ShidIntSub intSub -> treeList(treeIdentifier("int-sub")); - case LocalLoadInstruction localLoadInstruction -> + case ShidLocalLoad localLoadInstruction -> treeList( treeIdentifier("local-load"), treeString(localLoadInstruction.name()) ); - case LocalStoreInstruction localStoreInstruction -> + case ShidLocalStore localStoreInstruction -> treeList( treeIdentifier("local-store"), treeString(localStoreInstruction.name()) ); - case LoopInstruction loop -> + case ShidLoop loop -> treeListIndented( treeIdentifier("loop"), instructionsToTree(loop.body()) ); - case LoopBreakInstruction loopBreak -> + case ShidLoopBreak loopBreak -> treeList(treeIdentifier("break")); - case LoopContinueInstruction loopContinue -> + case ShidLoopContinue loopContinue -> treeList(treeIdentifier("continue")); - case NamespaceFieldStoreInstruction namespaceFieldStore -> + case ShidNamespaceFieldStore namespaceFieldStore -> treeList( treeIdentifier("namespace-field-store"), treeString(namespaceFieldStore.namespaceName().toString()), treeString(namespaceFieldStore.fieldName()) ); - case NamespaceImportInstruction namespaceImport -> + case ShidNamespaceImport namespaceImport -> treeList( treeIdentifier("namespace-import"), treeString(namespaceImport.namespaceName().toString()) ); - case PushBoolInstruction pushBoolInstruction -> + case ShidPushBool pushBoolInstruction -> treeList( treeIdentifier("push-bool"), treeIdentifier(Boolean.toString(pushBoolInstruction.value())) ); - case PushIntInstruction pushIntInstruction -> + case ShidPushInt pushIntInstruction -> treeList( treeIdentifier("push-int"), treeIdentifier(pushIntInstruction.value().toString()) ); - case PushStringInstruction pushStringInstruction -> + case ShidPushString pushStringInstruction -> treeList( treeIdentifier("push-string"), treeString(pushStringInstruction.value()) ); - case PushUnitInstruction pushUnitInstruction -> + case ShidPushUnit pushUnitInstruction -> treeList( treeIdentifier("push-unit") ); - case ResumeInstruction resumeInstruction -> + case ShidResume resumeInstruction -> treeList( treeIdentifier("resume") ); - case ReturnInstruction returnInstruction -> + case ShidReturn returnInstruction -> treeList( treeIdentifier("return") ); - case StringAddInstruction stringAddInstruction -> + case ShidStringAdd stringAddInstruction -> treeList(treeIdentifier("string-add")); - case SwitchInstruction switchInstruction -> + case ShidSwitch switchInstruction -> treeListIndented( treeIdentifier("switch"), treeListIndented( @@ -231,7 +231,7 @@ public class InstructionSerializer { ) ); - case TryInstruction tryInstruction -> + case ShidTry tryInstruction -> treeListIndented( treeIdentifier("try"), userDefinedEffectToTree(tryInstruction.handledEffect()), @@ -243,26 +243,26 @@ public class InstructionSerializer { instructionsToTree(tryInstruction.body()) ); - case TupleCreateInstruction tupleCreateInstruction -> + case ShidTupleCreate tupleCreateInstruction -> treeList( treeIdentifier("tuple-create"), treeInt(tupleCreateInstruction.elementCount()) ); - case TupleGetInstruction tupleGetInstruction -> + case ShidTupleGet tupleGetInstruction -> treeList( treeIdentifier("tuple-get"), treeInt(tupleGetInstruction.elementIndex()), treeInt(tupleGetInstruction.elementCount()) ); - case VarLoadInstruction varLoadInstruction -> + case ShidVarLoad varLoadInstruction -> treeList( treeIdentifier("var-load"), treeString(varLoadInstruction.name()) ); - case VarStoreInstruction varStoreInstruction -> + case ShidVarStore varStoreInstruction -> treeList( treeIdentifier("var-store"), treeString(varStoreInstruction.name()) diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java index 2e2b43b7..47190813 100644 --- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java +++ b/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java @@ -1,10 +1,10 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.pcollections.*; import org.shedlang.compiler.ShedBuiltins; import org.shedlang.compiler.ast.typed.*; import org.shedlang.compiler.sources.Source; -import org.shedlang.compiler.stackir.instructions.*; +import org.shedlang.compiler.shid.instructions.*; import org.shedlang.compiler.types.*; import org.shedlang.compiler.util.Iterables; import org.shedlang.compiler.util.P; @@ -12,8 +12,8 @@ import org.shedlang.compiler.util.P; import java.util.ArrayList; import java.util.List; -public class StackCompiler { - private StackCompiler() { +public class ShidCodeGen { + private ShidCodeGen() { } private static Context compileAssign(TypedAssignNode node, Context context) { @@ -32,15 +32,15 @@ public class StackCompiler { context = context.addInstruction(switch (node.operator()) { case INT_ADD -> - new IntAddInstruction(node.source()); + new ShidIntAdd(node.source()); case INT_EQUALS -> - new IntEqualsInstruction(node.source()); + new ShidIntEquals(node.source()); case INT_NOT_EQUAL -> - new IntNotEqualInstruction(node.source()); + new ShidIntNotEqual(node.source()); case INT_SUB -> - new IntSubInstruction(node.source()); + new ShidIntSub(node.source()); case STRING_ADD -> - new StringAddInstruction(node.source()); + new ShidStringAdd(node.source()); }); return context; @@ -55,7 +55,7 @@ public class StackCompiler { case TypedFunctionStatementBehaviour.BlockReturn blockReturn -> { } case TypedFunctionStatementBehaviour.Continue continue_ -> { - context = context.addInstruction(new PushUnitInstruction(node.source())); + context = context.addInstruction(new ShidPushUnit(node.source())); } case TypedFunctionStatementBehaviour.Terminate terminate -> { } @@ -71,7 +71,7 @@ public class StackCompiler { switch (node.behaviour()) { case TypedFunctionStatementBehaviour.BlockReturn blockReturn -> { - context = context.addInstruction(new DiscardInstruction(node.source())); + context = context.addInstruction(new ShidDiscard(node.source())); } case TypedFunctionStatementBehaviour.Continue continue_ -> { } @@ -87,7 +87,7 @@ public class StackCompiler { } private static Context compileBoolLiteral(TypedBoolLiteralNode node, Context context) { - return context.addInstruction(new PushBoolInstruction(node.value(), node.source())); + return context.addInstruction(new ShidPushBool(node.value(), node.source())); } private static Context compileCall(TypedCallNode node, Context context) { @@ -101,7 +101,7 @@ public class StackCompiler { context = compileExpression(arg.expression(), context); } - var callInstruction = new CallInstruction( + var callInstruction = new ShidCall( node.args().positional().size(), node.args().named().stream() .map(arg -> arg.name()) @@ -121,8 +121,8 @@ public class StackCompiler { var localName = context.shedVariableToLocal(node.effect().name()); return context - .addInstruction(new DefineEffectInstruction(node.effect(), node.source())) - .addInstruction(new LocalStoreInstruction(localName, node.source())); + .addInstruction(new ShidDefineEffect(node.effect(), node.source())) + .addInstruction(new ShidLocalStore(localName, node.source())); } public static Context compileExpression(TypedExpressionNode node, Context context) { @@ -173,7 +173,7 @@ public class StackCompiler { Context context ) { context = compileExpression(node.expression(), context); - context = context.addInstruction(new DiscardInstruction(node.source())); + context = context.addInstruction(new ShidDiscard(node.source())); return context; } @@ -185,14 +185,14 @@ public class StackCompiler { // TODO: handle not a type with fields var receiver = switch (node.receiver().type()) { case NamespaceType namespaceType -> - new FieldLoadInstruction.Receiver.Namespace(namespaceType.namespaceName()); + new ShidFieldLoad.Receiver.Namespace(namespaceType.namespaceName()); case StructType structType -> - new FieldLoadInstruction.Receiver.Struct(structType); + new ShidFieldLoad.Receiver.Struct(structType); case TypeLevelValueType typeLevelValueType -> { if (typeLevelValueType.value() instanceof UserDefinedEffect effect) { - yield new FieldLoadInstruction.Receiver.Effect(effect); + yield new ShidFieldLoad.Receiver.Effect(effect); } else { throw new RuntimeException("not a type with fields"); } @@ -202,7 +202,7 @@ public class StackCompiler { throw new RuntimeException("not a type with fields"); }; - context = context.addInstruction(new FieldLoadInstruction( + context = context.addInstruction(new ShidFieldLoad( receiver, node.fieldName(), node.source() @@ -222,14 +222,14 @@ public class StackCompiler { var c = context; var positionalParams = params.positional().stream() - .map(param -> new DefineFunctionInstruction.Param( + .map(param -> new ShidDefineFunction.Param( c.shedVariableToLocal(param.name()), param.source() )) .toList(); var namedParams = params.named().stream() - .map(param -> new DefineFunctionInstruction.Param( + .map(param -> new ShidDefineFunction.Param( c.shedVariableToLocal(param.name()), param.source() )) @@ -239,10 +239,10 @@ public class StackCompiler { switch (body.behaviour()) { case TypedFunctionStatementBehaviour.BlockReturn blockReturn -> { - context = context.addInstruction(new ReturnInstruction(body.source())); + context = context.addInstruction(new ShidReturn(body.source())); } case TypedFunctionStatementBehaviour.Continue continue_ -> { - context = context.addInstruction(new ReturnInstruction(body.source())); + context = context.addInstruction(new ShidReturn(body.source())); } case TypedFunctionStatementBehaviour.Terminate terminate -> { } @@ -263,7 +263,7 @@ public class StackCompiler { } } - var defineFunctionInstruction = new DefineFunctionInstruction( + var defineFunctionInstruction = new ShidDefineFunction( name, positionalParams, namedParams, @@ -288,7 +288,7 @@ public class StackCompiler { ); var localName = context.shedVariableToLocal(node.name()); - var storeInstruction = new LocalStoreInstruction(localName, node.source()); + var storeInstruction = new ShidLocalStore(localName, node.source()); return context.addInstruction(storeInstruction); } @@ -312,7 +312,7 @@ public class StackCompiler { Context context ) { context = compileExpression(node.expression(), context); - context = context.addInstruction(new ReturnInstruction(node.source())); + context = context.addInstruction(new ShidReturn(node.source())); return context; } @@ -380,7 +380,7 @@ public class StackCompiler { var ifFalseInstructions = context.instructions; context = context.exitBlock(); - context = context.addInstruction(new IfInstruction( + context = context.addInstruction(new ShidIf( 1, ifTrueInstructions, ifFalseInstructions, @@ -392,23 +392,23 @@ public class StackCompiler { } private static Context compileIntLiteral(TypedIntLiteralNode node, Context context) { - return context.addInstruction(new PushIntInstruction(node.value(), node.source())); + return context.addInstruction(new ShidPushInt(node.value(), node.source())); } - public static StackIrNamespace compileNamespace(TypedNamespaceNode node) { + public static ShidNamespace compileNamespace(TypedNamespaceNode node) { var context = Context.EMPTY; context = context.addShedVal(ShedBuiltins.PRINT_NAME); var printLocalName = context.shedVariableToLocal(ShedBuiltins.PRINT_NAME); context = context - .addInstruction(new NamespaceImportInstruction(ShedBuiltins.NAMESPACE_NAME, node.source())) - .addInstruction(new FieldLoadInstruction( - new FieldLoadInstruction.Receiver.Namespace(ShedBuiltins.NAMESPACE_NAME), + .addInstruction(new ShidNamespaceImport(ShedBuiltins.NAMESPACE_NAME, node.source())) + .addInstruction(new ShidFieldLoad( + new ShidFieldLoad.Receiver.Namespace(ShedBuiltins.NAMESPACE_NAME), ShedBuiltins.PRINT_NAME, node.source() )) - .addInstruction(new LocalStoreInstruction(printLocalName, node.source())); + .addInstruction(new ShidLocalStore(printLocalName, node.source())); for (var boundVariable : node.boundVariables()) { context = context.addShedVariable(boundVariable); @@ -417,11 +417,11 @@ public class StackCompiler { for (var importNode : node.imports()) { var localName = context.shedVariableToLocal(importNode.variableName()); context = context - .addInstruction(new NamespaceImportInstruction( + .addInstruction(new ShidNamespaceImport( importNode.namespaceName(), importNode.source() )) - .addInstruction(new LocalStoreInstruction( + .addInstruction(new ShidLocalStore( localName, importNode.source() )); @@ -452,15 +452,15 @@ public class StackCompiler { var localName = context.shedVariableToLocal(fieldName); context = context - .addInstruction(new LocalLoadInstruction(localName, node.source())) - .addInstruction(new NamespaceFieldStoreInstruction( + .addInstruction(new ShidLocalLoad(localName, node.source())) + .addInstruction(new ShidNamespaceFieldStore( node.namespaceName(), fieldName, node.source() )); } - return new StackIrNamespace(node.namespaceName(), context.instructions); + return new ShidNamespace(node.namespaceName(), context.instructions); } public static Context compileNamespaceStatement(TypedNamespaceStatementNode node, Context context) { @@ -486,13 +486,13 @@ public class StackCompiler { var shedVariable = context.shedVariable(node.name()); if (shedVariable.isVar) { - return context.addInstruction(new VarLoadInstruction( - shedVariable.stackIrLocalName, + return context.addInstruction(new ShidVarLoad( + shedVariable.shidLocalName, node.source() )); } else { - return context.addInstruction(new LocalLoadInstruction( - shedVariable.stackIrLocalName, + return context.addInstruction(new ShidLocalLoad( + shedVariable.shidLocalName, node.source() )); } @@ -500,7 +500,7 @@ public class StackCompiler { private static Context compileResume(TypedResumeNode node, Context context) { context = compileExpression(node.expression(), context); - context = context.addInstruction(new ResumeInstruction(node.source())); + context = context.addInstruction(new ShidResume(node.source())); return context; } @@ -508,7 +508,7 @@ public class StackCompiler { TypedStringLiteralNode node, Context context ) { - var instruction = new PushStringInstruction(node.value(), node.source()); + var instruction = new ShidPushString(node.value(), node.source()); return context.addInstruction(instruction); } @@ -516,16 +516,16 @@ public class StackCompiler { TypedStructDefinitionNode node, Context context ) { - var defineStructInstruction = new DefineStructInstruction( + var defineStructInstruction = new ShidDefineStruct( node.type(), node.fields().stream() - .map(field -> new DefineStructInstruction.Field(field.name(), field.source())) + .map(field -> new ShidDefineStruct.Field(field.name(), field.source())) .toList(), node.source() ); var localName = context.shedVariableToLocal(node.type().name()); - var storeInstruction = new LocalStoreInstruction(localName, node.source()); + var storeInstruction = new ShidLocalStore(localName, node.source()); return context .addInstruction(defineStructInstruction) @@ -536,10 +536,10 @@ public class StackCompiler { TypedSumTypeDefinitionNode node, Context context ) { - var defineSumTypeInstruction = new PushUnitInstruction(node.source()); + var defineSumTypeInstruction = new ShidPushUnit(node.source()); var localName = context.shedVariableToLocal(node.type().name()); - var storeInstruction = new LocalStoreInstruction(localName, node.source()); + var storeInstruction = new ShidLocalStore(localName, node.source()); return context .addInstruction(defineSumTypeInstruction) @@ -552,12 +552,12 @@ public class StackCompiler { ) { return switch (target) { case TypedTargetNode.Ignore ignore -> { - yield context.addInstruction(new DiscardInstruction(ignore.source())); + yield context.addInstruction(new ShidDiscard(ignore.source())); } case TypedTargetNode.Reassign reassign -> { context = context.addInstruction( - new VarStoreInstruction( + new ShidVarStore( context.shedVariableToLocal(reassign.name()), reassign.source() ) @@ -568,17 +568,17 @@ public class StackCompiler { case TypedTargetNode.Tuple tuple -> { if (tuple.elements().size() == 0) { - context = context.addInstruction(new DiscardInstruction(tuple.source())); + context = context.addInstruction(new ShidDiscard(tuple.source())); } for (var elementIndex = 0; elementIndex < tuple.elements().size(); elementIndex++) { if (elementIndex < tuple.elements().size() - 1) { context = context - .addInstruction(new DuplicateInstruction(tuple.source())); + .addInstruction(new ShidDuplicate(tuple.source())); } context = context - .addInstruction(new TupleGetInstruction( + .addInstruction(new ShidTupleGet( elementIndex, tuple.elements().size(), tuple.source() @@ -592,7 +592,7 @@ public class StackCompiler { case TypedTargetNode.Val val -> { context = context.addInstruction( - new LocalStoreInstruction( + new ShidLocalStore( context.shedVariableToLocal(val.name()), val.source() ) @@ -603,7 +603,7 @@ public class StackCompiler { case TypedTargetNode.Var var -> { context = context.addInstruction( - new VarStoreInstruction( + new ShidVarStore( context.shedVariableToLocal(var.name()), var.source() ) @@ -624,7 +624,7 @@ public class StackCompiler { var bodyInstructions = context.instructions; context = context.exitBlock(); - var instruction = new TryInstruction( + var instruction = new ShidTry( node.handledEffect().value(), node.handlerMethods().stream() .map(methodNode -> methodNode.name()) @@ -654,7 +654,7 @@ public class StackCompiler { context = compileExpression(elementNode, context); } - var instruction = new TupleCreateInstruction(node.elements().size(), node.source()); + var instruction = new ShidTupleCreate(node.elements().size(), node.source()); return context.addInstruction(instruction); } @@ -662,13 +662,13 @@ public class StackCompiler { TypedUnitLiteralNode node, Context context ) { - return context.addInstruction(new PushUnitInstruction(node.source())); + return context.addInstruction(new ShidPushUnit(node.source())); } private static Context compileWhen(TypedWhenNode node, Context context) { context = compileExpression(node.expression(), context); - var switchCases = new ArrayList<SwitchInstruction.Case>(); + var switchCases = new ArrayList<ShidSwitch.Case>(); for (var whenCase : node.cases()) { context = context.enterBlock(whenCase.body().boundVariables()); @@ -676,7 +676,7 @@ public class StackCompiler { var caseBodyInstructions = context.instructions; context = context.exitBlock(); - var switchCase = new SwitchInstruction.Case( + var switchCase = new ShidSwitch.Case( whenCase.caseType().value(), caseBodyInstructions, whenCase.source() @@ -684,7 +684,7 @@ public class StackCompiler { switchCases.add(switchCase); } - context = context.addInstruction(new SwitchInstruction( + context = context.addInstruction(new ShidSwitch( switchCases, node.source() )); @@ -701,23 +701,23 @@ public class StackCompiler { context = context.enterBlock(List.of()); context = compileExpression(node.condition(), context); - context = context.addInstruction(new IfInstruction( + context = context.addInstruction(new ShidIf( 0, List.of(), List.of( - new LoopBreakInstruction(node.source()) + new ShidLoopBreak(node.source()) ), node.source() )); context = context.addInstructions(ifTrueInstructions); - context = context.addInstruction(new LoopContinueInstruction(node.source())); + context = context.addInstruction(new ShidLoopContinue(node.source())); var bodyInstructions = context.instructions; context = context.exitBlock(); - context = context.addInstruction(new LoopInstruction(bodyInstructions, node.source())); + context = context.addInstruction(new ShidLoop(bodyInstructions, node.source())); return context; } @@ -731,15 +731,15 @@ public class StackCompiler { P.map() ); - private final PStack<PVector<Instruction>> instructionsStack; - private final PVector<Instruction> instructions; + private final PStack<PVector<ShidInstruction>> instructionsStack; + private final PVector<ShidInstruction> instructions; private final PSet<String> localNames; private final PStack<PMap<String, ShedVariable>> shedVariablesByNameStack; private final PMap<String, ShedVariable> shedVariablesByName; private Context( - PStack<PVector<Instruction>> instructionsStack, - PVector<Instruction> instructions, + PStack<PVector<ShidInstruction>> instructionsStack, + PVector<ShidInstruction> instructions, PSet<String> localNames, PStack<PMap<String, ShedVariable>> shedVariablesByNameStack, PMap<String, ShedVariable> shedVariablesByName @@ -777,7 +777,7 @@ public class StackCompiler { ); } - private Context addInstruction(Instruction instruction) { + private Context addInstruction(ShidInstruction instruction) { return new Context( this.instructionsStack, this.instructions.plus(instruction), @@ -787,7 +787,7 @@ public class StackCompiler { ); } - public Context addInstructions(PVector<Instruction> instructions) { + public Context addInstructions(PVector<ShidInstruction> instructions) { return new Context( this.instructionsStack, this.instructions.plusAll(instructions), @@ -798,7 +798,7 @@ public class StackCompiler { } public String shedVariableToLocal(String variableName) { - return shedVariable(variableName).stackIrLocalName; + return shedVariable(variableName).shidLocalName; } public ShedVariable shedVariable(String variableName) { @@ -839,10 +839,10 @@ public class StackCompiler { } } - public List<Instruction> instructions() { + public List<ShidInstruction> instructions() { return this.instructions; } } - private record ShedVariable(String stackIrLocalName, boolean isVar) {} + private record ShedVariable(String shidLocalName, boolean isVar) {} } diff --git a/src/main/java/org/shedlang/compiler/shid/ShidNamespace.java b/src/main/java/org/shedlang/compiler/shid/ShidNamespace.java new file mode 100644 index 00000000..4c5f134f --- /dev/null +++ b/src/main/java/org/shedlang/compiler/shid/ShidNamespace.java @@ -0,0 +1,12 @@ +package org.shedlang.compiler.shid; + +import org.shedlang.compiler.shid.instructions.ShidInstruction; +import org.shedlang.compiler.types.NamespaceName; + +import java.util.List; + +public record ShidNamespace( + NamespaceName namespaceName, + List<ShidInstruction> instructions +) { +} diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/CallInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidCall.java index a84c4af1..bb720696 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/CallInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidCall.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -17,9 +17,9 @@ import java.util.List; * <li>The named arguments, in the same order as <code>namedArgNames</code>.</li> * </ul> */ -public record CallInstruction( +public record ShidCall( int positionalArgCount, List<String> namedArgNames, Source source -) implements Instruction { +) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/DefineEffectInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineEffect.java index d87a6412..cbd24307 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/DefineEffectInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineEffect.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.types.UserDefinedEffect; @@ -7,8 +7,8 @@ import org.shedlang.compiler.types.UserDefinedEffect; * Push an effect value onto the temporary value stack with the given * definition. */ -public record DefineEffectInstruction( +public record ShidDefineEffect( UserDefinedEffect effect, Source source -) implements Instruction { +) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/DefineFunctionInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineFunction.java index 6ca40775..16561049 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/DefineFunctionInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineFunction.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.pcollections.PVector; import org.shedlang.compiler.ast.typed.FreeVariables; @@ -12,14 +12,14 @@ import java.util.List; * Push a function value onto the temporary value stack with the given * definition. */ -public record DefineFunctionInstruction( +public record ShidDefineFunction( String name, List<Param> positionalParams, List<Param> namedParams, FreeVariables freeVariables, - List<Instruction> body, + List<ShidInstruction> body, Source source -) implements Instruction { +) implements ShidInstruction { public record Param(String name, Source source) { } @@ -39,10 +39,10 @@ public record DefineFunctionInstruction( PVector<Param> positionalParams, PVector<Param> namedParams, FreeVariables.Builder freeVariables, - PVector<Instruction> body + PVector<ShidInstruction> body ) { - public DefineFunctionInstruction build() { - return new DefineFunctionInstruction( + public ShidDefineFunction build() { + return new ShidDefineFunction( name, positionalParams, namedParams, @@ -92,7 +92,7 @@ public record DefineFunctionInstruction( ); } - public Builder addBodyInstruction(Instruction instruction) { + public Builder addBodyInstruction(ShidInstruction instruction) { return new Builder( this.name, this.positionalParams, diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/DefineStructInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineStruct.java index 098c9245..82d165e6 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/DefineStructInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDefineStruct.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.types.StructType; @@ -9,12 +9,12 @@ import java.util.List; * Push a struct type value onto the temporary value stack with the given * definition. */ -public record DefineStructInstruction( +public record ShidDefineStruct( StructType type, // TODO: remove fields? We should have fields from the type info. List<Field> fields, Source source -) implements Instruction { +) implements ShidInstruction { public record Field(String name, Source source) { } diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidDiscard.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDiscard.java new file mode 100644 index 00000000..ac5940d2 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDiscard.java @@ -0,0 +1,9 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Pop a value from the temporary value stack and discard it. + */ +public record ShidDiscard(Source source) implements ShidInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidDuplicate.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDuplicate.java new file mode 100644 index 00000000..29714cd3 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidDuplicate.java @@ -0,0 +1,9 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Duplicates the value on top of the temporary value stack. + */ +public record ShidDuplicate(Source source) implements ShidInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/FieldLoadInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidFieldLoad.java index 53dc1ee8..0df10550 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/FieldLoadInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidFieldLoad.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.types.NamespaceName; @@ -9,11 +9,11 @@ import org.shedlang.compiler.types.UserDefinedEffect; * Pop a value from the temporary value stack, get the given field from the * popped value, and push the field's value onto the temporary value stack. */ -public record FieldLoadInstruction( +public record ShidFieldLoad( Receiver receiver, String fieldName, Source source -) implements Instruction { +) implements ShidInstruction { public sealed interface Receiver { record Effect(UserDefinedEffect effect) implements Receiver {} record Namespace(NamespaceName name) implements Receiver {} diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/IfInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIf.java index a6636b91..408ccbef 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/IfInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIf.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -13,10 +13,10 @@ import java.util.List; * Each branch body should push <code>resultCount</code> values onto the * temporary value stack. */ -public record IfInstruction( +public record ShidIf( int resultCount, - List<Instruction> trueBody, - List<Instruction> falseBody, + List<ShidInstruction> trueBody, + List<ShidInstruction> falseBody, Source source -) implements Instruction { +) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java new file mode 100644 index 00000000..308fe739 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidInstruction.java @@ -0,0 +1,9 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.sources.Source; + +public sealed interface ShidInstruction + permits ShidCall, ShidDefineEffect, ShidDefineFunction, ShidDefineStruct, ShidDiscard, ShidDuplicate, 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 { + + Source source(); +} diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/IntAddInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntAdd.java index 55a4fb1c..ed570cef 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/IntAddInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntAdd.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source; * Pop two values from the temporary value stack, assumed to be Ints, add them * together, and push the result onto the temporary value stack. */ -public record IntAddInstruction(Source source) implements Instruction { +public record ShidIntAdd(Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/IntEqualsInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntEquals.java index 7f0c97cf..f5543143 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/IntEqualsInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntEquals.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source; * Pop two values from the temporary value stack, compare them as Ints, and push * a Bool onto the temporary value stack: true if equal, false if not equal. */ -public record IntEqualsInstruction(Source source) implements Instruction { +public record ShidIntEquals(Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/IntNotEqualInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntNotEqual.java index 6b155f67..60eea7c5 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/IntNotEqualInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntNotEqual.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source; * Pop two values from the temporary value stack, compare them as Ints, and push * a Bool onto the temporary value stack: true if not equal, false if equal. */ -public record IntNotEqualInstruction(Source source) implements Instruction { +public record ShidIntNotEqual(Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/IntSubInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntSub.java index e2fa09b6..3fbd3e09 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/IntSubInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidIntSub.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -7,5 +7,5 @@ import org.shedlang.compiler.sources.Source; * from the temporary value stack, calculate the left operand minus the right * operand, then push the result onto the temporary value stack. */ -public record IntSubInstruction(Source source) implements Instruction { +public record ShidIntSub(Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/LocalLoadInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalLoad.java index d0753609..a1de23fe 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/LocalLoadInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalLoad.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source; * Load the local with the given name and push it onto the temporary value * stack. */ -public record LocalLoadInstruction(String name, Source source) implements Instruction { +public record ShidLocalLoad(String name, Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/LocalStoreInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalStore.java index 880c91f8..003aaf40 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/LocalStoreInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLocalStore.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source; * Pop a value from the temporary value stack and store it as the local with the * given name. */ -public record LocalStoreInstruction(String name, Source source) implements Instruction { +public record ShidLocalStore(String name, Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/LoopInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLoop.java index 119d9a52..bfa7a1fa 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/LoopInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLoop.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -10,8 +10,8 @@ import java.util.List; * start of the body. The <code>break</code> instruction can jump to the end of * the body. */ -public record LoopInstruction( - List<Instruction> body, +public record ShidLoop( + List<ShidInstruction> body, Source source -) implements Instruction { +) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/LoopBreakInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLoopBreak.java index 60a1d056..6e2e70d7 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/LoopBreakInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLoopBreak.java @@ -1,9 +1,9 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; /** * Jump to the end of the enclosing <code>loop</code> instruction's body. */ -public record LoopBreakInstruction(Source source) implements Instruction { +public record ShidLoopBreak(Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/LoopContinueInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLoopContinue.java index d7111ea9..d6ee6c3d 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/LoopContinueInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidLoopContinue.java @@ -1,9 +1,9 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; /** * Jump to the start of the enclosing <code>loop</code> instruction's body. */ -public record LoopContinueInstruction(Source source) implements Instruction { +public record ShidLoopContinue(Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/NamespaceFieldStoreInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidNamespaceFieldStore.java index b83964a1..583dbb5f 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/NamespaceFieldStoreInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidNamespaceFieldStore.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.types.NamespaceName; @@ -7,9 +7,9 @@ import org.shedlang.compiler.types.NamespaceName; * Pop a value from the temporary value stack and store it as the field with the * given name on the given namespace. */ -public record NamespaceFieldStoreInstruction( +public record ShidNamespaceFieldStore( NamespaceName namespaceName, String fieldName, Source source -) implements Instruction { +) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/NamespaceImportInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidNamespaceImport.java index cc600d5b..9e93a95f 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/NamespaceImportInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidNamespaceImport.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.types.NamespaceName; @@ -6,8 +6,8 @@ import org.shedlang.compiler.types.NamespaceName; /** * Import the given namespace and push it onto the temporary value stack. */ -public record NamespaceImportInstruction( +public record ShidNamespaceImport( NamespaceName namespaceName, Source source -) implements Instruction { +) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/PushBoolInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushBool.java index c732a390..c92e8959 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/PushBoolInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushBool.java @@ -1,12 +1,12 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; /** * Push a boolean onto the temporary value stack. */ -public record PushBoolInstruction( +public record ShidPushBool( boolean value, Source source -) implements Instruction { +) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushInt.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushInt.java new file mode 100644 index 00000000..e4673e9b --- /dev/null +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushInt.java @@ -0,0 +1,11 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.sources.Source; + +import java.math.BigInteger; + +/** + * Push an integer onto the temporary value stack. + */ +public record ShidPushInt(BigInteger value, Source source) implements ShidInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushString.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushString.java new file mode 100644 index 00000000..b0fa0183 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushString.java @@ -0,0 +1,9 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Push a string onto the temporary value stack. + */ +public record ShidPushString(String value, Source source) implements ShidInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushUnit.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushUnit.java new file mode 100644 index 00000000..85e5363e --- /dev/null +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidPushUnit.java @@ -0,0 +1,9 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Push the unit value onto the temporary value stack. + */ +public record ShidPushUnit(Source source) implements ShidInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/ResumeInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidResume.java index 836b5bac..12eaac48 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/ResumeInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidResume.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source; * Pop a value from the temporary value stack and return with that value from * the current effect handler method back to the effect call. */ -public record ResumeInstruction(Source source) implements Instruction { +public record ShidResume(Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/ReturnInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidReturn.java index 1b9e4213..fd0228fe 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/ReturnInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidReturn.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source; * Pop a value from the temporary value stack and return with that value from * the current function. */ -public record ReturnInstruction(Source source) implements Instruction { +public record ShidReturn(Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/StringAddInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidStringAdd.java index 5114beff..fea26d1e 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/StringAddInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidStringAdd.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -8,5 +8,5 @@ import org.shedlang.compiler.sources.Source; * the left and right operands, then push the result onto the temporary value * stack. */ -public record StringAddInstruction(Source source) implements Instruction { +public record ShidStringAdd(Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/SwitchInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidSwitch.java index 880349de..00126f3c 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/SwitchInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidSwitch.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.types.StructType; @@ -12,10 +12,10 @@ import java.util.List; * <p> * Each case body should push exactly one value onto the temporary value stack. */ -public record SwitchInstruction( +public record ShidSwitch( List<Case> cases, Source source -) implements Instruction { - public record Case(StructType caseType, List<Instruction> body, Source source) { +) implements ShidInstruction { + public record Case(StructType caseType, List<ShidInstruction> body, Source source) { } } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/TryInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidTry.java index 0b5051df..ef763eda 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/TryInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidTry.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -17,10 +17,10 @@ import java.util.List; * If the body runs to completion, it should leave a single value on the * temporary value stack. */ -public record TryInstruction( +public record ShidTry( UserDefinedEffect handledEffect, List<String> handlerMethodNames, - List<Instruction> body, + List<ShidInstruction> body, Source source -) implements Instruction { +) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/TupleCreateInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidTupleCreate.java index fa331d1c..3559be91 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/TupleCreateInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidTupleCreate.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -7,8 +7,8 @@ import org.shedlang.compiler.sources.Source; * tuple from those elements, and push the tuple onto the temporary value stack. * Elements should have been pushed onto the stack in index order. */ -public record TupleCreateInstruction( +public record ShidTupleCreate( int elementCount, Source source -) implements Instruction { +) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/TupleGetInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidTupleGet.java index ed52cc29..a8a12b1d 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/TupleGetInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidTupleGet.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -6,9 +6,9 @@ import org.shedlang.compiler.sources.Source; * Pop a tuple from the temporary value stack, get the element at the given * index, and push it onto the temporary value stack. */ -public record TupleGetInstruction( +public record ShidTupleGet( int elementIndex, int elementCount, Source source -) implements Instruction { +) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/VarLoadInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidVarLoad.java index fe35db14..ad0ae2ca 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/VarLoadInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidVarLoad.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source; * Load the value stored in the var with the given name and push it onto the * temporary value stack. */ -public record VarLoadInstruction(String name, Source source) implements Instruction { +public record ShidVarLoad(String name, Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/VarStoreInstruction.java b/src/main/java/org/shedlang/compiler/shid/instructions/ShidVarStore.java index 33a3ab45..f9d2fb51 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/VarStoreInstruction.java +++ b/src/main/java/org/shedlang/compiler/shid/instructions/ShidVarStore.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir.instructions; +package org.shedlang.compiler.shid.instructions; import org.shedlang.compiler.sources.Source; @@ -6,5 +6,5 @@ import org.shedlang.compiler.sources.Source; * Pop a value from the temporary value stack and store it in the var with the * given name. */ -public record VarStoreInstruction(String name, Source source) implements Instruction { +public record ShidVarStore(String name, Source source) implements ShidInstruction { } diff --git a/src/main/java/org/shedlang/compiler/stackir/StackIrNamespace.java b/src/main/java/org/shedlang/compiler/stackir/StackIrNamespace.java deleted file mode 100644 index 65fd41d3..00000000 --- a/src/main/java/org/shedlang/compiler/stackir/StackIrNamespace.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.shedlang.compiler.stackir; - -import org.shedlang.compiler.stackir.instructions.Instruction; -import org.shedlang.compiler.types.NamespaceName; - -import java.util.List; - -public record StackIrNamespace( - NamespaceName namespaceName, - List<Instruction> instructions -) { -} diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/DiscardInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/DiscardInstruction.java deleted file mode 100644 index 503ecc53..00000000 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/DiscardInstruction.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.shedlang.compiler.stackir.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Pop a value from the temporary value stack and discard it. - */ -public record DiscardInstruction(Source source) implements Instruction { -} diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/DuplicateInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/DuplicateInstruction.java deleted file mode 100644 index 03685e54..00000000 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/DuplicateInstruction.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.shedlang.compiler.stackir.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Duplicates the value on top of the temporary value stack. - */ -public record DuplicateInstruction(Source source) implements Instruction { -} diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/Instruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/Instruction.java deleted file mode 100644 index f84de210..00000000 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/Instruction.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.shedlang.compiler.stackir.instructions; - -import org.shedlang.compiler.sources.Source; - -public sealed interface Instruction - permits CallInstruction, DefineEffectInstruction, DefineFunctionInstruction, DefineStructInstruction, DiscardInstruction, DuplicateInstruction, FieldLoadInstruction, IfInstruction, IntAddInstruction, IntEqualsInstruction, IntNotEqualInstruction, IntSubInstruction, LocalLoadInstruction, LocalStoreInstruction, LoopBreakInstruction, LoopContinueInstruction, LoopInstruction, NamespaceFieldStoreInstruction, NamespaceImportInstruction, PushBoolInstruction, PushIntInstruction, PushStringInstruction, PushUnitInstruction, ResumeInstruction, ReturnInstruction, StringAddInstruction, SwitchInstruction, TryInstruction, TupleCreateInstruction, TupleGetInstruction, VarLoadInstruction, VarStoreInstruction { - - Source source(); -} diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/PushIntInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/PushIntInstruction.java deleted file mode 100644 index cba3f217..00000000 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/PushIntInstruction.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.shedlang.compiler.stackir.instructions; - -import org.shedlang.compiler.sources.Source; - -import java.math.BigInteger; - -/** - * Push an integer onto the temporary value stack. - */ -public record PushIntInstruction(BigInteger value, Source source) implements Instruction { -} diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/PushStringInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/PushStringInstruction.java deleted file mode 100644 index e33051e5..00000000 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/PushStringInstruction.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.shedlang.compiler.stackir.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Push a string onto the temporary value stack. - */ -public record PushStringInstruction(String value, Source source) implements Instruction { -} diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/PushUnitInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/PushUnitInstruction.java deleted file mode 100644 index 998624e1..00000000 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/PushUnitInstruction.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.shedlang.compiler.stackir.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Push the unit value onto the temporary value stack. - */ -public record PushUnitInstruction(Source source) implements Instruction { -} diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenCallTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenCallTests.java index a802351e..a4ed029f 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenCallTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenCallTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -16,7 +16,7 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenCallTests { @Test public void canCallFunctionWithNoArgs(Snapshotter snapshotter) throws IOException { - var instruction = Instructions.call(0, List.of()); + var instruction = Shid.call(0, List.of()); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("other")) .temporaryPush(new PatioLocalRef("receiver")); @@ -28,7 +28,7 @@ public class PatioCodeGenCallTests { @Test public void canCallFunctionWithArgs(Snapshotter snapshotter) throws IOException { - var instruction = Instructions.call(2, List.of("b", "a")); + var instruction = Shid.call(2, List.of("b", "a")); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("other")) .temporaryPush(new PatioLocalRef("receiver")) diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineEffectTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineEffectTests.java index a6135d0a..7137affe 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineEffectTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineEffectTests.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; import org.shedlang.compiler.typechecker.TypeInfos; @@ -17,7 +17,7 @@ public class PatioCodeGenDefineEffectTests { @Test public void canGenerateCodeForDefineEffect(Snapshotter snapshotter) throws IOException { var effect = Effects.userDefined(NamespaceName.of("Example", "Project"), "State"); - var instruction = Instructions.defineEffect(effect); + var instruction = Shid.defineEffect(effect); var typeInfos = TypeInfos.EMPTY .addUserDefinedEffectInfo( effect, diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java index 696876b9..b5b9d0b5 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java @@ -6,8 +6,8 @@ import org.shedlang.compiler.ast.typed.FreeVariables; import org.shedlang.compiler.patio.ast.types.PatioTypes; import org.shedlang.compiler.patio.instructions.Patio; import org.shedlang.compiler.sources.Sources; -import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.ShidDefineFunction; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -20,14 +20,14 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenDefineFunctionTests { @Test public void canDefineMinimalFunction(Snapshotter snapshotter) throws IOException { - var instruction = new DefineFunctionInstruction( + var instruction = new ShidDefineFunction( "f", List.of(), List.of(), FreeVariables.empty(), List.of( - Instructions.pushUnit(), - Instructions.return_() + Shid.pushUnit(), + Shid.return_() ), Sources.NULL ); @@ -40,20 +40,20 @@ public class PatioCodeGenDefineFunctionTests { @Test public void immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(Snapshotter snapshotter) throws IOException { - var instruction = new DefineFunctionInstruction( + var instruction = new ShidDefineFunction( "f", List.of(), List.of(), FreeVariables.builder().plus("a", Sources.NULL).plus("b", Sources.NULL).build(), List.of( - Instructions.localLoad("a"), - Instructions.return_() + Shid.localLoad("a"), + Shid.return_() ), Sources.NULL ); var context = PatioCodeGenContext.EMPTY - .defineStackIrParam("a") - .defineStackIrParam("b"); + .defineShidParam("a") + .defineShidParam("b"); var result = PatioCodeGen.generateInstruction(instruction, context); @@ -62,20 +62,20 @@ public class PatioCodeGenDefineFunctionTests { @Test public void canCaptureFreeVariablesThatAreSetAfterDefinition(Snapshotter snapshotter) throws IOException { - var instruction = new DefineFunctionInstruction( + var instruction = new ShidDefineFunction( "f", List.of(), List.of(), FreeVariables.builder().plus("a", Sources.NULL).plus("b", Sources.NULL).build(), List.of( - Instructions.localLoad("a"), - Instructions.return_() + Shid.localLoad("a"), + Shid.return_() ), Sources.NULL ); var context = PatioCodeGenContext.EMPTY - .declareStackIrVal("a", PatioCodeGenTypes.VALUE_TYPE).context() - .declareStackIrVal("b", PatioCodeGenTypes.VALUE_TYPE).context(); + .declareShidVal("a", PatioCodeGenTypes.VALUE_TYPE).context() + .declareShidVal("b", PatioCodeGenTypes.VALUE_TYPE).context(); context = PatioCodeGen.generateInstruction(instruction, context); @@ -84,16 +84,16 @@ public class PatioCodeGenDefineFunctionTests { // into the closure upon closure creation (i.e. too soon) versus after // the free variable is set. context = context.addInstruction(Patio.localStore(Patio.localRef("a"), Patio.int_(42))); - context = context.initStackIrLocal("a"); + context = context.initShidLocal("a"); context = context.addInstruction(Patio.localStore(Patio.localRef("b"), Patio.int_(47))); - context = context.initStackIrLocal("b"); + context = context.initShidLocal("b"); snapshotter.assertSnapshot(serialize(context)); } @Test public void pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(Snapshotter snapshotter) throws IOException { - var instruction = new DefineFunctionInstruction( + var instruction = new ShidDefineFunction( "f", List.of(), List.of(), @@ -102,16 +102,16 @@ public class PatioCodeGenDefineFunctionTests { .plus("b", Sources.NULL) .build(), List.of( - Instructions.localLoad("a"), - Instructions.return_() + Shid.localLoad("a"), + Shid.return_() ), Sources.NULL ); var context = PatioCodeGenContext.EMPTY - .declareStackIrVal("a", PatioTypes.DATA_POINTER).context() - .initStackIrLocal("a") - .declareStackIrVal("b", PatioTypes.DATA_POINTER).context() - .initStackIrLocal("b"); + .declareShidVal("a", PatioTypes.DATA_POINTER).context() + .initShidLocal("a") + .declareShidVal("b", PatioTypes.DATA_POINTER).context() + .initShidLocal("b"); var result = PatioCodeGen.generateInstruction(instruction, context); @@ -120,25 +120,25 @@ public class PatioCodeGenDefineFunctionTests { @Test public void positionalAndNamedParamsAreDefined(Snapshotter snapshotter) throws IOException { - var instruction = new DefineFunctionInstruction( + var instruction = new ShidDefineFunction( "f", - List.of(Instructions.param("param1"), Instructions.param("param2")), + List.of(Shid.param("param1"), Shid.param("param2")), // Define named params in non-lexical order - List.of(Instructions.param("paramB"), Instructions.param("paramC"), Instructions.param("paramA")), + List.of(Shid.param("paramB"), Shid.param("paramC"), Shid.param("paramA")), FreeVariables.builder().plus("a", Sources.NULL).plus("b", Sources.NULL).build(), List.of( - Instructions.localLoad("a"), - Instructions.localLoad("param1"), - Instructions.intAdd(), - Instructions.localLoad("paramA"), - Instructions.intAdd(), - Instructions.return_() + Shid.localLoad("a"), + Shid.localLoad("param1"), + Shid.intAdd(), + Shid.localLoad("paramA"), + Shid.intAdd(), + Shid.return_() ), Sources.NULL ); var context = PatioCodeGenContext.EMPTY - .defineStackIrParam("a") - .defineStackIrParam("b"); + .defineShidParam("a") + .defineShidParam("b"); var result = PatioCodeGen.generateInstruction(instruction, context); diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineStructTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineStructTests.java index d79a33fd..450dcba2 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineStructTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineStructTests.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; import org.shedlang.compiler.typechecker.TypeInfos; @@ -22,11 +22,11 @@ public class PatioCodeGenDefineStructTests { @Test public void canGenerateCodeForDefineStruct(Snapshotter snapshotter) throws IOException { var structType = Types.struct(NamespaceName.of("Example", "Project"), "User"); - var instruction = Instructions.defineStruct( + var instruction = Shid.defineStruct( structType, List.of( - Instructions.defineStructField("name"), - Instructions.defineStructField("isActive") + Shid.defineStructField("name"), + Shid.defineStructField("isActive") ) ); var typeInfos = TypeInfos.EMPTY @@ -51,8 +51,8 @@ public class PatioCodeGenDefineStructTests { // will suffice for now var structType1 = Types.struct(NamespaceName.of("Example", "Project"), "User"); var structType2 = Types.struct(NamespaceName.of("Example", "Project"), "Id"); - var instruction1 = Instructions.defineStruct(structType1, List.of()); - var instruction2 = Instructions.defineStruct(structType1, List.of()); + var instruction1 = Shid.defineStruct(structType1, List.of()); + var instruction2 = Shid.defineStruct(structType1, List.of()); var typeInfos = TypeInfos.EMPTY .addStructTypeInfo(structType1, StructTypeInfo.builder().build()) .addStructTypeInfo(structType2, StructTypeInfo.builder().build()); diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDiscardTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDiscardTests.java index da7e55de..ff66e6bb 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDiscardTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDiscardTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,12 +15,12 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenDiscardTests { @Test public void discardInstructionPopsFromTemporaryStack(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.discard(); + var shid = Shid.discard(); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java index 1b313b84..24ec9c18 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; import org.shedlang.compiler.typechecker.TypeCheckerContext; @@ -20,7 +20,7 @@ public class PatioCodeGenFieldLoadTests { @Test public void canGenerateCodeForNamespaceFieldLoad(Snapshotter snapshotter) throws IOException { var namespaceName = new NamespaceName(List.of("Example", "Project")); - var stackIrInstruction = Instructions.fieldLoad(namespaceName, "y"); + var shidInstruction = Shid.fieldLoad(namespaceName, "y"); var typeInfos = TypeCheckerContext.EMPTY .addNamespaceTypeInfo( namespaceName, @@ -35,7 +35,7 @@ public class PatioCodeGenFieldLoadTests { .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); - var result = PatioCodeGen.generateInstruction(stackIrInstruction, context); + var result = PatioCodeGen.generateInstruction(shidInstruction, context); snapshotter.assertSnapshot(serialize(result)); } @@ -44,7 +44,7 @@ public class PatioCodeGenFieldLoadTests { public void canGenerateCodeForStructFieldLoad(Snapshotter snapshotter) throws IOException { var namespaceName = NamespaceName.of("Example", "Project"); var structType = Types.struct(namespaceName, "User"); - var stackIrInstruction = Instructions.fieldLoad(structType, "id"); + var shidInstruction = Shid.fieldLoad(structType, "id"); var typeInfos = TypeInfos.EMPTY .addStructTypeInfo( structType, @@ -58,7 +58,7 @@ public class PatioCodeGenFieldLoadTests { .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); - var result = PatioCodeGen.generateInstruction(stackIrInstruction, context); + var result = PatioCodeGen.generateInstruction(shidInstruction, context); snapshotter.assertSnapshot(serialize(result)); } @@ -67,7 +67,7 @@ public class PatioCodeGenFieldLoadTests { public void canGenerateCodeForUserDefinedEffectFieldLoad(Snapshotter snapshotter) throws IOException { var namespaceName = NamespaceName.of("Example", "Project"); var effect = Effects.userDefined(namespaceName, "State"); - var stackIrInstruction = Instructions.fieldLoad(effect, "fence"); + var shidInstruction = Shid.fieldLoad(effect, "fence"); var typeInfos = TypeInfos.EMPTY .addUserDefinedEffectInfo( effect, @@ -81,7 +81,7 @@ public class PatioCodeGenFieldLoadTests { .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); - var result = PatioCodeGen.generateInstruction(stackIrInstruction, context); + var result = PatioCodeGen.generateInstruction(shidInstruction, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIfTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIfTests.java index c06f0c5e..34edd733 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIfTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIfTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -16,15 +16,15 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenIfTests { @Test public void canGenerateCodeForIfWithNoResults(Snapshotter snapshotter) throws IOException { - var instruction = Instructions.if_( + var instruction = Shid.if_( 0, List.of( - Instructions.pushInt(1), - Instructions.discard() + Shid.pushInt(1), + Shid.discard() ), List.of( - Instructions.pushInt(101), - Instructions.discard() + Shid.pushInt(101), + Shid.discard() ) ); var context = PatioCodeGenContext.EMPTY @@ -38,17 +38,17 @@ public class PatioCodeGenIfTests { @Test public void canGenerateCodeForIfWithSingleResult(Snapshotter snapshotter) throws IOException { - var instruction = Instructions.if_( + var instruction = Shid.if_( 1, List.of( - Instructions.pushInt(1), - Instructions.pushInt(2), - Instructions.intAdd() + Shid.pushInt(1), + Shid.pushInt(2), + Shid.intAdd() ), List.of( - Instructions.pushInt(101), - Instructions.pushInt(102), - Instructions.intAdd() + Shid.pushInt(101), + Shid.pushInt(102), + Shid.intAdd() ) ); var context = PatioCodeGenContext.EMPTY @@ -62,15 +62,15 @@ public class PatioCodeGenIfTests { @Test public void canGenerateCodeForIfWithMultipleResults(Snapshotter snapshotter) throws IOException { - var instruction = Instructions.if_( + var instruction = Shid.if_( 2, List.of( - Instructions.pushInt(1), - Instructions.pushInt(2) + Shid.pushInt(1), + Shid.pushInt(2) ), List.of( - Instructions.pushInt(101), - Instructions.pushInt(102) + Shid.pushInt(101), + Shid.pushInt(102) ) ); var context = PatioCodeGenContext.EMPTY diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntAddTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntAddTests.java index 12016446..53158d0d 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntAddTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntAddTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,13 +15,13 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenIntAddTests { @Test public void canGenerateCodeForIntAdd(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.intAdd(); + var shid = Shid.intAdd(); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")) .temporaryPush(new PatioLocalRef("c")); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntEqualsTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntEqualsTests.java index cc1eaf2d..8b9fe35f 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntEqualsTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntEqualsTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,13 +15,13 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenIntEqualsTests { @Test public void canGenerateCodeForIntEquals(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.intEquals(); + var shid = Shid.intEquals(); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")) .temporaryPush(new PatioLocalRef("c")); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntNotEqualTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntNotEqualTests.java index 253781d3..5715f0d4 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntNotEqualTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntNotEqualTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,13 +15,13 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenIntNotEqualTests { @Test public void canGenerateCodeForIntNotEqual(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.intNotEqual(); + var shid = Shid.intNotEqual(); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")) .temporaryPush(new PatioLocalRef("c")); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntSubTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntSubTests.java index 9c0ccae9..e2036764 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntSubTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntSubTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,13 +15,13 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenIntSubTests { @Test public void canGenerateCodeForIntSub(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.intSub(); + var shid = Shid.intSub(); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")) .temporaryPush(new PatioLocalRef("c")); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java index 7e6b5705..f452583b 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -14,11 +14,11 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenLocalLoadTests { @Test public void localLoadPushesLocalOntoStack(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.localLoad("x"); + var shid = Shid.localLoad("x"); var context = PatioCodeGenContext.EMPTY - .defineStackIrParam("x"); + .defineShidParam("x"); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java index dd37b35f..00b50c44 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,13 +15,13 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenLocalStoreTests { @Test public void localStorePopsTemporaryIntoLocal(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.localStore("x"); + var shid = Shid.localStore("x"); var context = PatioCodeGenContext.EMPTY - .declareStackIrVal("x", PatioCodeGenTypes.VALUE_TYPE).context() + .declareShidVal("x", PatioCodeGenTypes.VALUE_TYPE).context() .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopBreakTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopBreakTests.java index 76a3799c..16ab525d 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopBreakTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopBreakTests.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -14,7 +14,7 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenLoopBreakTests { @Test public void canGenerateCodeForLoopBreak(Snapshotter snapshotter) throws IOException { - var instruction = Instructions.loopBreak(); + var instruction = Shid.loopBreak(); var context = PatioCodeGenContext.EMPTY; var result = PatioCodeGen.generateInstruction(instruction, context); diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopContinueTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopContinueTests.java index 281f6dcd..0e9372fc 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopContinueTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopContinueTests.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -14,7 +14,7 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenLoopContinueTests { @Test public void canGenerateCodeForLoopContinue(Snapshotter snapshotter) throws IOException { - var instruction = Instructions.loopContinue(); + var instruction = Shid.loopContinue(); var context = PatioCodeGenContext.EMPTY; var result = PatioCodeGen.generateInstruction(instruction, context); diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopTests.java index ff74a17b..6a9648db 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopTests.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,10 +15,10 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenLoopTests { @Test public void canGenerateCodeForLoop(Snapshotter snapshotter) throws IOException { - var instruction = Instructions.loop( + var instruction = Shid.loop( List.of( - Instructions.pushInt(1), - Instructions.discard() + Shid.pushInt(1), + Shid.discard() ) ); var context = PatioCodeGenContext.EMPTY; diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceFieldStoreTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceFieldStoreTests.java index c905d0ce..254249e0 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceFieldStoreTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceFieldStoreTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; import org.shedlang.compiler.typechecker.TypeCheckerContext; @@ -21,7 +21,7 @@ public class PatioCodeGenNamespaceFieldStoreTests { @Test public void canGenerateCodeForNamespaceFieldStore(Snapshotter snapshotter) throws IOException { var namespaceName = new NamespaceName(List.of("Example", "Project")); - var stackIrInstruction = Instructions.namespaceFieldStore(namespaceName, "y"); + var shidInstruction = Shid.namespaceFieldStore(namespaceName, "y"); var typeInfo = TypeCheckerContext.EMPTY .addNamespaceTypeInfo( namespaceName, @@ -36,7 +36,7 @@ public class PatioCodeGenNamespaceFieldStoreTests { .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); - var result = PatioCodeGen.generateInstruction(stackIrInstruction, context); + var result = PatioCodeGen.generateInstruction(shidInstruction, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceImportTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceImportTests.java index 705e90dc..f86388cb 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceImportTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceImportTests.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; import org.shedlang.compiler.types.NamespaceName; @@ -17,7 +17,7 @@ public class PatioCodeGenNamespaceImportTests { @Test public void canGenerateCodeForNamespaceImport(Snapshotter snapshotter) throws IOException { var namespaceName = new NamespaceName(List.of("Example", "Project")); - var instruction = Instructions.namespaceImport(namespaceName); + var instruction = Shid.namespaceImport(namespaceName); var context = PatioCodeGenContext.EMPTY; var result = PatioCodeGen.generateInstruction(instruction, context); diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java index 2a3154ef..852eda6f 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java @@ -4,10 +4,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.ast.typed.FreeVariables; import org.shedlang.compiler.sources.Sources; -import org.shedlang.compiler.stackir.StackIrNamespace; -import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; -import org.shedlang.compiler.stackir.instructions.Instruction; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.ShidNamespace; +import org.shedlang.compiler.shid.instructions.ShidDefineFunction; +import org.shedlang.compiler.shid.instructions.ShidInstruction; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; import org.shedlang.compiler.typechecker.TypeInfos; @@ -24,18 +24,18 @@ import static org.shedlang.compiler.patio.PatioTesting.serializeCompilationUnit; public class PatioCodeGenNamespaceTests { @Test public void canDefineNamespace(Snapshotter snapshotter) throws IOException { - var instruction = new DefineFunctionInstruction( + var instruction = new ShidDefineFunction( "f", List.of(), List.of(), FreeVariables.empty(), List.of( - Instructions.pushUnit(), - Instructions.return_() + Shid.pushUnit(), + Shid.return_() ), Sources.NULL ); - var instructions = List.<Instruction>of(instruction); + var instructions = List.<ShidInstruction>of(instruction); var namespaceName = NamespaceName.of("An","Example"); var typeInfos = TypeInfos.EMPTY .addNamespaceTypeInfo( @@ -46,9 +46,9 @@ public class PatioCodeGenNamespaceTests { .build() ); var context = PatioCodeGenContext.forTypeInfos(typeInfos); - var stackIrNamespace = new StackIrNamespace(namespaceName, instructions); + var shidNamespace = new ShidNamespace(namespaceName, instructions); - var result = PatioCodeGen.generateNamespace(stackIrNamespace, context); + var result = PatioCodeGen.generateNamespace(shidNamespace, context); snapshotter.assertSnapshot(serializeCompilationUnit(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushBoolTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushBoolTests.java index 8045decf..4b3c869c 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushBoolTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushBoolTests.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -14,20 +14,20 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenPushBoolTests { @Test public void pushBoolFalseInstructionGeneratesIntGetZeroInstruction(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.pushBool(false); + var shid = Shid.pushBool(false); var context = PatioCodeGenContext.EMPTY; - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } @Test public void pushBoolTrueInstructionGeneratesIntGetOneInstruction(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.pushBool(true); + var shid = Shid.pushBool(true); var context = PatioCodeGenContext.EMPTY; - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java index b1790fda..0996f981 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -14,10 +14,10 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenPushIntTests { @Test public void pushIntInstructionGeneratesIntGetInstruction(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.pushInt(42); + var shid = Shid.pushInt(42); var context = PatioCodeGenContext.EMPTY; - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushStringTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushStringTests.java index 28989deb..3a878afe 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushStringTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushStringTests.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -14,10 +14,10 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenPushStringTests { @Test public void pushStringIsCompiledToDataAndIndexToData(Snapshotter snapshotter) throws IOException { - var stackIrInstruction = Instructions.pushString("hello"); + var shidInstruction = Shid.pushString("hello"); var context = PatioCodeGenContext.EMPTY; - var result = PatioCodeGen.generateInstruction(stackIrInstruction, context); + var result = PatioCodeGen.generateInstruction(shidInstruction, context); snapshotter.assertSnapshot(serialize(result)); } @@ -26,8 +26,8 @@ public class PatioCodeGenPushStringTests { public void canHaveMultipleStrings(Snapshotter snapshotter) throws IOException { var context = PatioCodeGenContext.EMPTY; - var result = PatioCodeGen.generateInstruction(Instructions.pushString("hello"), context); - result = PatioCodeGen.generateInstruction(Instructions.pushString("world"), result); + var result = PatioCodeGen.generateInstruction(Shid.pushString("hello"), context); + result = PatioCodeGen.generateInstruction(Shid.pushString("world"), result); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushUnitTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushUnitTests.java index 3aec3619..d1aa4bd8 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushUnitTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushUnitTests.java @@ -2,7 +2,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -14,10 +14,10 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenPushUnitTests { @Test public void pushUnitInstructionGeneratesIntGetInstruction(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.pushUnit(); + var shid = Shid.pushUnit(); var context = PatioCodeGenContext.EMPTY; - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java index 5f23b926..57d16015 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,12 +15,12 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenResumeTests { @Test public void resumeInstructionGeneratesResumeInstruction(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.resume(); + var shid = Shid.resume(); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java index 760f23e8..9a7166c5 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,12 +15,12 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenReturnTests { @Test public void returnInstructionGeneratesReturnInstruction(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.return_(); + var shid = Shid.return_(); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenStringAddTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenStringAddTests.java index 0ff8dade..8eb09cb7 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenStringAddTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenStringAddTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,13 +15,13 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenStringAddTests { @Test public void canGenerateCodeForStringAdd(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.stringAdd(); + var shid = Shid.stringAdd(); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")) .temporaryPush(new PatioLocalRef("c")); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenSwitchTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenSwitchTests.java index 979743e3..58463cb4 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenSwitchTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenSwitchTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; import org.shedlang.compiler.typechecker.TypeInfos; @@ -23,22 +23,22 @@ public class PatioCodeGenSwitchTests { var namespaceName = NamespaceName.of("Example", "Project"); var structType1 = Types.struct(namespaceName, "A"); var structType2 = Types.struct(namespaceName, "B"); - var instruction = Instructions.switch_( + var instruction = Shid.switch_( List.of( - Instructions.switchCase( + Shid.switchCase( structType1, List.of( - Instructions.pushInt(1), - Instructions.pushInt(2), - Instructions.intAdd() + Shid.pushInt(1), + Shid.pushInt(2), + Shid.intAdd() ) ), - Instructions.switchCase( + Shid.switchCase( structType2, List.of( - Instructions.pushInt(101), - Instructions.pushInt(102), - Instructions.intAdd() + Shid.pushInt(101), + Shid.pushInt(102), + Shid.intAdd() ) ) ) diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java index 1a9535d1..f534534c 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; import org.shedlang.compiler.typechecker.TypeCheckerContext; @@ -20,11 +20,11 @@ public class PatioCodeGenTryTests { public void canGenerateCodeForTry(Snapshotter snapshotter) throws IOException { var namespaceName = new NamespaceName(List.of("Example", "Project")); var effect = Effects.userDefined(namespaceName, "State"); - var stackIrInstruction = Instructions.try_( + var shidInstruction = Shid.try_( effect, List.of("a", "c", "b"), List.of( - Instructions.pushInt(42) + Shid.pushInt(42) ) ); var typeInfos = TypeCheckerContext.EMPTY @@ -43,7 +43,7 @@ public class PatioCodeGenTryTests { .temporaryPush(new PatioLocalRef("handlerC")) .temporaryPush(new PatioLocalRef("handlerB")); - var result = PatioCodeGen.generateInstruction(stackIrInstruction, context); + var result = PatioCodeGen.generateInstruction(shidInstruction, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleCreateTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleCreateTests.java index e489fb37..d5cb6ef1 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleCreateTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleCreateTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,24 +15,24 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenTupleCreateTests { @Test public void canGenerateCodeForTupleCreate(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.tupleCreate(3); + var shid = Shid.tupleCreate(3); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")) .temporaryPush(new PatioLocalRef("c")) .temporaryPush(new PatioLocalRef("d")); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } @Test public void zeroElementTupleIsCreatedWithoutAlloc(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.tupleCreate(0); + var shid = Shid.tupleCreate(0); var context = PatioCodeGenContext.EMPTY; - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleGetTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleGetTests.java index fc1cf272..41a037b0 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleGetTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTupleGetTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,12 +15,12 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenTupleGetTests { @Test public void canGenerateCodeForTupleGet(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.tupleGet(2, 3); + var shid = Shid.tupleGet(2, 3); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarLoadTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarLoadTests.java index 4cff0dd4..3eae5cf9 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarLoadTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarLoadTests.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.types.PatioTypes; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -15,11 +15,11 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenVarLoadTests { @Test public void canGenerateCodeForVarLoad(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.varLoad("x"); + var shid = Shid.varLoad("x"); var context = PatioCodeGenContext.EMPTY - .declareStackIrVal("x", PatioTypes.DATA_POINTER).context(); + .declareShidVal("x", PatioTypes.DATA_POINTER).context(); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarStoreTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarStoreTests.java index 66038785..4f9d4430 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarStoreTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarStoreTests.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; import org.shedlang.compiler.patio.ast.types.PatioTypes; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; @@ -16,27 +16,27 @@ import static org.shedlang.compiler.patio.PatioTesting.serialize; public class PatioCodeGenVarStoreTests { @Test public void canGenerateCodeForVarStore(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.varStore("x"); + var shid = Shid.varStore("x"); var context = PatioCodeGenContext.EMPTY - .declareStackIrVal("x", PatioTypes.DATA_POINTER).context() + .declareShidVal("x", PatioTypes.DATA_POINTER).context() .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); - var result = PatioCodeGen.generateInstruction(stackIr, context); + var result = PatioCodeGen.generateInstruction(shid, context); snapshotter.assertSnapshot(serialize(result)); } @Test public void canStoreIntoVarMultipleTimes(Snapshotter snapshotter) throws IOException { - var stackIr = Instructions.varStore("x"); + var shid = Shid.varStore("x"); var context = PatioCodeGenContext.EMPTY - .declareStackIrVal("x", PatioTypes.DATA_POINTER).context() + .declareShidVal("x", PatioTypes.DATA_POINTER).context() .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); - var result = PatioCodeGen.generateInstruction(stackIr, context); - result = PatioCodeGen.generateInstruction(stackIr, result); + var result = PatioCodeGen.generateInstruction(shid, context); + result = PatioCodeGen.generateInstruction(shid, result); snapshotter.assertSnapshot(serialize(result)); } diff --git a/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java b/src/test/java/org/shedlang/compiler/shid/InstructionSerializerTests.java index c36977cf..9f6bdcf1 100644 --- a/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java +++ b/src/test/java/org/shedlang/compiler/shid/InstructionSerializerTests.java @@ -1,9 +1,9 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; -import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; -import org.shedlang.compiler.stackir.instructions.Instruction; -import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.shid.instructions.ShidDefineFunction; +import org.shedlang.compiler.shid.instructions.ShidInstruction; +import org.shedlang.compiler.shid.instructions.Shid; import org.shedlang.compiler.types.Effects; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.Types; @@ -16,7 +16,7 @@ import static org.zwobble.precisely.Matchers.equalTo; public class InstructionSerializerTests { @Test public void canSerializeCall() { - var instruction = Instructions.call(1, List.of("x", "y")); + var instruction = Shid.call(1, List.of("x", "y")); var string = serialize(instruction); @@ -25,7 +25,7 @@ public class InstructionSerializerTests { @Test public void canSerializeDefineEffect() { - var instruction = Instructions.defineEffect( + var instruction = Shid.defineEffect( Effects.userDefined(NamespaceName.of("Example", "Project"), "State") ); @@ -38,7 +38,7 @@ public class InstructionSerializerTests { @Test public void canSerializeDefineFunction() { - var instruction = DefineFunctionInstruction.builder() + var instruction = ShidDefineFunction.builder() .withName("f") .addPositionalParam("p1") .addPositionalParam("p2") @@ -46,8 +46,8 @@ public class InstructionSerializerTests { .addNamedParam("n2") .addFreeVariable("fv1") .addFreeVariable("fv2") - .addBodyInstruction(Instructions.pushBool(true)) - .addBodyInstruction(Instructions.pushBool(false)) + .addBodyInstruction(Shid.pushBool(true)) + .addBodyInstruction(Shid.pushBool(false)) .build(); var string = serialize(instruction); @@ -68,11 +68,11 @@ public class InstructionSerializerTests { @Test public void canSerializeDefineStruct() { - var instruction = Instructions.defineStruct( + var instruction = Shid.defineStruct( Types.struct(NamespaceName.of("Example", "Project"), "User"), List.of( - Instructions.defineStructField("name"), - Instructions.defineStructField("id") + Shid.defineStructField("name"), + Shid.defineStructField("id") ) ); @@ -88,7 +88,7 @@ public class InstructionSerializerTests { @Test public void canSerializeDiscard() { - var instruction = Instructions.discard(); + var instruction = Shid.discard(); var string = serialize(instruction); @@ -97,7 +97,7 @@ public class InstructionSerializerTests { @Test public void canSerializeDuplicate() { - var instruction = Instructions.duplicate(); + var instruction = Shid.duplicate(); var string = serialize(instruction); @@ -106,7 +106,7 @@ public class InstructionSerializerTests { @Test public void canSerializeNamespaceFieldLoad() { - var instruction = Instructions.fieldLoad( + var instruction = Shid.fieldLoad( new NamespaceName(List.of("Example", "Lib")), "x" ); @@ -118,7 +118,7 @@ public class InstructionSerializerTests { @Test public void canSerializeStructFieldLoad() { - var instruction = Instructions.fieldLoad( + var instruction = Shid.fieldLoad( Types.struct(NamespaceName.of("Example", "Project"), "User"), "name" ); @@ -130,7 +130,7 @@ public class InstructionSerializerTests { @Test public void canSerializeUserDefinedEffectFieldLoad() { - var instruction = Instructions.fieldLoad( + var instruction = Shid.fieldLoad( Effects.userDefined(NamespaceName.of("Example", "Project"), "State"), "read" ); @@ -142,15 +142,15 @@ public class InstructionSerializerTests { @Test public void canSerializeIf() { - var instruction = Instructions.if_( + var instruction = Shid.if_( 1, List.of( - Instructions.pushUnit() + Shid.pushUnit() ), List.of( - Instructions.localLoad("x"), - Instructions.discard(), - Instructions.pushBool(true) + Shid.localLoad("x"), + Shid.discard(), + Shid.pushBool(true) ) ); @@ -173,7 +173,7 @@ public class InstructionSerializerTests { @Test public void canSerializeIntAdd() { - var instruction = Instructions.intAdd(); + var instruction = Shid.intAdd(); var string = serialize(instruction); @@ -182,7 +182,7 @@ public class InstructionSerializerTests { @Test public void canSerializeIntEquals() { - var instruction = Instructions.intEquals(); + var instruction = Shid.intEquals(); var string = serialize(instruction); @@ -191,7 +191,7 @@ public class InstructionSerializerTests { @Test public void canSerializeIntNotEqual() { - var instruction = Instructions.intNotEqual(); + var instruction = Shid.intNotEqual(); var string = serialize(instruction); @@ -200,7 +200,7 @@ public class InstructionSerializerTests { @Test public void canSerializeIntSub() { - var instruction = Instructions.intSub(); + var instruction = Shid.intSub(); var string = serialize(instruction); @@ -209,7 +209,7 @@ public class InstructionSerializerTests { @Test public void canSerializeLocalLoad() { - var instruction = Instructions.localLoad("x"); + var instruction = Shid.localLoad("x"); var string = serialize(instruction); @@ -218,7 +218,7 @@ public class InstructionSerializerTests { @Test public void canSerializeLocalStore() { - var instruction = Instructions.localStore("x"); + var instruction = Shid.localStore("x"); var string = serialize(instruction); @@ -227,10 +227,10 @@ public class InstructionSerializerTests { @Test public void canSerializeLoop() { - var instruction = Instructions.loop( + var instruction = Shid.loop( List.of( - Instructions.localLoad("x"), - Instructions.discard() + Shid.localLoad("x"), + Shid.discard() ) ); @@ -248,7 +248,7 @@ public class InstructionSerializerTests { @Test public void canSerializeLoopBreak() { - var instruction = Instructions.loopBreak(); + var instruction = Shid.loopBreak(); var string = serialize(instruction); @@ -257,7 +257,7 @@ public class InstructionSerializerTests { @Test public void canSerializeLoopContinue() { - var instruction = Instructions.loopContinue(); + var instruction = Shid.loopContinue(); var string = serialize(instruction); @@ -266,7 +266,7 @@ public class InstructionSerializerTests { @Test public void canSerializeNamespaceFieldStore() { - var instruction = Instructions.namespaceFieldStore( + var instruction = Shid.namespaceFieldStore( new NamespaceName(List.of("Example", "Lib")), "x" ); @@ -278,7 +278,7 @@ public class InstructionSerializerTests { @Test public void canSerializeNamespaceImport() { - var instruction = Instructions.namespaceImport( + var instruction = Shid.namespaceImport( new NamespaceName(List.of("Example", "Lib")) ); @@ -289,7 +289,7 @@ public class InstructionSerializerTests { @Test public void canSerializePushBool() { - var instruction = Instructions.pushBool(true); + var instruction = Shid.pushBool(true); var string = serialize(instruction); @@ -298,7 +298,7 @@ public class InstructionSerializerTests { @Test public void canSerializePushInt() { - var instruction = Instructions.pushInt(42); + var instruction = Shid.pushInt(42); var string = serialize(instruction); @@ -307,7 +307,7 @@ public class InstructionSerializerTests { @Test public void canSerializePushString() { - var instruction = Instructions.pushString("hello"); + var instruction = Shid.pushString("hello"); var string = serialize(instruction); @@ -316,7 +316,7 @@ public class InstructionSerializerTests { @Test public void specialCharactersInStringAreEscaped() { - var instruction = Instructions.pushString("\b\t\n\f\r\"\\"); + var instruction = Shid.pushString("\b\t\n\f\r\"\\"); var string = serialize(instruction); @@ -325,7 +325,7 @@ public class InstructionSerializerTests { @Test public void canSerializePushUnit() { - var instruction = Instructions.pushUnit(); + var instruction = Shid.pushUnit(); var string = serialize(instruction); @@ -334,7 +334,7 @@ public class InstructionSerializerTests { @Test public void canSerializeResume() { - var instruction = Instructions.resume(); + var instruction = Shid.resume(); var string = serialize(instruction); @@ -343,7 +343,7 @@ public class InstructionSerializerTests { @Test public void canSerializeReturn() { - var instruction = Instructions.return_(); + var instruction = Shid.return_(); var string = serialize(instruction); @@ -352,7 +352,7 @@ public class InstructionSerializerTests { @Test public void canSerializeStringAdd() { - var instruction = Instructions.stringAdd(); + var instruction = Shid.stringAdd(); var string = serialize(instruction); @@ -361,17 +361,17 @@ public class InstructionSerializerTests { @Test public void canSerializeSwitch() { - var instruction = Instructions.switch_(List.of( - Instructions.switchCase( + var instruction = Shid.switch_(List.of( + Shid.switchCase( Types.struct(NamespaceName.of("Example", "Project"), "A"), List.of( - Instructions.return_() + Shid.return_() ) ), - Instructions.switchCase( + Shid.switchCase( Types.struct(NamespaceName.of("Example", "Project"), "B"), List.of( - Instructions.discard() + Shid.discard() ) ) )); @@ -401,11 +401,11 @@ public class InstructionSerializerTests { @Test public void canSerializeTry() { var effect = Effects.userDefined(NamespaceName.of("Example", "Project"), "State"); - var instruction = Instructions.try_( + var instruction = Shid.try_( effect, List.of("read", "write"), List.of( - Instructions.pushUnit() + Shid.pushUnit() ) ); @@ -427,7 +427,7 @@ public class InstructionSerializerTests { @Test public void canSerializeTupleCreate() { - var instruction = Instructions.tupleCreate(2); + var instruction = Shid.tupleCreate(2); var string = serialize(instruction); @@ -436,7 +436,7 @@ public class InstructionSerializerTests { @Test public void canSerializeTupleGet() { - var instruction = Instructions.tupleGet(2, 3); + var instruction = Shid.tupleGet(2, 3); var string = serialize(instruction); @@ -445,7 +445,7 @@ public class InstructionSerializerTests { @Test public void canSerializeVarLoad() { - var instruction = Instructions.varLoad("x"); + var instruction = Shid.varLoad("x"); var string = serialize(instruction); @@ -454,14 +454,14 @@ public class InstructionSerializerTests { @Test public void canSerializeVarStore() { - var instruction = Instructions.varStore("x"); + var instruction = Shid.varStore("x"); var string = serialize(instruction); assertThat(string, equalTo("(var-store \"x\")")); } - private String serialize(Instruction instruction) { + private String serialize(ShidInstruction instruction) { var builder = new StringBuilder(); InstructionSerializer.serializeInstruction(instruction, builder); return builder.toString(); diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerAssignTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenAssignTests.java index 431556a0..65e30e5a 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerAssignTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenAssignTests.java @@ -1,25 +1,25 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; import java.util.List; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerAssignTests { +public class ShidCodeGenAssignTests { @Test public void targetIgnoreIsCompiledToDiscard() { var node = Typed.assign( Typed.targetIgnore(), Typed.reference("x") ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("x"); - var result = StackCompiler.compileFunctionStatement(node, context); + var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( isLocalLoadInstruction("x__0"), @@ -33,10 +33,10 @@ public class StackCompilerAssignTests { Typed.targetReassign("x"), Typed.stringLiteral("hello") ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("x"); - var result = StackCompiler.compileFunctionStatement(node, context); + var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( isPushStringInstruction("hello"), @@ -54,13 +54,13 @@ public class StackCompilerAssignTests { )), Typed.reference("x") ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("x") .addShedVal("a") .addShedVal("b") .addShedVal("c"); - var result = StackCompiler.compileFunctionStatement(node, context); + var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( isLocalLoadInstruction("x__0"), @@ -81,10 +81,10 @@ public class StackCompilerAssignTests { Typed.targetTuple(List.of()), Typed.reference("x") ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("x"); - var result = StackCompiler.compileFunctionStatement(node, context); + var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( isLocalLoadInstruction("x__0"), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerBlockReturnTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBlockReturnTests.java index df738405..082560b7 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerBlockReturnTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBlockReturnTests.java @@ -1,19 +1,19 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isPushStringInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushStringInstruction; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerBlockReturnTests { +public class ShidCodeGenBlockReturnTests { @Test public void expressionIsEvaluated() { var node = Typed.blockReturn(Typed.stringLiteral("hello")); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileFunctionStatement(node, context); + var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( isPushStringInstruction("hello") diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerBoolLiteralTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBoolLiteralTests.java index ac96c48e..965f9b3c 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerBoolLiteralTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBoolLiteralTests.java @@ -1,19 +1,19 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isPushBoolInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushBoolInstruction; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerBoolLiteralTests { +public class ShidCodeGenBoolLiteralTests { @Test public void boolLiteralIsCompiledToPushBoolInstruction() { var node = Typed.boolLiteral(true); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isPushBoolInstruction(true) diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerCallTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenCallTests.java index 2cf25bb1..5d14cc31 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerCallTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenCallTests.java @@ -1,15 +1,15 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; import java.util.List; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerCallTests { +public class ShidCodeGenCallTests { @Test public void callIsCompiledToInstructionsForOperandThenCall() { var node = Typed.call( @@ -24,10 +24,10 @@ public class StackCompilerCallTests { Typed.namedArg("x1", Typed.stringLiteral("n1")) ) ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("f"); - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isLocalLoadInstruction("f__0"), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerEffectDefinitionTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenEffectDefinitionTests.java index 051c03e4..4777f5a7 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerEffectDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenEffectDefinitionTests.java @@ -1,28 +1,28 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import org.shedlang.compiler.stackir.instructions.DefineEffectInstruction; +import org.shedlang.compiler.shid.instructions.ShidDefineEffect; import org.shedlang.compiler.types.Effects; import org.shedlang.compiler.types.NamespaceName; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isLocalStoreInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isLocalStoreInstruction; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; -public class StackCompilerEffectDefinitionTests { +public class ShidCodeGenEffectDefinitionTests { @Test public void effectDefinitionIsCompiledToDefineEffectInstruction() { var effect = Effects.userDefined(NamespaceName.of("Example", "Project"), "State"); var node = Typed.effectDefinition(effect); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("State"); - var result = StackCompiler.compileNamespaceStatement(node, context); + var result = ShidCodeGen.compileNamespaceStatement(node, context); assertThat(result.instructions(), isSequence( instanceOf( - DefineEffectInstruction.class, + ShidDefineEffect.class, has("effect", x -> x.effect(), equalTo(effect)) ), isLocalStoreInstruction("State__0") diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerExpressionStatementTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenExpressionStatementTests.java index f644408b..05a47d39 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerExpressionStatementTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenExpressionStatementTests.java @@ -1,20 +1,20 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isDiscardInstruction; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isPushStringInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isDiscardInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushStringInstruction; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerExpressionStatementTests { +public class ShidCodeGenExpressionStatementTests { @Test public void expressionIsEvaluatedAndTheResultDiscarded() { var node = Typed.expressionStatement(Typed.stringLiteral("hello")); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileFunctionStatement(node, context); + var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( isPushStringInstruction("hello"), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerFieldAccessTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFieldAccessTests.java index 4c0821a6..0e869445 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerFieldAccessTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFieldAccessTests.java @@ -1,18 +1,18 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import org.shedlang.compiler.stackir.instructions.FieldLoadInstruction; +import org.shedlang.compiler.shid.instructions.ShidFieldLoad; import org.shedlang.compiler.types.Effects; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.Types; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isFieldLoadInstruction; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isLocalLoadInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isFieldLoadInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isLocalLoadInstruction; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerFieldAccessTests { +public class ShidCodeGenFieldAccessTests { @Test public void namespaceFieldAccessIsCompiledToFieldLoad() { var namespaceType = Types.namespace(NamespaceName.of("Example", "Project")); @@ -21,15 +21,15 @@ public class StackCompilerFieldAccessTests { "name", Types.STRING ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("Project"); - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isLocalLoadInstruction("Project__0"), isFieldLoadInstruction( - new FieldLoadInstruction.Receiver.Namespace(namespaceType.namespaceName()), + new ShidFieldLoad.Receiver.Namespace(namespaceType.namespaceName()), "name" ) )); @@ -43,10 +43,10 @@ public class StackCompilerFieldAccessTests { "name", Types.STRING ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("user"); - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isLocalLoadInstruction("user__0"), @@ -62,15 +62,15 @@ public class StackCompilerFieldAccessTests { "read", Types.STRING ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("State"); - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isLocalLoadInstruction("State__0"), isFieldLoadInstruction( - new FieldLoadInstruction.Receiver.Effect(effect), + new ShidFieldLoad.Receiver.Effect(effect), "read" ) )); diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerFunctionDefinitionTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionDefinitionTests.java index d28a3eb5..0f6a3835 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerFunctionDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionDefinitionTests.java @@ -1,16 +1,16 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; import org.shedlang.compiler.ast.typed.TypedFunctionDefinitionNode; -import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; +import org.shedlang.compiler.shid.instructions.ShidDefineFunction; import org.shedlang.compiler.types.Types; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; -public class StackCompilerFunctionDefinitionTests { +public class ShidCodeGenFunctionDefinitionTests { @Test public void functionIsCompiledToDefineFunctionInstruction() { var node = TypedFunctionDefinitionNode.builder() @@ -20,15 +20,15 @@ public class StackCompilerFunctionDefinitionTests { .addFreeVariable("z") .addStatement(Typed.expressionStatement(Typed.stringLiteral("hello"))) .build(); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("f") .addShedVal("z"); - var result = StackCompiler.compileNamespaceStatement(node, context); + var result = ShidCodeGen.compileNamespaceStatement(node, context); assertThat(result.instructions(), isSequence( instanceOf( - DefineFunctionInstruction.class, + ShidDefineFunction.class, has("name", x -> x.name(), equalTo("f")), has("positionalParams", x -> x.positionalParams(), isSequence( isDefineFunctionInstructionParam("x__0") @@ -56,14 +56,14 @@ public class StackCompilerFunctionDefinitionTests { .withName("f") .addStatement(Typed.blockReturn(Typed.stringLiteral("hello"))) .build(); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("f"); - var result = StackCompiler.compileNamespaceStatement(node, context); + var result = ShidCodeGen.compileNamespaceStatement(node, context); assertThat(result.instructions(), isSequence( instanceOf( - DefineFunctionInstruction.class, + ShidDefineFunction.class, has("body", x -> x.body(), isSequence( isPushStringInstruction("hello"), isReturnInstruction() diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerFunctionExpressionTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionExpressionTests.java index d14356f7..c5f78340 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerFunctionExpressionTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionExpressionTests.java @@ -1,16 +1,16 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; import org.shedlang.compiler.ast.typed.TypedFunctionExpressionNode; -import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; +import org.shedlang.compiler.shid.instructions.ShidDefineFunction; import org.shedlang.compiler.types.Types; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; -public class StackCompilerFunctionExpressionTests { +public class ShidCodeGenFunctionExpressionTests { @Test public void functionIsCompiledToDefineFunctionInstruction() { var node = TypedFunctionExpressionNode.builder() @@ -19,15 +19,15 @@ public class StackCompilerFunctionExpressionTests { .addFreeVariable("z") .addStatement(Typed.expressionStatement(Typed.stringLiteral("hello"))) .build(); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("f") .addShedVal("z"); - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( instanceOf( - DefineFunctionInstruction.class, + ShidDefineFunction.class, has("name", x -> x.name(), equalTo("anonymous")), has("positionalParams", x -> x.positionalParams(), isSequence( isDefineFunctionInstructionParam("x__0") @@ -53,14 +53,14 @@ public class StackCompilerFunctionExpressionTests { var node = TypedFunctionExpressionNode.builder() .addStatement(Typed.blockReturn(Typed.stringLiteral("hello"))) .build(); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("f"); - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( instanceOf( - DefineFunctionInstruction.class, + ShidDefineFunction.class, has("body", x -> x.body(), isSequence( isPushStringInstruction("hello"), isReturnInstruction() diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerFunctionReturnTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionReturnTests.java index 8bd5c64d..d6a63c1f 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerFunctionReturnTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionReturnTests.java @@ -1,19 +1,19 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerFunctionReturnTests { +public class ShidCodeGenFunctionReturnTests { @Test public void expressionIsEvaluatedAndReturned() { var node = Typed.functionReturn(Typed.stringLiteral("hello")); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileFunctionStatement(node, context); + var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( isPushStringInstruction("hello"), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIfTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIfTests.java index dca0be02..f1f81e95 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIfTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIfTests.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; @@ -6,11 +6,11 @@ import org.shedlang.compiler.types.Types; import java.util.List; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerIfTests { +public class ShidCodeGenIfTests { @Test public void ifWithSingleConditionalBranchIsCompiledToSingleIfInstruction() { var node = Typed.if_( @@ -27,10 +27,10 @@ public class StackCompilerIfTests { )), Types.INT ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("c"); - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isLocalLoadInstruction("c__0"), @@ -68,11 +68,11 @@ public class StackCompilerIfTests { )), Types.INT ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("c") .addShedVal("d"); - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isLocalLoadInstruction("c__0"), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntAddTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntAddTests.java index 4724b867..4ff0e6eb 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntAddTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntAddTests.java @@ -1,23 +1,23 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isIntAddInstruction; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isPushIntInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isIntAddInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushIntInstruction; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerIntAddTests { +public class ShidCodeGenIntAddTests { @Test public void intAddIsCompiledToIntAddInstruction() { var node = Typed.intAdd( Typed.intLiteral(42), Typed.intLiteral(47) ); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isPushIntInstruction(42), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntEqualsTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntEqualsTests.java index 61eb93f9..464e73f4 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntEqualsTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntEqualsTests.java @@ -1,22 +1,22 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerIntEqualsTests { +public class ShidCodeGenIntEqualsTests { @Test public void intEqualsIsCompiledToIntEqualsInstruction() { var node = Typed.intEquals( Typed.intLiteral(42), Typed.intLiteral(47) ); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isPushIntInstruction(42), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntLiteralTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntLiteralTests.java index 402c6dac..ed95e765 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntLiteralTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntLiteralTests.java @@ -1,19 +1,19 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isPushIntInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushIntInstruction; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerIntLiteralTests { +public class ShidCodeGenIntLiteralTests { @Test public void intLiteralIsCompiledToPushIntInstruction() { var node = Typed.intLiteral(42); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isPushIntInstruction(42) diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntNotEqualTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntNotEqualTests.java index 8364bc81..9c55f222 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntNotEqualTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntNotEqualTests.java @@ -1,22 +1,22 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerIntNotEqualTests { +public class ShidCodeGenIntNotEqualTests { @Test public void intNotEqualsIsCompiledToIntNotEqualInstruction() { var node = Typed.intNotEqual( Typed.intLiteral(42), Typed.intLiteral(47) ); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isPushIntInstruction(42), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntSubTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntSubTests.java index 110be63a..df3e9791 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntSubTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntSubTests.java @@ -1,22 +1,22 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerIntSubTests { +public class ShidCodeGenIntSubTests { @Test public void intSubIsCompiledToIntSubInstruction() { var node = Typed.intSub( Typed.intLiteral(42), Typed.intLiteral(47) ); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isPushIntInstruction(42), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerNamespaceTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNamespaceTests.java index 322bf49f..f56ba972 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerNamespaceTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNamespaceTests.java @@ -1,18 +1,18 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.*; -import org.shedlang.compiler.stackir.instructions.*; +import org.shedlang.compiler.shid.instructions.*; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.Types; import java.util.List; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; -public class StackCompilerNamespaceTests { +public class ShidCodeGenNamespaceTests { @Test public void bodyOfNamespaceIsCompiledWithNamesBeingExported() { var namespaceName = new NamespaceName(List.of("Example")); @@ -31,16 +31,16 @@ public class StackCompilerNamespaceTests { List.of("f") ); - var stackIrNamespace = StackCompiler.compileNamespace(node); + var shidNamespace = ShidCodeGen.compileNamespace(node); - assertThat(stackIrNamespace.instructions(), isSequence( + assertThat(shidNamespace.instructions(), isSequence( // TODO: test the builtin loading properly - instanceOf(NamespaceImportInstruction.class), - instanceOf(FieldLoadInstruction.class), - instanceOf(LocalStoreInstruction.class), + instanceOf(ShidNamespaceImport.class), + instanceOf(ShidFieldLoad.class), + instanceOf(ShidLocalStore.class), instanceOf( - DefineFunctionInstruction.class, + ShidDefineFunction.class, has("name", x -> x.name(), equalTo("f")) ), isLocalStoreInstruction("f__0"), @@ -58,13 +58,13 @@ public class StackCompilerNamespaceTests { .addBoundVariable(BoundVariable.immutable("B")) .build(); - var stackIrNamespace = StackCompiler.compileNamespace(node); + var shidNamespace = ShidCodeGen.compileNamespace(node); - assertThat(stackIrNamespace.instructions(), isSequence( + assertThat(shidNamespace.instructions(), isSequence( // TODO: test the builtin loading properly - instanceOf(NamespaceImportInstruction.class), - instanceOf(FieldLoadInstruction.class), - instanceOf(LocalStoreInstruction.class), + instanceOf(ShidNamespaceImport.class), + instanceOf(ShidFieldLoad.class), + instanceOf(ShidLocalStore.class), isNamespaceImportInstruction(NamespaceName.of("A")), isLocalStoreInstruction("A__0"), @@ -91,21 +91,21 @@ public class StackCompilerNamespaceTests { List.of("f", "None") ); - var stackIrNamespace = StackCompiler.compileNamespace(node); + var shidNamespace = ShidCodeGen.compileNamespace(node); - assertThat(stackIrNamespace.instructions(), isSequence( + assertThat(shidNamespace.instructions(), isSequence( // TODO: test the builtin loading properly - instanceOf(NamespaceImportInstruction.class), - instanceOf(FieldLoadInstruction.class), - instanceOf(LocalStoreInstruction.class), + instanceOf(ShidNamespaceImport.class), + instanceOf(ShidFieldLoad.class), + instanceOf(ShidLocalStore.class), instanceOf( - DefineStructInstruction.class, + ShidDefineStruct.class, has("type", x -> x.type(), equalTo(structType)) ), isLocalStoreInstruction("None__0"), instanceOf( - DefineFunctionInstruction.class, + ShidDefineFunction.class, has("name", x -> x.name(), equalTo("f")) ), isLocalStoreInstruction("f__0"), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerReferenceTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenReferenceTests.java index 038351c4..2a30266b 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerReferenceTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenReferenceTests.java @@ -1,21 +1,21 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.BoundVariable; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerReferenceTests { +public class ShidCodeGenReferenceTests { @Test public void referenceIsCompiledToLocalLoad() { var node = Typed.reference("x"); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVariable(BoundVariable.immutable("x")); - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isLocalLoadInstruction("x__0") @@ -25,14 +25,14 @@ public class StackCompilerReferenceTests { @Test public void whenLocalIsVarThenReferenceIsCompiledToVarLoad() { var node = Typed.reference("x"); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVariable(BoundVariable.mutable("x")); - context = StackCompiler.compileFunctionStatement( + context = ShidCodeGen.compileFunctionStatement( Typed.var("x", Typed.intLiteral(0)), context ); - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isPushIntInstruction(0), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerResumeTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenResumeTests.java index 8ee1f909..6992783d 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerResumeTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenResumeTests.java @@ -1,19 +1,19 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerResumeTests { +public class ShidCodeGenResumeTests { @Test public void expressionIsEvaluatedAndReturned() { var node = Typed.resume(Typed.stringLiteral("hello")); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileFunctionStatement(node, context); + var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( isPushStringInstruction("hello"), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerStringAddTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStringAddTests.java index 42557970..56b2750e 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerStringAddTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStringAddTests.java @@ -1,22 +1,22 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerStringAddTests { +public class ShidCodeGenStringAddTests { @Test public void stringAddIsCompiledToStringAddInstruction() { var node = Typed.stringAdd( Typed.stringLiteral("a"), Typed.stringLiteral("b") ); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isPushStringInstruction("a"), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerStringLiteralTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStringLiteralTests.java index 44133713..b308c300 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerStringLiteralTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStringLiteralTests.java @@ -1,19 +1,19 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isPushStringInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushStringInstruction; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerStringLiteralTests { +public class ShidCodeGenStringLiteralTests { @Test public void stringLiteralIsCompiledToPushStringInstruction() { var node = Typed.stringLiteral("hello"); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isPushStringInstruction("hello") diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerStructDefinitionTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStructDefinitionTests.java index 6dc845bd..4e989e9b 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerStructDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStructDefinitionTests.java @@ -1,17 +1,17 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; import org.shedlang.compiler.ast.typed.TypedStructDefinitionNode; -import org.shedlang.compiler.stackir.instructions.DefineStructInstruction; +import org.shedlang.compiler.shid.instructions.ShidDefineStruct; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.Types; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isLocalStoreInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isLocalStoreInstruction; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; -public class StackCompilerStructDefinitionTests { +public class ShidCodeGenStructDefinitionTests { @Test public void structDefinitionIsCompiledToDefineStructInstruction() { var structType = Types.struct(NamespaceName.of("Example", "Project"), "User"); @@ -20,14 +20,14 @@ public class StackCompilerStructDefinitionTests { .addField(Typed.structFieldDefinition("name", Typed.typeLevelReference("String", Types.STRING))) .addField(Typed.structFieldDefinition("isActive", Typed.typeLevelReference("Bool", Types.BOOL))) .build(); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("User"); - var result = StackCompiler.compileNamespaceStatement(node, context); + var result = ShidCodeGen.compileNamespaceStatement(node, context); assertThat(result.instructions(), isSequence( instanceOf( - DefineStructInstruction.class, + ShidDefineStruct.class, has("type", x -> x.type(), equalTo(structType)), has("fields", x -> x.fields(), isSequence( has("name", x -> x.name(), equalTo("name")), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerSumTypeDefinitionTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenSumTypeDefinitionTests.java index 849e2df7..74521d29 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerSumTypeDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenSumTypeDefinitionTests.java @@ -1,26 +1,26 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.Types; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isLocalStoreInstruction; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isPushUnitInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isLocalStoreInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushUnitInstruction; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerSumTypeDefinitionTests { +public class ShidCodeGenSumTypeDefinitionTests { @Test public void sumTypeDefinitionIsCompiledToUnit() { // TODO: this is a bit of a hack, we probably want to be able to have // sum types in some potential backends (e.g. the JVM) var sumType = Types.sum(NamespaceName.of("Example", "Project"), "Option"); var node = Typed.sumTypeDefinition(sumType); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("Option"); - var result = StackCompiler.compileNamespaceStatement(node, context); + var result = ShidCodeGen.compileNamespaceStatement(node, context); assertThat(result.instructions(), isSequence( isPushUnitInstruction(), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerTryTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenTryTests.java index f4e87f8f..daff19b0 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerTryTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenTryTests.java @@ -1,19 +1,19 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; import org.shedlang.compiler.ast.typed.TypedTryHandlerMethodNode; import org.shedlang.compiler.ast.typed.TypedTryNode; -import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; -import org.shedlang.compiler.stackir.instructions.TryInstruction; +import org.shedlang.compiler.shid.instructions.ShidDefineFunction; +import org.shedlang.compiler.shid.instructions.ShidTry; import org.shedlang.compiler.types.Effects; import org.shedlang.compiler.types.NamespaceName; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isPushIntInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushIntInstruction; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; -public class StackCompilerTryTests { +public class ShidCodeGenTryTests { @Test public void tryNodeIsCompiledToTryInstruction() { var effect = Effects.userDefined(NamespaceName.of("Example"), "State"); @@ -33,22 +33,22 @@ public class StackCompilerTryTests { .build() ) .build(); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("c"); - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( instanceOf( - DefineFunctionInstruction.class, + ShidDefineFunction.class, has("name", x -> x.name(), equalTo("read")) ), instanceOf( - DefineFunctionInstruction.class, + ShidDefineFunction.class, has("name", x -> x.name(), equalTo("write")) ), instanceOf( - TryInstruction.class, + ShidTry.class, has("handledEffect", x -> x.handledEffect(), equalTo(effect)), has("handlerMethodNames", x -> x.handlerMethodNames(), isSequence( equalTo("read"), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerTupleTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenTupleTests.java index f05e9257..c3194182 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerTupleTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenTupleTests.java @@ -1,15 +1,15 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; import java.util.List; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerTupleTests { +public class ShidCodeGenTupleTests { @Test public void stringAddIsCompiledToStringAddInstruction() { var node = Typed.tuple(List.of( @@ -17,9 +17,9 @@ public class StackCompilerTupleTests { Typed.boolLiteral(true), Typed.intLiteral(4) )); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isPushStringInstruction("a"), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerUnitLiteralTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenUnitLiteralTests.java index 024b9561..27b7ed6c 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerUnitLiteralTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenUnitLiteralTests.java @@ -1,19 +1,19 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isPushUnitInstruction; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushUnitInstruction; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerUnitLiteralTests { +public class ShidCodeGenUnitLiteralTests { @Test public void unitLiteralIsCompiledToPushUnitInstruction() { var node = Typed.unitLiteral(); - var context = StackCompiler.Context.EMPTY; + var context = ShidCodeGen.Context.EMPTY; - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isPushUnitInstruction() diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerValTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenValTests.java index 2e6194ca..5007e1e8 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerValTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenValTests.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.BoundVariable; @@ -7,18 +7,18 @@ import org.shedlang.compiler.types.Types; import java.util.List; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerValTests { +public class ShidCodeGenValTests { @Test public void whenValIsFunctionStatementThenExpressionIsEvaluatedAndStoredAsLocal() { var node = Typed.val("x", Typed.stringLiteral("hello")); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("x"); - var result = StackCompiler.compileFunctionStatement(node, context); + var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( isPushStringInstruction("hello"), @@ -29,10 +29,10 @@ public class StackCompilerValTests { @Test public void whenValIsNamespaceStatementThenExpressionIsEvaluatedAndStoredAsLocal() { var node = Typed.val("x", Typed.stringLiteral("hello")); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("x"); - var result = StackCompiler.compileNamespaceStatement(node, context); + var result = ShidCodeGen.compileNamespaceStatement(node, context); assertThat(result.instructions(), isSequence( isPushStringInstruction("hello"), @@ -69,11 +69,11 @@ public class StackCompilerValTests { )), Typed.expressionStatement(Typed.reference("x")) ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("x"); for (var node : nodes) { - context = StackCompiler.compileFunctionStatement(node, context); + context = ShidCodeGen.compileFunctionStatement(node, context); } assertThat(context.instructions(), isSequence( diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerVarTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenVarTests.java index 7df00442..a1e264ad 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerVarTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenVarTests.java @@ -1,20 +1,20 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerVarTests { +public class ShidCodeGenVarTests { @Test public void expressionIsEvaluatedAndStoredAsVar() { var node = Typed.var("x", Typed.stringLiteral("hello")); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("x"); - var result = StackCompiler.compileFunctionStatement(node, context); + var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( isPushStringInstruction("hello"), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerWhenTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenWhenTests.java index d19eb525..f3e2880c 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerWhenTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenWhenTests.java @@ -1,4 +1,4 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; @@ -7,11 +7,11 @@ import org.shedlang.compiler.types.Types; import java.util.List; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerWhenTests { +public class ShidCodeGenWhenTests { private final static NamespaceName NAMESPACE_NAME = NamespaceName.of("Example", "Project"); @Test @@ -34,10 +34,10 @@ public class StackCompilerWhenTests { ), Types.STRING ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("x"); - var result = StackCompiler.compileExpression(node, context); + var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( isLocalLoadInstruction("x__0"), diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerWhileTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenWhileTests.java index 006c0b4c..1ab5240a 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerWhileTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenWhileTests.java @@ -1,15 +1,15 @@ -package org.shedlang.compiler.stackir; +package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; import java.util.List; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; -public class StackCompilerWhileTests { +public class ShidCodeGenWhileTests { @Test public void whileIsCompiledToLoop() { var node = Typed.while_( @@ -18,10 +18,10 @@ public class StackCompilerWhileTests { Typed.expressionStatement(Typed.intLiteral(42)) )) ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("c"); - var result = StackCompiler.compileFunctionStatement(node, context); + var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( isLoopInstruction( @@ -51,10 +51,10 @@ public class StackCompilerWhileTests { Typed.blockReturn(Typed.intLiteral(42)) )) ); - var context = StackCompiler.Context.EMPTY + var context = ShidCodeGen.Context.EMPTY .addShedVal("c"); - var result = StackCompiler.compileFunctionStatement(node, context); + var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( isLoopInstruction( diff --git a/src/test/java/org/shedlang/compiler/shid/instructions/InstructionMatchers.java b/src/test/java/org/shedlang/compiler/shid/instructions/InstructionMatchers.java new file mode 100644 index 00000000..c7c89825 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/shid/instructions/InstructionMatchers.java @@ -0,0 +1,229 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.types.NamespaceName; +import org.shedlang.compiler.types.StructType; +import org.zwobble.precisely.Matcher; + +import java.math.BigInteger; +import java.util.List; + +import static org.zwobble.precisely.Matchers.*; + +public class InstructionMatchers { + private InstructionMatchers() { + } + + public static Matcher<ShidInstruction> isCallInstruction( + int positionalArgCount, + List<String> namedArgNames + ) { + return instanceOf( + ShidCall.class, + has("positionalArgCount", x -> x.positionalArgCount(), equalTo(positionalArgCount)), + has("namedArgNames", x -> x.namedArgNames(), equalTo(namedArgNames)) + ); + } + + public static Matcher<ShidDefineFunction.Param> isDefineFunctionInstructionParam(String name) { + return has("name", x -> x.name(), equalTo(name)); + } + + public static Matcher<ShidInstruction> isDiscardInstruction() { + return instanceOf( + ShidDiscard.class + ); + } + + public static Matcher<ShidInstruction> isDuplicateInstruction() { + return instanceOf(ShidDuplicate.class); + } + + public static Matcher<ShidInstruction> isFieldLoadInstruction( + ShidFieldLoad.Receiver receiver, + String fieldName + ) { + return instanceOf( + ShidFieldLoad.class, + has("receiver", x -> x.receiver(), equalTo(receiver)), + has("fieldName", x -> x.fieldName(), equalTo(fieldName)) + ); + } + + public static Matcher<ShidInstruction> isFieldLoadInstruction( + StructType receiverType, + String fieldName + ) { + return isFieldLoadInstruction( + new ShidFieldLoad.Receiver.Struct(receiverType), + fieldName + ); + } + + public static Matcher<ShidInstruction> isIfInstruction( + Matcher<Iterable<? extends ShidInstruction>> trueBody, + Matcher<Iterable<? extends ShidInstruction>> falseBody + ) { + return instanceOf( + ShidIf.class, + has("trueBody", x -> x.trueBody(), trueBody), + has("falseBody", x -> x.falseBody(), falseBody) + ); + } + + public static Matcher<ShidInstruction> isIntAddInstruction() { + return instanceOf(ShidIntAdd.class); + } + + public static Matcher<ShidInstruction> isIntEqualsInstruction() { + return instanceOf(ShidIntEquals.class); + } + + public static Matcher<ShidInstruction> isIntNotEqualInstruction() { + return instanceOf(ShidIntNotEqual.class); + } + + public static Matcher<ShidInstruction> isIntSubInstruction() { + return instanceOf(ShidIntSub.class); + } + + public static Matcher<ShidInstruction> isLocalLoadInstruction(String name) { + return instanceOf( + ShidLocalLoad.class, + has("name", x -> x.name(), equalTo(name)) + ); + } + + public static Matcher<ShidInstruction> isLocalStoreInstruction(String name) { + return instanceOf( + ShidLocalStore.class, + has("name", x -> x.name(), equalTo(name)) + ); + } + + public static Matcher<ShidInstruction> isLoopInstruction( + Matcher<Iterable<? extends ShidInstruction>> body + ) { + return instanceOf( + ShidLoop.class, + has("body", x -> x.body(), body) + ); + } + + public static Matcher<ShidInstruction> isLoopBreakInstruction() { + return instanceOf(ShidLoopBreak.class); + } + + public static Matcher<ShidInstruction> isLoopContinueInstruction() { + return instanceOf(ShidLoopContinue.class); + } + + public static Matcher<ShidInstruction> isNamespaceFieldStoreInstruction( + NamespaceName namespaceName, + String fieldName + ) { + return instanceOf( + ShidNamespaceFieldStore.class, + has("namespaceName", x -> x.namespaceName(), equalTo(namespaceName)), + has("fieldName", x -> x.fieldName(), equalTo(fieldName)) + ); + } + + public static Matcher<ShidInstruction> isNamespaceImportInstruction( + NamespaceName namespaceName + ) { + return instanceOf( + ShidNamespaceImport.class, + has("namespaceName", x -> x.namespaceName(), equalTo(namespaceName)) + ); + } + + public static Matcher<ShidInstruction> isPushBoolInstruction(boolean value) { + return instanceOf( + ShidPushBool.class, + has("value", x -> x.value(), equalTo(value)) + ); + } + + public static Matcher<ShidInstruction> isPushIntInstruction(int value) { + return instanceOf( + ShidPushInt.class, + has("value", x -> x.value(), equalTo(BigInteger.valueOf(value))) + ); + } + + public static Matcher<ShidInstruction> isPushStringInstruction(String value) { + return instanceOf( + ShidPushString.class, + has("value", x -> x.value(), equalTo(value)) + ); + } + + public static Matcher<ShidInstruction> isPushUnitInstruction() { + return instanceOf( + ShidPushUnit.class + ); + } + + public static Matcher<ShidInstruction> isResumeInstruction() { + return instanceOf( + ShidResume.class + ); + } + + public static Matcher<ShidInstruction> isReturnInstruction() { + return instanceOf( + ShidReturn.class + ); + } + + public static Matcher<ShidInstruction> isStringAddInstruction() { + return instanceOf(ShidStringAdd.class); + } + + public static Matcher<ShidInstruction> isSwitchInstruction( + Matcher<Iterable<? extends ShidSwitch.Case>> cases + ) { + return instanceOf( + ShidSwitch.class, + has("cases", x -> x.cases(), cases) + ); + } + + public static Matcher<ShidSwitch.Case> isSwitchInstructionCase( + StructType caseType, + Matcher<Iterable<? extends ShidInstruction>> body + ) { + return allOf( + has("caseType", x -> x.caseType(), equalTo(caseType)), + has("body", x -> x.body(), body) + ); + } + + public static Matcher<ShidInstruction> isTupleCreateInstruction(int elementCount) { + return instanceOf( + ShidTupleCreate.class, + has("elementCount", x -> x.elementCount(), equalTo(elementCount)) + ); + } + + public static Matcher<ShidInstruction> isTupleGetInstruction(int elementIndex) { + return instanceOf( + ShidTupleGet.class, + has("elementIndex", x -> x.elementIndex(), equalTo(elementIndex)) + ); + } + + public static Matcher<ShidInstruction> isVarLoadInstruction(String name) { + return instanceOf( + ShidVarLoad.class, + has("name", x -> x.name(), equalTo(name)) + ); + } + + public static Matcher<ShidInstruction> isVarStoreInstruction(String name) { + return instanceOf( + ShidVarStore.class, + has("name", x -> x.name(), equalTo(name)) + ); + } +} diff --git a/src/test/java/org/shedlang/compiler/shid/instructions/Shid.java b/src/test/java/org/shedlang/compiler/shid/instructions/Shid.java new file mode 100644 index 00000000..cd8e41fd --- /dev/null +++ b/src/test/java/org/shedlang/compiler/shid/instructions/Shid.java @@ -0,0 +1,193 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.sources.Sources; +import org.shedlang.compiler.types.NamespaceName; +import org.shedlang.compiler.types.StructType; +import org.shedlang.compiler.types.UserDefinedEffect; + +import java.math.BigInteger; +import java.util.List; + +public class Shid { + private Shid() { + } + + public static ShidInstruction call(int positionalArgCount, List<String> namedArgNames) { + return new ShidCall(positionalArgCount, namedArgNames, Sources.NULL); + } + + public static ShidInstruction defineEffect(UserDefinedEffect effect) { + return new ShidDefineEffect(effect, Sources.NULL); + } + + public static ShidInstruction defineStruct( + StructType type, + List<ShidDefineStruct.Field> fields + ) { + return new ShidDefineStruct( + type, + fields, + Sources.NULL + ); + } + + public static ShidDefineStruct.Field defineStructField(String name) { + return new ShidDefineStruct.Field(name, Sources.NULL); + } + + public static ShidInstruction discard() { + return new ShidDiscard(Sources.NULL); + } + + public static ShidInstruction duplicate() { + return new ShidDuplicate(Sources.NULL); + } + + public static ShidInstruction fieldLoad(NamespaceName namespaceName, String fieldName) { + return new ShidFieldLoad( + new ShidFieldLoad.Receiver.Namespace(namespaceName), + fieldName, + Sources.NULL + ); + } + + public static ShidInstruction fieldLoad(StructType type, String fieldName) { + return new ShidFieldLoad( + new ShidFieldLoad.Receiver.Struct(type), + fieldName, + Sources.NULL + ); + } + + public static ShidInstruction fieldLoad(UserDefinedEffect effect, String fieldName) { + return new ShidFieldLoad( + new ShidFieldLoad.Receiver.Effect(effect), + fieldName, + Sources.NULL + ); + } + + public static ShidInstruction if_( + int resultCount, + List<ShidInstruction> trueBody, + List<ShidInstruction> falseBody + ) { + return new ShidIf(resultCount, trueBody, falseBody, Sources.NULL); + } + + public static ShidInstruction intAdd() { + return new ShidIntAdd(Sources.NULL); + } + + public static ShidInstruction intEquals() { + return new ShidIntEquals(Sources.NULL); + } + + public static ShidInstruction intNotEqual() { + return new ShidIntNotEqual(Sources.NULL); + } + + public static ShidInstruction intSub() { + return new ShidIntSub(Sources.NULL); + } + + public static ShidInstruction localLoad(String name) { + return new ShidLocalLoad(name, Sources.NULL); + } + + public static ShidInstruction localStore(String name) { + return new ShidLocalStore(name, Sources.NULL); + } + + public static ShidInstruction loop(List<ShidInstruction> body) { + return new ShidLoop(body, Sources.NULL); + } + + public static ShidInstruction loopBreak() { + return new ShidLoopBreak(Sources.NULL); + } + + public static ShidInstruction loopContinue() { + return new ShidLoopContinue(Sources.NULL); + } + + public static ShidInstruction namespaceFieldStore(NamespaceName namespaceName, String fieldName) { + return new ShidNamespaceFieldStore(namespaceName, fieldName, Sources.NULL); + } + + public static ShidInstruction namespaceImport(NamespaceName namespaceName) { + return new ShidNamespaceImport(namespaceName, Sources.NULL); + } + + public static ShidDefineFunction.Param param(String name) { + return new ShidDefineFunction.Param(name, Sources.NULL); + } + + public static ShidInstruction pushBool(boolean value) { + return new ShidPushBool(value, Sources.NULL); + } + + public static ShidInstruction pushInt(int value) { + return new ShidPushInt(BigInteger.valueOf(value), Sources.NULL); + } + + public static ShidInstruction pushString(String value) { + return new ShidPushString(value, Sources.NULL); + } + + public static ShidInstruction pushUnit() { + return new ShidPushUnit(Sources.NULL); + } + + public static ShidInstruction resume() { + return new ShidResume(Sources.NULL); + } + + public static ShidInstruction return_() { + return new ShidReturn(Sources.NULL); + } + + public static ShidInstruction stringAdd() { + return new ShidStringAdd(Sources.NULL); + } + + public static ShidInstruction switch_(List<ShidSwitch.Case> cases) { + return new ShidSwitch(cases, Sources.NULL); + } + + public static ShidSwitch.Case switchCase( + StructType type, + List<ShidInstruction> body + ) { + return new ShidSwitch.Case(type, body, Sources.NULL); + } + + public static ShidInstruction try_( + UserDefinedEffect handledEffect, + List<String> handlerMethodNames, + List<ShidInstruction> body + ) { + return new ShidTry( + handledEffect, + handlerMethodNames, + body, + Sources.NULL + ); + } + + public static ShidInstruction tupleCreate(int elementCount) { + return new ShidTupleCreate(elementCount, Sources.NULL); + } + + public static ShidInstruction tupleGet(int elementIndex, int elementCount) { + return new ShidTupleGet(elementIndex, elementCount, Sources.NULL); + } + + public static ShidInstruction varLoad(String name) { + return new ShidVarLoad(name, Sources.NULL); + } + + public static ShidInstruction varStore(String name) { + return new ShidVarStore(name, Sources.NULL); + } +} diff --git a/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java b/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java deleted file mode 100644 index 34c94f0e..00000000 --- a/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java +++ /dev/null @@ -1,229 +0,0 @@ -package org.shedlang.compiler.stackir.instructions; - -import org.shedlang.compiler.types.NamespaceName; -import org.shedlang.compiler.types.StructType; -import org.zwobble.precisely.Matcher; - -import java.math.BigInteger; -import java.util.List; - -import static org.zwobble.precisely.Matchers.*; - -public class InstructionMatchers { - private InstructionMatchers() { - } - - public static Matcher<Instruction> isCallInstruction( - int positionalArgCount, - List<String> namedArgNames - ) { - return instanceOf( - CallInstruction.class, - has("positionalArgCount", x -> x.positionalArgCount(), equalTo(positionalArgCount)), - has("namedArgNames", x -> x.namedArgNames(), equalTo(namedArgNames)) - ); - } - - public static Matcher<DefineFunctionInstruction.Param> isDefineFunctionInstructionParam(String name) { - return has("name", x -> x.name(), equalTo(name)); - } - - public static Matcher<Instruction> isDiscardInstruction() { - return instanceOf( - DiscardInstruction.class - ); - } - - public static Matcher<Instruction> isDuplicateInstruction() { - return instanceOf(DuplicateInstruction.class); - } - - public static Matcher<Instruction> isFieldLoadInstruction( - FieldLoadInstruction.Receiver receiver, - String fieldName - ) { - return instanceOf( - FieldLoadInstruction.class, - has("receiver", x -> x.receiver(), equalTo(receiver)), - has("fieldName", x -> x.fieldName(), equalTo(fieldName)) - ); - } - - public static Matcher<Instruction> isFieldLoadInstruction( - StructType receiverType, - String fieldName - ) { - return isFieldLoadInstruction( - new FieldLoadInstruction.Receiver.Struct(receiverType), - fieldName - ); - } - - public static Matcher<Instruction> isIfInstruction( - Matcher<Iterable<? extends Instruction>> trueBody, - Matcher<Iterable<? extends Instruction>> falseBody - ) { - return instanceOf( - IfInstruction.class, - has("trueBody", x -> x.trueBody(), trueBody), - has("falseBody", x -> x.falseBody(), falseBody) - ); - } - - public static Matcher<Instruction> isIntAddInstruction() { - return instanceOf(IntAddInstruction.class); - } - - public static Matcher<Instruction> isIntEqualsInstruction() { - return instanceOf(IntEqualsInstruction.class); - } - - public static Matcher<Instruction> isIntNotEqualInstruction() { - return instanceOf(IntNotEqualInstruction.class); - } - - public static Matcher<Instruction> isIntSubInstruction() { - return instanceOf(IntSubInstruction.class); - } - - public static Matcher<Instruction> isLocalLoadInstruction(String name) { - return instanceOf( - LocalLoadInstruction.class, - has("name", x -> x.name(), equalTo(name)) - ); - } - - public static Matcher<Instruction> isLocalStoreInstruction(String name) { - return instanceOf( - LocalStoreInstruction.class, - has("name", x -> x.name(), equalTo(name)) - ); - } - - public static Matcher<Instruction> isLoopInstruction( - Matcher<Iterable<? extends Instruction>> body - ) { - return instanceOf( - LoopInstruction.class, - has("body", x -> x.body(), body) - ); - } - - public static Matcher<Instruction> isLoopBreakInstruction() { - return instanceOf(LoopBreakInstruction.class); - } - - public static Matcher<Instruction> isLoopContinueInstruction() { - return instanceOf(LoopContinueInstruction.class); - } - - public static Matcher<Instruction> isNamespaceFieldStoreInstruction( - NamespaceName namespaceName, - String fieldName - ) { - return instanceOf( - NamespaceFieldStoreInstruction.class, - has("namespaceName", x -> x.namespaceName(), equalTo(namespaceName)), - has("fieldName", x -> x.fieldName(), equalTo(fieldName)) - ); - } - - public static Matcher<Instruction> isNamespaceImportInstruction( - NamespaceName namespaceName - ) { - return instanceOf( - NamespaceImportInstruction.class, - has("namespaceName", x -> x.namespaceName(), equalTo(namespaceName)) - ); - } - - public static Matcher<Instruction> isPushBoolInstruction(boolean value) { - return instanceOf( - PushBoolInstruction.class, - has("value", x -> x.value(), equalTo(value)) - ); - } - - public static Matcher<Instruction> isPushIntInstruction(int value) { - return instanceOf( - PushIntInstruction.class, - has("value", x -> x.value(), equalTo(BigInteger.valueOf(value))) - ); - } - - public static Matcher<Instruction> isPushStringInstruction(String value) { - return instanceOf( - PushStringInstruction.class, - has("value", x -> x.value(), equalTo(value)) - ); - } - - public static Matcher<Instruction> isPushUnitInstruction() { - return instanceOf( - PushUnitInstruction.class - ); - } - - public static Matcher<Instruction> isResumeInstruction() { - return instanceOf( - ResumeInstruction.class - ); - } - - public static Matcher<Instruction> isReturnInstruction() { - return instanceOf( - ReturnInstruction.class - ); - } - - public static Matcher<Instruction> isStringAddInstruction() { - return instanceOf(StringAddInstruction.class); - } - - public static Matcher<Instruction> isSwitchInstruction( - Matcher<Iterable<? extends SwitchInstruction.Case>> cases - ) { - return instanceOf( - SwitchInstruction.class, - has("cases", x -> x.cases(), cases) - ); - } - - public static Matcher<SwitchInstruction.Case> isSwitchInstructionCase( - StructType caseType, - Matcher<Iterable<? extends Instruction>> body - ) { - return allOf( - has("caseType", x -> x.caseType(), equalTo(caseType)), - has("body", x -> x.body(), body) - ); - } - - public static Matcher<Instruction> isTupleCreateInstruction(int elementCount) { - return instanceOf( - TupleCreateInstruction.class, - has("elementCount", x -> x.elementCount(), equalTo(elementCount)) - ); - } - - public static Matcher<Instruction> isTupleGetInstruction(int elementIndex) { - return instanceOf( - TupleGetInstruction.class, - has("elementIndex", x -> x.elementIndex(), equalTo(elementIndex)) - ); - } - - public static Matcher<Instruction> isVarLoadInstruction(String name) { - return instanceOf( - VarLoadInstruction.class, - has("name", x -> x.name(), equalTo(name)) - ); - } - - public static Matcher<Instruction> isVarStoreInstruction(String name) { - return instanceOf( - VarStoreInstruction.class, - has("name", x -> x.name(), equalTo(name)) - ); - } -} diff --git a/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java b/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java deleted file mode 100644 index ce6ebf37..00000000 --- a/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java +++ /dev/null @@ -1,193 +0,0 @@ -package org.shedlang.compiler.stackir.instructions; - -import org.shedlang.compiler.sources.Sources; -import org.shedlang.compiler.types.NamespaceName; -import org.shedlang.compiler.types.StructType; -import org.shedlang.compiler.types.UserDefinedEffect; - -import java.math.BigInteger; -import java.util.List; - -public class Instructions { - private Instructions() { - } - - public static Instruction call(int positionalArgCount, List<String> namedArgNames) { - return new CallInstruction(positionalArgCount, namedArgNames, Sources.NULL); - } - - public static Instruction defineEffect(UserDefinedEffect effect) { - return new DefineEffectInstruction(effect, Sources.NULL); - } - - public static Instruction defineStruct( - StructType type, - List<DefineStructInstruction.Field> fields - ) { - return new DefineStructInstruction( - type, - fields, - Sources.NULL - ); - } - - public static DefineStructInstruction.Field defineStructField(String name) { - return new DefineStructInstruction.Field(name, Sources.NULL); - } - - public static Instruction discard() { - return new DiscardInstruction(Sources.NULL); - } - - public static Instruction duplicate() { - return new DuplicateInstruction(Sources.NULL); - } - - public static Instruction fieldLoad(NamespaceName namespaceName, String fieldName) { - return new FieldLoadInstruction( - new FieldLoadInstruction.Receiver.Namespace(namespaceName), - fieldName, - Sources.NULL - ); - } - - public static Instruction fieldLoad(StructType type, String fieldName) { - return new FieldLoadInstruction( - new FieldLoadInstruction.Receiver.Struct(type), - fieldName, - Sources.NULL - ); - } - - public static Instruction fieldLoad(UserDefinedEffect effect, String fieldName) { - return new FieldLoadInstruction( - new FieldLoadInstruction.Receiver.Effect(effect), - fieldName, - Sources.NULL - ); - } - - public static Instruction if_( - int resultCount, - List<Instruction> trueBody, - List<Instruction> falseBody - ) { - return new IfInstruction(resultCount, trueBody, falseBody, Sources.NULL); - } - - public static Instruction intAdd() { - return new IntAddInstruction(Sources.NULL); - } - - public static Instruction intEquals() { - return new IntEqualsInstruction(Sources.NULL); - } - - public static Instruction intNotEqual() { - return new IntNotEqualInstruction(Sources.NULL); - } - - public static Instruction intSub() { - return new IntSubInstruction(Sources.NULL); - } - - public static Instruction localLoad(String name) { - return new LocalLoadInstruction(name, Sources.NULL); - } - - public static Instruction localStore(String name) { - return new LocalStoreInstruction(name, Sources.NULL); - } - - public static Instruction loop(List<Instruction> body) { - return new LoopInstruction(body, Sources.NULL); - } - - public static Instruction loopBreak() { - return new LoopBreakInstruction(Sources.NULL); - } - - public static Instruction loopContinue() { - return new LoopContinueInstruction(Sources.NULL); - } - - public static Instruction namespaceFieldStore(NamespaceName namespaceName, String fieldName) { - return new NamespaceFieldStoreInstruction(namespaceName, fieldName, Sources.NULL); - } - - public static Instruction namespaceImport(NamespaceName namespaceName) { - return new NamespaceImportInstruction(namespaceName, Sources.NULL); - } - - public static DefineFunctionInstruction.Param param(String name) { - return new DefineFunctionInstruction.Param(name, Sources.NULL); - } - - public static Instruction pushBool(boolean value) { - return new PushBoolInstruction(value, Sources.NULL); - } - - public static Instruction pushInt(int value) { - return new PushIntInstruction(BigInteger.valueOf(value), Sources.NULL); - } - - public static Instruction pushString(String value) { - return new PushStringInstruction(value, Sources.NULL); - } - - public static Instruction pushUnit() { - return new PushUnitInstruction(Sources.NULL); - } - - public static Instruction resume() { - return new ResumeInstruction(Sources.NULL); - } - - public static Instruction return_() { - return new ReturnInstruction(Sources.NULL); - } - - public static Instruction stringAdd() { - return new StringAddInstruction(Sources.NULL); - } - - public static Instruction switch_(List<SwitchInstruction.Case> cases) { - return new SwitchInstruction(cases, Sources.NULL); - } - - public static SwitchInstruction.Case switchCase( - StructType type, - List<Instruction> body - ) { - return new SwitchInstruction.Case(type, body, Sources.NULL); - } - - public static Instruction try_( - UserDefinedEffect handledEffect, - List<String> handlerMethodNames, - List<Instruction> body - ) { - return new TryInstruction( - handledEffect, - handlerMethodNames, - body, - Sources.NULL - ); - } - - public static Instruction tupleCreate(int elementCount) { - return new TupleCreateInstruction(elementCount, Sources.NULL); - } - - public static Instruction tupleGet(int elementIndex, int elementCount) { - return new TupleGetInstruction(elementIndex, elementCount, Sources.NULL); - } - - public static Instruction varLoad(String name) { - return new VarLoadInstruction(name, Sources.NULL); - } - - public static Instruction varStore(String name) { - return new VarStoreInstruction(name, Sources.NULL); - } -} |
