public void DoExp(DoExp e) { Type RetType; for (ExpList el = e.Vars; el != null; el = el.Tail) { el.Head.Visit(this); } for (ExpList el = e.Conds; el != null; el = el.Tail) { el.Head.Visit(this); } RetType = e.Conds.Head.ExpType; for (ExpList el = e.Conds; el != null; el = el.Tail) { if (RetType != el.Head.ExpType) { Console.WriteLine("Error 104: Return Type from Do Conditionals should be same"); success = false; } } e.ExpType = RetType; }
public void DoExp(DoExp e) { Label l1 = il.DefineLabel(); Label l2 = il.DefineLabel(); Label EndLabel = il.DefineLabel(); for (ExpList el = e.Vars; el != null; el = el.Tail) { el.Head.Visit(this); } il.Emit(OpCodes.Br, l1); il.MarkLabel(l2); for (ExpList el = e.Vars; el != null; el = el.Tail) { DoVarIter((DoVarDef)el.Head); } il.MarkLabel(l1); for (ExpList el = e.Conds; el != null; el = el.Tail) { ((DoCondExp)el.Head).EndLabel = EndLabel; el.Head.Visit(this); } il.Emit(OpCodes.Br, l2); il.MarkLabel(EndLabel); }
void CheckList(ref Exp e) { if (e.ExpType == typeof(int)) { e = new ToListExp(e); e.ExpType = typeof(CList); } if (e.ExpType != typeof(CList)) { if (e is VarExp && e.ExpType == typeof(void)) { e.ExpType = typeof(CList); CurrentFuncDef.Add(((VarExp)e).Name, typeof(CList)); } else if (e is DoVarExp && e.ExpType == typeof(void)) { e.ExpType = typeof(CList); DoVars.Add(((DoVarExp)e).Pos, typeof(CList)); } else if (e is CallExp && e.ExpType == typeof(void)) //Recursive function call. Assume first occurence { e.ExpType = typeof(int); } else if (!(e is IntExp)) //IntExp will be coerceto List { Console.WriteLine("List expected"); success = false; } } }
public CodeGen(ExpList ex, Hashtable f, Hashtable g) { expr = ex; Functions = new Hashtable(); GlobalVars = new Hashtable(); DoVars = new Hashtable(); }
Temp.Temp TranslateExpr(CALL expr) { Call c = new Call(); c.Name = new Label((expr.Func as NAME).Label); TempList args = null, ptr = null; for (ExpList exp = expr.Args; exp != null; exp = exp.Tail) { Temp.Temp arg = TranslateExpr(exp.Head); if (args == null) { ptr = args = new TempList(arg, null); } else { ptr = ptr.Tail = new TempList(arg, null); } } c.Param = args; MipsFrame t = null; foreach (MipsFrame f in MipsFrame.AllFrames) { if (c.Name.Lab == f.Name) { t = f; break; } } if (t == null) { int count = 0; for (ptr = c.Param; ptr != null; ptr = ptr.Tail) { InstrList.Add(new Move(Frame.A(count), ptr.Head)); ++count; } } else { int count = 0; ptr = c.Param; for (AccessList al = t.Formals; al != null; al = al.Tail, ptr = ptr.Tail) { if (al.Head is InReg) { InstrList.Add(new Move(t.A(count), ptr.Head)); ++count; } else { InstrList.Add(new Store(t.SP(), (al.Head as InFrame).Offset, ptr.Head)); } } } InstrList.Add(c); return(Frame.RV()); }
public bool Check() { for (ExpList el = e; el != null; el = el.Tail) { el.Head.Visit(this); } return(success); }
public CodeExpression VisitExpList(ExpList l) { var fn = m.MethodRef( m.TypeRefExpr("Tuple"), "Create"); return(m.Appl (fn, l.Expressions.Select(e => e.Accept(this)).ToArray())); }
void PrintExp(CALL e, int d) { Indent(d); SayLn("CALL("); PrintExp(e.Func, d + 1); for (ExpList a = e.Args; a != null; a = a.Tail) { SayLn(","); PrintExp(a.Head, d + 2); } Say(")"); }
public override Stm Build(ExpList kids) { if (Dst is MEM) { return(new MOVE(new MEM(kids.Head), kids.Tail.Head)); } else { return(new MOVE(Dst, kids.Head)); } }
public Exp TranslateLetExp(ExpList eDec, Exp body, bool isVOID) { if (isVOID) { return(new Nx(new SEQ(TranslateSeqExp(eDec, true).UnNx(), body.UnNx()))); } else { return(new Ex(new ESEQ(TranslateSeqExp(eDec, true).UnNx(), body.UnEx()))); } }
public DataType VisitExpList(ExpList list) { var t = new TupleType(); var elTypes = new List <DataType>(); foreach (var el in list.Expressions) { var elt = el.Accept(this); elTypes.Add(elt); } return(new TupleType(elTypes)); }
public bool Parse() { //e = null; e = MatchStm(); // Match(TokenType.EoFSym); MatchToken(TokenType.EOFSYM); Tc = new TypeCheck(e, Functions); bool tsuccess = Tc.Check(); e = Tc.e; //Exp is modified in TypeCheck return(success && tsuccess); //Return success if both parsing and typechecking succeed. }
public JsonResult adacount(string expnme) { SyDB db = new SyDB(); var ca = db.ExpList.ToList().LastOrDefault().ExpID + 1; ExpList bi = new ExpList(); bi.ExpID = ca; bi.ExpName = expnme; bi.IsActive = true; db.ExpList.Add(bi); db.SaveChanges(); return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); }
public CodeExpression VisitExpList(ExpList l) { //$TODO: there is no notion of a list element type. var(elemType, nms) = types.TranslateListElementType(l); if (ContainsStarExp(l.Expressions)) { return(ExpandIterableExpanders("TupleUtils", l.Expressions, elemType)); } else { return(m.ValueTuple(l.Expressions.Select(e => e.Accept(this)))); } }
public void Generate(String filename) { AppDomain ad = Thread.GetDomain(); //AppDomain.CreateDomain("First", null, null); AssemblyName an = new AssemblyName(); an.Name = filename + ".exe"; //AssemblyName.CreateSimpleName(filename + ".exe", "LispExe", "Lisp Executable", "default_alias"); AssemblyBuilder ab = ad.DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave); ModuleBuilder mb = ab.DefineDynamicModule(filename + ".exe", filename + ".exe"); MethodBuilder methodb; //DescriptorInfo di = new DescriptorInfo(0); tb = mb.DefineType(filename); //di.SetReturnType(typeof(void)); //di.MethodAttributes = MethodAttributes.Static | MethodAttributes.Public; methodb = tb.DefineMethod("Main", MethodAttributes.Static | MethodAttributes.Public, typeof(void), null); il = methodb.GetILGenerator(); do { expr.Head.Visit(this); if (expr.Head is FunctionDef) { GenerateDefStub(((FunctionDef)expr.Head).Name); } else if (expr.Head is GlobalVarDef) { GenerateDefStub(((GlobalVarDef)expr.Head).Name); } else if (expr.Head.ExpType == typeof(int)) { GenerateNumericExpStub(); } else if (expr.Head.ExpType == typeof(bool)) { GenerateBoolExpStub(); } else if (expr.Head.ExpType == typeof(CList)) { GenerateListExpStub(); } expr = expr.Tail; }while(expr != null); il.Emit(OpCodes.Ret); tb.CreateType(); ab.SetEntryPoint((mb.GetType(filename)).GetMethod("Main")); ab.Save(filename + ".exe"); }
ExpList MatchStm() { ExpList ex1 = new ExpList(); ex1.Head = MatchExp(); if (((Token)tokens.Peek()).Type != TokenType.EOFSYM) { ex1.Tail = MatchStm(); } else { ex1.Tail = null; } return(ex1); }
public CodeExpression VisitExpList(ExpList l) { //$TODO: there is no notion of a list element type. var(elemType, nms) = types.TranslateListElementType(l); if (ContainsStarExp(l.Expressions)) { return(ExpandIterableExpanders("TupleUtils", l.Expressions, elemType)); } else { var fn = m.MethodRef( m.TypeRefExpr("Tuple"), "Create"); return(m.Appl (fn, l.Expressions.Select(e => e.Accept(this)).ToArray())); } }
public Exp TranslateSeqExp(ExpList el, bool isVOID) { if (el == null) { return(new Ex(new CONST(0))); } if (el.Tail == null) { return(el.Head); } if (el.Tail.Tail == null) { if (isVOID) { return(new Nx(new SEQ(el.Head.UnNx(), el.Tail.Head.UnNx()))); } else { return(new Ex(new ESEQ(el.Head.UnNx(), el.Tail.Head.UnEx()))); } } ExpList ptr = el.Tail, prev = el; SEQ res = null; for (; ptr.Tail != null; ptr = ptr.Tail) { if (res == null) { res = new SEQ(prev.Head.UnNx(), ptr.Head.UnNx()); } else { res = new SEQ(res, ptr.Head.UnNx()); } } if (isVOID) { return(new Nx(new SEQ(res, ptr.Head.UnNx()))); } else { return(new Ex(new ESEQ(res, ptr.Head.UnEx()))); } }
ExpList MatchDoCondList() { ExpList el1 = new ExpList(); //MatchToken(TokenType.LPAREN); el1.Head = MatchDoCond(); if (((Token)tokens.Peek()).Type != TokenType.RPAREN) { el1.Tail = MatchDoCondList(); } else { el1.Tail = null; } //MatchToken(TokenType.RPAREN); return(el1); }
public TypeCheck(ExpList el, Hashtable f) { e = el; Functions = new Hashtable(); ArrayList Params = new ArrayList(); Params.Add(typeof(CList)); Functions.Add("Cdr", new FunctionDef("Cdr", Params, null)); Functions.Add("IsNull", new FunctionDef("IsNull", Params, null)); Functions.Add("IsAtom", new FunctionDef("IsAtom", Params, null)); Params.Add(typeof(CList)); Functions.Add("Cons", new FunctionDef("Cons", Params, null)); Params.Add(typeof(CList)); Functions.Add("Subst", new FunctionDef("Subst", Params, null)); GlobalVars = new Hashtable(); success = true; CurrentFuncDef = null; }
ExpressionType TranslateExpression(SequenceExpression e) { Types.Type type = Types.Type._void; ExpressionType et; ExpList el = null, ptr = null; for (ExpressionList h = e.Exps; h != null; h = h.Tail) { et = TranslateExpression(h.Head); type = et.Type; if (el == null) { el = ptr = new ExpList(et.Exp, null); } else { ptr = ptr.Tail = new ExpList(et.Exp, null); } } return(new ExpressionType(Translate.TranslateSeqExp(el, type.CoerceTo(Types.Type._void)), type)); }
ExpressionType TranslateExpression(LetExpression e) { Env.ValueEnvironment.BeginScope(); Env.TypeEnvironment.BeginScope(); ExpList eDec = null, p = null; for (DeclarationList ptr = e.Decs; ptr != null; ptr = ptr.Tail) { if (eDec == null) { p = eDec = new ExpList(TranslateDeclaration(ptr.Head), null); } else { p = p.Tail = new ExpList(TranslateDeclaration(ptr.Head), null); } } ExpressionType eBody = TranslateExpression(e.Body); Env.ValueEnvironment.EndScope(); Env.TypeEnvironment.EndScope(); return(new ExpressionType(Translate.TranslateLetExp(eDec, eBody.Exp, eBody.Type.CoerceTo(Types.Type._void)), eBody.Type)); }
public override Stm Build(ExpList kids) { return new CJUMP(Relop, kids.Head, kids.Tail.Head, IfTrue, IfFalse); }
public abstract Expr Build(ExpList kids);
public ExpList(Exp h, ExpList t) { Head = h; Tail = t; }
public override Expr Build(ExpList kids) { return new BINOP(Binop, kids.Head, kids.Tail.Head); }
public abstract Expr ExternalCall(string funcName, ExpList args);
public override Expr Build(ExpList kids) { return new MEM(kids.Head); }
public override Stm Build(ExpList kids) { return new JUMP(kids.Head, Targets); }
public override Stm Build(ExpList kids) { throw new FatalError("Build() not applicable to SEQ"); }
public CALL(Expr func, ExpList args) { Func = func; Args = args; }
public Exp TranslateLetExp(ExpList eDec, Exp body, bool isVOID) { if (isVOID) return new Nx(new SEQ(TranslateSeqExp(eDec, true).UnNx(), body.UnNx())); else return new Ex(new ESEQ(TranslateSeqExp(eDec, true).UnNx(), body.UnEx())); }
public override Expr Build(ExpList kids) { return new CALL(kids.Head, kids.Tail); }
public ExpList(Expr head, ExpList tail) { Head = head; Tail = tail; }
public override Stm Build(ExpList kids) { return new EXP(kids.Head); }
public override Expr Build(ExpList kids) { return(new BINOP(Binop, kids.Head, kids.Tail.Head)); }
public abstract Stm Build(ExpList kids);
public override Expr Build(ExpList kids) { return(new CALL(kids.Head, kids.Tail)); }
public override Stm Build(ExpList kids) { if (Dst is MEM) { return new MOVE(new MEM(kids.Head), kids.Tail.Head); } else { return new MOVE(Dst, kids.Head); } }
public void VisitExpList(ExpList list) { throw new NotImplementedException(); }
public override Expr Build(ExpList kids) { return this; }
public override Expr Build(ExpList kids) { return(this); }
public Exp TranslateSeqExp(ExpList el, bool isVOID) { if (el == null) return new Ex(new CONST(0)); if (el.Tail == null) return el.Head; if (el.Tail.Tail == null) if (isVOID) return new Nx(new SEQ(el.Head.UnNx(), el.Tail.Head.UnNx())); else return new Ex(new ESEQ(el.Head.UnNx(), el.Tail.Head.UnEx())); ExpList ptr = el.Tail, prev = el; SEQ res = null; for (; ptr.Tail != null; ptr = ptr.Tail) { if (res == null) res = new SEQ(prev.Head.UnNx(), ptr.Head.UnNx()); else res = new SEQ(res, ptr.Head.UnNx()); } if (isVOID) return new Nx(new SEQ(res, ptr.Head.UnNx())); else return new Ex(new ESEQ(res, ptr.Head.UnEx())); }