Jas: scripting function and variable list

Variable list

Basic functions

define
(define symbol binding)
set!
(set! symbol binding)
lambda
(lambda (arg1 arg2 ...) body)
quote
(quote body)
car
(car (a1 a2 ...))
cdr
(cdr (a1 a2 ...))
cons
(cons a1 (a2 a3...))
+
(+ num1 num2)
-
(- num1 num2)
*
(* num1 num2)
/
(/ num1 num2)
|
Bitwise or
(| num1 num2)
cond
(cond (expr1 body1) (expr2 body2) ...)
>
return non-nil if num1 is bigger than num2
(> num1 num2)
<
return non-nil if num1 is smaller than num2
(< num1 num2)
eq?
(eq? obj1 obj2)
num?
returns non-nill if the argument is a number
(num? something)
string?
returns non-nil if the argument is a number
(string? something)
progn
evaluate a sequence of expressions in one body, returning the value of the last expression.
(progn body1 body2 ...)
mapcar
apply the function to each element on the list, returning a list of the return values.
(mapcar fn (arg1 arg2 ...))

Creating various objects

Constant pool items
make-ascii-cpe
Make an ascii cpe entry
(make-ascii-cpe "stringval")
make-class-cpe
Make a class cpe entry
(make-class-cpe "classname")
make-name-type-cpe
Make a name type entry
(make-name-type-cpe "name" "signature")
make-field-cpe
Make a field cpe
(make-field-cpe "classname" "fieldname" "signature")
make-interface-cpe
Make a interface cpe
(make-interface-cpe "classname" "interfacename" "signature")
make-integer-cpe
Make a constant integer in cp
(make-integer-cpe num)
make-float-cpe
Make a constant float in cp
(make-float-cpe num)
make-long-cpe
Make a constant long in cpe
(make-long-cpe num)
make-double-cpe
Make a constant double in cp
(make-double-cpe num)
make-string-cpe
Make a constant string in cpe
(make-string-cpe "string val")
make-method-cpe
Make a method cpe
(make-method-cpe "classname" "methodname" "signature")
Instructions
Instructions are objects that are created with the following set of functions. Any instruction not mentioned here is generated with a function of the same name and no arguments.
bipush
sipush
ret
iload
lload
fload
dload
aload
istore
lstore
fstore
dstore
astore
newarray
All the above take a single argument, a number. For instance,
(bipush 3)
jsr
goto
if_acmpne
if_acmpeq
if_icmpge
if_icmple
if_icmpgt
if_icmplt
if_icmpne
if_icmpeq
ifge
ifgt
ifne
ifle
iflt
ifeq
ifnull
ifnonnull
goto_w
jsr_w
All of these take a label object as an argument. Label objects are generated with the label function. For instance,
(jsr (make-label "targetname"))
anewarray
ldc_w
ldc2_w
invokenonvirtual
invokestatic
invokevirtual
new
checkcast
instanceof
getstatic
putstatic
getfield
putfield
ldc
All of these take a cpe item as an argument. You should be aware of the appropriate type of cpe item to pass to the instruction, though the assembler itself does not care about it. For instance,
(ldc (make-string-cpe "someval"))
invokeinterface
(invokeinterface cpeitem numargs)
iinc
(iinc varindex const)
Both these are numbers.
multinewarray
(multinewarray cpe dimensions)
cpe is the cpe for the class to be created, and dimension is a number.
Miscellanous objects
make-field
Create a field definition for the class.
(jas-define-class access cpeitem-name cpeitem-signature [optional constant attribute])
access is a number specifying the access restriction for the variable. The two cpeitems should be ascii-cpe's defining the name and signature.
make-const
Create a constant attribute
(make-const const-cpe-item)
make-outputstream
Open a file stream suitable for writing.
(make-outputstream "filename")
make-label
This is a special form that takes a string as its argument, and generates an object that behaves as a placemarker for instructions that need labels.
(make-label "sometarget")
(pop)
(pop)
(goto (make-label "sometarget"))
demonstrates the method, but be aware that this example will not pass the verifier, since the stack depths are not identical. You can reuse labels, or create new ones. Equivalence is solely by the name used to create the label.
make-class-env
Create a new container that will be the repository of information about a class.
(make-class-env)
make-code
Create an new method body
(make-code)
make-exception
Create a new exception attribute
(make-exception)
make-catchtable
(make-catchtable)
make-catch-entry
(make-catch-entry)

Manipulating the various objects

Class environment
jas-class-addcpe
Add a cpe directly to a class. You shouldn't need to do this unless you are trying to validate a VM implementation.
(jas-class-addcpe class-env cpeitem)
jas-class-addfield
Add a new field to this class
(jas-class-addfield class-env field)
jas-class-addinterface
Note that the cpe-item is expected to be a ClassCP by the VM
(jas-class-addinterface class-env cpe-item)
jas-class-setclass
Set the classname to this value
(jas-class-setclass class-env cpeitem)
jas-class-setsuperclass
Set the superclass to this value
(jas-class-setsuperclass class-env cpeitem)
jas-class-addmethod
Add a new code body to the class. access is a number describing the access permissions to the method.
(jas-class-addmethod class-env access "methodname" "methodsignature" code-body exception-attribute)
jas-class-setaccess
(jas-class-setaccess class-env access)
jas-class-write
Write out the representation of the class on the output stream. (jas-class-write class-env outputstream)
Code object
jas-code-addinsn
(jas-code-addinsn code-body insn)
jas-code-stack-size
Set the stack size on the code body.
(jas-code-stack-size code-body num)
jas-code-var-size
Set the local vars size on the code body.
(jas-code-var-size code-body num)
jas-set-catchtable
(jas-set-catchtable code-body catch-table)
Exception attribute
jas-exception-add
(jas-exception-add exception cpe-item)
Catchtable
jas-add-catch-entry
(jas-add-catch-entry catchtable catchentry)

kbs@best.com