예제 #1
0
파일: typecheck.cs 프로젝트: ydunk/masters
    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;
    }
예제 #2
0
파일: codegen.cs 프로젝트: ydunk/masters
    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);
    }
예제 #3
0
파일: typecheck.cs 프로젝트: ydunk/masters
    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;
            }
        }
    }
예제 #4
0
파일: codegen.cs 프로젝트: ydunk/masters
 public CodeGen(ExpList ex, Hashtable f, Hashtable g)
 {
     expr       = ex;
     Functions  = new Hashtable();
     GlobalVars = new Hashtable();
     DoVars     = new Hashtable();
 }
예제 #5
0
            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());
            }
예제 #6
0
파일: typecheck.cs 프로젝트: ydunk/masters
 public bool Check()
 {
     for (ExpList el = e; el != null; el = el.Tail)
     {
         el.Head.Visit(this);
     }
     return(success);
 }
예제 #7
0
        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()));
        }
예제 #8
0
 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(")");
 }
예제 #9
0
 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));
     }
 }
예제 #10
0
 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())));
     }
 }
예제 #11
0
        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));
        }
예제 #12
0
    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.
    }
예제 #13
0
        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));
        }
예제 #14
0
 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))));
     }
 }
예제 #15
0
파일: codegen.cs 프로젝트: ydunk/masters
    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");
    }
예제 #16
0
    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);
    }
예제 #17
0
 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()));
     }
 }
예제 #18
0
            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())));
                }
            }
예제 #19
0
    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);
    }
예제 #20
0
파일: typecheck.cs 프로젝트: ydunk/masters
    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;
    }
예제 #21
0
            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));
            }
예제 #22
0
            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));
            }
예제 #23
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 public override Stm Build(ExpList kids)
 {
     return new CJUMP(Relop, kids.Head, kids.Tail.Head, IfTrue, IfFalse);
 }
예제 #24
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 public abstract Expr Build(ExpList kids);
예제 #25
0
 public ExpList(Exp h, ExpList t)
 {
     Head = h;
     Tail = t;
 }
예제 #26
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 public override Expr Build(ExpList kids)
 {
     return new BINOP(Binop, kids.Head, kids.Tail.Head);
 }
예제 #27
0
 public abstract Expr ExternalCall(string funcName, ExpList args);
예제 #28
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 public override Expr Build(ExpList kids)
 {
     return new MEM(kids.Head);
 }
예제 #29
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 public override Stm Build(ExpList kids)
 {
     return new JUMP(kids.Head, Targets);
 }
예제 #30
0
 public override Stm Build(ExpList kids)
 {
     throw new FatalError("Build() not applicable to SEQ");
 }
예제 #31
0
 public CALL(Expr func, ExpList args)
 {
     Func = func;
     Args = args;
 }
예제 #32
0
 public abstract Expr Build(ExpList kids);
예제 #33
0
 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()));
 }
예제 #34
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 public override Expr Build(ExpList kids)
 {
     return new CALL(kids.Head, kids.Tail);
 }
예제 #35
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 public ExpList(Expr head, ExpList tail)
 {
     Head = head;
     Tail = tail;
 }
예제 #36
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 public override Stm Build(ExpList kids)
 {
     throw new FatalError("Build() not applicable to SEQ");
 }
예제 #37
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 public override Stm Build(ExpList kids)
 {
     return new EXP(kids.Head);
 }
예제 #38
0
 public override Expr Build(ExpList kids)
 {
     return(new BINOP(Binop, kids.Head, kids.Tail.Head));
 }
예제 #39
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 public abstract Stm Build(ExpList kids);
예제 #40
0
 public override Expr Build(ExpList kids)
 {
     return(new CALL(kids.Head, kids.Tail));
 }
예제 #41
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 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);
     }
 }
예제 #42
0
 public void VisitExpList(ExpList list)
 {
     throw new NotImplementedException();
 }
예제 #43
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 public override Expr Build(ExpList kids)
 {
     return this;
 }
예제 #44
0
 public override Expr Build(ExpList kids)
 {
     return(this);
 }
예제 #45
0
파일: Tree.cs 프로젝트: Nxun/Naive-Tiger
 public CALL(Expr func, ExpList args)
 {
     Func = func;
     Args = args;
 }
예제 #46
0
 public void VisitExpList(ExpList list)
 {
     throw new NotImplementedException();
 }
예제 #47
0
파일: Frame.cs 프로젝트: Nxun/Naive-Tiger
 public abstract Expr ExternalCall(string funcName, ExpList args);
예제 #48
0
 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()));
 }