Exemplo n.º 1
0
        public static DMExpression Create(DMObject dmObject, DMProc proc, DMASTExpression expression, DreamPath?inferredPath = null)
        {
            var instance = new DMVisitorExpression(dmObject, proc, inferredPath);

            expression.Visit(instance);
            return(instance.Result);
        }
Exemplo n.º 2
0
 public DMASTProcStatementForRange(DMASTProcStatement initializer, DMASTIdentifier variable, DMASTExpression rangeStart, DMASTExpression rangeEnd, DMASTExpression step, DMASTProcBlockInner body) : base(initializer, body)
 {
     Variable   = variable;
     RangeStart = rangeStart;
     RangeEnd   = rangeEnd;
     Step       = step;
 }
Exemplo n.º 3
0
 public DMASTDefinitionParameter(DMASTPath path, DMASTExpression value, DMValueType type, DMASTExpression possibleValues)
 {
     Path           = path;
     Value          = value;
     Type           = type;
     PossibleValues = possibleValues;
 }
Exemplo n.º 4
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
                },
Exemplo n.º 5
0
 public DMASTProcStatementForLoop(DMASTProcStatementVarDeclaration variableDeclaration, DMASTCallable variable, DMASTExpression condition, DMASTExpression incrementer, DMASTProcBlockInner body)
 {
     VariableDeclaration = variableDeclaration;
     Variable            = variable;
     Condition           = condition;
     Incrementer         = incrementer;
     Body = body;
 }
Exemplo n.º 6
0
        public DMASTProcStatementVarDeclaration(DMASTPath path, DMASTExpression value)
        {
            int       varElementIndex = path.Path.FindElement("var");
            DreamPath typePath        = path.Path.FromElements(varElementIndex + 1, -2);

            Type  = (typePath.Elements.Length > 0) ? new DMASTPath(typePath) : null;
            Name  = path.Path.LastElement;
            Value = value;
        }
Exemplo n.º 7
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");
            }

            switch (expression)
            {
            case Expressions.List:
            case Expressions.NewList:
            case Expressions.NewPath:

            //TODO: A better way of handling procs evaluated at compile time
            case Expressions.ProcCall procCall when procCall.GetTargetProc(_currentObject).Proc?.Name == "rgb":
                variable.Value = new Expressions.Null(Location.Unknown);

                EmitInitializationAssign(variable, expression);
                break;

            case Expressions.ProcCall procCall when procCall.GetTargetProc(_currentObject).Proc?.Name == "generator":
                variable.Value = new Expressions.Null(Location.Unknown);

                EmitInitializationAssign(variable, expression);
                break;

            case Expressions.StringFormat:
            case Expressions.ProcCall:
                if (!variable.IsGlobal)
                {
                    throw new CompileErrorException(value.Location, $"Invalid initial value for \"{variable.Name}\"");
                }

                variable.Value = new Expressions.Null(Location.Unknown);
                EmitInitializationAssign(variable, expression);
                break;

            default:
                throw new CompileErrorException(value.Location, $"Invalid initial value for \"{variable.Name}\"");
            }
        }
Exemplo n.º 8
0
        bool?SimpleTruth(DMASTExpression expr)
        {
            switch (expr)
            {
            case DMASTConstantInteger e: return(e.Value != 0);

            case DMASTConstantFloat e: return(e.Value != 0);

            case DMASTConstantString e: return(e.Value.Length != 0);

            case DMASTConstantNull: return(false);

            case DMASTConstantPath: return(true);

            case DMASTConstantResource: return(true);

            default: return(null);
            }
        }
Exemplo n.º 9
0
        public DMASTObjectVarDefinition(DMASTPath astPath, DMASTExpression value)
        {
            DreamPath path = astPath.Path;

            int globalElementIndex = path.FindElement("global");

            if (globalElementIndex != -1)
            {
                path     = path.RemoveElement(globalElementIndex);
                IsGlobal = true;
            }

            int       varElementIndex = path.FindElement("var");
            DreamPath varPath         = path.FromElements(varElementIndex + 1, -1);

            ObjectPath = (varElementIndex > 1) ? new DMASTPath(path.FromElements(0, varElementIndex)) : null;
            Type       = (varPath.Elements.Length > 1) ? new DMASTPath(varPath.FromElements(0, -2)) : null;
            Name       = varPath.LastElement;
            Value      = value;
        }
