Example #1
1
		public FunctionCall(Expression root, Token parenToken, IList<Expression> args, Executable owner)
			: base(root.FirstToken, owner)
		{
			this.Root = root;
			this.ParenToken = parenToken;
			this.Args = args.ToArray();
		}
		public override void TranslateGlDrawArrays(List<string> output, Expression gl, Expression vertexCount)
		{
			this.Translator.TranslateExpression(output, gl);
			output.Add(".glDrawArrays(javax.microedition.khronos.opengles.GL10.GL_TRIANGLE_STRIP, 0, ");
			this.Translator.TranslateExpression(output, vertexCount);
			output.Add(")");
		}
Example #3
0
		public DotStep(Expression root, Token dotToken, Token stepToken, Executable owner)
			: base(root.FirstToken, owner)
		{
			this.Root = root;
			this.DotToken = dotToken;
			this.StepToken = stepToken;
		}
Example #4
0
		public int GetLiteralId(Expression value)
		{
			if (value is NullConstant)
			{
				return GetNullConstant();
			}

			if (value is IntegerConstant)
			{
				return this.GetIntConstant(((IntegerConstant)value).Value);
			}

			if (value is FloatConstant)
			{
				return this.GetFloatConstant(((FloatConstant)value).Value);
			}

			if (value is BooleanConstant)
			{
				return this.GetBoolConstant(((BooleanConstant)value).Value);
			}

			if (value is StringConstant)
			{
				return this.GetStringConstant(((StringConstant)value).Value);
			}

			return -1;
		}
		public override void TranslateGetButtonValue(List<string> output, Expression device, Expression buttonIndex)
		{
			this.Translator.TranslateExpression(output, device);
			output.Add(".get_button(");
			this.Translator.TranslateExpression(output, buttonIndex);
			output.Add(")");
		}
Example #6
0
		public IfStatement(Token ifToken, Expression condition, IList<Executable> trueCode, IList<Executable> falseCode, Executable owner)
			: base(ifToken, owner)
		{
			this.Condition = condition;
			this.TrueCode = trueCode.ToArray();
			this.FalseCode = falseCode.ToArray();
		}
		public override void TranslateGetAnalogAxisValue(List<string> output, Expression device, Expression analogAxisIndex)
		{
			this.Translator.TranslateExpression(output, device);
			output.Add(".get_axis(");
			this.Translator.TranslateExpression(output, analogAxisIndex);
			output.Add(")");
		}
		public override void TranslateGet2dDigitalAxisValue(List<string> output, Expression device, Expression digitalAxisIndex)
		{
			this.Translator.TranslateExpression(output, device);
			output.Add(".get_hat(");
			this.Translator.TranslateExpression(output, digitalAxisIndex);
			output.Add(")");
		}
		protected override void TranslateArrayGet(List<string> output, Expression list, Expression index)
		{
			this.Translator.TranslateExpression(output, list);
			output.Add("[");
			this.Translator.TranslateExpression(output, index);
			output.Add("]");
		}
Example #10
0
		public SwitchStatement(Token switchToken, Expression condition, List<Token> firstTokens, List<List<Expression>> cases, List<List<Executable>> code, Expression explicitMax, Token explicitMaxToken, Executable owner)
			: base(switchToken, owner)
		{
			if (cases.Count == 0) throw new ParserException(switchToken, "Switch statement needs cases.");
			if (code.Count == 0) throw new ParserException(switchToken, "Switch statement needs code.");
			if (cases[0] == null) throw new ParserException(switchToken, "Switch statement must start with a case.");
			if (cases[cases.Count - 1] != null) throw new ParserException(switchToken, "Last case in switch statement is empty.");

			this.Condition = condition;
			this.explicitMax = explicitMax;
			this.explicitMaxToken = explicitMaxToken;

			List<Chunk> chunks = new List<Chunk>();
			int counter = 0;
			for (int i = 0; i < cases.Count; i += 2)
			{
				if (cases[i] == null) throw new Exception("This should not happen.");
				if (code[i + 1] == null) throw new Exception("This should not happen.");
				Chunk chunk = new Chunk(counter++, firstTokens[i], cases[i], code[i + 1]);
				if (chunk.Code.Length > 0 && chunk.ContainsFallthrough)
				{
					throw new ParserException(firstTokens[i], "This switch statement case contains code, but falls through to the next case. Cases that contain code must end with a return or break statement.");
				}
				chunks.Add(chunk);
			}
			this.chunks = chunks.ToArray();

			if (this.chunks.Length == 1 && this.chunks[0].Cases.Length == 1 && this.chunks[0].Cases[0] == null)
			{
				throw new ParserException(switchToken, "Switches need at least 1 case to indicate type.");
			}
		}
