diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2016-06-28 21:09:43 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2016-07-26 19:47:12 +0300 |
| commit | 8f84c00978dc05007873a9fe1de6a18511dc3cf8 (patch) | |
| tree | 39fead540e22addee40b95b68db08cbea620745b /main/core/runtime/State.java | |
| parent | 48dcd488054024d98fe1e659a4029630130d1d35 (diff) | |
Restructure project for use with maven
Diffstat (limited to 'main/core/runtime/State.java')
| -rw-r--r-- | main/core/runtime/State.java | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/main/core/runtime/State.java b/main/core/runtime/State.java deleted file mode 100644 index 8563a77..0000000 --- a/main/core/runtime/State.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.jantuomi.interpreter.main.core.runtime; - -import com.jantuomi.interpreter.main.core.parser.datatype.DataContainer; -import com.jantuomi.interpreter.main.core.runtime.builtins.BuiltinManager; -import com.jantuomi.interpreter.main.exception.InterpreterException; - -import java.util.Arrays; -import java.util.List; -import java.util.Stack; - -/** - * Created by jan on 11.6.2016. - */ -public class State { - private static final State instance = new State(); - - public static State getInstance() { - return instance; - } - - private Stack<Scope> scopes = new Stack<>(); - - private State() { - /* Push global scope onto the stack */ - Scope globalScope = new Scope(); - - for (Function builtin : BuiltinManager.getInstance().getBuiltins()) { - globalScope.addFunction(builtin.getName(), builtin); - } - - scopes.push(globalScope); - - } - - private DataContainer resolveSymbol(String symbol) throws InterpreterException { - return scopes.peek().resolveSymbol(symbol, Arrays.asList()); - } - - public DataContainer getSymbolValue(String symbol) throws InterpreterException { - DataContainer d = resolveSymbol(symbol); - return d; - } - - public DataContainer getSymbolValue(String symbol, List<DataContainer> parameters) throws InterpreterException { - return scopes.peek().resolveSymbol(symbol, parameters); - } - - public Scope createScope() { - Scope scope = new Scope(); - if (scopes.size() > 0) { - scope.setParent(scopes.peek()); - } else { - scope.setParent(null); - } - scopes.push(scope); - return scope; - } - - public void addSymbolToScope(String symbol) { - scopes.peek().addVariable(symbol); - } - - public void addFunctionToScope(String symbol, Function func) { - scopes.peek().addFunction(symbol, func); - } - - public void setSymbolValueToScope(String symbol, DataContainer value) { - scopes.peek().setVariableValue(symbol, value); - } - - public Scope popScope() { - return scopes.pop(); - } -} |
