Jasml Home
User Guide
A Simple Example
Jasml Syntax
Attributes
Java Macro Instructions
Java Macro Instruction Index
Javadoc
Download
|
Jasm Syntax
JASML is very easy to use, it uses java like syntax. Indeed, if one has experiences working with java macro instructins, one would know that fields, methods and classes are stored quite differently inside the .class files. For example, java.lang.String is internally stored as java/lang/String, and int[][] as [[I. JASML deliberately avoids these.
Each .jasm files may have the follwing structures:
Minor and Major Version
Class or interface Declarations
Field Declarations
Method Declarations
Class Attribute Declarations
Comments
1. Minor and Major versions
Minor and Major versions must be defined in the beginning of jasm file, exactly like
[Major : minor_number]
[Minor : major_number]
The two words "Major" and "Minor" are case sensitive and must be followed by ":".
Minor and Major version definitions are optional. If omitted, Minor version will be defaulted to 0, Major version 46.
2. Class or Interface Declarations
Classes and interfaces are declared like what is done in .java files, except:
3. Field Declarations
Fields are defined as what is done in .java files, with the following exceptions:
- Only final field of primitive types(int, long, double, etc.) or java.lang.String can have an value definition.
For example, this is allowed:
public final int aFinalField = 5
while this will generate compilation errors:
public final java.lang.Integer anIntegerField = new java.lang.Integer(5)
Indeed, code like this must be put into class constructors.
- If the field has attributes like Synthetic or Deprecated, they must be put after, and in the same line with, the field definitions, like:
public final int aFinalField = 5 [Deprecated]
And this is not valid:
public final int aFinalField = 5
[Deprecated] The [Deprecated] should be put in the same line with the field declaration.
- Field declarations, including its attribute defintion, must be in a single line.
- Field declarations must follow directly after class declarations and precede method declarations.
4. Methods Declarations
Methods declarations are of the following structure:
Method Descriptor and Signatures and throws Clause{
Insctructions
Method/Code Attributes and Structures
}
- For each method, there must be a method body. This means for the abstract or interface method which has no instructions, there must be a method body enclosed with "{" and "}".
So, to define an public void AMethodOfInterface() in a certain interface:
public abstract void AMethodOfInterface (){
}
-
Unlike what is done in .java files, method parameter lists are composed types only, without any name definitions. To find which parameter maps to which name, one have to refer to the local variable table.
So, to define an public void AMethodOfInterface(int a, String b) in a certain interface:
public abstract void AMethodOfInterface (int, java.lang.String){
} -
Method Attributes(including Synthetic, Deprecated), attributes of the Code attribute(including LineNumberTable, LocalVariableTable) and exception_table, max_stack, max_locals of the Code attribute must be defined at the bottom of the method body. And there is no special order of how they should be defined.
Method may also contain Exceptions attribute, which is mapped to the throws clause.
- Method declarations must follow directly after field declarations and precede class attribute declarations.
5. Class Attributes Declaration
Class attributes can be SourceFile, Deprecated and InnerClasses.
They must follow directly after method declarations and precede the closing "}" of class definitions. And there is no special order of how they should be defined.
6. Numbers and Strings and Chars
- Strings and Chars
Strings and Chars are defined the same as in .java files. And all the escaping chars and sequences are supported. Special unicode are displayed like /u****. For example, the chinese character "ĪŅ" will be displayed as "\u6211".
- Numbers
1. int numbers are defined the same as they are in .java files. Hex numbers starting with "0x" or "0X" is supported.
2. long numbers must be followed by 'l' or "L", or they will be treated as int.
For example, when defining a long field,
public static final long fieldLong = 5 is not a legal definitions. It should be like:
public static final long fieldLong = 5L
3. float numbers are followed by 'f' or "F". If an number has decimal point in it, but not followed with 'f' or 'd', it will be treated as float.
4. double numbers are followed by 'd' or "D".
6. boolean, byte types are represented using int. 0 represents boolean value "false", while 1 represents "true".
7. scientific numbers are supported, but must be followed with the type char, 'f', 'd' etc. For example, 4.9e-324D or 1.7976931348623157e+10F are valid numbers.
8. For float and double numbers there are three special types, postive infinity(1.0/0.0), negative infinity(-1.0/0.0) and NaN(not a number, 0.0/0.0). For float and double types these are represented as Infinityf, -Infinityf, NaNf, Infinityd, -Infinityd, NaNd.
7. Comments
Comments are defined the same way as they are in the .java files.
"//" starts a single line comment.
"/*" and "*/" enclose multi line comment.
|