Package compiler.frames

Examples of compiler.frames.Frame


    {
      int id = 0;
      // fun new(p:ptr):void;
      {
        AbsFunDecl funDecl = new AbsFunDecl("new", null, null, null);
        funDecl.frame = new Frame(funDecl, 0);
       
        id--; funDecl.declId = id;
        funDecl.semTyp = new SemFunTyp(new SemAtomTyp(SemAtomTyp.VOID));
        ((SemFunTyp)funDecl.semTyp).args.add(new SemPtrTyp(null));
        try { SymTable.names.put(funDecl.name, funDecl); }
        catch (SymDefinedAtThisScope _) {}
      }
      // fun free(p:ptr):void;
      {
        AbsFunDecl funDecl = new AbsFunDecl("free", null, null, null);
        funDecl.frame = new Frame(funDecl, 0);
        id--; funDecl.declId = id;
        funDecl.semTyp = new SemFunTyp(new SemAtomTyp(SemAtomTyp.VOID));
        ((SemFunTyp)funDecl.semTyp).args.add(new SemPtrTyp(null));
        try { SymTable.names.put(funDecl.name, funDecl); }
        catch (SymDefinedAtThisScope _) {}
      }
      // fun read_char():char;
      {
        AbsFunDecl funDecl = new AbsFunDecl("read_char", null, null, null);
        funDecl.frame = new Frame(funDecl, 0);
        id--; funDecl.declId = id;
        funDecl.semTyp = new SemFunTyp(new SemAtomTyp(SemAtomTyp.CHAR));
        try { SymTable.names.put(funDecl.name, funDecl); }
        catch (SymDefinedAtThisScope _) {}
      }
      // fun read_int():int;
      {
        AbsFunDecl funDecl = new AbsFunDecl("read_int", null, null, null);
        funDecl.frame = new Frame(funDecl, 0);
        id--; funDecl.declId = id;
        funDecl.semTyp = new SemFunTyp(new SemAtomTyp(SemAtomTyp.INT));
        try { SymTable.names.put(funDecl.name, funDecl); }
        catch (SymDefinedAtThisScope _) {}
      }
      // fun print_char(c:char):void;
      {
        AbsFunDecl funDecl = new AbsFunDecl("print_char", null, null, null);
        funDecl.frame = new Frame(funDecl, 0);
        id--; funDecl.declId = id;
        funDecl.semTyp = new SemFunTyp(new SemAtomTyp(SemAtomTyp.VOID));
        ((SemFunTyp)funDecl.semTyp).args.add(new SemAtomTyp(SemAtomTyp.CHAR));
        try { SymTable.names.put(funDecl.name, funDecl); }
        catch (SymDefinedAtThisScope _) {}
      }
      // fun print_int(i:int):void;
      {
        AbsFunDecl funDecl = new AbsFunDecl("print_int", null, null, null);
        funDecl.frame = new Frame(funDecl, 0);
        id--; funDecl.declId = id;
        funDecl.semTyp = new SemFunTyp(new SemAtomTyp(SemAtomTyp.VOID));
        ((SemFunTyp)funDecl.semTyp).args.add(new SemAtomTyp(SemAtomTyp.INT));
        try { SymTable.names.put(funDecl.name, funDecl); }
        catch (SymDefinedAtThisScope _) {}
View Full Code Here


  public Object visit(AbsFunDecl node)
  {
    // Change valid scope level
    scopeLevel++;
   
    Frame oldFrame = currentFrame;
    currentFrame = node.frame;
   
    // Evaluate function code, then check if the result is an expression
    // Because void functions can have non-expressions as code we need to check that and wrap them into
    // ESEQ call with 0 result
View Full Code Here

    }

    if (debug == 1) System.err.println(prefix + "=> " + label + " SP:" + SP + " FP:" + FP);

    ImcCodeChunk chunk = chunks.get(label);
    Frame frame = chunk.frame;
    HashMap<String,Integer> outerTemps = temps;
    temps = new HashMap<String,Integer>();

    // Prolog:
    ST(SP - frame.sizeLocs - 4, FP);
    FP = SP;
    SP = SP - frame.size();
    ST(frame.FP, FP);
    if (debug == 1) System.err.println(prefix + "in " + label + " SP:" + SP + " FP:" + FP);

    // jedro:
    LinkedList<ImcStmt> stmts = ((ImcSEQ)(chunk.lincode)).stmts;
    int PC = 0;
    while (PC < stmts.size()) {
      Label newLabel = execStmt(stmts.get(PC));
      if (newLabel != null) {
        // Razveljavimo cevovod:
        PC = stmts.indexOf(new ImcLABEL(newLabel));
      }
      else PC++;
    }

    // Epilog:
    SP = SP + frame.size();
    FP = LD(SP - frame.sizeLocs - 4);
    Integer retValue = LD(frame.RV);
    if (debug == 1) System.err.println(prefix + "<= " + label + " SP:" + SP + " FP:" + FP);

    temps = outerTemps;
View Full Code Here

TOP

Related Classes of compiler.frames.Frame

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.