public static NeuFloat Divide(
     this NeuInterpreter interpreter,
     NeuFloat lhs,
     NeuFloat rhs)
 {
     return(new NeuFloat(lhs.Value / rhs.Value));
 }
 public static NeuInteger Divide(
     this NeuInterpreter interpreter,
     NeuInteger lhs,
     NeuInteger rhs)
 {
     return(new NeuInteger(lhs.Value / rhs.Value));
 }
    ///

    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 NeuFloat Add(
     this NeuInterpreter interpreter,
     NeuFloat lhs,
     NeuFloat rhs)
 {
     return(new NeuFloat(lhs.Value + rhs.Value));
 }
示例#5
0
 public static NeuInteger Multiply(
     this NeuInterpreter interpreter,
     NeuInteger lhs,
     NeuInteger rhs)
 {
     return(new NeuInteger(lhs.Value * rhs.Value));
 }
    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();
        }
    }
    public static NeuHoistedFrame?GetHoistedFrameWithinScope(
        this NeuInterpreter interpreter,
        String name)
    {
        foreach (var frame in interpreter.Stack)
        {
            switch (frame)
            {
            case NeuScopeFrame _:

                return(null);

            ///

            case NeuHoistedFrame hoistedFrame when hoistedFrame.Hoist.Name == name:

                return(hoistedFrame);

            ///

            default:

                continue;
            }
        }

        ///

        return(null);
    }
示例#8
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();
        }
    }
    ///

    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);
    }
示例#10
0
    public static void Exit(
        this NeuInterpreter interpreter,
        NeuNode node)
    {
        var frame = interpreter.Stack.First();

        ///

        var frameNode = frame.Node as NeuNode;

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

        ///

        if (!Equals(frameNode, node))
        {
            throw new Exception();
        }

        ///

        interpreter.Stack.Pop();
    }
    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();
        }
    }
示例#12
0
 public static NeuInteger Subtract(
     this NeuInterpreter interpreter,
     NeuInteger lhs,
     NeuInteger rhs)
 {
     return(new NeuInteger(lhs.Value - rhs.Value));
 }
示例#13
0
    public (String Filename, NeuOperation?Result) Evaluate(
        IEnumerable <IArgument> arguments)
    {
        var interpreter = new NeuInterpreter();

        ///

        this.Interpreter = interpreter;

        ///

        var droppedArgs = arguments.DropArguments(number: 1);

        ///

        var filename = droppedArgs.GetFirstArgumentSource();

        if (IsNullOrWhiteSpace(filename))
        {
            throw new Exception();
        }

        ///

        var silent = arguments.Get("--silent") == null
            ? false
            : true;

        ///

        var dumpAST = arguments.Get("--dump-ast") is String;

        ///

        if (silent)
        {
            dumpAST = false;
        }

        ///

        if (!silent)
        {
            Write($"  Running test {filename}{(dumpAST ? "\n" : "")}");
            // WriteLine($"  Running test {filename}{(dumpAST ? "\n" : "")}");
        }

        var result = interpreter.Evaluate(filename, droppedArgs, dumpAST: dumpAST, indent: 2);

        ///

        // if (!silent) { // --diagnostic?

        //     WriteLine($"  Result: {result.Dump()}");
        // }

        ///

        return(filename, result);
    }
示例#14
0
 public static NeuFloat Multiply(
     this NeuInterpreter interpreter,
     NeuFloat lhs,
     NeuFloat rhs)
 {
     return(new NeuFloat(lhs.Value * rhs.Value));
 }
示例#15
0
 public static NeuFloat Subtract(
     this NeuInterpreter interpreter,
     NeuFloat lhs,
     NeuFloat rhs)
 {
     return(new NeuFloat(lhs.Value - rhs.Value));
 }
 public static NeuInteger Add(
     this NeuInterpreter interpreter,
     NeuInteger lhs,
     NeuInteger rhs)
 {
     return(new NeuInteger(lhs.Value + rhs.Value));
 }
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuCallExpression callExpression)
    {
        var name = callExpression.GetName();

        if (IsNullOrWhiteSpace(name))
        {
            throw new Exception();
        }


        ///

        var rawArgs = callExpression.GetArguments();

        ///

        return(interpreter.Call(name, rawArgs));

        // ///



        // ///

        // if (IsNeuPrimitive(name)) {


        // }
    }
