Exemplo n.º 1
0
 public void VisitConstantFloat(DMASTConstantFloat constant)
 {
     Result = new Expressions.Number(constant.Location, constant.Value);
 }
Exemplo n.º 2
0
 public And(Location location, DMExpression lhs, DMExpression rhs)
     : base(location, lhs, rhs)
 {
 }
Exemplo n.º 3
0
 public In(Location location, DMExpression expr, DMExpression container)
     : base(location, expr, container)
 {
 }
Exemplo n.º 4
0
 public BinaryOr(Location location, DMExpression lhs, DMExpression rhs)
     : base(location, lhs, rhs)
 {
 }
Exemplo n.º 5
0
 public GreaterThan(Location location, DMExpression lhs, DMExpression rhs)
     : base(location, lhs, rhs)
 {
 }
Exemplo n.º 6
0
 public Divide(Location location, DMExpression lhs, DMExpression rhs)
     : base(location, lhs, rhs)
 {
 }
Exemplo n.º 7
0
 public Modulo(Location location, DMExpression lhs, DMExpression rhs)
     : base(location, lhs, rhs)
 {
 }
Exemplo n.º 8
0
        public void VisitPostDecrement(DMASTPostDecrement postDecrement)
        {
            var expr = DMExpression.Create(_dmObject, _proc, postDecrement.Expression, _inferredPath);

            Result = new Expressions.PostDecrement(postDecrement.Location, expr);
        }
Exemplo n.º 9
0
        public void VisitIsSaved(DMASTIsSaved isSaved)
        {
            var expr = DMExpression.Create(_dmObject, _proc, isSaved.Expression, _inferredPath);

            Result = new Expressions.IsSaved(isSaved.Location, expr);
        }
Exemplo n.º 10
0
        public void VisitNewPath(DMASTNewPath newPath)
        {
            var args = new ArgumentList(newPath.Location, _dmObject, _proc, newPath.Parameters, _inferredPath);

            Result = new Expressions.NewPath(newPath.Location, newPath.Path.Path, args);
        }
Exemplo n.º 11
0
 public void VisitConstantPath(DMASTConstantPath constant)
 {
     Result = new Expressions.Path(constant.Location, constant.Value.Path);
 }
Exemplo n.º 12
0
        public void VisitDereferenceProc(DMASTDereferenceProc dereferenceProc)
        {
            var expr = DMExpression.Create(_dmObject, _proc, dereferenceProc.Expression, _inferredPath);

            Result = new Expressions.DereferenceProc(dereferenceProc.Location, expr, dereferenceProc);
        }
Exemplo n.º 13
0
 public void VisitConstantResource(DMASTConstantResource constant)
 {
     Result = new Expressions.Resource(constant.Location, constant.Path);
 }
Exemplo n.º 14
0
 public void VisitConstantString(DMASTConstantString constant)
 {
     Result = new Expressions.String(constant.Location, constant.Value);
 }
Exemplo n.º 15
0
 public void ProcessStatementDel(DMASTProcStatementDel statementDel)
 {
     DMExpression.Emit(_dmObject, _proc, statementDel.Value);
     _proc.DeleteObject();
 }
Exemplo n.º 16
0
 public void VisitList(DMASTList list)
 {
     Result = new Expressions.List(list.Location, list);
 }
