public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuInfixOperator op,
        NeuOperation lhsResult,
        NeuOperation rhsResult)
    {
        switch (op)
        {
        case NeuAssignOperator assignOp:

            throw new Exception();

        ///

        case NeuBinaryOperator binaryOp:

            return(interpreter.Execute(binaryOp, lhsResult, rhsResult));

        ///

        default:

            throw new Exception();
        }
    }
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuBinaryOperator op,
        NeuOperation lhsResult,
        NeuOperation rhsResult)
    {
        switch (op.OperatorType)
        {
        case NeuBinaryOperatorType.Multiply:
            return(interpreter.Multiply(lhsResult, rhsResult));

        ///

        case NeuBinaryOperatorType.Divide:
            return(interpreter.Divide(lhsResult, rhsResult));

        ///

        case NeuBinaryOperatorType.Add:
            return(interpreter.Add(lhsResult, rhsResult));

        ///

        case NeuBinaryOperatorType.Subtract:
            return(interpreter.Subtract(lhsResult, rhsResult));

        ///

        default:
            throw new Exception();
        }
    }
Example #3
0
    public static NeuOperation Multiply(
        this NeuInterpreter interpreter,
        NeuOperation lhs,
        NeuOperation rhs)
    {
        switch (true)
        {
        case var _
            when
            lhs is NeuFloat lhsFloat && rhs is NeuFloat rhsFloat:

            return(interpreter.Multiply(lhsFloat, rhsFloat));

        ///

        case var _ when
            lhs is NeuInteger lhsInt && rhs is NeuInteger rhsInt:

            return(interpreter.Multiply(lhsInt, rhsInt));

        ///

        default:

            throw new Exception();
        }
    }
Example #4
0
    }                                       // Maybe change this to init for lets?

    public NeuVar(
        String?name,
        NeuOperation value)
        : base(name, null, null, null, null, false, false)
    {
        this.Value = value;
    }
Example #5
0
    public static String Dump(
        this NeuOperation operation)
    {
        switch (operation)
        {
        case NeuReturnResult returnResult:

            return(returnResult.Dump());

        ///

        case NeuValue value:

            return(value.Dump());

        ///

        case NeuVoid _:

            return("void");

        ///

        case var op:

            return($"{op} (unknown)");
        }
    }
    ///

    public static bool SetGlobalVar(
        this NeuInterpreter interpreter,
        String name,
        NeuOperation newValue)
    {
        var ops = interpreter.GetOperations(name, null, null, null);

        ///

        var op = ops.SingleOrDefault();

        if (op == null)
        {
            return(false);
        }

        ///

        var v = op as NeuVar;

        if (v == null)
        {
            throw new Exception();
        }

        ///

        v.Value = newValue;

        ///

        return(true);
    }
    ///

    public static bool SetLocalVar(
        this NeuInterpreter interpreter,
        String name,
        NeuOperation newValue)
    {
        var hoistedFrame = interpreter.GetHoistedFrameWithinScope(name);

        if (hoistedFrame == null)
        {
            return(false);
        }

        ///

        var v = hoistedFrame.Operation as NeuVar;

        if (v == null)
        {
            throw new Exception();
        }

        ///

        v.Value = newValue;

        ///

        return(true);
    }
    public static NeuVar?HoistVar(
        this Interpreter <NeuFrame, NeuOperation> interpreter,
        NeuKeywordType keywordType,
        String name,
        NeuOperation value)
    {
        var v = new NeuVar(name, value);

        ///

        interpreter.Hoist(keywordType, name, v);

        ///

        return(v);
    }
Example #9
0
    public static bool MatchOperation(
        this Interpreter <NeuFrame, NeuOperation> interpreter,
        String?name,
        bool nameIsNull,
        String?moduleName,
        bool moduleNameIsNull,
        String?namespaceName,
        bool namespaceNameIsNull,
        String?typeName,
        bool typeNameIsNull,
        NeuOperation candidate)
    {
        var candidateNameIsNull          = IsNullOrWhiteSpace(candidate.Name);
        var candidateModuleNameIsNull    = IsNullOrWhiteSpace(candidate.ModuleName);
        var candidateNamespaceNameIsNull = IsNullOrWhiteSpace(candidate.NamespaceName);
        var candidateTypeNameIsNull      = IsNullOrWhiteSpace(candidate.TypeName);

        ///

        if (candidateNameIsNull && candidateModuleNameIsNull && candidateNamespaceNameIsNull && candidateTypeNameIsNull)
        {
            return(false);
        }

        ///

        // ALL

        if (!nameIsNull &&
            !moduleNameIsNull &&
            !namespaceNameIsNull &&
            !typeNameIsNull &&
            !candidateNameIsNull &&
            !candidateModuleNameIsNull &&
            !candidateNamespaceNameIsNull &&
            !candidateTypeNameIsNull)
        {
            return(candidate.Name == name &&
                   candidate.ModuleName == moduleName &&
                   candidate.NamespaceName == namespaceName &&
                   candidate.TypeName == typeName);
        }

        ///

        return(candidate.Name == name);
    }
Example #10
0
    public static NeuHoistedFrame Hoist(
        this Interpreter <NeuFrame, NeuOperation> interpreter,
        NeuKeywordType keywordType,
        String name,
        NeuOperation operation)
    {
        var hoist = new NeuHoist(keywordType, name);

        ///

        var hoistedFrame = new NeuHoistedFrame(hoist, operation);

        ///

        interpreter.Stack.Push(hoistedFrame);

        ///

        return(hoistedFrame);
    }
    public static NeuOperation?CreateOperation(
        this Interpreter <NeuFrame, NeuOperation> interpreter,
        String?name,
        String?moduleName,
        String?namespaceName,
        String?typeName,
        NeuNode node)
    {
        if (interpreter.OperationExists(name, moduleName, namespaceName, typeName))
        {
            throw new Exception();
        }

        ///

        var op = new NeuOperation(name, moduleName, namespaceName, typeName, node, false, true);

        interpreter.VTable.Add(op);

        return(op);
    }
    public static NeuVar?CreateVar(
        this Interpreter <NeuFrame, NeuOperation> interpreter,
        String name,
        String?moduleName,
        String?namespaceName,
        String?typeName,
        NeuOperation value)
    {
        if (interpreter.OperationExists(name, moduleName, namespaceName, typeName))
        {
            throw new Exception();
        }

        ///

        var v = new NeuVar(name, value);

        interpreter.VTable.Add(v);

        return(v);
    }
    public static bool SetVar(
        this NeuInterpreter interpreter,
        String name,
        NeuOperation newValue)
    {
        /// Locals

        if (interpreter.SetLocalVar(name, newValue))
        {
            return(true);
        }

        /// Globals

        if (interpreter.SetGlobalVar(name, newValue))
        {
            return(true);
        }

        ///

        return(false);
    }
Example #14
0
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuOperation op,
        IEnumerable <NeuArgument> args)
    {
        var returnType = op.GetReturnType();

        ///

        var body = op.GetBodyCodeBlock();

        if (body == null)
        {
            throw new Exception();
        }

        ///

        var returnResult = interpreter.Execute(body, args) as NeuReturnResult;

        if (returnResult == null)
        {
            throw new Exception();
        }

        ///

        if (!returnResult.Matches(returnType))
        {
            throw new Exception("Value does not match return type");
        }

        ///

        return(returnResult.Result ?? NeuOperation.Void);
    }