Ejemplo n.º 1
0
 static ArrayList<String> popArray(Variable v, String fileName, long line, boolean sizeKnown)
     throws CompilerException {
   ArrayList<String> res = new ArrayList<>();
   Tokenizer t = new Tokenizer();
   String code1 = "#pop array\n";
   if (!sizeKnown) {
     code1 += "asm:\n" + "\tpop " + v.sizeVarName() + " ;\n" + "end\n";
   }
   code1 +=
       "for var __ALZ_I=sub("
           + v.sizeVarName()
           + " 1); moreeq(__ALZ_I 0); __ALZ_I=sub(__ALZ_I 1);\n";
   String code2 = "endfor\n";
   ArrayList<Token> tokens1 = t.tokenize(code1);
   ArrayList<Token> tokens2 = t.tokenize(code2);
   Compiler c = new Compiler();
   try {
     res.addAll(c.compile(tokens1, false));
     res.addAll(v.type.pop(v.nameWithoutIndex() + "[__ALZ_I]"));
     res.addAll(c.compile(tokens2, false));
   } catch (Exception e) {
     CompilerException ex =
         new CompilerException("failed to pop array " + v.nameWithoutIndex(), fileName, line);
     ex.initCause(e);
     throw ex;
   }
   exec("delv __ALZ_I ;", res);
   return res;
 }
Ejemplo n.º 2
0
 static ArrayList<String> pushArray(Variable v, String fileName, long line)
     throws CompilerException {
   ArrayList<String> res = new ArrayList<>();
   Tokenizer t = new Tokenizer();
   String code1 =
       ""
           + "#push array\n"
           + "for var __ALZ_I=0; less(__ALZ_I "
           + v.sizeVarName()
           + "); __ALZ_I=add(__ALZ_I 1);\n";
   String code2 =
       "" + "endfor\n" + "asm:\n" + "\tpush " + v.nameWithoutIndex() + ".size ;\n" + "end";
   ArrayList<Token> tokens1 = t.tokenize(code1);
   ArrayList<Token> tokens2 = t.tokenize(code2);
   Compiler c = new Compiler();
   try {
     res.addAll(c.compile(tokens1, false));
     res.addAll(v.type.push(v.nameWithoutIndex() + "[__ALZ_I]"));
     res.addAll(c.compile(tokens2, false));
   } catch (Exception e) {
     CompilerException ex =
         new CompilerException("failed to push array " + v.nameWithoutIndex(), fileName, line);
     ex.initCause(e);
     throw ex;
   }
   exec("delv __ALZ_I ;", res);
   return res;
 }