public void TestSet() { var foo = new Id(new Word("foo", Tag.ID), Sara.Type.Int, 0x20); var bar = new Constant(55); var set = new Set(foo, bar); set.Gen(10, 20); //output: // foo = 55 }
public void TestConstant() { Assert.AreEqual("true", Constant.True.ToString()); Assert.AreEqual("false", Constant.False.ToString()); Constant.True.Jumping(42, 99); Constant.False.Jumping(100, 8); //output : //goto L42 //goto L8 var c1 = new Constant(42); Assert.AreEqual("42", c1.ToString()); var c2 = new Constant(new Real(3.14f), Sara.Type.Int); Assert.AreEqual("3.14", c2.ToString()); }
public Access Offset(Id a) { Expr i, w, t1, t2, loc; Type type = a.Type; this.Match('['); i = this.Bool(); this.Match(']'); type = (type as Array).Of; w = new Constant(type.Width); t1 = new Arith(new Token('*'), i, w); loc = t1; while(_look.TagValue == '[') { this.Match('['); i = this.Bool(); this.Match(']'); type = (type as Array).Of; w = new Constant(type.Width); t1 = new Arith(new Token('*'), i, w); t2 = new Arith(new Token('+'), loc, t1); loc = t2; } return new Access(a, loc, type); }
public Expr Factor() { Expr expr = null; switch(_look.TagValue) { case'(': this.Move(); expr = this.Bool(); this.Match(')'); return expr; case Tag.NUM: expr = new Constant(_look, Sara.Type.Int); this.Move(); return expr; case Tag.REAL: expr = new Constant(_look, Sara.Type.Float); this.Move(); return expr; case Tag.TRUE: expr = Constant.True; this.Move(); return expr; case Tag.FALSE: expr = Constant.False; this.Move(); return expr; default: this.Error("syntax error"); return expr; case Tag.ID: string s = _look.ToString(); Id id = this.Top.Get(_look); if (id == null) this.Error(_look.ToString() + " undeclared"); this.Move(); if (_look.TagValue != '[') return id; else return this.Offset(id); } }