org.xwt.js
Class Function

java.lang.Object
  extended byorg.xwt.js.JS
      extended byorg.xwt.js.JS.Obj
          extended byorg.xwt.js.Function
All Implemented Interfaces:
org.xwt.js.ByteCodes, org.xwt.js.Tokens

public class Function
extends JS.Obj
implements org.xwt.js.ByteCodes, org.xwt.js.Tokens

a JavaScript function, compiled into bytecode


Nested Class Summary
static class Function.CallMarker
           
static class Function.CatchMarker
           
static class Function.FinallyData
           
static class Function.LoopMarker
           
static class Function.TryMarker
           
 
Nested classes inherited from class org.xwt.js.JS
JS.Array, JS.Callable, JS.Context, JS.Exn, JS.GlobalScope, JS.Graft, JS.Obj, JS.Scope, JS.TailCall
 
Field Summary
static int ADD
           
static int AND
           
static byte ARRAY
          push a new array onto the stack with length equal to the literal
static int ASSERT
           
static int ASSIGN
           
static int ASSIGN_ADD
           
static int ASSIGN_BITAND
           
static int ASSIGN_BITNOT
           
static int ASSIGN_BITOR
           
static int ASSIGN_BITXOR
           
static int ASSIGN_DIV
           
static int ASSIGN_LSH
           
static int ASSIGN_MOD
           
static int ASSIGN_MUL
           
static int ASSIGN_RSH
           
static int ASSIGN_SUB
           
static int ASSIGN_URSH
           
static int BANG
           
static int BITAND
           
static int BITNOT
           
static int BITOR
           
static int BITXOR
           
static int BREAK
           
static java.lang.String[] bytecodeToString
           
static byte CALL
          pop two elements; call stack[-n](stack[-n+1], stack[-n+2]...) where n is the number of args to the function
static byte CALL_REVERSED
          same as CALL, except that the function is on top of the arguments instead of beneath them
static byte CALLMETHOD
          pop three elements off the stack; method arguments, method name, and an object to call the method on, then calls the method Has a similar effect a a GET followed by a CALL
static int CASE
           
static int CATCH
           
static java.lang.String[] codeToString
           
static int COLON
           
static int COMMA
           
static int CONTINUE
           
static int DEC
           
static byte DECLARE
          if given a non-null argument declare its argument in the current scope and push it to the stack, else, declares the element on the top of the stack and leaves it there
static int DEFAULT
           
static int DIV
           
static int DO
           
static int DOT
           
static byte DUP
          push a copy of the top stack element
static int ELSE
           
static int EQ
           
static int FALSE
           
static int FINALLY
           
static byte FINALLY_DONE
          finish a finally block and carry out whatever instruction initiated the finally block
static int FOR
           
static int FUNCTION
           
static int GE
           
static byte GET
          if given a null literal pop two elements off the stack; push stack[-1].get(stack[top]) else pop one element off the stack, push stack[top].get(literal)
static byte GET_PRESERVE
          push stack[-1].get(stack[top])
static int GT
           
static int HOOK
           
static int IF
           
static int IN
           
static int INC
           
static byte JF
          literal is a relative address; pop stacktop and jump if the value is false
static byte JMP
          literal is a relative address; jump to it
static byte JT
          literal is a relative address; pop stacktop and jump if the value is true
static byte LABEL
          a NOP; confers a label upon the following instruction
static int LB
           
static int LC
           
static int LE
           
static byte LITERAL
          push the literal onto the stack
static byte LOOP
          execute the ForthBlock pointed to by the literal until BREAK encountered; push TRUE onto the stack for the first iteration and FALSE for all subsequent iterations
static int LP
           
static int LSH
           
static int LT
           
static int MAX_TOKEN
           
static int MOD
           
static int MUL
           
static int NAME
           
static int NE
           
static byte NEWFUNCTION
          create a new instance; literal is a reference to the corresponding ForthBlock
static byte NEWSCOPE
          execute the ForthBlock pointed to by the literal in a fresh scope with parentScope==THIS
static int NULL
           
static int NUMBER
           
static byte OBJECT
          push an empty object onto the stack
static byte OLDSCOPE
          execute the ForthBlock pointed to by the literal in a fresh scope with parentScope==THIS
static int OR
           
static byte POP
          discard the top stack element
static byte PUSHKEYS
          pop an element; push a JS.JS.Array containing the keys of the popped element
static byte PUT
          pop two elements off the stack; stack[-2].put(stack[-1], stack[top]); push stack[top]
static int RB
           
static int RC
           
static int RESERVED
           
static int RETURN
           
static int RP
           
static int RSH
           
static int SEMI
           
static int SHEQ
           
static int SHNE
           
static int STRING
           
static int SUB
           
static byte SWAP
          swap the top two elements on the stack
static int SWITCH
           
static int THIS
           
static int THROW
           
static byte TOPSCOPE
          push a reference to the current scope onto the stack
static int TRUE
           
static int TRY
           
static int TYPEOF
           
static int URSH
           
static int VAR
           
static int WHILE
           
