示例#1
0
文件: Exprs.cs 项目: ZiCog/HomeSpun
 public void Visit(DollarExpr e)
 {
     result = new FloInt(e.SymbolTable.Here);
 }
示例#2
0
文件: Exprs.cs 项目: ZiCog/HomeSpun
 public void Visit(AtAtAtExpr e)
 {
     SymbolInfo si = e.SymbolTable.LookupExisting(e.Token);
     if (!(si is DatSymbolInfo))
         throw new ParseException("Expected DAT symbol", e.Token);
     result = new FloInt((si as DatSymbolInfo).Dp + e.SymbolTable.HubAddress);
 }
示例#3
0
文件: Exprs.cs 项目: ZiCog/HomeSpun
 public void Visit(ConverterExpr e)
 {
     switch (e.Token.Text.ToUpper())
     {
         case "FLOAT":
             result = new FloInt((float)Expr.EvaluateIntConstant(e.Operand, this.insideDat));
             break;
         case "ROUND":
             result = new FloInt((int)(Expr.EvaluateFloatConstant(e.Operand, this.insideDat) + 0.5));
             break;
         case "TRUNC":
             result = new FloInt((int)(Expr.EvaluateFloatConstant(e.Operand, this.insideDat)));
             break;
     }
 }
示例#4
0
文件: Exprs.cs 项目: ZiCog/HomeSpun
 public void Visit(ConstantExpr e)
 {
     result = Expr.EvaluateConstant(e, this.insideDat);
 }
示例#5
0
文件: Exprs.cs 项目: ZiCog/HomeSpun
 public void Visit(FloatExpr e)
 {
     result = new FloInt(e.FloatValue);
 }
示例#6
0
文件: Exprs.cs 项目: ZiCog/HomeSpun
 public void Visit(RegisterExpr e)
 {
     if (insideDat)
         result = new FloInt(e.Reg + 0x1f0);
     else
         throw new ParseException("Registers not allowed in constant expression", e.Token);
 }
示例#7
0
文件: Exprs.cs 项目: ZiCog/HomeSpun
 public void Visit(IntExpr e)
 {
     result = new FloInt(e.IntValue);
 }
示例#8
0
文件: Exprs.cs 项目: ZiCog/HomeSpun
 public void Visit(ConExpr e)
 {
     if (e.ObjectToken == null)
     {
         ConSymbolInfo csi = e.SymbolTable.LookupExisting(e.Token) as ConSymbolInfo;
         if (csi == null)
             throw new ParseException("Expected " + e.Token.Text + " to be CON", e.Token);
         result = csi.Value;
     }
     else
     {
         ObjSymbolInfo osi = e.SymbolTable.LookupExisting(e.ObjectToken) as ObjSymbolInfo;
         if (osi == null)
             throw new ParseException("Not an object", e.ObjectToken);
         GlobalSymbolInfo gsi = GlobalSymbolTable.LookupExisting(osi.FilenameToken);
         ConSymbolInfo csi = gsi.SymbolTable.LookupExisting(e.Token) as ConSymbolInfo;
         if (csi == null)
             throw new ParseException("Expected " + e.Token.Text + " to be CON", e.Token);
         result = csi.Value;
     }
 }
示例#9
0
文件: Exprs.cs 项目: ZiCog/HomeSpun
 public void Visit(IdExpr e)
 {
     SymbolInfo symbolInfo = e.SymbolTable.LookupExisting(e.Token);
     if (symbolInfo is DatSymbolInfo)
     {
         if (insideDat)
         {
             int x = (symbolInfo as DatSymbolInfo).CogAddressX4;
             if ((x & 3) != 0)
                 throw new ParseException("Address is not long", e.Token);
             result = new FloInt(x / 4);
             return;
         }
         // else
         result = new FloInt((symbolInfo as DatSymbolInfo).Dp);
         return;
     }
     ConSymbolInfo conSymbolInfo = e.SymbolTable.LookupExisting(e.Token) as ConSymbolInfo;
     if (conSymbolInfo == null)
         throw new ParseException("Non-constant symbol", e.Token);
     result = conSymbolInfo.Value;
 }