Exemplo n.º 17
0
        public void ProcessStatementSwitch(DMASTProcStatementSwitch statementSwitch)
        {
            string endLabel = _proc.NewLabelName();
            List <(string CaseLabel, DMASTProcBlockInner CaseBody)> valueCases = new();
            DMASTProcBlockInner defaultCaseBody = null;

            DMExpression.Emit(_dmObject, _proc, statementSwitch.Value);
            foreach (DMASTProcStatementSwitch.SwitchCase switchCase in statementSwitch.Cases)
            {
                if (switchCase is DMASTProcStatementSwitch.SwitchCaseValues switchCaseValues)
                {
                    string caseLabel = _proc.NewLabelName();

                    foreach (DMASTExpression value in switchCaseValues.Values)
                    {
                        if (value is DMASTSwitchCaseRange range)
                        {
                            if (!DMExpression.TryConstant(_dmObject, _proc, range.RangeStart, out var lower))
                            {
                                throw new CompileErrorException(new CompilerError(range.RangeStart.Location, "Expected a constant"));
                            }
                            if (!DMExpression.TryConstant(_dmObject, _proc, range.RangeEnd, out var upper))
                            {
                                throw new CompileErrorException(new CompilerError(range.RangeEnd.Location, "Expected a constant"));
                            }

                            lower.EmitPushValue(_dmObject, _proc);
                            upper.EmitPushValue(_dmObject, _proc);
                            _proc.SwitchCaseRange(caseLabel);
                        }
                        else
                        {
                            if (!DMExpression.TryConstant(_dmObject, _proc, value, out var constant))
                            {
                                throw new CompileErrorException(new CompilerError(value.Location, "Expected a constant"));
                            }

                            constant.EmitPushValue(_dmObject, _proc);
                            _proc.SwitchCase(caseLabel);
                        }
                    }

                    valueCases.Add((caseLabel, switchCase.Body));
                }
                else
                {
                    defaultCaseBody = ((DMASTProcStatementSwitch.SwitchCaseDefault)switchCase).Body;
                }
            }
            _proc.Pop();

            if (defaultCaseBody != null)
            {
                _proc.StartScope();
                {
                    ProcessBlockInner(defaultCaseBody);
                }
                _proc.EndScope();
            }
            _proc.Jump(endLabel);

            foreach ((string CaseLabel, DMASTProcBlockInner CaseBody)valueCase in valueCases)
            {
                _proc.AddLabel(valueCase.CaseLabel);
                _proc.StartScope();
                {
                    ProcessBlockInner(valueCase.CaseBody);
                }
                _proc.EndScope();
                _proc.Jump(endLabel);
            }

            _proc.AddLabel(endLabel);
        }
Exemplo n.º 18
0
 public void VisitInput(DMASTInput input)
 {
     Result = new Expressions.Input(input.Location, input);
 }
Exemplo n.º 19
0
 public BinaryOp(Location location, DMExpression lhs, DMExpression rhs) : base(location)
 {
     LHS = lhs;
     RHS = rhs;
 }
Exemplo n.º 20
0
        public void VisitInitial(DMASTInitial initial)
        {
            var expr = DMExpression.Create(_dmObject, _proc, initial.Expression, _inferredPath);

            Result = new Expressions.Initial(initial.Location, expr);
        }
Exemplo n.º 21
0
 public RightShift(Location location, DMExpression lhs, DMExpression rhs)
     : base(location, lhs, rhs)
 {
 }
Exemplo n.º 22
0
 public ProcCall(Location location, DMExpression target, ArgumentList arguments) : base(location)
 {
     _target    = target;
     _arguments = arguments;
 }
Exemplo n.º 23
0
 public NotEquivalent(Location location, DMExpression lhs, DMExpression rhs)
     : base(location, lhs, rhs)
 {
 }