static int WITH
           
 
Constructor Summary
protected Function(java.lang.String sourceName, int firstLine, java.io.Reader sourceCode, JS.Scope parentScope)
           
 
Method Summary
 java.lang.String dump()
           
 int getNumFormalArgs()
           
 java.lang.String toString()
           
 
Methods inherited from class org.xwt.js.JS.Obj
get, get, keys, put, put2, setSeal
 
Methods inherited from class org.xwt.js.JS
callMethod, coerceToBoolean, coerceToNumber, coerceToString, parse, toBoolean, toDouble, toInt, toLong, toNumber, toString, typeName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LITERAL

public static final byte LITERAL
push the literal onto the stack

See Also:
Constant Field Values

ARRAY

public static final byte ARRAY
push a new array onto the stack with length equal to the literal

See Also:
Constant Field Values

OBJECT

public static final byte OBJECT
push an empty object onto the stack

See Also:
Constant Field Values

NEWFUNCTION

public static final byte NEWFUNCTION
create a new instance; literal is a reference to the corresponding ForthBlock

See Also:
Constant Field Values

DECLARE

public static final byte DECLARE
if given a non-null argument declare its argument in the current scope and push it to the stack, else, declares the element on the top of the stack and leaves it there

See Also:
Constant Field Values

TOPSCOPE

public static final byte TOPSCOPE
push a reference to the current scope onto the stack

See Also:
Constant Field Values

GET

public static final byte GET
if given a null literal pop two elements off the stack; push stack[-1].get(stack[top]) else pop one element off the stack, push stack[top].get(literal)

See Also:
Constant Field Values

GET_PRESERVE

public static final byte GET_PRESERVE
push stack[-1].get(stack[top])

See Also:
Constant Field Values

PUT

public static final byte PUT
pop two elements off the stack; stack[-2].put(stack[-1], stack[top]); push stack[top]

See Also:
Constant Field Values

JT

public static final byte JT
literal is a relative address; pop stacktop and jump if the value is true

See Also:
Constant Field Values

JF

public static final byte JF
literal is a relative address; pop stacktop and jump if the value is false

See Also:
Constant Field Values

JMP

public static final byte JMP
literal is a relative address; jump to it

See Also:
Constant Field Values

POP

public static final byte POP
discard the top stack element

See Also:
Constant Field Values

CALL

public static final byte CALL
pop two elements; call stack[-n](stack[-n+1], stack[-n+2]...) where n is the number of args to the function

See Also:
Constant Field Values

PUSHKEYS

public static final byte PUSHKEYS
pop an element; push a JS.JS.Array containing the keys of the popped element

See Also:
Constant Field Values

SWAP

public static final byte SWAP
swap the top two elements on the stack

See Also:
Constant Field Values

NEWSCOPE

public static final byte NEWSCOPE
execute the ForthBlock pointed to by the literal in a fresh scope with parentScope==THIS

See Also:
Constant Field Values

OLDSCOPE

public static final byte OLDSCOPE
execute the ForthBlock pointed to by the literal in a fresh scope with parentScope==THIS

See Also:
Constant Field Values

DUP

public static final byte DUP
push a copy of the top stack element

See Also:
Constant Field Values

LABEL

public static final byte LABEL
a NOP; confers a label upon the following instruction

See Also:
Constant Field Values

LOOP

public static final byte LOOP
execute the ForthBlock pointed to by the literal until BREAK encountered; push TRUE onto the stack for the first iteration and FALSE for all subsequent iterations

See Also:
Constant Field Values

CALLMETHOD

public static final byte CALLMETHOD
pop three elements off the stack; method arguments, method name, and an object to call the method on, then calls the method Has a similar effect a a GET followed by a CALL

See Also:
Constant Field Values

FINALLY_DONE

public static final byte FINALLY_DONE
finish a finally block and carry out whatever instruction initiated the finally block

See Also:
Constant Field Values

CALL_REVERSED

public static final byte CALL_REVERSED
same as CALL, except that the function is on top of the arguments instead of beneath them

See Also:
Constant Field Values

bytecodeToString

public static final java.lang.String[] bytecodeToString

BITOR

public static final int BITOR
See Also:
Constant Field Values

ASSIGN_BITOR

public static final int ASSIGN_BITOR
See Also:
Constant Field Values

BITXOR

public static final int BITXOR
See Also:
Constant Field Values

ASSIGN_BITXOR

public static final int ASSIGN_BITXOR
See Also:
Constant Field Values

BITAND

public static final int BITAND
See Also:
Constant Field Values

ASSIGN_BITAND

public static final int ASSIGN_BITAND
See Also:
Constant Field Values

LSH

public static final int LSH
See Also:
Constant Field Values

ASSIGN_LSH

public static final int ASSIGN_LSH
See Also:
Constant Field Values

RSH

public static final int RSH
See Also:
Constant Field Values

ASSIGN_RSH

public static final int ASSIGN_RSH
See Also:
Constant Field Values

URSH

public static final int URSH
See Also:
Constant Field Values

ASSIGN_URSH

