コード例 #1
0
        public void VisitDivide(DMASTDivide divide)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, divide.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, divide.B, _inferredPath);

            Result = new Expressions.Divide(divide.Location, lhs, rhs);
        }
コード例 #2
0
        public void VisitIn(DMASTExpressionIn expressionIn)
        {
            var expr      = DMExpression.Create(_dmObject, _proc, expressionIn.Value, _inferredPath);
            var container = DMExpression.Create(_dmObject, _proc, expressionIn.List, _inferredPath);

            Result = new Expressions.In(expressionIn.Location, expr, container);
        }
コード例 #3
0
        public void ProcessStatementForRange(DMASTProcStatementForRange statementForRange)
        {
            DMExpression.Emit(_dmObject, _proc, statementForRange.RangeStart);
            DMExpression.Emit(_dmObject, _proc, statementForRange.RangeEnd);
            DMExpression.Emit(_dmObject, _proc, statementForRange.Step);
            _proc.CreateRangeEnumerator();
            _proc.StartScope();
            {
                if (statementForRange.Initializer != null)
                {
                    ProcessStatement(statementForRange.Initializer);
                }

                string loopLabel = _proc.NewLabelName();
                _proc.LoopStart(loopLabel);
                {
                    DMExpression outputVariable = DMExpression.Create(_dmObject, _proc, statementForRange.Variable);
                    (DMReference outputRef, _) = outputVariable.EmitReference(_dmObject, _proc);
                    _proc.Enumerate(outputRef);
                    _proc.BreakIfFalse();

                    ProcessBlockInner(statementForRange.Body);

                    _proc.LoopContinue(loopLabel);
                    _proc.LoopJumpToStart(loopLabel);
                }
                _proc.LoopEnd();
            }
            _proc.EndScope();
            _proc.DestroyEnumerator();
        }
コード例 #4
0
        public void VisitListIndex(DMASTListIndex listIndex)
        {
            var expr  = DMExpression.Create(_dmObject, _proc, listIndex.Expression, _inferredPath);
            var index = DMExpression.Create(_dmObject, _proc, listIndex.Index, expr.Path);

            Result = new Expressions.ListIndex(listIndex.Location, expr, index, expr.Path, listIndex.Conditional);
        }
コード例 #5
0
        public void VisitNewDereference(DMASTNewDereference newDereference)
        {
            var expr = DMExpression.Create(_dmObject, _proc, newDereference.Dereference, _inferredPath);
            var args = new ArgumentList(newDereference.Location, _dmObject, _proc, newDereference.Parameters, _inferredPath);

            Result = new Expressions.New(newDereference.Location, expr, args);
        }
コード例 #6
0
        public void VisitGreaterThanOrEqual(DMASTGreaterThanOrEqual greaterThanOrEqual)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, greaterThanOrEqual.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, greaterThanOrEqual.B, _inferredPath);

            Result = new Expressions.GreaterThanOrEqual(greaterThanOrEqual.Location, lhs, rhs);
        }
コード例 #7
0
        public void VisitOr(DMASTOr or)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, or.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, or.B, _inferredPath);

            Result = new Expressions.Or(or.Location, lhs, rhs);
        }
コード例 #8
0
        public void VisitLogicalOrAssign(DMASTLogicalOrAssign lor)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, lor.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, lor.B, _inferredPath);

            Result = new Expressions.LogicalOrAssign(lor.Location, lhs, rhs);
        }
コード例 #9
0
        public void VisitDivideAssign(DMASTDivideAssign divideAssign)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, divideAssign.A);
            var rhs = DMExpression.Create(_dmObject, _proc, divideAssign.B);

            Result = new Expressions.DivideAssign(divideAssign.Location, lhs, rhs);
        }
コード例 #10
0
        public void VisitRemove(DMASTRemove remove)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, remove.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, remove.B, _inferredPath);

            Result = new Expressions.Remove(remove.Location, lhs, rhs);
        }
コード例 #11
0
        public void VisitMask(DMASTMask mask)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, mask.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, mask.B, _inferredPath);

            Result = new Expressions.Mask(mask.Location, lhs, rhs);
        }
コード例 #12
0
        public void VisitCombine(DMASTCombine combine)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, combine.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, combine.B, _inferredPath);

            Result = new Expressions.Combine(combine.Location, lhs, rhs);
        }
コード例 #13
0
        public void VisitPower(DMASTPower power)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, power.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, power.B, _inferredPath);

            Result = new Expressions.Power(power.Location, lhs, rhs);
        }
コード例 #14
0
        public void VisitModulus(DMASTModulus modulus)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, modulus.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, modulus.B, _inferredPath);

            Result = new Expressions.Modulo(modulus.Location, lhs, rhs);
        }
コード例 #15
0
        public void VisitEqual(DMASTEqual equal)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, equal.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, equal.B, _inferredPath);

            Result = new Expressions.Equal(equal.Location, lhs, rhs);
        }
コード例 #16
0
        public void VisitLeftShiftAssign(DMASTLeftShiftAssign leftShiftAssign)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, leftShiftAssign.A);
            var rhs = DMExpression.Create(_dmObject, _proc, leftShiftAssign.B);

            Result = new Expressions.LeftShiftAssign(leftShiftAssign.Location, lhs, rhs);
        }
コード例 #17
0
        public void VisitNotEquivalent(DMASTNotEquivalent notEquivalent)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, notEquivalent.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, notEquivalent.B, _inferredPath);

            Result = new Expressions.NotEquivalent(notEquivalent.Location, lhs, rhs);
        }
