Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        private static void CompileNoneConstructor(FunctionCompiler compiler, FunctionalNode noneConstructorNode)
        {
            VariableReference output = noneConstructorNode.OutputTerminals.ElementAt(0).GetTrueVariable();

            compiler.LoadLocalAllocationReference(output);
            compiler._builder.EmitLoadIntegerImmediate(0);
            compiler._builder.EmitStoreInteger();
        }
Exemplo n.º 3
0
        private static void CompilePureUnaryPrimitive(FunctionCompiler compiler, FunctionalNode primitiveNode, UnaryPrimitiveOps operation)
        {
            VariableReference input  = primitiveNode.InputTerminals.ElementAt(0).GetTrueVariable(),
                              output = primitiveNode.OutputTerminals.ElementAt(1).GetTrueVariable();

            compiler.LoadLocalAllocationReference(output);
            compiler.EmitUnaryOperationOnVariable(input, operation);
            compiler._builder.EmitStoreInteger();
        }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
0
        private static void CompileRange(FunctionCompiler compiler, FunctionalNode rangeNode)
        {
            VariableReference lowInput  = rangeNode.InputTerminals.ElementAt(0).GetTrueVariable(),
                              highInput = rangeNode.InputTerminals.ElementAt(1).GetTrueVariable(),
                              output    = rangeNode.OutputTerminals.ElementAt(0).GetTrueVariable();

            compiler.LoadLocalAllocationReference(output);
            compiler._builder.EmitDuplicate();
            compiler.LoadLocalAllocationReference(lowInput);
            compiler._builder.EmitDerefInteger();
            compiler._builder.EmitLoadIntegerImmediate(1);
            compiler._builder.EmitSubtract();
            compiler._builder.EmitStoreInteger();

            compiler._builder.EmitLoadIntegerImmediate(4);
            compiler._builder.EmitAdd();
            compiler.LoadLocalAllocationReference(highInput);
            compiler._builder.EmitDerefInteger();
            compiler._builder.EmitStoreInteger();
        }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
0
        private static void CompilePureBinaryPrimitive(FunctionCompiler compiler, FunctionalNode primitiveNode, BinaryPrimitiveOps operation)
        {
            VariableReference input1 = primitiveNode.InputTerminals.ElementAt(0).GetTrueVariable(),
                              input2 = primitiveNode.InputTerminals.ElementAt(1).GetTrueVariable(),
                              output = primitiveNode.OutputTerminals.ElementAt(2).GetTrueVariable();

            compiler.LoadLocalAllocationReference(output);
            compiler.LoadValueAsReference(input1);
            compiler._builder.EmitDerefInteger();
            compiler.LoadValueAsReference(input2);
            compiler._builder.EmitDerefInteger();
            compiler.EmitBinaryOperation(operation);
            compiler._builder.EmitStoreInteger();
        }