Example #1
0
    def jasmin_init(self):
        if self.var.type == ('bool', []) or self.var.type == ('int', []):
            string = "ldc 0\n"
        else:
            if self.var.type == ('string', []):
                string = "aconst_null\n"
            else:
                string = ""
                for i in self.var.type[1]:
                    string += "ldc %d\n" % i
                string += "multianewarray %s %d\n" % (jasmin_types(self.var.type), len(self.var.type[1]))

        string += "putstatic %s/%s %s\n" % (className, self.var.name, jasmin_types(self.var.type))
        return string
Example #2
0
 def jasmin_reference(self):
     if self.var.is_static:
         string = "getstatic %s/%s %s\n" % (className, self.var.name, jasmin_types(self.var.type))
     else:
         string = "aload %d\n" % self.var.local
     for i in self.indices[0:-1]:
         string += i.jasmin()
         string += "aaload\n"
     string += self.indices[-1].jasmin()
     return string
Example #3
0
 def jasmin(self):
     if not curr_proc:
         self.var.is_static = True
         string = ".field public static %s %s\n" % (self.var.name, jasmin_types(self.var.type))
     else:
         global local_count
         s = local_count
         local_count += 1
         if self.var.type == ('bool', []) or self.var.type == ('int', []):
             string = "ldc 0\n"
             string += "istore %d\n" % (s)
         else:
             if self.var.type == ('string', []):
                 string = "aconst_null\n"
             else:
                 string = ""
                 for i in self.var.type[1]:
                     string += "ldc %d\n" % i
                 string += "multianewarray %s %d\n" % (jasmin_types(self.var.type), len(self.var.type[1]))
             string += "astore %d\n" % (s)
         self.var.local = s
     return string
Example #4
0
 def jasmin_set(self):
     if self.is_static:
         string = "putstatic %s/%s %s\n" % (className, self.name, jasmin_types(self.type))
     else:
         if self.type == ('string', []):
             string = "astore %i\n" % self.local
         elif self.type == ('int', []):
             string = "istore %i\n" % self.local
         elif self.type == ('bool', []):
             string = "istore %i\n" % self.local
         else:
             string = "astore %i\n" % self.local
     return string
Example #5
0
 def jasmin(self):
     string = self.args.jasmin()
     string += "invokestatic %s/%s(%s)%s\n" % (className, self.proc.name, self.proc.declist.jasmin_types(), jasmin_types(self.proc.ret))
     return string
Example #6
0
 def jasmin(self):
     global local_count
     global curr_proc
     curr_proc = self
     local_count = 0
     self.declist.setup()
     if self.ret_var:
         jas_ret = VarDeclNode(self.ret_var).jasmin()
     else:
         jas_ret = ""
     string = ".method public static %s(%s)%s\n" % (self.name, self.declist.jasmin_types(), jasmin_types(self.ret))
     string += ".limit stack 100\n"
     string += jas_ret
     jas_typevars = self.typevars.jasmin()
     jas_stms = self.stmts.jasmin()
     string += ".limit locals %d\n" % (local_count+len(self.declist)+2) # declist become the first n local variables, and 1 for padding
     string += jas_typevars
     string += jas_stms
     # This is because functions can have an implicit return
     string += ReturnNode().jasmin()
     string += ".end method\n"
     curr_proc = None
     return string
Example #7
0
 def jasmin_types(self):
     string = ""
     for v in self.var_nodes:
         string += jasmin_types(v.type)
     return string