Esempio n. 1
0
		public override byte[] Compile(Compiler compiler)
		{
			byte instr;
			switch (GetOperator().Identifier)
			{
				default:
				case TokenType.Plus:
					instr = Instruction.Add.AsByte();
					break;

				case TokenType.Minus:
					instr = Instruction.Subtract.AsByte();
					break;

				case TokenType.Multiply:
					instr = Instruction.Multiply.AsByte();
					break;

				case TokenType.Divide:
					instr = Instruction.Divide.AsByte();
					break;

				case TokenType.Exponent:
					instr = Instruction.PowerOf.AsByte();
					break;
			}

			List<byte> code = new List<byte>();
			code.AddRange(GetLeftExpression().Compile(compiler));
			code.AddRange(GetRightExpression().Compile(compiler));
			code.Add(instr);
			return code.ToArray();
		}
Esempio n. 2
0
		public byte[] Compile(Compiler compiler)
		{
			List<byte> code = new List<byte>();

			code.Add(Instruction.Call.AsByte());

			code.Add((byte)name.Length);
			code.AddRange(name.AsBytes());
			return code.ToArray();
		}
Esempio n. 3
0
		public byte[] Compile(Compiler compiler)
		{
			List<byte> code = new List<byte>();
			code.Add(Instruction.SetVar.AsByte());

			byte[] bytes = ((string)name.GetValue()).AsBytes();
			code.Add((byte)bytes.Length);
			code.AddRange(bytes);

			code.AddRange(right.Compile(compiler));
			return code.ToArray();
		}
Esempio n. 4
0
		public byte[] Compile(Compiler compiler)
		{
			List<byte> code = new List<byte>();
			code.Add(Instruction.Func.AsByte());

			string name = this.name.GetName();
			code.Add((byte)name.Length);
			code.AddRange(name.AsBytes());

			List<byte> innerCode = new List<byte>();
			foreach (var expr in inner)
				innerCode.AddRange(expr.Compile(compiler));

			code.AddRange(((double)innerCode.Count).AsBytes()); // this may not be the best way since there is a limit
			code.AddRange(innerCode);
			return code.ToArray();
		}
Esempio n. 5
0
		public virtual byte[] Compile(Compiler compiler)
		{
			throw new NotImplementedException();
		}