Roy Janik (zinereem) wrote,
Roy Janik
zinereem

something is wrong with my brain

I'm spending the weekend coding in what amount to Assembly for Java.

It rules.


.class public streams/filein
.super java/lang/Object

.field private currVal I = -99
.field private br Ljava/io/BufferedReader;
.field private name Ljava/lang/String;
;
; standard initializer
.method public ()V
.limit stack 2
aload_0
invokenonvirtual java/lang/Object/()V
aload_0
invokenonvirtual streams/filein/setupFile()V
aload_0
ldc "filein"
putfield streams/filein/name Ljava/lang/String;
return
.end method

.method public getName()Ljava/lang/String;
.limit stack 2
aload_0
getfield streams/filein/name Ljava/lang/String;
areturn
.end method


.method private setupFile()V
.limit stack 3
.limit locals 2
.catch java/lang/Exception from TRY to ENDTRY using HANDLER
TRY:
new java/io/FileReader
dup
ldc "teldata.txt"
invokenonvirtual java/io/FileReader/(Ljava/lang/String;)V
astore_1
new java/io/BufferedReader
dup
aload_1
invokenonvirtual java/io/BufferedReader/(Ljava/io/Reader;)V
aload_0
swap
putfield streams/filein/br Ljava/io/BufferedReader;
return
ENDTRY:
HANDLER:
pop
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc "Exception caught!"
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
return
.end method

.method public getLastVal()I
.limit stack 3
.limit locals 2
.catch java/lang/Exception from TRYLAST to ENDTRYLAST using HANDLERLAST
TRYLAST:
aload_0
getfield streams/filein/br Ljava/io/BufferedReader;
invokevirtual java/io/BufferedReader/readLine()Ljava/lang/String;
dup
ifnull ENDTRYLAST
invokestatic java/lang/Integer/parseInt(Ljava/lang/String;)I
aload_0
swap
putfield streams/filein/currVal I
goto TRYLAST
ENDTRYLAST:
aload_0
getfield streams/filein/currVal I
ireturn
HANDLERLAST:
pop
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc "Exception caught!"
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
bipush -99
ireturn
.end method
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments