Exemplo n.º 1
0
  @Override
  public int check(final int locals) throws ContextError, HeapTooSmallError {
    if (locals >= 0) {
      throw new ContextError("Function declarations are only allowed globally!", ident.getLine());
    }

    Routine routine = IMLCompiler.getRoutineTable().getRoutine(ident.getIdent().toString());
    IMLCompiler.setScope(routine.getScope());

    Store retStore = returnDecl.check();
    retStore.setAddress(-routine.getParamList().size() - 1);
    retStore.setReference(false);
    retStore.setRelative(true);

    globImp.check(routine);

    int localsCount = param.calculateAddress(routine.getParamList().size(), 0);

    cpsDecl.check(localsCount);
    cmd.check(false);

    if (!routine.getScope().getStoreTable().getStore(returnDecl.getIdent()).isInitialized()) {
      throw new ContextError(
          "Return value never initialized! Function: " + ident.getIdent(), ident.getLine());
    }

    IMLCompiler.setScope(null);
    return -1;
  }
Exemplo n.º 2
0
 @Override
 public String toString(final String indent) {
   return indent
       + "<FunDecl>\n"
       + ident.toString(indent + '\t')
       + param.toString(indent + '\t')
       + returnDecl.toString(indent + '\t')
       + globImp.toString(indent + '\t')
       + cpsDecl.toString(indent + '\t')
       + cmd.toString(indent + '\t')
       + indent
       + "</FunDecl>\n";
 }