コード例 #18
0
        public void VisitRightShiftAssign(DMASTRightShiftAssign rightShiftAssign)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, rightShiftAssign.A);
            var rhs = DMExpression.Create(_dmObject, _proc, rightShiftAssign.B);

            Result = new Expressions.RightShiftAssign(rightShiftAssign.Location, lhs, rhs);
        }
コード例 #19
0
        public void VisitLessThanOrEqual(DMASTLessThanOrEqual lessThanOrEqual)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, lessThanOrEqual.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, lessThanOrEqual.B, _inferredPath);

            Result = new Expressions.LessThanOrEqual(lessThanOrEqual.Location, lhs, rhs);
        }
コード例 #20
0
        public void VisitXorAssign(DMASTXorAssign xorAssign)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, xorAssign.A);
            var rhs = DMExpression.Create(_dmObject, _proc, xorAssign.B);

            Result = new Expressions.XorAssign(xorAssign.Location, lhs, rhs);
        }
コード例 #21
0
        public void VisitAnd(DMASTAnd and)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, and.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, and.B, _inferredPath);

            Result = new Expressions.And(and.Location, lhs, rhs);
        }
コード例 #22
0
        public void VisitModulusAssign(DMASTModulusAssign modulusAssign)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, modulusAssign.A);
            var rhs = DMExpression.Create(_dmObject, _proc, modulusAssign.B);

            Result = new Expressions.ModulusAssign(modulusAssign.Location, lhs, rhs);
        }
コード例 #23
0
        public void VisitNewIdentifier(DMASTNewIdentifier newIdentifier)
        {
            var expr = DMExpression.Create(_dmObject, _proc, newIdentifier.Identifier, _inferredPath);
            var args = new ArgumentList(newIdentifier.Location, _dmObject, _proc, newIdentifier.Parameters, _inferredPath);

            Result = new Expressions.New(newIdentifier.Location, expr, args);
        }
コード例 #24
0
        public void VisitLeftShift(DMASTLeftShift leftShift)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, leftShift.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, leftShift.B, _inferredPath);

            Result = new Expressions.LeftShift(leftShift.Location, lhs, rhs);
        }
コード例 #25
0
        public void VisitIsType(DMASTIsType isType)
        {
            var expr = DMExpression.Create(_dmObject, _proc, isType.Value, _inferredPath);
            var path = DMExpression.Create(_dmObject, _proc, isType.Type, _inferredPath);

            Result = new Expressions.IsType(isType.Location, expr, path);
        }
コード例 #26
0
        public void VisitRightShift(DMASTRightShift rightShift)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, rightShift.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, rightShift.B, _inferredPath);

            Result = new Expressions.RightShift(rightShift.Location, lhs, rhs);
        }
コード例 #27
0
        public void VisitCall(DMASTCall call)
        {
            var procArgs = new ArgumentList(call.Location, _dmObject, _proc, call.ProcParameters, _inferredPath);

            switch (call.CallParameters.Length)
            {
            case 1:
            {
                var a = DMExpression.Create(_dmObject, _proc, call.CallParameters[0].Value, _inferredPath);
                Result = new Expressions.CallStatement(call.Location, a, procArgs);
            }
            break;

            case 2:
            {
                var a = DMExpression.Create(_dmObject, _proc, call.CallParameters[0].Value, _inferredPath);
                var b = DMExpression.Create(_dmObject, _proc, call.CallParameters[1].Value, _inferredPath);
                Result = new Expressions.CallStatement(call.Location, a, b, procArgs);
            }
            break;

            default:
                throw new CompileErrorException(call.Location, "invalid argument count for call()");
            }
        }
コード例 #28
0
        public void VisitBinaryOr(DMASTBinaryOr binaryOr)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, binaryOr.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, binaryOr.B, _inferredPath);

            Result = new Expressions.BinaryOr(binaryOr.Location, lhs, rhs);
        }
コード例 #29
0
        private void SetVariableValue(DMVariable variable, DMASTExpression value, DMValueType valType = DMValueType.Anything)
        {
            DMVisitorExpression._scopeMode = variable.IsGlobal ? "static" : "normal";
            DMExpression expression = DMExpression.Create(_currentObject, variable.IsGlobal ? DMObjectTree.GlobalInitProc : null, value, variable.Type);

            DMVisitorExpression._scopeMode = "normal";
            expression.ValType             = valType;

            if (expression.TryAsConstant(out var constant))
            {
                variable.Value = constant;
                return;
            }

            if (variable.IsConst)
            {
                throw new CompileErrorException(value.Location, "Value of const var must be a constant");
            }

            //Whether this should be initialized at runtime
            bool isValid = expression switch {
                //TODO: A better way of handling procs evaluated at compile time
                Expressions.ProcCall procCall => procCall.GetTargetProc(_currentObject).Proc?.Name switch {
                    "rgb" => true,
                    "generator" => true,
                    "matrix" => true,
                    "icon" => true,
                    "file" => true,
                    "sound" => true,
                    _ => variable.IsGlobal
                },
コード例 #30
0
        public void VisitMultiply(DMASTMultiply multiply)
        {
            var lhs = DMExpression.Create(_dmObject, _proc, multiply.A, _inferredPath);
            var rhs = DMExpression.Create(_dmObject, _proc, multiply.B, _inferredPath);

            Result = new Expressions.Multiply(multiply.Location, lhs, rhs);
        }