public static final int ASSIGN_URSH
See Also:
Constant Field Values

ADD

public static final int ADD
See Also:
Constant Field Values

ASSIGN_ADD

public static final int ASSIGN_ADD
See Also:
Constant Field Values

SUB

public static final int SUB
See Also:
Constant Field Values

ASSIGN_SUB

public static final int ASSIGN_SUB
See Also:
Constant Field Values

MUL

public static final int MUL
See Also:
Constant Field Values

ASSIGN_MUL

public static final int ASSIGN_MUL
See Also:
Constant Field Values

DIV

public static final int DIV
See Also:
Constant Field Values

ASSIGN_DIV

public static final int ASSIGN_DIV
See Also:
Constant Field Values

MOD

public static final int MOD
See Also:
Constant Field Values

ASSIGN_MOD

public static final int ASSIGN_MOD
See Also:
Constant Field Values

BITNOT

public static final int BITNOT
See Also:
Constant Field Values

ASSIGN_BITNOT

public static final int ASSIGN_BITNOT
See Also:
Constant Field Values

OR

public static final int OR
See Also:
Constant Field Values

AND

public static final int AND
See Also:
Constant Field Values

BANG

public static final int BANG
See Also:
Constant Field Values

EQ

public static final int EQ
See Also:
Constant Field Values

NE

public static final int NE
See Also:
Constant Field Values

LT

public static final int LT
See Also:
Constant Field Values

LE

public static final int LE
See Also:
Constant Field Values

GT

public static final int GT
See Also:
Constant Field Values

GE

public static final int GE
See Also:
Constant Field Values

SHEQ

public static final int SHEQ
See Also:
Constant Field Values

SHNE

public static final int SHNE
See Also:
Constant Field Values

RETURN

public static final int RETURN
See Also:
Constant Field Values

TYPEOF

public static final int TYPEOF
See Also:
Constant Field Values

BREAK

public static final int BREAK
See Also:
Constant Field Values

CONTINUE

public static final int CONTINUE
See Also:
Constant Field Values

TRY

public static final int TRY
See Also:
Constant Field Values

THROW

public static final int THROW
See Also:
Constant Field Values

ASSERT

public static final int ASSERT
See Also:
Constant Field Values

NAME

public static final int NAME
See Also:
Constant Field Values

NUMBER

public static final int NUMBER
See Also:
Constant Field Values

STRING

public static final int STRING
See Also:
Constant Field Values

NULL

public static final int NULL
See Also:
Constant Field Values

THIS

public static final int THIS
See Also:
Constant Field Values

FALSE

public static final int FALSE
See Also:
Constant Field Values

TRUE

public static final int TRUE
See Also:
Constant Field Values

IN

public static final int IN
See Also:
Constant Field Values

SEMI

public static final int SEMI
See Also:
Constant Field Values

LB

public static final int LB
See Also:
Constant Field Values

RB

public static final int RB
See Also:
Constant Field Values

LC

public static final int LC
See Also:
Constant Field Values

RC

public static final int RC
See Also:
Constant Field Values

LP

public static final int LP
See Also:
Constant Field Values

RP

public static final int RP
See Also:
Constant Field Values

COMMA

public static final int COMMA
See Also:
Constant Field Values

ASSIGN

public static final int ASSIGN
See Also:
Constant Field Values

HOOK

public static final int HOOK
See Also:
Constant Field Values

COLON

public static final int COLON
See Also:
Constant Field Values

INC

public static final int INC
See Also:
Constant Field Values

DEC

public static final int DEC
See Also:
Constant Field Values

DOT

public static final int DOT
See Also:
Constant Field Values

FUNCTION

public static final int FUNCTION
See Also:
Constant Field Values

IF

public static final int IF
See Also:
Constant Field Values

ELSE

public static final int ELSE
See Also:
Constant Field Values

SWITCH

public static final int SWITCH
See Also:
Constant Field Values

CASE

public static final int CASE
See Also:
Constant Field Values

DEFAULT

public static final int DEFAULT
See Also:
Constant Field Values

WHILE

public static final int WHILE
See Also:
Constant Field Values

DO

public static final int DO
See Also:
Constant Field Values

FOR

public static final int FOR
See Also:
Constant Field Values

VAR

public static final int VAR
See Also:
Constant Field Values

WITH

public static final int WITH
See Also:
Constant Field Values

CATCH

public static final int CATCH
See Also:
Constant Field Values

FINALLY

public static final int FINALLY
See Also:
Constant Field Values

RESERVED

public static final int RESERVED
See Also:
Constant Field Values

MAX_TOKEN

public static final int MAX_TOKEN
See Also:
Constant Field Values

codeToString

public static final java.lang.String[] codeToString
Constructor Detail

Function

protected Function(java.lang.String sourceName,
                   int firstLine,
                   java.io.Reader sourceCode,
                   JS.Scope parentScope)
            throws java.io.IOException
Method Detail

getNumFormalArgs

public int getNumFormalArgs()

toString

public java.lang.String toString()

dump

public java.lang.String dump()