Back to index

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

List of all members.

Package Functions

 SimpleCodeGen (SyntaxException exception)
SimpleCodeGen setSymbols (Symbols symbols)
void start ()
void push (Token token) throws SyntaxException
double getValue ()
 SimpleCodeGen (SyntaxException exception)
SimpleCodeGen setSymbols (Symbols symbols)
void start ()
void push (Token token) throws SyntaxException
double getValue ()

Package Attributes

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()

Private Attributes

CompiledFunction compiledFunction = new CompiledFunction()

Detailed Description

Definition at line 25 of file SimpleCodeGen.java.


Constructor & Destructor Documentation

Definition at line 38 of file SimpleCodeGen.java.

                                             {
        this.exception = exception;
    }

Definition at line 38 of file SimpleCodeGen.java.

                                             {
        this.exception = exception;
    }

Member Function Documentation

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

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]

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.SimpleCodeGen.push ( Token  token) throws SyntaxException [inline, package, virtual]

Implements org.javia.arity.TokenConsumer.

Reimplemented in org.javia.arity.OptCodeGen, and org.javia.arity.OptCodeGen.

Definition at line 54 of file SimpleCodeGen.java.

                                                  {
        byte op;
        switch (token.id) {
        case Lexer.NUMBER:
            op = VM.CONST;
            consts.push(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) {
                    throw HAS_ARGUMENTS.set("eval() on implicit function", exception.position);
                }
            } else if (symbol.fun != null) { // function call
                op = VM.CALL;
                funcs.push(symbol.fun);
            } else { // variable reference
                op = VM.CONST;
                consts.push(symbol.value);
            }
            break;
                        
        default:
            op = token.vmop;
            if (op <= 0) {
                throw new Error("wrong vmop: " + op);
            }
        }
        code.push(op);
    }

Here is the call graph for this function:

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

Implements org.javia.arity.TokenConsumer.

Reimplemented in org.javia.arity.OptCodeGen, and org.javia.arity.OptCodeGen.

Definition at line 54 of file SimpleCodeGen.java.

                                                  {
        byte op;
        switch (token.id) {
        case Lexer.NUMBER:
            op = VM.CONST;
            consts.push(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) {
                    throw HAS_ARGUMENTS.set("eval() on implicit function", exception.position);
                }
            } else if (symbol.fun != null) { // function call
                op = VM.CALL;
                funcs.push(symbol.fun);
            } else { // variable reference
                op = VM.CONST;
                consts.push(symbol.value);
            }
            break;
                        
        default:
            op = token.vmop;
            if (op <= 0) {
                throw new Error("wrong vmop: " + op);
            }
        }
        code.push(op);
    }

Here is the call graph for this function:

Definition at line 42 of file SimpleCodeGen.java.

                                              {
        this.symbols = symbols;
        return this;
    }

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.SimpleCodeGen.start ( ) [inline, package]

Reimplemented from org.javia.arity.TokenConsumer.

Reimplemented in org.javia.arity.OptCodeGen, and org.javia.arity.OptCodeGen.

Definition at line 48 of file SimpleCodeGen.java.

                 {
        code.clear();
        consts.clear();
        funcs.clear();
    }

Here is the call graph for this function:

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

Reimplemented from org.javia.arity.TokenConsumer.

Reimplemented in org.javia.arity.OptCodeGen, and org.javia.arity.OptCodeGen.

Definition at line 48 of file SimpleCodeGen.java.

                 {
        code.clear();
        consts.clear();
        funcs.clear();
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 29 of file SimpleCodeGen.java.

Definition at line 26 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.

Definition at line 27 of file SimpleCodeGen.java.

Definition at line 34 of file SimpleCodeGen.java.


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