private HybInstance RunBinaryExpression(BinaryExpressionSyntax node)
        {
            var op = node.OperatorToken.ValueText;

            if (op == "is")
            {
                return(RunIs(node));
            }

            var left = RunExpression(node.Left);

            if (op == "||")
            {
                if (IsTrueOrEquivalent(left))
                {
                    return(HybInstance.Bool(true));
                }
            }
            else if (op == "&&")
            {
                if (IsTrueOrEquivalent(left) == false)
                {
                    return(HybInstance.Bool(false));
                }
            }

            var right = RunExpression(node.Right);

            return(MadMath.Op(left, right, op));
        }
Exemple #2
0
        private void RunSwitch(SwitchStatementSyntax node)
        {
            var value = RunExpression(node.Expression);

            foreach (var section in node.Sections)
            {
                foreach (var label in section.Labels)
                {
                    if (label is DefaultSwitchLabelSyntax)
                    {
                        foreach (var statement in section.Statements)
                        {
                            Run(statement);

                            if (Halt != HaltType.None)
                            {
                                break;
                            }
                        }
                    }
                    else if (label is CaseSwitchLabelSyntax caseLabel)
                    {
                        var caseValue = RunExpression(caseLabel.Value);

                        if (MadMath.Eq(value, caseValue).As <bool>())
                        {
                            foreach (var statement in section.Statements)
                            {
                                Run(statement);

                                if (Halt != HaltType.None)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (Halt != HaltType.None)
                    {
                        break;
                    }
                }

                if (Halt != HaltType.None)
                {
                    break;
                }
            }

            if (Halt == HaltType.Break)
            {
                Halt = HaltType.None;
            }
        }
Exemple #3
0
        private void RunAssignWithOp(AssignmentExpressionSyntax node)
        {
            var right = RunExpression(node.Right);

            if (node.Left is IdentifierNameSyntax id)
            {
                var key   = id.Identifier.ValueText;
                var value = MadMath.Op(ResolveId(id), right, node.OperatorToken.Text.Substring(0, 1));

                UpdateVariable(key, value);
            }
            else if (node.Left is MemberAccessExpressionSyntax ma)
            {
                HybInstance left  = null;
                HybInstance value = null;

                if (ma.Expression is IdentifierNameSyntax idNode)
                {
                    var     key = $"{idNode.Identifier}";
                    HybType leftType;
                    if (Resolver.TryGetType(key, out leftType))
                    {
                        leftType.GetStaticPropertyOrField($"{ma.Name.Identifier}", out left);
                        value = MadMath.Op(left, right, node.OperatorToken.Text.Substring(0, 1));
                        leftType.SetStaticPropertyOrField($"{ma.Name.Identifier}", value);
                        return;
                    }
                }

                var callee      = RunExpression(ma.Expression);
                var accessLevel = AccessLevel.Outside;

                if (ma.Expression is ThisExpressionSyntax)
                {
                    accessLevel = AccessLevel.This;
                }

                callee.GetPropertyOrField($"{ma.Name}", out left, accessLevel);
                value = MadMath.Op(left, right, node.OperatorToken.Text.Substring(0, 1));
                callee.SetPropertyOrField($"{ma.Name}", value, accessLevel);
            }
            else if (node.Left is ElementAccessExpressionSyntax ea)
            {
                var callee = RunExpression(ea.Expression);
                var args   = new HybInstance[ea.ArgumentList.Arguments.Count];

                var count = 0;
                foreach (var arg in ea.ArgumentList.Arguments)
                {
                    args[count++] = RunExpression(arg.Expression);
                }

                HybInstance value;
                callee.GetIndexer(args, out value);

                value = MadMath.Op(value, right, node.OperatorToken.Text.Substring(0, 1));

                if (callee.SetIndexer(args, value) == false)
                {
                    throw new NoSuchMemberException("[]");
                }
            }
        }