diff -r ba3edaf7dc49 -r 2b9956d29038 progs/while/compile.sc --- a/progs/while/compile.sc Wed Nov 18 12:18:33 2020 +0000 +++ b/progs/while/compile.sc Tue Nov 24 21:22:31 2020 +0000 @@ -47,40 +47,6 @@ return .end method -.method public static read()I - .limit locals 10 - .limit stack 10 - - ldc 0 - istore 1 ; this will hold our final integer -Label1: - getstatic java/lang/System/in Ljava/io/InputStream; - invokevirtual java/io/InputStream/read()I - istore 2 - iload 2 - ldc 10 ; the newline delimiter - isub - ifeq Label2 - iload 2 - ldc 32 ; the space delimiter - isub - ifeq Label2 - - iload 2 - ldc 48 ; we have our digit in ASCII, have to subtract it from 48 - isub - ldc 10 - iload 1 - imul - iadd - istore 1 - goto Label1 -Label2: - ;when we come here we have our integer computed in local variable 1 - iload 1 - ireturn -.end method - .method public static main([Ljava/lang/String;)V .limit locals 200 .limit stack 200 @@ -118,7 +84,7 @@ } // this allows us to write things like -// i"add" and l"Label" +// i"iadd" and l"Label" // environments @@ -139,6 +105,7 @@ compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ compile_op(op) } + // boolean expression compilation // - the jump-label is for where to jump if the condition is not true def compile_bexp(b: BExp, env : Env, jmp: String) : String = b match { @@ -256,3 +223,46 @@ @main def test2() = run(fib_test, "fib") + + + + + + +/* Jasmin code for reading an integer + +.method public static read()I + .limit locals 10 + .limit stack 10 + + ldc 0 + istore 1 ; this will hold our final integer +Label1: + getstatic java/lang/System/in Ljava/io/InputStream; + invokevirtual java/io/InputStream/read()I + istore 2 + iload 2 + ldc 10 ; the newline delimiter + isub + ifeq Label2 + iload 2 + ldc 32 ; the space delimiter + isub + ifeq Label2 + + iload 2 + ldc 48 ; we have our digit in ASCII, have to subtract it from 48 + isub + ldc 10 + iload 1 + imul + iadd + istore 1 + goto Label1 +Label2: + ;when we come here we have our integer computed in local variable 1 + iload 1 + ireturn +.end method + +*/ \ No newline at end of file