示例#18
0
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuExpression expr)
    {
        switch (expr)
        {
        case NeuLiteralExpression litExpr:

            return(interpreter.Execute(litExpr));

        ///

        case NeuIdentifierExpression idExpr:

            return(interpreter.Execute(idExpr));

        ///

        case NeuCallExpression callExpr:

            return(interpreter.Execute(callExpr));



        ///

        case NeuUnaryExpression unaryExpr when !unaryExpr.IsFixExpression():

            return(interpreter.Execute(unaryExpr));

        ///

        case NeuPrefixExpression prefixExpr:

            return(interpreter.Execute(prefixExpr));

        ///

        case NeuInfixExpression infixExpr:

            return(interpreter.Execute(infixExpr));

        ///

        case NeuPostfixExpression postfixExpr:

            return(interpreter.Execute(postfixExpr));


        ///

        default:

            throw new Exception();
        }
    }
    public static NeuOperation CallVTable(
        this NeuInterpreter interpreter,
        String name,
        IEnumerable <Node> rawArgs,
        IList <NeuArgument> evalArguments)
    {
        ///

        var ops = interpreter.GetOperations(name, null, null, null);

        ///

        var callee = ops.SingleOrDefault() as NeuOperation;

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

        ///

        var calleeeParamClause = callee.GetParamClause();

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

        ///

        var calleeParamList = calleeeParamClause.GetFuncParamList();

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

        ///

        switch (true)
        {
        case var _ when rawArgs.Count() == 0 && calleeParamList.Count() == 0:

            break;

        ///

        default:

            throw new Exception();
        }

        ///

        return(interpreter.Execute(callee, evalArguments));
    }
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuVarDecl varDecl)
    {
        // TODO: Change this so it's non-function scoped stack

        var inGlobalScope = interpreter.Stack.Count() == 0;

        ///

        var lastValue = NeuOperation.Void;

        ///

        var kind = varDecl.GetDeclarationKindKeyword();

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

        ///

        var patternBindingList = varDecl.GetPatternBindingList();

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

        ///

        foreach (var c in patternBindingList.Children)
        {
            switch (c)
            {
            case NeuPatternBinding patternBinding:

                lastValue = interpreter.Execute(inGlobalScope, kind, patternBinding);

                break;

            ///

            default:

                throw new Exception();
            }
        }

        ///

        return(lastValue);
    }
示例#21
0
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuExpressionStatement expressionStatement)
    {
        var expression = expressionStatement.GetExpression();

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

        return(interpreter.Execute(expression));
    }
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuNumberLiteralExpression numberLiteralExpr)
    {
        var numberLit = numberLiteralExpr.GetNumberLiteral();

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

        ///

        return(interpreter.Execute(numberLit));
    }
示例#23
0
    public static NeuVar?GetLocalVar(
        this NeuInterpreter interpreter,
        String name)
    {
        var hoistedFrame = interpreter.GetHoistedFrameWithinScope(name);

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

        ///

        return(hoistedFrame.Operation as NeuVar);
    }
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuIdentifierExpression idExpr)
    {
        var id = idExpr.GetIdentifier();

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

        ///

        return(interpreter.Execute(id));
    }
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuBoolLiteralExpression boolLiteralExpr)
    {
        var boolKeyword = boolLiteralExpr.GetBoolKeyword();

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

        ///

        return(interpreter.Execute(boolKeyword));
    }
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuLiteral literal)
    {
        switch (literal)
        {
        case NeuNumberLiteral numberLiteral:
            return(interpreter.Execute(numberLiteral));

        ///

        default:
            throw new Exception();
        }
    }
示例#27
0
    public static NeuOperation PrefixIncrement(
        this NeuInterpreter interpreter,
        String name,
        NeuInteger intResult)
    {
        var updatedResult = new NeuInteger(intResult.Value + 1);

        ///

        if (!interpreter.SetVar(name, updatedResult))
        {
            throw new Exception();
        }

        ///

        return(updatedResult);
    }
示例#28
0
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuIdentifier id)
    {
        var name = id.Source;

        ///

        var v = interpreter.GetVar(name);

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

        ///

        return(v.Value);
    }
示例#29
0
    ///

    public static NeuVar?GetGlobalVar(
        this NeuInterpreter interpreter,
        String name)
    {
        var ops = interpreter.GetOperations(name, null, null, null);

        ///

        var op = ops.SingleOrDefault();

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

        ///

        return(op as NeuVar);
    }
    public static NeuOperation Execute(
        this NeuInterpreter interpreter,
        NeuReturnStatement retStmt)
    {
        var argument = retStmt.GetArgument();

        if (argument == null)
        {
            return(new NeuReturnResult(NeuOperation.Void));
        }

        ///

        var result = interpreter.Execute(argument);

        ///

        return(new NeuReturnResult(result));
    }