Example #1
0
 public TableSet(int line, Expression table, Expression index, Expression @value, bool isTable, int timestamp) : base(line)
 {
     this.table     = table;
     this.index     = index;
     this.value     = @value;
     this.isTable   = isTable;
     this.timestamp = timestamp;
 }
Example #2
0
	  public TableSet(int line, Expression table, Expression index, Expression @value, bool isTable, int timestamp) : base(line)
	  {
		this.table = table;
		this.index = index;
		this.value = @value;
		this.isTable = isTable;
		this.timestamp = timestamp;
	  }
Example #3
0
        public RegisterSet(int line, int register, Expression @value) : base(line)
        {
            this.register = register;
            this.value    = @value;
//
//    if(value.isMultiple()) {
//      System.out.println("-- multiple @" + register);
//    }
//
        }
Example #4
0
	  public RegisterSet(int line, int register, Expression @value) : base(line)
	  {
		this.register = register;
		this.value = @value;
//    
//    if(value.isMultiple()) {
//      System.out.println("-- multiple @" + register);
//    }
//    
	  }
Example #5
0
 public virtual void addLast(Target target, Expression @value)
 {
     if(targets.Contains(target))
     {
       int index = targets.IndexOf(target);
       targets.RemoveAt(index);
       @value = values[index];
       values.RemoveAt(index);
     }
     targets.Add(target);
     values.Add(@value);
     allnil = allnil && @value.isNil();
 }
Example #6
0
        public override Expression asExpression(Registers r)
        {
            bool       transpose       = false;
            Expression leftExpression  = r.getKExpression(left, line);
            Expression rightExpression = r.getKExpression(right, line);

            if (((left | right) & 256) == 0)
            {
                transpose = r.getUpdated(left, line) > r.getUpdated(right, line);
            }
            else
            {
                transpose = rightExpression.getConstantIndex() < leftExpression.getConstantIndex();
            }
            string     op  = !transpose ? "<=" : ">=";
            Expression rtn = new BinaryExpression(op, !transpose ? leftExpression : rightExpression, !transpose ? rightExpression : leftExpression, Expression.PRECEDENCE_COMPARE, Expression.ASSOCIATIVITY_LEFT);

            if (_invert)
            {
                rtn = new UnaryExpression("not ", rtn, Expression.PRECEDENCE_UNARY);
            }
            return(rtn);
        }
Example #7
0
 public UpvalueSet(int line, string upvalue, Expression @value) : base(line)
 {
     target     = new UpvalueTarget(upvalue);
     this.value = @value;
 }
Example #8
0
 public virtual void setValue(int register, int line, Expression expression)
 {
     values[register,line] = expression;
     updated[register,line] = line;
 }
Example #9
0
 public IfThenEndBlockOperation(int line, Assignment _assign, Expression _expr)
     : base(line)
 {
     assign = _assign;
     expr = _expr;
 }
Example #10
0
	  public ReturnOperation(int line, Expression[] values) : base(line)
	  {
		this.values = values;
	  }
Example #11
0
 public TableTarget(Expression table, Expression index)
 {
     this.table = table;
     this.index = index;
 }
Example #12
0
 abstract public void useExpression(Expression expression);
Example #13
0
	  public TableTarget(Expression table, Expression index)
	  {
		this.table = table;
		this.index = index;
	  }
Example #14
0
 public override void useExpression(Expression expression)
 {
     left.useExpression(expression);
     right.useExpression(expression);
 }
Example #15
0
	  public UpvalueSet(int line, string upvalue, Expression @value) : base(line)
	  {
		target = new UpvalueTarget(upvalue);
		this.value = @value;
	  }
Example #16
0
 public virtual void addFirst(Target target, Expression @value)
 {
     targets.Insert(0, target);
     values.Insert(0, @value);
     allnil = allnil && @value.isNil();
 }
Example #17
0
 public Assignment(Target target, Expression @value)
 {
     targets.Add(target);
     values.Add(@value);
     allnil = allnil && @value.isNil();
 }
Example #18
0
 public ReturnOperation(int line, Expression @value) : base(line)
 {
     values    = new Expression[1];
     values[0] = @value;
 }
Example #19
0
 public SetBlockOperation(int line, Target target, Expression value)
     : base(line)
 {
     _target = target;
     _value = value;
 }
Example #20
0
	  public override void useExpression(Expression expression)
	  {
	// Do nothing 
	  }
Example #21
0
 public abstract void useExpression(Expression expression);
Example #22
0
	  public GlobalSet(int line, string global, Expression @value) : base(line)
	  {
		this.global = global;
		this.value = @value;
	  }
