Back to index

wims  3.65+svn20090927
Package Functions | Package Attributes | Static Package Attributes
org.javia.arity.OptCodeGen Class Reference
Inheritance diagram for org.javia.arity.OptCodeGen:
Inheritance graph
[legend]
Collaboration diagram for org.javia.arity.OptCodeGen:
Collaboration graph
[legend]

List of all members.

Package Functions

 OptCodeGen (SyntaxException e)
void start ()
void push (Token token) throws SyntaxException
CompiledFunction getFun (int arity)
 OptCodeGen (SyntaxException e)
void start ()
void push (Token token) throws SyntaxException
CompiledFunction getFun (int arity)
SimpleCodeGen setSymbols (Symbols symbols)
SimpleCodeGen setSymbols (Symbols symbols)
double getValue ()
double getValue ()

Package Attributes

double stack [] = new double[CompiledFunction.MAX_STACK_SIZE]
int sp = -1
double traceConsts [] = new double[1]
Function traceFuncs [] = new Function[1]
byte traceCode [] = new byte[1]
CompiledFunction tracer = new CompiledFunction(0, traceCode, traceConsts, traceFuncs)
int intrinsicArity
ByteStack code = new ByteStack()
DoubleStack consts = new DoubleStack()
FunctionStack funcs = new FunctionStack()
Symbols symbols
SyntaxException exception

Static Package Attributes

static final SyntaxException HAS_ARGUMENTS = new SyntaxException()

Detailed Description

Definition at line 25 of file OptCodeGen.java.


Constructor & Destructor Documentation

Definition at line 36 of file OptCodeGen.java.

                                  {
        super(e);
    }

Definition at line 36 of file OptCodeGen.java.

                                  {
        super(e);
    }

Member Function Documentation

CompiledFunction org.javia.arity.OptCodeGen.getFun ( int  arity) [inline, package]

Definition at line 105 of file OptCodeGen.java.

                                       {
        return new CompiledFunction(arity, code.toArray(), consts.toArray(), funcs.toArray());
    }

Here is the call graph for this function:

Here is the caller graph for this function:

CompiledFunction org.javia.arity.OptCodeGen.getFun ( int  arity) [inline, package]

Definition at line 105 of file OptCodeGen.java.

                                       {
        return new CompiledFunction(arity, code.toArray(), consts.toArray(), funcs.toArray());
    }

Here is the call graph for this function:

double org.javia.arity.SimpleCodeGen.getValue ( ) [inline, package, inherited]