Exemplo n.º 24
0
        public void ProcessStatementSet(DMASTProcStatementSet statementSet)
        {
            var attribute = statementSet.Attribute.ToLower();

            // TODO deal with "src"
            if (!DMExpression.TryConstant(_dmObject, _proc, statementSet.Value, out var constant) && attribute != "src")
            {
                throw new CompileErrorException(statementSet.Location, $"{attribute} attribute should be a constant");
            }

            switch (statementSet.Attribute.ToLower())
            {
            case "waitfor": {
                _proc.WaitFor(constant.IsTruthy());
                break;
            }

            case "opendream_unimplemented": {
                if (constant.IsTruthy())
                {
                    _proc.Attributes |= ProcAttributes.Unimplemented;
                }
                else
                {
                    _proc.Attributes &= ~ProcAttributes.Unimplemented;
                }
                break;
            }

            case "hidden":
                if (constant.IsTruthy())
                {
                    _proc.Attributes |= ProcAttributes.Hidden;
                }
                else
                {
                    _proc.Attributes &= ~ProcAttributes.Hidden;
                }
                break;

            case "popup_menu":
                if (constant.IsTruthy())     // The default is to show it so we flag it if it's hidden
                {
                    _proc.Attributes &= ~ProcAttributes.HidePopupMenu;
                }
                else
                {
                    _proc.Attributes |= ProcAttributes.HidePopupMenu;
                }

                DMCompiler.UnimplementedWarning(statementSet.Location, "set popup_menu is not implemented");
                break;

            case "instant":
                if (constant.IsTruthy())
                {
                    _proc.Attributes |= ProcAttributes.Instant;
                }
                else
                {
                    _proc.Attributes &= ~ProcAttributes.Instant;
                }

                DMCompiler.UnimplementedWarning(statementSet.Location, "set instant is not implemented");
                break;

            case "background":
                if (constant.IsTruthy())
                {
                    _proc.Attributes |= ProcAttributes.Background;
                }
                else
                {
                    _proc.Attributes &= ~ProcAttributes.Background;
                }
                break;

            case "name":
                if (constant is not Expressions.String nameStr)
                {
                    throw new CompileErrorException(statementSet.Location, "name attribute must be a string");
                }

                _proc.VerbName = nameStr.Value;
                break;

            case "category":
                _proc.VerbCategory = constant switch {
                    Expressions.String str => str.Value,
                                       Expressions.Null => null,
                                       _ => throw new CompileErrorException(statementSet.Location, "category attribute must be a string or null")
                };

                break;

            case "desc":
                if (constant is not Expressions.String descStr)
                {
                    throw new CompileErrorException(statementSet.Location, "desc attribute must be a string");
                }

                _proc.VerbDesc = descStr.Value;
                DMCompiler.UnimplementedWarning(statementSet.Location, "set desc is not implemented");
                break;

            case "invisibility":
                // The ref says 0-101 for atoms and 0-100 for verbs
                // BYOND doesn't clamp the actual var value but it does seem to treat out-of-range values as their extreme
                if (constant is not Expressions.Number invisNum)
                {
                    throw new CompileErrorException(statementSet.Location, "invisibility attribute must be an int");
                }

                _proc.Invisibility = Convert.ToSByte(Math.Clamp(Math.Floor(invisNum.Value), 0, 100));
                DMCompiler.UnimplementedWarning(statementSet.Location, "set invisibility is not implemented");
                break;

            case "src":
                DMCompiler.UnimplementedWarning(statementSet.Location, "set src is not implemented");
                break;
            }
        }
Exemplo n.º 25
0
 public LessThanOrEqual(Location location, DMExpression lhs, DMExpression rhs)
     : base(location, lhs, rhs)
 {
 }
Exemplo n.º 26
0
 public void ProcessStatementExpression(DMASTProcStatementExpression statement)
 {
     DMExpression.Emit(_dmObject, _proc, statement.Expression);
     _proc.Pop();
 }
Exemplo n.º 27
0
 public Subtract(Location location, DMExpression lhs, DMExpression rhs)
     : base(location, lhs, rhs)
 {
 }