Example #23
0
	  public ReturnOperation(int line, Expression @value) : base(line)
	  {
		values = new Expression[1];
		values[0] = @value;
	  }
Example #24
0
 public override void useExpression(Expression expression)
 {
     left.useExpression(expression);
     right.useExpression(expression);
 }
Example #25
0
        private List<Operation> processLine(int line)
        {
            List<Operation> operations = new List<Operation>();
            int A = code.A(line);
            int B = code.B(line);
            int C = code.C(line);
            int Bx = code.Bx(line);

            switch(code.op(line))
            {
              case Op.MOVE:
            operations.Add(new RegisterSet(line, A, r.getExpression(B, line)));
            break;
              case Op.LOADK:
            operations.Add(new RegisterSet(line, A, f.getConstantExpression(Bx)));
            break;
              case Op.LOADBOOL:
            operations.Add(new RegisterSet(line, A, new ConstantExpression(new Constant(B != 0 ? LBoolean.LTRUE : LBoolean.LFALSE), -1)));
            break;
              case Op.LOADNIL:
              {
            int maximum;
            if(function.header.version.usesOldLoadNilEncoding())
            {
              maximum = B;
            }
            else
            {
              maximum = A + B;
            }
            while(A <= maximum)
            {
              operations.Add(new RegisterSet(line, A, Expression.NIL));
              A++;
            }
            break;
              }
            //JAVA TO VB & C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
              case Op.GETUPVAL:
            operations.Add(new RegisterSet(line, A, upvalues.getExpression(B)));
            break;
              case Op.GETTABUP:
            if(B == 0 && (C & 0x100) != 0)
            {
              operations.Add(new RegisterSet(line, A, f.getGlobalExpression(C & 0xFF))); //TODO: check
            }
            else
            {
              operations.Add(new RegisterSet(line, A, new TableReference(upvalues.getExpression(B), r.getKExpression(C, line))));
            }
            break;
              case Op.GETGLOBAL:
            operations.Add(new RegisterSet(line, A, f.getGlobalExpression(Bx)));
            break;
              case Op.GETTABLE:
            operations.Add(new RegisterSet(line, A, new TableReference(r.getExpression(B, line), r.getKExpression(C, line))));
            break;
              case Op.SETUPVAL:
            operations.Add(new UpvalueSet(line, upvalues.getName(B), r.getExpression(A, line)));
            break;
              case Op.SETTABUP:
            if(A == 0 && (B & 0x100) != 0)
            {
              operations.Add(new GlobalSet(line, f.getGlobalName(B & 0xFF), r.getKExpression(C, line))); //TODO: check
            }
            else
            {
              operations.Add(new TableSet(line, upvalues.getExpression(A), r.getKExpression(B, line), r.getKExpression(C, line), true, line));
            }
            break;
              case Op.SETGLOBAL:
            operations.Add(new GlobalSet(line, f.getGlobalName(Bx), r.getExpression(A, line)));
            break;
              case Op.SETTABLE:
            operations.Add(new TableSet(line, r.getExpression(A, line), r.getKExpression(B, line), r.getKExpression(C, line), true, line));
            break;
              case Op.NEWTABLE:
            operations.Add(new RegisterSet(line, A, new TableLiteral(B, C)));
            break;
              case Op.SELF:
              {
            // We can later determine is : syntax was used by comparing subexpressions with ==
            Expression common = r.getExpression(B, line);
            operations.Add(new RegisterSet(line, A + 1, common));
            operations.Add(new RegisterSet(line, A, new TableReference(common, r.getKExpression(C, line))));
            break;
              }
            //JAVA TO VB & C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
              case Op.ADD:
            operations.Add(new RegisterSet(line, A, Expression.makeADD(r.getKExpression(B, line), r.getKExpression(C, line))));
            break;
              case Op.SUB:
            operations.Add(new RegisterSet(line, A, Expression.makeSUB(r.getKExpression(B, line), r.getKExpression(C, line))));
            break;
              case Op.MUL:
            operations.Add(new RegisterSet(line, A, Expression.makeMUL(r.getKExpression(B, line), r.getKExpression(C, line))));
            break;
              case Op.DIV:
            operations.Add(new RegisterSet(line, A, Expression.makeDIV(r.getKExpression(B, line), r.getKExpression(C, line))));
            break;
              case Op.MOD:
            operations.Add(new RegisterSet(line, A, Expression.makeMOD(r.getKExpression(B, line), r.getKExpression(C, line))));
            break;
              case Op.POW:
            operations.Add(new RegisterSet(line, A, Expression.makePOW(r.getKExpression(B, line), r.getKExpression(C, line))));
            break;
              case Op.UNM:
            operations.Add(new RegisterSet(line, A, Expression.makeUNM(r.getExpression(B, line))));
            break;
              case Op.NOT:
            operations.Add(new RegisterSet(line, A, Expression.makeNOT(r.getExpression(B, line))));
            break;
              case Op.LEN:
            operations.Add(new RegisterSet(line, A, Expression.makeLEN(r.getExpression(B, line))));
            break;
              case Op.CONCAT:

            Expression @value1 = r.getExpression(C, line);
            //Remember that CONCAT is right associative.
            while(C-- > B)
            {
              @value1 = Expression.makeCONCAT(r.getExpression(C, line), @value1);
            }
            operations.Add(new RegisterSet(line, A, @value1));
            break;

            //JAVA TO VB & C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
              case Op.JMP:
              case Op.EQ:
              case Op.LT:
              case Op.LE:
              case Op.TEST:
              case Op.TESTSET:
            // Do nothing... handled with branches
            break;
              case Op.CALL:
              {
            bool multiple = (C >= 3 || C == 0);
            if(B == 0)
                B = registers - A;
            if(C == 0)
                C = registers - A + 1;
            Expression function2 = r.getExpression(A, line);
            Expression[] arguments = new Expression[B - 1];
            for(int register = A + 1; register <= A + B - 1; register++)
            {
              arguments[register - A - 1] = r.getExpression(register, line);
            }
            FunctionCall @value = new FunctionCall(function2, arguments, multiple);
            if(C == 1)
            {
              operations.Add(new CallOperation(line, @value));
            }
            else
            {
              if(C == 2 && !multiple)
              {
                operations.Add(new RegisterSet(line, A, @value));
              }
              else
              {
                for(int register = A; register <= A + C - 2; register++)
                {
                  operations.Add(new RegisterSet(line, register, @value));
                }
              }
            }
            break;
              }
            //JAVA TO VB & C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
              case Op.TAILCALL:
              {
            if(B == 0)
                B = registers - A;
            Expression function1 = r.getExpression(A, line);
            Expression[] arguments = new Expression[B - 1];
            for(int register = A + 1; register <= A + B - 1; register++)
            {
              arguments[register - A - 1] = r.getExpression(register, line);
            }
            FunctionCall @value2 = new FunctionCall(function1, arguments, true);
            operations.Add(new ReturnOperation(line, @value2));
            skip[line + 1] = true;
            break;
              }
            //JAVA TO VB & C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
              case Op.RETURN:
              {
            if(B == 0)
                B = registers - A + 1;
            Expression[] values = new Expression[B - 1];
            for(int register = A; register <= A + B - 2; register++)
            {
              values[register - A] = r.getExpression(register, line);
            }
            operations.Add(new ReturnOperation(line, values));
            break;
              }
            //JAVA TO VB & C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
              case Op.FORLOOP:
              case Op.FORPREP:
              case Op.TFORCALL:
              case Op.TFORLOOP:
            // Do nothing... handled with branches
            break;
              case Op.SETLIST:

            if(C == 0)
            {
              C = code.codepoint(line + 1);
              skip[line + 1] = true;
            }
            if(B == 0)
            {
              B = registers - A - 1;
            }
            Expression table = r.getValue(A, line);
            for(int i = 1; i <= B; i++)
            {
              operations.Add(new TableSet(line, table, new ConstantExpression(new Constant((C - 1) * 50 + i), -1), r.getExpression(A + i, line), false, r.getUpdated(A + i, line)));
            }
            break;

            //JAVA TO VB & C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
              case Op.CLOSE:
            break;
              case Op.CLOSURE:

            LFunction f2 = functions[Bx];
            operations.Add(new RegisterSet(line, A, new ClosureExpression(f2, declList, line + 1)));
            if(function.header.version.usesInlineUpvalueDeclarations())
            {
              // Skip upvalue declarations
              for(int i = 0; i < f2.numUpvalues; i++)
              {
                skip[line + 1 + i] = true;
              }
            }
            break;

            //JAVA TO VB & C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
              case Op.VARARG:

            bool multiple1 = (B != 2);
            if(B == 1)
                throw new Exception();
            if(B == 0)
                B = registers - A + 1;
            Expression @value3 = new Vararg(B - 1, multiple1);
            for(int register = A; register <= A + B - 2; register++)
            {
              operations.Add(new RegisterSet(line, register, @value3));
            }
            break;

            //JAVA TO VB & C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
              default:
            throw new Exception("Illegal instruction: " + code.op(line));
            }
            return operations;
        }
Example #26
0
 public override void useExpression(Expression expression)
 {
     // Do nothing
 }
Example #27
0
 public GlobalSet(int line, string global, Expression @value) : base(line)
 {
     this.global = global;
     this.value  = @value;
 }