Definition at line 91 of file SimpleCodeGen.java.

                      {
        compiledFunction.init(0, code.toArray(), consts.toArray(), funcs.toArray());
        try {
            return compiledFunction.eval();
        } catch (ArityException e) {
            throw new Error("" + e); //never
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

double org.javia.arity.SimpleCodeGen.getValue ( ) [inline, package, inherited]

Definition at line 91 of file SimpleCodeGen.java.

                      {
        compiledFunction.init(0, code.toArray(), consts.toArray(), funcs.toArray());
        try {
            return compiledFunction.eval();
        } catch (ArityException e) {
            throw new Error("" + e); //never
        }
    }

Here is the call graph for this function:

void org.javia.arity.OptCodeGen.push ( Token  token) throws SyntaxException [inline, package, virtual]

Reimplemented from org.javia.arity.SimpleCodeGen.

Definition at line 48 of file OptCodeGen.java.

                                                  {
        byte op;
        switch (token.id) {
        case Lexer.NUMBER:
            op = VM.CONST;
            traceConsts[0] = token.value;
            break;
            
        case Lexer.CONST:
        case Lexer.CALL:
            Symbol symbol = symbols.lookup(token.name, token.arity);
            if (symbol == null) {
                throw exception.set("undefined '" + token.name + "' with arity " + token.arity, token.position); 
            }
            if (symbol.op > 0) { // built-in
                op = symbol.op;
                if (op >= VM.LOAD0 && op <= VM.LOAD4) {
                    int arg = op - VM.LOAD0;
                    if (arg + 1 > intrinsicArity) {
                        intrinsicArity = arg + 1;
                    }
                }
            } else if (symbol.fun != null) { // function call
                op = VM.CALL;
                traceFuncs[0] = symbol.fun;
            } else { // variable reference
                op = VM.CONST;
                traceConsts[0] = symbol.value;
            }
            break;
                        
        default:
            op = token.vmop;
            if (op <= 0) {
                throw new Error("wrong vmop: " + op);
            }
        }
        int oldSP = sp;
        traceCode[0] = op;
        if (op != VM.RND) {
            sp = tracer.execWithoutCheck(stack, sp);
        } else {
            stack[++sp] = Double.NaN;
        }

        //constant folding
        if (!Double.isNaN(stack[sp]) || op == VM.CONST) {
            code.pop(oldSP + 1 - sp);
            consts.pop(oldSP + 1 - sp);
            consts.push(stack[sp]);
            op = VM.CONST;
        } else if (op == VM.CALL) {
            funcs.push(traceFuncs[0]);
        }
        code.push(op);
    }

Here is the call graph for this function:

void org.javia.arity.OptCodeGen.push ( Token  token) throws SyntaxException [inline, package, virtual]

Reimplemented from org.javia.arity.SimpleCodeGen.

Definition at line 48 of file OptCodeGen.java.

                                                  {
        byte op;
        switch (token.id) {
        case Lexer.NUMBER:
            op = VM.CONST;
            traceConsts[0] = token.value;
            break;
            
        case Lexer.CONST:
        case Lexer.CALL:
            Symbol symbol = symbols.lookup(token.name, token.arity);
            if (symbol == null) {
                throw exception.set("undefined '" + token.name + "' with arity " + token.arity, token.position); 
            }
            if (symbol.op > 0) { // built-in
                op = symbol.op;
                if (op >= VM.LOAD0 && op <= VM.LOAD4) {
                    int arg = op - VM.LOAD0;
                    if (arg + 1 > intrinsicArity) {
                        intrinsicArity = arg + 1;
                    }
                }
            } else if (symbol.fun != null) { // function call
                op = VM.CALL;
                traceFuncs[0] = symbol.fun;
            } else { // variable reference
                op = VM.CONST;
                traceConsts[0] = symbol.value;
            }
            break;
                        
        default:
            op = token.vmop;
            if (op <= 0) {
                throw new Error("wrong vmop: " + op);
            }
        }
        int oldSP = sp;
        traceCode[0] = op;
        if (op != VM.RND) {
            sp = tracer.execWithoutCheck(stack, sp);
        } else {
            stack[++sp] = Double.NaN;
        }

        //constant folding
        if (!Double.isNaN(stack[sp]) || op == VM.CONST) {
            code.pop(oldSP + 1 - sp);
            consts.pop(oldSP + 1 - sp);
            consts.push(stack[sp]);
            op = VM.CONST;
        } else if (op == VM.CALL) {
            funcs.push(traceFuncs[0]);
        }
        code.push(op);
    }

Here is the call graph for this function:

SimpleCodeGen org.javia.arity.SimpleCodeGen.setSymbols ( Symbols  symbols) [inline, package, inherited]

Definition at line 42 of file SimpleCodeGen.java.

                                              {
        this.symbols = symbols;
        return this;
    }
SimpleCodeGen org.javia.arity.SimpleCodeGen.setSymbols ( Symbols  symbols) [inline, package, inherited]

Definition at line 42 of file SimpleCodeGen.java.

                                              {
        this.symbols = symbols;
        return this;
    }

Here is the caller graph for this function:

void org.javia.arity.OptCodeGen.start ( ) [inline, package]

Reimplemented from org.javia.arity.SimpleCodeGen.

Definition at line 41 of file OptCodeGen.java.

                 {
        super.start();
        sp = -1;
        intrinsicArity = 0;
    }
void org.javia.arity.OptCodeGen.start ( ) [inline, package]

Reimplemented from org.javia.arity.SimpleCodeGen.

Definition at line 41 of file OptCodeGen.java.

                 {
        super.start();
        sp = -1;
        intrinsicArity = 0;
    }

Member Data Documentation

Definition at line 29 of file SimpleCodeGen.java.

Definition at line 30 of file SimpleCodeGen.java.

Definition at line 36 of file SimpleCodeGen.java.

Definition at line 31 of file SimpleCodeGen.java.

static final SyntaxException org.javia.arity.SimpleCodeGen.HAS_ARGUMENTS = new SyntaxException() [static, package, inherited]

Definition at line 27 of file SimpleCodeGen.java.

Definition at line 34 of file OptCodeGen.java.

int org.javia.arity.OptCodeGen.sp = -1 [package]

Definition at line 27 of file OptCodeGen.java.

Definition at line 26 of file OptCodeGen.java.

Definition at line 34 of file SimpleCodeGen.java.

byte org.javia.arity.OptCodeGen.traceCode = new byte[1] [package]

Definition at line 31 of file OptCodeGen.java.

double org.javia.arity.OptCodeGen.traceConsts = new double[1] [package]

Definition at line 29 of file OptCodeGen.java.

Definition at line 30 of file OptCodeGen.java.

Definition at line 32 of file OptCodeGen.java.


The documentation for this class was generated from the following files: