[Bprocessor-commit] bscript/src/net/sourceforge/bprocessor/model/evaluator Environment.java, 1.1,
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-09-13 06:48:32
|
Update of /cvsroot/bprocessor/bscript/src/net/sourceforge/bprocessor/model/evaluator In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv2396/src/net/sourceforge/bprocessor/model/evaluator Modified Files: Environment.java Call.java Log Message: refactoring of scripting Index: Call.java =================================================================== RCS file: /cvsroot/bprocessor/bscript/src/net/sourceforge/bprocessor/model/evaluator/Call.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Call.java 12 Sep 2006 09:27:30 -0000 1.1 --- Call.java 13 Sep 2006 06:48:30 -0000 1.2 *************** *** 8,12 **** package net.sourceforge.bprocessor.model.evaluator; ! import java.util.LinkedList; import java.util.List; import java.util.Stack; --- 8,13 ---- package net.sourceforge.bprocessor.model.evaluator; ! import java.util.ArrayList; ! import java.util.HashMap; import java.util.List; import java.util.Stack; *************** *** 34,46 **** */ public void evaluate(Environment env, Stack stack) { ! List arguments = new LinkedList(); ! Object current = stack.pop(); ! while (current != Function.mark) { ! arguments.add(current); ! current = stack.pop(); } ! Invokable function = env.lookupFunction(name); if (function != null) { ! Object result = function.evaluate(env.copy(arguments)); stack.push(result); } else { --- 35,53 ---- */ public void evaluate(Environment env, Stack stack) { ! int length = stack.search(Function.mark) - 1; ! List arguments = new ArrayList(length); ! for (int i = 0; i < length; i++) { ! arguments.add(null); } ! while (length > 0) { ! Object current = stack.pop(); ! arguments.set(length - 1, current); ! length--; ! } ! stack.pop(); ! Invokable function = (Invokable) env.lookupGlobal(name); if (function != null) { ! Environment activation = new Environment(env, new HashMap(), arguments); ! Object result = function.evaluate(activation); stack.push(result); } else { Index: Environment.java =================================================================== RCS file: /cvsroot/bprocessor/bscript/src/net/sourceforge/bprocessor/model/evaluator/Environment.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Environment.java 12 Sep 2006 09:27:30 -0000 1.1 --- Environment.java 13 Sep 2006 06:48:30 -0000 1.2 *************** *** 17,54 **** */ public class Environment { ! /** Functions */ ! private HashMap functions; /** Globals */ ! private HashMap globals; /** Locals */ ! private List locals; /** * Constructor */ ! public Environment(HashMap functions, HashMap globals, List locals) { super(); ! this.functions = functions; ! this.globals = globals; ! this.locals = locals; } /** ! * Return a copy with locals replaced ! * @param locals List ! * @return Environment */ ! public Environment copy(List locals) { ! return new Environment(functions, globals, locals); } /** ! * @param name String ! * @return Function */ ! public Invokable lookupFunction(String name) { ! return (Invokable) functions.get(name); } --- 17,59 ---- */ public class Environment { ! ! /** Lexical link */ ! private Environment origin; /** Globals */ ! private HashMap variables; /** Locals */ ! private List indexables; /** * Constructor */ ! public Environment(HashMap variables, List indexables) { super(); ! this.variables = variables; ! this.indexables = indexables; } /** ! * ! * @param origin Environment ! * @param variables HashMap ! * @param indexables List */ ! public Environment(Environment origin, HashMap variables, List indexables) { ! super(); ! this.variables = variables; ! this.indexables = indexables; ! this.origin = origin; } /** ! * Return a copy with locals replaced ! * @param locals List ! * @return Environment */ ! public Environment copy(List locals) { ! return new Environment(variables, locals); } *************** *** 58,62 **** */ public Object lookupGlobal(String name) { ! Object value = globals.get(name); if (value == null) { Space active = Project.getInstance().getActiveSpace(); --- 63,72 ---- */ public Object lookupGlobal(String name) { ! Object value = variables.get(name); ! if (value == null) { ! if (origin != null) { ! value = origin.lookupGlobal(name); ! } ! } if (value == null) { Space active = Project.getInstance().getActiveSpace(); *************** *** 76,80 **** */ public Object get(int i) { ! return locals.get(i); } } --- 86,90 ---- */ public Object get(int i) { ! return indexables.get(i); } } |