示例#10
0
文件: Exprs.cs 项目: ZiCog/HomeSpun
        public void Visit(BinaryExpr e)
        {
            FloInt r1 = Expr.EvaluateConstant(e.Operand1, insideDat);
            FloInt r2 = Expr.EvaluateConstant(e.Operand2, insideDat);

            if (r1.IsInt)
            {
                if (!r2.IsInt)
                    throw new ParseException("Can't mix int and floating-point", e.Token);
                int i1 = r1.IntValue;
                int i2 = r2.IntValue;
                switch (e.Token.Text.ToUpper())
                {
                    case "->": result = new FloInt(Ror(i1, i2)); break;
                    case "<-": result = new FloInt(Rol(i1, i2)); break;
                    case ">>": result = new FloInt(Shr(i1, i2)); break;
                    case "<<": result = new FloInt(i1 << i2); break;
                    case "~>": result = new FloInt(Sar(i1, i2)); break;
                    case "><": result = new FloInt(Rev(i1, i2)); break;
                    case "&": result = new FloInt(i1 & i2); break;
                    case "|": result = new FloInt(i1 | i2); break;
                    case "^": result = new FloInt(i1 ^ i2); break;
                    case "*": result = new FloInt(i1 * i2); break;
                    case "**": result = new FloInt((int)(((long)i1 * (long)i2) >> 32)); break;
                    case "/": result = new FloInt(i1 / i2); break;
                    case "//": result = new FloInt(i1 % i2); break;
                    case "+": result = new FloInt(i1 + i2); break;
                    case "-": result = new FloInt(i1 - i2); break;
                    case "#>": result = new FloInt(i1 > i2 ? i1 : i2); break;
                    case "<#": result = new FloInt(i1 > i2 ? i2 : i1); break;
                    case "<": result = new FloInt(i1 < i2 ? -1 : 0); break;
                    case ">": result = new FloInt(i1 > i2 ? -1 : 0); break;
                    case "<>": result = new FloInt(i1 != i2 ? -1 : 0); break;
                    case "==": result = new FloInt(i1 == i2 ? -1 : 0); break;
                    case "=<": result = new FloInt(i1 <= i2 ? -1 : 0); break;
                    case "=>": result = new FloInt(i1 >= i2 ? -1 : 0); break;
                    case "AND": result = new FloInt((i1 != 0) && (i2 != 0) ? -1 : 0); break;
                    case "OR": result = new FloInt((i1 != 0) || (i2 != 0) ? -1 : 0); break;
                    default: throw new ParseException("Bad operator in constant expression: " + e.Token.Text, e.Token);
                }
            }
            else	// r1 is float
            {
                if (r2.IsInt)
                    throw new ParseException("Can't mix int and floating-point", e.Token);
                float f1 = r1.FloatValue;
                float f2 = r2.FloatValue;
                switch (e.Token.Text.ToUpper())
                {
                    case "*": result = new FloInt(f1 * f2); break;
                    case "/": result = new FloInt(f1 / f2); break;
                    case "+": result = new FloInt(f1 + f2); break;
                    case "-": result = new FloInt(f1 - f2); break;
                    case "#>": result = new FloInt(f1 > f2 ? f1 : f2); break;
                    case "<#": result = new FloInt(f1 > f2 ? f2 : f1); break;
                    case "<": result = new FloInt(f1 < f2 ? 1.0f : 0.0f); break;
                    case ">": result = new FloInt(f1 > f2 ? 1.0f : 0.0f); break;
                    case "<>": result = new FloInt(f1 != f2 ? 1.0f : 0.0f); break;
                    case "==": result = new FloInt(f1 == f2 ? 1.0f : 0.0f); break;
                    case "=<": result = new FloInt(f1 <= f2 ? 1.0f : 0.0f); break;
                    case "=>": result = new FloInt(f1 >= f2 ? 1.0f : 0.0f); break;
                    case "AND": result = new FloInt((f1 != 0.0f) && (f2 != 0.0f) ? 1.0f : 0.0f); break;
                    case "OR": result = new FloInt((f1 != 0.0f) || (f2 != 0.0f) ? 1.0f : 0.0f); break;
                    default: throw new ParseException("Bad operator in constant expression: " + e.Token.Text, e.Token);
                }
            }
        }
示例#11
0
文件: Exprs.cs 项目: ZiCog/HomeSpun
 public void Visit(UnaryExpr e)
 {
     if (e.Token.Text == "@")
     {
         result = new FloInt(EvaluateAt(e.Operand));
         return;
     }
     result = Expr.EvaluateConstant(e.Operand, insideDat);
     if (result.IsInt)
     {
         switch (e.Token.Text.ToUpper())
         {
             case "^^": result = new FloInt((int)Math.Sqrt((uint)result.IntValue)); break;
             case "||": result = new FloInt(Math.Abs(result.IntValue)); break;
             case "|<": result = new FloInt(1 << result.IntValue); break;
             case ">|": result = new FloInt(Encode(result.IntValue)); break;
             case "!": result = new FloInt(~result.IntValue); break;
             case "NOT": result = new FloInt(result.IntValue != 0 ? 0 : -1); break;
             case "-": result = new FloInt(-result.IntValue); break;
             default: throw new ParseException("Bad operator in constant expression: " + e.Token.Text, e.Token);
         }
     }
     else
     {
         switch (e.Token.Text.ToUpper())
         {
             case "^^": result = new FloInt((float)Math.Sqrt(result.FloatValue)); break;
             case "||": result = new FloInt(Math.Abs(result.FloatValue)); break;
             case "NOT": result = new FloInt(result.FloatValue != 0.0f ? 0.0f : 1.0f); break;
             case "-": result = new FloInt(-result.FloatValue); break;
             default: throw new ParseException("Bad operator in constant expression: " + e.Token.Text, e.Token);
         }
     }
 }