Example #11
0
		public BinaryOpChain(Expression left, Token op, Expression right, Executable owner)
			: base(left.FirstToken, owner)
		{
			this.Left = left;
			this.Right = right;
			this.Op = op;
		}
Example #12
0
		public ForEachLoop(Token forToken, Token iterationVariable, Expression iterationExpression, IList<Executable> code, Executable owner)
			: base(forToken, owner)
		{
			this.IterationVariable = iterationVariable;
			this.IterationExpression = iterationExpression;
			this.Code = code.ToArray();
		}
		public override void TranslateGlBindTexture(List<string> output, Expression gl, Expression textureId)
		{
			this.Translator.TranslateExpression(output, gl);
			output.Add(".glBindTexture(javax.microedition.khronos.opengles.GL10.GL_TEXTURE_2D, ");
			this.Translator.TranslateExpression(output, textureId);
			output.Add(")");
		}
Example #14
0
		public ConstStatement(Token constToken, Token nameToken, string ns, Expression expression, Executable owner)
			: base(constToken, owner)
		{
			this.Expression = expression;
			this.NameToken = nameToken;
			this.Name = nameToken.Value;
			this.Namespace = ns;
		}
Example #15
0
		internal override IList<Executable> Resolve(Parser parser)
		{
			this.Code = Resolve(parser, this.Code).ToArray();

			this.Condition = this.Condition.Resolve(parser);

			return Listify(this);
		}
Example #16
0
		internal override IList<Executable> Resolve(Parser parser)
		{
			if (this.Expression != null)
			{
				this.Expression = this.Expression.Resolve(parser);
			}
			return Listify(this);
		}
		public override void TranslateGetButtonValue(List<string> output, Expression device, Expression buttonIndex)
		{
			output.Add("GamepadTranslationHelper.GetButtonValue(");
			this.Translator.TranslateExpression(output, device);
			output.Add(", ");
			this.Translator.TranslateExpression(output, buttonIndex);
			output.Add(")");
		}
		protected override void TranslateArraySet(List<string> output, Expression list, Expression index, Expression value)
		{
			this.Translator.TranslateExpression(output, list);
			output.Add("[");
			this.Translator.TranslateExpression(output, index);
			output.Add(this.Shorten("] = "));
			this.Translator.TranslateExpression(output, value);
		}
		protected override void TranslateArcTan(List<string> output, Expression dy, Expression dx)
		{
			output.Add("Math.atan2(");
			this.Translator.TranslateExpression(output, dy);
			output.Add(", ");
			this.Translator.TranslateExpression(output, dx);
			output.Add(")");
		}
		protected override void TranslateGamepadGetAxisValue(List<string> output, Expression device, Expression axisIndex)
		{
			output.Add("GameWindow.Instance.GetGamepadAxisValue((OpenTK.Input.JoystickDevice)");
			this.Translator.TranslateExpression(output, device);
			output.Add(", ");
			this.Translator.TranslateExpression(output, axisIndex);
			output.Add(")");
		}
		public override void TranslateGet2dDigitalAxisValue(List<string> output, Expression device, Expression digitalAxisIndex)
		{
			output.Add("GamepadTranslationHelper.GetDigitalAxis(");
			this.Translator.TranslateExpression(output, device);
			output.Add(", ");
			this.Translator.TranslateExpression(output, digitalAxisIndex);
			output.Add(")");
		}
