progs/fun/fun.sc
changeset 814 1fbaa5f05516
parent 813 059f970287d1
child 869 81ee93b87258
equal deleted inserted replaced
813:059f970287d1 814:1fbaa5f05516
    48 val library = """
    48 val library = """
    49 .class public XXX.XXX
    49 .class public XXX.XXX
    50 .super java/lang/Object
    50 .super java/lang/Object
    51 
    51 
    52 .method public static write(I)V 
    52 .method public static write(I)V 
    53         .limit locals 5 
    53     .limit locals 1 
    54         .limit stack 5 
    54     .limit stack 2 
    55         iload 0 
    55     getstatic java/lang/System/out Ljava/io/PrintStream; 
    56         getstatic java/lang/System/out Ljava/io/PrintStream; 
    56     iload 0
    57         swap 
    57     invokevirtual java/io/PrintStream/println(I)V
    58         invokevirtual java/io/PrintStream/println(I)V 
    58     return 
    59         return 
       
    60 .end method
    59 .end method
    61 
    60 
    62 """
    61 """
    63 
    62 
    64 // for generating new labels
    63 // for generating new labels
   140 def compile_decl(d: Decl) : String = d match {
   139 def compile_decl(d: Decl) : String = d match {
   141   case Def(name, args, a) => { 
   140   case Def(name, args, a) => { 
   142     val env = args.zipWithIndex.toMap
   141     val env = args.zipWithIndex.toMap
   143     val is = "I" * args.length
   142     val is = "I" * args.length
   144     m".method public static $name($is)I" ++
   143     m".method public static $name($is)I" ++
   145     m".limit locals ${args.length.toString}" ++
   144     m".limit locals ${args.length}" ++
   146     m".limit stack ${1 + max_stack_exp(a)}" ++
   145     m".limit stack ${1 + max_stack_exp(a)}" ++
   147     l"${name}_Start" ++   
   146     l"${name}_Start" ++   
   148     compile_exp(a, env) ++
   147     compile_exp(a, env) ++
   149     i"ireturn" ++
   148     i"ireturn" ++
   150     m".end method\n"
   149     m".end method\n"