public Expression ExpandConstant(string name) { if (EvaluatingConstants.Contains(name)) { throw new CompilationException("Cycle in constants evaluation detected", name, 0); } EvaluatingConstants.Add(name); Constants[name] = Constants[name].ExpandConstants(this); EvaluatingConstants.Remove(name); return(Constants[name]); }
public void EvaluateAllExpressions() { var address = 0; foreach (var constant in Constants.Keys.ToArray()) { EvaluatingConstants.Clear(); ExpandConstant(constant); } foreach (var statement in Statements) { statement.FieldA = statement.FieldA.ExpandConstants(this); statement.FieldB = statement.FieldB.ExpandConstants(this); } foreach (var statement in Statements) { statement.FieldA = new NumberExpression(ModularArith.Mod(statement.FieldA.Calculate(this, address))); statement.FieldB = new NumberExpression(ModularArith.Mod(statement.FieldB.Calculate(this, address))); address++; } if (StartAddressExpression == null) { StartAddress = 0; } else { StartAddressExpression = StartAddressExpression.ExpandConstants(this); if (StartAddressExpression.GetType() == typeof(VariableExpression)) { StartAddress = ModularArith.Mod(Statements.Count + StartAddressExpression.Calculate(this, Statements.Count)); } else if (StartAddressExpression.GetType() == typeof(NumberExpression)) { StartAddress = StartAddressExpression.Calculate(this, Statements.Count); } else { throw new CompilationException("END argument must be label, constant name or number", StartAddressExpression.ToString(), 0); } } }