Example #22
0
		public Assignment(Expression target, Token assignmentOpToken, string assignmentOp, Expression assignedValue, Executable owner)
			: base(target.FirstToken, owner)
		{
			this.Target = target;
			this.AssignmentOpToken = assignmentOpToken;
			this.AssignmentOp = assignmentOp;
			this.Value = assignedValue;
		}
		protected override void TranslateArrayLength(List<string> output, Expression list)
		{
			// need to slowly convert these into int + pointer instead of just pointers where possible.
			// Otherwise create a $_new_array_with_length that allocates an extra integer before the pointer.
			output.Add("TODO_array_length(");
			this.Translator.TranslateExpression(output, list);
			output.Add(")");
		}
Example #24
0
		public ForLoop(Token forToken, IList<Executable> init, Expression condition, IList<Executable> step, IList<Executable> code, Executable owner)
			: base(forToken, owner)
		{
			this.Init = init.ToArray();
			this.Condition = condition ?? new BooleanConstant(forToken, true, owner);
			this.Step = step.ToArray();
			this.Code = code.ToArray();
		}
Example #25
0
		internal override Executable ResolveNames(Parser parser, Dictionary<string, Executable> lookup, string[] imports)
		{
			if (this.Expression != null)
			{
				this.Expression = this.Expression.ResolveNames(parser, lookup, imports);
			}
			return this;
		}
Example #26
0
		private string GetType(Expression expr)
		{
			if (expr is IntegerConstant) return "int";
			if (expr is FloatConstant) return "float";
			if (expr is BooleanConstant) return "bool";
			if (expr is NullConstant) return "null";
			if (expr is StringConstant) return "string";
			return "other";
		}
		protected override void TranslateFillScreen(List<string> output, Expression red, Expression green, Expression blue)
		{
			output.Add("RenderEngine.fillScreen(");
			this.Translator.TranslateExpression(output, red);
			output.Add(", ");
			this.Translator.TranslateExpression(output, green);
			output.Add(", ");
			this.Translator.TranslateExpression(output, blue);
			output.Add(")");
		}
		protected override void TranslateBlitImage(List<string> output, Expression image, Expression x, Expression y)
		{
			output.Add("R._global_vars.ctx.drawImage(");
			this.Translator.TranslateExpression(output, image);
			output.Add(this.Shorten("[1], "));
			this.Translator.TranslateExpression(output, x);
			output.Add(this.Shorten(", "));
			this.Translator.TranslateExpression(output, y);
			output.Add(")");
		}
		protected override void TranslateCast(List<string> output, StringConstant typeValue, Expression expression)
		{
			CSharpPlatform platform = (CSharpPlatform)this.Platform;
			string typeString = platform.GetTypeStringFromAnnotation(typeValue.FirstToken, ((StringConstant)typeValue).Value);

			output.Add("(");
			output.Add(typeString);
			output.Add(")");
			this.Translator.TranslateExpression(output, expression);
		}
		protected override void TranslateImageCreateFlippedCopyOfNativeBitmap(List<string> output, Expression image, Expression flipX, Expression flipY)
		{
			output.Add("AwtTranslationHelper.flipImage(");
			this.Translator.TranslateExpression(output, image);
			output.Add(", ");
			this.Translator.TranslateExpression(output, flipX);
			output.Add(", ");
			this.Translator.TranslateExpression(output, flipY);
			output.Add(")");
		}
Example #31
0
 public Assignment(Expression target, Token assignmentOpToken, string assignmentOp, Expression assignedValue, Executable owner)
     : base(target.FirstToken, owner)
 {
     this.Target            = target;
     this.AssignmentOpToken = assignmentOpToken;
     this.AssignmentOp      = assignmentOp;
     this.Value             = assignedValue;
     this.HACK_IsVmGlobal   = false;
 }