Exemplo n.º 10
0
 public DMASTLeftShift(DMASTExpression a, DMASTExpression b)
 {
     A = a;
     B = b;
 }
Exemplo n.º 11
0
 public DMASTBinaryNot(DMASTExpression value)
 {
     Value = value;
 }
Exemplo n.º 12
0
 public DMASTProcStatementForList(DMASTProcStatement initializer, DMASTIdentifier variable, DMASTExpression list, DMASTProcBlockInner body) : base(initializer, body)
 {
     Variable = variable;
     List     = list;
 }
Exemplo n.º 13
0
 public DMASTProcStatementForStandard(DMASTProcStatement initializer, DMASTExpression comparator, DMASTExpression incrementor, DMASTProcBlockInner body) : base(initializer, body)
 {
     Comparator  = comparator;
     Incrementor = incrementor;
 }
Exemplo n.º 14
0
 public DMASTProcStatementIf(DMASTExpression condition, DMASTProcBlockInner body, DMASTProcBlockInner elseBody = null)
 {
     Condition = condition;
     Body      = body;
     ElseBody  = elseBody;
 }
Exemplo n.º 15
0
 public DMASTListIndex(DMASTExpression expression, DMASTExpression index)
 {
     Expression = expression;
     Index      = index;
 }
Exemplo n.º 16
0
 public DMASTProcStatementOutputControl(DMASTExpression receiver, DMASTExpression message, DMASTExpression control)
 {
     Receiver = receiver;
     Message  = message;
     Control  = control;
 }
Exemplo n.º 17
0
 public DMASTProcStatementBrowse(DMASTExpression receiver, DMASTExpression body, DMASTExpression options)
 {
     Receiver = receiver;
     Body     = body;
     Options  = options;
 }
Exemplo n.º 18
0
 public DMASTProcStatementDoWhile(DMASTExpression conditional, DMASTProcBlockInner body)
 {
     Conditional = conditional;
     Body        = body;
 }
Exemplo n.º 19
0
 public DMASTProcStatementExpression(DMASTExpression expression)
 {
     Expression = expression;
 }
Exemplo n.º 20
0
 public DMASTObjectVarOverride(DMASTPath path, DMASTExpression value)
 {
     ObjectPath = (path.Path.Elements.Length > 1) ? new DMASTPath(path.Path.FromElements(0, -2)) : null;
     VarName    = path.Path.LastElement;
     Value      = value;
 }
Exemplo n.º 21
0
 public DMASTDereferenceProc(DMASTExpression expression, Dereference[] dereferences) : base(expression, dereferences)
 {
 }
Exemplo n.º 22
0
 public DMASTDereference(DMASTExpression expression, Dereference[] dereferences)
 {
     Expression   = expression;
     Dereferences = dereferences;
 }
Exemplo n.º 23
0
 public DMASTRightShift(DMASTExpression a, DMASTExpression b)
 {
     A = a;
     B = b;
 }
Exemplo n.º 24
0
 public DMASTCallParameter(DMASTExpression value, string name = null)
 {
     Value = value;
     Name  = name;
 }
Exemplo n.º 25
0
 public DMASTProcStatementSwitch(DMASTExpression value, SwitchCase[] cases)
 {
     Value = value;
     Cases = cases;
 }
Exemplo n.º 26
0
 public DMASTProcStatementReturn(DMASTExpression value)
 {
     Value = value;
 }
Exemplo n.º 27
0
 public DMASTProcStatementBrowseResource(DMASTExpression receiver, DMASTExpression file, DMASTExpression filename)
 {
     Receiver = receiver;
     File     = file;
     Filename = filename;
 }
Exemplo n.º 28
0
 public DMASTProcStatementDel(DMASTExpression value)
 {
     Value = value;
 }
Exemplo n.º 29
0
 public DMASTProcStatementSpawn(DMASTExpression time, DMASTProcBlockInner body)
 {
     Time = time;
     Body = body;
 }
Exemplo n.º 30
0
 public DMASTExpressionIn(DMASTExpression value, DMASTExpression list)
 {
     Value = value;
     List  = list;
 }