first commit
This commit is contained in:
commit
063194f8be
349 changed files with 36508 additions and 0 deletions
52
jasmin/jasmin-2.4/examples/ANewArray.j
Normal file
52
jasmin/jasmin-2.4/examples/ANewArray.j
Normal file
|
@ -0,0 +1,52 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/ANewArray.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Shows how to use anewarray instruction
|
||||
; -------------------------------------------------------------------------
|
||||
;
|
||||
; This class demonstrates how to allocate a multidimensional
|
||||
; array using anewarray.
|
||||
;
|
||||
|
||||
.class public examples/ANewArray
|
||||
.super java/lang/Object
|
||||
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
.limit stack 4
|
||||
.limit locals 2
|
||||
|
||||
;
|
||||
; Allocates an array like:
|
||||
; String x[][] = new String[2][5]
|
||||
;
|
||||
|
||||
; Allocate spine for array and store it in local var 1
|
||||
; (i.e. String[2][])
|
||||
|
||||
iconst_2
|
||||
anewarray [Ljava/lang/String;
|
||||
astore_1
|
||||
|
||||
; allocate first array of String[5] and store it in index 0
|
||||
aload_1
|
||||
iconst_0
|
||||
bipush 5
|
||||
anewarray java/lang/String
|
||||
aastore
|
||||
|
||||
; allocate second array of String[5] and store it in index 1
|
||||
aload_1
|
||||
iconst_1
|
||||
bipush 5
|
||||
anewarray java/lang/String
|
||||
aastore
|
||||
|
||||
; done ...
|
||||
return
|
||||
.end method
|
31
jasmin/jasmin-2.4/examples/AnInterface.j
Normal file
31
jasmin/jasmin-2.4/examples/AnInterface.j
Normal file
|
@ -0,0 +1,31 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/AnInterface.j
|
||||
; Author: Jonathan Meyer, 1 Oct 1996
|
||||
; Purpose: A Java interface written in Jasmin
|
||||
; -------------------------------------------------------------------------
|
||||
|
||||
;
|
||||
; This file shows how to use Jasmin to define an interface. It
|
||||
; is like the Java code:
|
||||
;
|
||||
; interface public examples.AnInterface {
|
||||
; void foo();
|
||||
; }
|
||||
;
|
||||
; See examples.Implementor for an example of a class that implements
|
||||
; this interface.
|
||||
;
|
||||
|
||||
.interface public examples/AnInterface
|
||||
.super java/lang/Object
|
||||
|
||||
; (Interfaces should either inherit from Object, or from
|
||||
; another interface.)
|
||||
|
||||
;
|
||||
; declare abstract method foo() - note that the method body is empty.
|
||||
;
|
||||
.method abstract foo()V
|
||||
.end method
|
||||
|
||||
|
53
jasmin/jasmin-2.4/examples/Arrays.j
Normal file
53
jasmin/jasmin-2.4/examples/Arrays.j
Normal file
|
@ -0,0 +1,53 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/Arrays.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Example using JVM's anewarray and aaload/aastore
|
||||
; -------------------------------------------------------------------------
|
||||
|
||||
;
|
||||
; This illustrates how to use the various JVM array instructions - though
|
||||
; it doesn't actually do anything very interesting with the arrays.
|
||||
;
|
||||
|
||||
.class public examples/Arrays
|
||||
.super java/lang/Object
|
||||
|
||||
; standard initializer
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
.limit locals 2
|
||||
.limit stack 4
|
||||
|
||||
; creates a new array of strings,
|
||||
; like:
|
||||
; String[] myarray = new String[2];
|
||||
iconst_2
|
||||
anewarray java/lang/String
|
||||
astore_1 ; stores this in local variable 1
|
||||
|
||||
; this is like the code:
|
||||
; myarray[0] = args[0];
|
||||
|
||||
aload_1 ; push my array on the stack
|
||||
iconst_0
|
||||
aload_0 ; push the array argument to main() on the stack
|
||||
iconst_0
|
||||
aaload ; get its zero'th entry
|
||||
aastore ; and store it in my zero'th entry
|
||||
|
||||
; now print out myarray[0]
|
||||
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
aload_1
|
||||
iconst_0
|
||||
aaload
|
||||
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
|
||||
|
||||
; done
|
||||
return
|
||||
.end method
|
79
jasmin/jasmin-2.4/examples/Catch.j
Normal file
79
jasmin/jasmin-2.4/examples/Catch.j
Normal file
|
@ -0,0 +1,79 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/Catch.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Catching and throwing exceptions
|
||||
; -------------------------------------------------------------------------
|
||||
|
||||
;
|
||||
; This hows how to throw and catch Exceptions in Jasmin
|
||||
;
|
||||
|
||||
.class public examples/Catch
|
||||
.super java/lang/Object
|
||||
|
||||
; standard initializer
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object.<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
|
||||
.limit locals 3
|
||||
.limit stack 5
|
||||
|
||||
; set up a handler to catch subclasses of java.lang.Exception
|
||||
.catch java/lang/Exception from Label1 to Label2 using Handler
|
||||
|
||||
; store System.out in local variable 1
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
astore_1
|
||||
|
||||
; print out a message
|
||||
aload_1
|
||||
ldc " -- Before exception"
|
||||
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
|
||||
|
||||
; construct an instance of Exception, initialize it with a string,
|
||||
; throw it. This is like the Java statement :
|
||||
;
|
||||
; throw new Exception("My exception");
|
||||
;
|
||||
|
||||
Label1:
|
||||
new java/lang/Exception
|
||||
dup
|
||||
ldc "<my exception>"
|
||||
invokenonvirtual java/lang/Exception/<init>(Ljava/lang/String;)V
|
||||
athrow
|
||||
|
||||
Label2:
|
||||
aload_1
|
||||
ldc " -- After exception"
|
||||
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
|
||||
|
||||
return
|
||||
|
||||
; This is the handler for the exception
|
||||
|
||||
Handler:
|
||||
; store the exception in local variable 2
|
||||
astore_2
|
||||
|
||||
; print out a message
|
||||
aload_1
|
||||
ldc " -- Caught exception: "
|
||||
invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V
|
||||
|
||||
; call getMessage() to retrieve the message from the Exception...
|
||||
aload_1
|
||||
aload_2
|
||||
invokevirtual java/lang/Throwable/getMessage()Ljava/lang/String;
|
||||
; ... now print it
|
||||
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
|
||||
|
||||
; return to the code
|
||||
goto Label2
|
||||
|
||||
.end method
|
35
jasmin/jasmin-2.4/examples/Checkcast.j
Normal file
35
jasmin/jasmin-2.4/examples/Checkcast.j
Normal file
|
@ -0,0 +1,35 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/Checkcast.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Catching and throwing exceptions
|
||||
; -------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
;
|
||||
; Simple test for checkcast instruction
|
||||
;
|
||||
|
||||
.class examples/Checkcast
|
||||
.super java/lang/Object
|
||||
|
||||
;
|
||||
; standard initializer
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
.limit stack 2
|
||||
|
||||
; push System.out onto the stack
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
|
||||
; check that it is a PrintStream
|
||||
checkcast java/io/PrintStream
|
||||
|
||||
; done
|
||||
return
|
||||
.end method
|
56
jasmin/jasmin-2.4/examples/Count.j
Normal file
56
jasmin/jasmin-2.4/examples/Count.j
Normal file
|
@ -0,0 +1,56 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/Count.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Counts from 0 to 9, printing out the value
|
||||
; -------------------------------------------------------------------------
|
||||
|
||||
.class public examples/Count
|
||||
.super java/lang/Object
|
||||
|
||||
;
|
||||
; standard initializer
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
; set limits used by this method
|
||||
.limit locals 4
|
||||
.limit stack 3
|
||||
|
||||
; setup local variables:
|
||||
|
||||
; 1 - the PrintStream object held in java.lang.System.out
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
astore_1
|
||||
|
||||
; 2 - the integer 10 - the counter used in the loop
|
||||
bipush 10
|
||||
istore_2
|
||||
|
||||
; now loop 10 times printing out a number
|
||||
|
||||
Loop:
|
||||
|
||||
; compute 10 - <local variable 2> ...
|
||||
bipush 10
|
||||
iload_2
|
||||
isub
|
||||
invokestatic java/lang/String/valueOf(I)Ljava/lang/String;
|
||||
astore_3
|
||||
; ... and print it
|
||||
aload_1 ; push the PrintStream object
|
||||
aload_3 ; push the string we just created - then ...
|
||||
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
|
||||
|
||||
; decrement the counter and loop
|
||||
iinc 2 -1
|
||||
iload_2
|
||||
ifne Loop
|
||||
|
||||
; done
|
||||
return
|
||||
|
||||
.end method
|
5
jasmin/jasmin-2.4/examples/HelloWeb.html
Normal file
5
jasmin/jasmin-2.4/examples/HelloWeb.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
This shows how to run HelloApplet:<p>
|
||||
|
||||
<applet code="HelloWeb.class" width=350 height=75>
|
||||
</applet>
|
91
jasmin/jasmin-2.4/examples/HelloWeb.j
Normal file
91
jasmin/jasmin-2.4/examples/HelloWeb.j
Normal file
|
@ -0,0 +1,91 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/HelloWeb.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Demonstration of a Jasmin-created applet
|
||||
; -------------------------------------------------------------------------
|
||||
; HelloWeb.j
|
||||
|
||||
; This demonstrates how you can use Jasmin to create an applet.
|
||||
|
||||
; The code below is like the Java code:
|
||||
;
|
||||
; import java.applet.*;
|
||||
; import java.awt.*;
|
||||
;
|
||||
; public class HelloWeb extends Applet {
|
||||
; private Font font;
|
||||
;
|
||||
; public void init() {
|
||||
; font = new Font("Helvetica", Font.BOLD, 48);
|
||||
; }
|
||||
;
|
||||
; public void paint(Graphics g) {
|
||||
; g.setFont(font);
|
||||
; g.drawString("Hello World!", 25, 50);
|
||||
; }
|
||||
; }
|
||||
|
||||
|
||||
.class public HelloWeb
|
||||
.super java/applet/Applet
|
||||
|
||||
.field private font Ljava/awt/Font;
|
||||
|
||||
|
||||
; my init() method - allocate a font and assign it to this.font.
|
||||
|
||||
.method public init()V
|
||||
.limit stack 5
|
||||
|
||||
; Create a new Font and call its constructor with
|
||||
; "Helvetica", 1 (i.e. Font.BOLD), and 48.
|
||||
|
||||
new java/awt/Font
|
||||
dup
|
||||
ldc "Helvetica"
|
||||
iconst_1
|
||||
bipush 48
|
||||
invokenonvirtual java/awt/Font/<init>(Ljava/lang/String;II)V
|
||||
|
||||
; now store the Font on the stack in this.font
|
||||
aload_0
|
||||
swap
|
||||
putfield HelloWeb/font Ljava/awt/Font;
|
||||
|
||||
; done
|
||||
return
|
||||
.end method
|
||||
|
||||
; my paint() method - draws the string "Hello World!" using this.font.
|
||||
|
||||
.method public paint(Ljava/awt/Graphics;)V
|
||||
.limit stack 4
|
||||
.limit locals 2
|
||||
|
||||
; local variable 0 holds <this>
|
||||
; local variable 1 holds the java.awt.Graphics instance ('g').
|
||||
|
||||
; g.setFont(this.font);
|
||||
aload_1
|
||||
aload_0
|
||||
getfield HelloWeb/font Ljava/awt/Font;
|
||||
invokevirtual java/awt/Graphics/setFont(Ljava/awt/Font;)V
|
||||
|
||||
; g.drawString("Hello Web!", 25, 50);
|
||||
aload_1
|
||||
ldc "Hello Web!"
|
||||
bipush 25
|
||||
bipush 50
|
||||
invokevirtual java/awt/Graphics/drawString(Ljava/lang/String;II)V
|
||||
|
||||
; done
|
||||
return
|
||||
.end method
|
||||
|
||||
|
||||
; standard constructor
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/applet/Applet/<init>()V
|
||||
return
|
||||
.end method
|
BIN
jasmin/jasmin-2.4/examples/HelloWorld.class
Normal file
BIN
jasmin/jasmin-2.4/examples/HelloWorld.class
Normal file
Binary file not shown.
35
jasmin/jasmin-2.4/examples/HelloWorld.j
Normal file
35
jasmin/jasmin-2.4/examples/HelloWorld.j
Normal file
|
@ -0,0 +1,35 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/HelloWorld.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Prints out "Hello World!"
|
||||
; -------------------------------------------------------------------------
|
||||
|
||||
|
||||
.class public NoJad.j
|
||||
.super java/lang/Object
|
||||
|
||||
;
|
||||
; standard initializer
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
.limit stack 2
|
||||
.limit locals 2
|
||||
|
||||
bipush 2
|
||||
astore 0
|
||||
bipush 3
|
||||
astore 1
|
||||
|
||||
aload 0
|
||||
aload 1
|
||||
astore 0
|
||||
astore 1
|
||||
|
||||
return
|
||||
.end method
|
53
jasmin/jasmin-2.4/examples/Implementor.j
Normal file
53
jasmin/jasmin-2.4/examples/Implementor.j
Normal file
|
@ -0,0 +1,53 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/HelloWorld.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Shows how to define a class that implements an interface
|
||||
; -------------------------------------------------------------------------
|
||||
|
||||
;
|
||||
; This class implements the examples.AnInterface interface - see
|
||||
; AnInterface.j
|
||||
;
|
||||
.class public examples/Implementor
|
||||
.super java/lang/Object
|
||||
.implements examples/AnInterface
|
||||
|
||||
;
|
||||
; standard initializer
|
||||
;
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
;
|
||||
; implement the foo()V method - this is an interface method
|
||||
;
|
||||
.method public foo()V
|
||||
.limit stack 2
|
||||
|
||||
; print a simple message
|
||||
getstatic java/lang/System/out Ljava/io/PrintStream;
|
||||
ldc "Hello Interface"
|
||||
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
|
||||
|
||||
; done
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
.limit stack 2
|
||||
|
||||
; create a new one of me
|
||||
new examples/Implementor
|
||||
dup
|
||||
invokenonvirtual examples/Implementor/<init>()V
|
||||
|
||||
; now call my interface method foo()
|
||||
invokeinterface examples/AnInterface/foo()V 1
|
||||
|
||||
return
|
||||
.end method
|
||||
|
45
jasmin/jasmin-2.4/examples/InvokeInterface.j
Normal file
45
jasmin/jasmin-2.4/examples/InvokeInterface.j
Normal file
|
@ -0,0 +1,45 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/InvokeInterface.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Example of using invokeinterface
|
||||
; -------------------------------------------------------------------------
|
||||
;
|
||||
; Demonstrates invoking an interface method
|
||||
;
|
||||
|
||||
.class public examples/InvokeInterface
|
||||
.super java/lang/Object
|
||||
|
||||
; standard initializer
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
;
|
||||
; This is a rather silly example - since the result of calling the
|
||||
; interface method isn't actually used. But it does illustrate how to
|
||||
; use invokeinterface.
|
||||
;
|
||||
|
||||
.method public example(Ljava/util/Enumeration;)V
|
||||
.limit stack 1
|
||||
.limit locals 3
|
||||
|
||||
; push local variable 1 (the Enumeration object)
|
||||
aload_1
|
||||
|
||||
; now call the hasMoreElements() interface method.
|
||||
invokeinterface java/util/Enumeration/hasMoreElements()Z 1
|
||||
|
||||
; store the integer result in local variable 2
|
||||
istore_2
|
||||
|
||||
; done
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
return
|
||||
.end method
|
37
jasmin/jasmin-2.4/examples/MultiANewArray.j
Normal file
37
jasmin/jasmin-2.4/examples/MultiANewArray.j
Normal file
|
@ -0,0 +1,37 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/MultiANewArray.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Example of multanewarray instruction
|
||||
; -------------------------------------------------------------------------
|
||||
;
|
||||
; This illustrates how to use multianewarray to allocate
|
||||
; an array.
|
||||
;
|
||||
|
||||
.class public examples/MultiANewArray
|
||||
.super java/lang/Object
|
||||
|
||||
; standard initializer
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
|
||||
.limit locals 4
|
||||
.limit stack 2
|
||||
|
||||
;
|
||||
; This allocates an array like:
|
||||
;
|
||||
; String s[][] = new String[2][5];
|
||||
;
|
||||
iconst_2
|
||||
iconst_5
|
||||
multianewarray [[Ljava/lang/String; 2
|
||||
astore_1
|
||||
|
||||
return
|
||||
.end method
|
55
jasmin/jasmin-2.4/examples/MultiArrays.j
Normal file
55
jasmin/jasmin-2.4/examples/MultiArrays.j
Normal file
|
@ -0,0 +1,55 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/MultiArrays.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Examples involving multi-dimensional arrays
|
||||
; -------------------------------------------------------------------------
|
||||
;
|
||||
; This illustrates how to use multi-dimensional arrays in the Java VM
|
||||
; (though it doesn't actually do anything very interesting with the arrays.)
|
||||
;
|
||||
|
||||
.class public examples/MultiArrays
|
||||
.super java/lang/Object
|
||||
|
||||
; standard initializer
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
|
||||
.limit locals 4
|
||||
.limit stack 5
|
||||
|
||||
; this is like:
|
||||
; new int[2][5][]
|
||||
iconst_2
|
||||
iconst_5
|
||||
multianewarray [[[I 2
|
||||
|
||||
; store the result in local variable 1
|
||||
astore_1
|
||||
|
||||
aload_1
|
||||
iconst_1
|
||||
aaload ; stack now contains x[0]
|
||||
astore_2 ; store the array in local variable 2
|
||||
|
||||
; create a new array of 50 ints and store it in x[1][1]
|
||||
aload_2
|
||||
iconst_1
|
||||
bipush 50
|
||||
newarray int
|
||||
aastore
|
||||
|
||||
; create a new array of 60 ints and store it in x[1][2]
|
||||
aload_2
|
||||
iconst_2
|
||||
bipush 60
|
||||
newarray int
|
||||
aastore
|
||||
|
||||
return
|
||||
.end method
|
41
jasmin/jasmin-2.4/examples/NewArray.j
Normal file
41
jasmin/jasmin-2.4/examples/NewArray.j
Normal file
|
@ -0,0 +1,41 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/NewArray.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Example of newarray
|
||||
; -------------------------------------------------------------------------
|
||||
;
|
||||
; Example showing how to allocate an array using
|
||||
; newarray.
|
||||
;
|
||||
|
||||
.class public examples/NewArray
|
||||
.super java/lang/Object
|
||||
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
.limit stack 4
|
||||
.limit locals 2
|
||||
|
||||
; create an array like:
|
||||
;
|
||||
; boolean b[] = new boolean[2]
|
||||
;
|
||||
; (stores it in local var 1)
|
||||
|
||||
iconst_2
|
||||
newarray boolean
|
||||
astore_1
|
||||
|
||||
; b[0] = true;
|
||||
aload_1
|
||||
iconst_0
|
||||
iconst_1
|
||||
bastore
|
||||
|
||||
return
|
||||
.end method
|
41
jasmin/jasmin-2.4/examples/Switch.j
Normal file
41
jasmin/jasmin-2.4/examples/Switch.j
Normal file
|
@ -0,0 +1,41 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/Switch.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Shows usage of lookupswitch and tableswitch
|
||||
; -------------------------------------------------------------------------
|
||||
|
||||
;
|
||||
; Illustrates lookupswitch and tableswitch syntax for Jasmin
|
||||
;
|
||||
|
||||
.class public examples/Switch
|
||||
.super java/lang/Object
|
||||
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
.limit stack 3
|
||||
|
||||
iconst_1
|
||||
lookupswitch
|
||||
1 : Hello
|
||||
2 : Goodbye
|
||||
default : Foo
|
||||
|
||||
iconst_1
|
||||
tableswitch 0
|
||||
Hello
|
||||
Goodbye
|
||||
default : Foo
|
||||
|
||||
Hello:
|
||||
Goodbye:
|
||||
Foo:
|
||||
|
||||
return
|
||||
|
||||
.end method
|
36
jasmin/jasmin-2.4/examples/Uncaught.j
Normal file
36
jasmin/jasmin-2.4/examples/Uncaught.j
Normal file
|
@ -0,0 +1,36 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/Uncaught.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Throws an exception - doesn't catch it
|
||||
; -------------------------------------------------------------------------
|
||||
|
||||
;
|
||||
; This example class contains a main() method that throws
|
||||
; an exception but doesn't catch it -
|
||||
;
|
||||
.source Uncaught.j
|
||||
.class public examples/Uncaught
|
||||
.super java/lang/Object
|
||||
|
||||
; specify the initializer method (as for HelloWorld)
|
||||
|
||||
.method public <init>()V
|
||||
; just call Object's initializer
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
; specify the "main" method - this throws an uncaught exception
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
.limit stack 2
|
||||
|
||||
new java/lang/Exception
|
||||
dup
|
||||
invokenonvirtual java/lang/Exception/<init>()V
|
||||
athrow
|
||||
|
||||
; without this the verifier might complain ...
|
||||
return
|
||||
.end method
|
41
jasmin/jasmin-2.4/examples/VerifyTest.j
Normal file
41
jasmin/jasmin-2.4/examples/VerifyTest.j
Normal file
|
@ -0,0 +1,41 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/VerifyTest.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Treats an int as an object - should alert the Verifier
|
||||
; -------------------------------------------------------------------------
|
||||
|
||||
;
|
||||
; This code demonstrates the verifier at work. See also VerifyTest1.j.
|
||||
;
|
||||
; The main() method below tries to clone the integer 100 - this
|
||||
; is clearly an error since clone() expects an Object, not an integer.
|
||||
;
|
||||
; If you run this with no verification on, it is likely to crash the
|
||||
; interpreter. Running this with the -verify option produces a
|
||||
; Verifier error.
|
||||
;
|
||||
|
||||
; This is similar to the Java code:
|
||||
;
|
||||
; class VerifyTest {
|
||||
; public static void main(String args[]) {
|
||||
; int x = 100;
|
||||
; x.clone();
|
||||
; }
|
||||
; }
|
||||
|
||||
|
||||
.class public examples/VerifyTest
|
||||
.super java/lang/Object
|
||||
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
bipush 100
|
||||
invokevirtual java/lang/Object/clone()Ljava/lang/Object;
|
||||
return
|
||||
.end method
|
62
jasmin/jasmin-2.4/examples/VerifyTest1.j
Normal file
62
jasmin/jasmin-2.4/examples/VerifyTest1.j
Normal file
|
@ -0,0 +1,62 @@
|
|||
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
|
||||
; File: jasmin/examples/VerifyTest1.j
|
||||
; Author: Jonathan Meyer, 10 July 1996
|
||||
; Purpose: Trys to pull one on the verifier
|
||||
; -------------------------------------------------------------------------
|
||||
|
||||
; This file illustrates the bytecode verifier at work - the
|
||||
; code in the example() method below seems reasonable, but
|
||||
; Java's bytecode verifier will fail the code because the two points leading
|
||||
; to the Loop label (from the top of the method and from the ifne
|
||||
; statement) have different stack states. Instead, a different approach
|
||||
; must be adopted - e.g. by allocating an array, or simply writing:
|
||||
;
|
||||
; aconst_null
|
||||
; aconst_null
|
||||
; aconst_null
|
||||
; aconst_null
|
||||
|
||||
; Note that many interpreters will run this code OK if you don't use
|
||||
; a verifier. The code itself is well behaved (it doesn't trash the
|
||||
; interpreter), but the approach it uses is disallowed by the verifier.
|
||||
;
|
||||
|
||||
; Compile the example, then run it using:
|
||||
;
|
||||
; % java -verify VerifyTest1
|
||||
; VERIFIER ERROR VerifyTest1.example()V:
|
||||
; Inconsistent stack height 1 != 0
|
||||
;
|
||||
|
||||
.class public examples/VerifyTest1
|
||||
.super java/lang/Object
|
||||
|
||||
.method public <init>()V
|
||||
aload_0
|
||||
invokenonvirtual java/lang/Object/<init>()V
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public example()V
|
||||
.limit locals 2
|
||||
.limit stack 10
|
||||
|
||||
; this tries to push four nulls onto the stack
|
||||
; using a loop - Java's verifier will fail this program
|
||||
|
||||
iconst_4 ; store 4 in local variable 1 (used as a counter)
|
||||
istore_1
|
||||
|
||||
Loop:
|
||||
aconst_null ; push null onto the stack
|
||||
iinc 1 -1 ; decrement local variable 4 (the counter variable)
|
||||
iload_1
|
||||
ifne Loop ; jump back to Loop unless the variable has reached 0
|
||||
|
||||
return
|
||||
.end method
|
||||
|
||||
.method public static main([Ljava/lang/String;)V
|
||||
; - do nothing : this is only to illustrate the bytecode verifier at work.
|
||||
return
|
||||
.end method
|
Loading…
Add table
Add a link
Reference in a new issue