Пример #1
0
        private static void CompileOutput(FunctionCompiler compiler, FunctionalNode outputNode)
        {
            VariableReference input        = outputNode.InputTerminals.ElementAt(0).GetTrueVariable();
            NIType            referentType = input.Type.GetReferentType();

            if (referentType.IsInt32())
            {
                compiler.LoadValueAsReference(input);
                compiler._builder.EmitDerefInteger();
                compiler._builder.EmitOutput_TEMP();
            }
            else if (referentType.IsString())
            {
                compiler.LoadValueAsReference(input);
                compiler._builder.EmitDerefPointer();
                compiler.LoadValueAsReference(input);
                compiler._builder.EmitLoadIntegerImmediate(TargetConstants.PointerSize);
                compiler._builder.EmitAdd();
                compiler._builder.EmitDerefInteger();
                compiler._builder.EmitOutputString_TEMP();
            }
            else if (referentType == DataTypes.StringSliceType)
            {
                compiler.LoadStringSliceReferencePointer(input);
                compiler._builder.EmitDerefPointer();
                compiler.LoadStringSliceReferenceSizeReference(input);
                compiler._builder.EmitDerefInteger();
                compiler._builder.EmitOutputString_TEMP();
            }
            else
            {
                throw new NotImplementedException($"Don't know how to display type {referentType} yet.");
            }
        }
Пример #2
0
        private static void CompileSelectReference(FunctionCompiler compiler, FunctionalNode selectReferenceNode)
        {
            LabelBuilder falseLabel             = compiler._builder.CreateLabel(),
                         endLabel               = compiler._builder.CreateLabel();
            VariableReference input1            = selectReferenceNode.InputTerminals.ElementAt(1).GetTrueVariable(),
                              input2            = selectReferenceNode.InputTerminals.ElementAt(2).GetTrueVariable(),
                              selector          = selectReferenceNode.InputTerminals.ElementAt(0).GetTrueVariable(),
                              selectedReference = selectReferenceNode.OutputTerminals.ElementAt(1).GetTrueVariable();

            compiler.LoadLocalAllocationReference(selectedReference);
            compiler.LoadValueAsReference(selector);
            compiler._builder.EmitDerefInteger();
            compiler._builder.EmitBranchIfFalse(falseLabel);

            // true
            compiler.LoadValueAsReference(input1);
            compiler._builder.EmitBranch(endLabel);

            // false
            compiler._builder.SetLabel(falseLabel);
            compiler.LoadValueAsReference(input2);

            // end
            compiler._builder.SetLabel(endLabel);
            compiler._builder.EmitStorePointer();
        }
Пример #3
0
        private static void CompileExchangeValues(FunctionCompiler compiler, FunctionalNode exchangeValuesNode)
        {
            VariableReference var1 = exchangeValuesNode.InputTerminals.ElementAt(0).GetTrueVariable(),
                              var2 = exchangeValuesNode.InputTerminals.ElementAt(1).GetTrueVariable();

            compiler.LoadValueAsReference(var1);
            compiler.LoadValueAsReference(var2);
            compiler._builder.EmitLoadIntegerImmediate(BytecodeInterpreterAllocator.GetTypeSize(var1.Type.GetReferentType()));
            compiler._builder.EmitExchangeBytes_TEMP();
        }
Пример #4
0
        private static void CompileMutatingBinaryPrimitive(FunctionCompiler compiler, FunctionalNode primitiveNode, BinaryPrimitiveOps operation)
        {
            VariableReference input1 = primitiveNode.InputTerminals.ElementAt(0).GetTrueVariable(),
                              input2 = primitiveNode.InputTerminals.ElementAt(1).GetTrueVariable();

            compiler.LoadValueAsReference(input1);
            compiler._builder.EmitDuplicate();
            compiler._builder.EmitDerefInteger();
            compiler.LoadValueAsReference(input2);
            compiler._builder.EmitDerefInteger();
            compiler.EmitBinaryOperation(operation);
            compiler._builder.EmitStoreInteger();
        }
Пример #5
0
        private static void CompileComparison(FunctionCompiler compiler, FunctionalNode comparisonNode, Action <FunctionBuilder> emitOperation)
        {
            VariableReference input1 = comparisonNode.InputTerminals[0].GetTrueVariable(),
                              input2 = comparisonNode.InputTerminals[1].GetTrueVariable(),
                              output = comparisonNode.OutputTerminals[2].GetTrueVariable();

            compiler.LoadLocalAllocationReference(output);
            compiler.LoadValueAsReference(input1);
            compiler._builder.EmitDerefInteger();
            compiler.LoadValueAsReference(input2);
            compiler._builder.EmitDerefInteger();
            emitOperation(compiler._builder);
            compiler._builder.EmitStoreInteger();
        }
Пример #6
0
        private static void CompileMutatingUnaryPrimitive(FunctionCompiler compiler, FunctionalNode primitiveNode, UnaryPrimitiveOps operation)
        {
            VariableReference input = primitiveNode.InputTerminals.ElementAt(0).GetTrueVariable();

            compiler.LoadValueAsReference(input);
            compiler.EmitUnaryOperationOnVariable(input, operation);
            compiler._builder.EmitStoreInteger();
        }
Пример #7
0
        private static void CompileCreateCopy(FunctionCompiler compiler, FunctionalNode createCopyNode)
        {
            VariableReference copyFrom = createCopyNode.InputTerminals.ElementAt(0).GetTrueVariable(),
                              copyTo   = createCopyNode.OutputTerminals.ElementAt(1).GetTrueVariable();

            compiler.CopyValue(
                () => compiler.LoadValueAsReference(copyFrom),
                () => compiler.LoadLocalAllocationReference(copyTo),
                copyFrom.Type.GetReferentType());
        }
Пример #8
0
        private static void CompileInspect(FunctionCompiler compiler, FunctionalNode inspectNode)
        {
            VariableReference input      = inspectNode.InputTerminals[0].GetTrueVariable();
            int typeSize                 = BytecodeInterpreterAllocator.GetTypeSize(input.Type.GetReferentType());
            StaticDataBuilder staticData = compiler._builder.DefineStaticData();

            staticData.Data       = new byte[typeSize];
            staticData.Identifier = StaticDataIdentifier.CreateFromNode(inspectNode);

            compiler.LoadValueAsReference(input);
            compiler._builder.EmitLoadStaticDataAddress(staticData);
            compiler._builder.EmitLoadIntegerImmediate(typeSize);
            compiler._builder.EmitCopyBytes_TEMP();
        }