Exemplo n.º 28
0
        public void ProcessStatementSet(DMASTProcStatementSet statementSet)
        {
            var attribute = statementSet.Attribute.ToLower();

            if (!DMExpression.TryConstant(_dmObject, _proc, statementSet.Value, out var constant))
            {
                throw new CompileErrorException(statementSet.Location, $"{attribute} attribute should be a constant");
            }

            switch (statementSet.Attribute.ToLower())
            {
            case "waitfor": {
                _proc.WaitFor(constant.IsTruthy());
                break;
            }

            case "opendream_unimplemented": {
                if (constant.IsTruthy())
                {
                    _proc.Attributes |= ProcAttributes.Unimplemented;
                }
                else
                {
                    _proc.Attributes &= ~ProcAttributes.Unimplemented;
                }
                break;
            }

            case "hidden":
                if (constant.IsTruthy())
                {
                    _proc.Attributes |= ProcAttributes.Hidden;
                }
                else
                {
                    _proc.Attributes &= ~ProcAttributes.Hidden;
                }

                if (!DMCompiler.Settings.SuppressUnimplementedWarnings)
                {
                    DMCompiler.Warning(new CompilerWarning(statementSet.Location, "set hidden is not implemented"));
                }

                break;

            case "popup_menu":
                if (constant.IsTruthy())     // The default is to show it so we flag it if it's hidden
                {
                    _proc.Attributes &= ~ProcAttributes.HidePopupMenu;
                }
                else
                {
                    _proc.Attributes |= ProcAttributes.HidePopupMenu;
                }

                if (!DMCompiler.Settings.SuppressUnimplementedWarnings)
                {
                    DMCompiler.Warning(new CompilerWarning(statementSet.Location, "set popup_menu is not implemented"));
                }

                break;

            case "instant":
                if (constant.IsTruthy())
                {
                    _proc.Attributes |= ProcAttributes.Instant;
                }
                else
                {
                    _proc.Attributes &= ~ProcAttributes.Instant;
                }

                if (!DMCompiler.Settings.SuppressUnimplementedWarnings)
                {
                    DMCompiler.Warning(new CompilerWarning(statementSet.Location, "set instant is not implemented"));
                }
                break;

            case "background":
                if (constant.IsTruthy())
                {
                    _proc.Attributes |= ProcAttributes.Background;
                }
                else
                {
                    _proc.Attributes &= ~ProcAttributes.Background;
                }

                if (!DMCompiler.Settings.SuppressUnimplementedWarnings)
                {
                    DMCompiler.Warning(new CompilerWarning(statementSet.Location, "set background is not implemented"));
                }
                break;

            case "name":
                DMASTConstantString name = statementSet.Value as DMASTConstantString;
                if (name is null)
                {
                    throw new CompileErrorException(statementSet.Location, "bad text");
                }
                _proc.VerbName = name.Value;

                if (!DMCompiler.Settings.SuppressUnimplementedWarnings)
                {
                    DMCompiler.Warning(new CompilerWarning(statementSet.Location, "set name is not implemented"));
                }

                break;

            case "category":
                DMASTConstantString category = statementSet.Value as DMASTConstantString;
                if (category is null)
                {
                    throw new CompileErrorException(statementSet.Location, "bad text");
                }
                _proc.VerbCategory = category.Value;

                if (!DMCompiler.Settings.SuppressUnimplementedWarnings)
                {
                    DMCompiler.Warning(new CompilerWarning(statementSet.Location, "set category is not implemented"));
                }
                break;

            case "desc":
                DMASTConstantString desc = statementSet.Value as DMASTConstantString;
                if (desc is null)
                {
                    throw new CompileErrorException(statementSet.Location, "bad text");
                }
                _proc.VerbDesc = desc.Value;

                if (!DMCompiler.Settings.SuppressUnimplementedWarnings)
                {
                    DMCompiler.Warning(new CompilerWarning(statementSet.Location, "set desc is not implemented"));
                }
                break;

            case "invisibility":
                // The ref says 0-101 for atoms and 0-100 for verbs
                // BYOND doesn't clamp the actual var value but it does seem to treat out-of-range values as their extreme
                DMASTConstantFloat invisFloat = statementSet.Value as DMASTConstantFloat;
                if (invisFloat is null)
                {
                    DMASTConstantInteger invisInt = statementSet.Value as DMASTConstantInteger;
                    if (invisInt is null)
                    {
                        throw new CompileErrorException(statementSet.Location, "bad num");
                    }
                    _proc.Invisibility = Convert.ToSByte(Math.Clamp(invisInt.Value, 0, 100));
                }
                else
                {
                    _proc.Invisibility = Convert.ToSByte(Math.Clamp(Math.Floor(invisFloat.Value), 0, 100));
                }

                if (!DMCompiler.Settings.SuppressUnimplementedWarnings)
                {
                    DMCompiler.Warning(new CompilerWarning(statementSet.Location, "set invisibility is not implemented"));
                }
                break;

            case "src":
                if (!DMCompiler.Settings.SuppressUnimplementedWarnings)
                {
                    DMCompiler.Warning(new CompilerWarning(statementSet.Location, "set src is not implemented"));
                }
                break;
            }
        }
Exemplo n.º 29
0
 public Assignment(Location location, DMExpression lhs, DMExpression rhs)
     : base(location, lhs, rhs)
 {
 }
Exemplo n.º 30
0
 public void VisitConstantNull(DMASTConstantNull constant)
 {
     Result = new Expressions.Null(constant.Location);
 }