Static import of 'eval'

This commit is contained in:
Mike Cifelli 2017-02-21 13:59:56 -05:00
parent 0c3d3ae024
commit 013707e11a
9 changed files with 28 additions and 19 deletions

View File

@ -1,8 +1,9 @@
package function; package function;
import static function.builtin.EVAL.eval;
import java.util.ArrayList; import java.util.ArrayList;
import function.builtin.EVAL;
import sexpression.*; import sexpression.*;
import table.*; import table.*;
@ -40,7 +41,7 @@ public class UserDefinedFunction extends LispFunction {
SExpression lastEvaluation = Nil.getInstance(); SExpression lastEvaluation = Nil.getInstance();
for (Cons expression = body; expression.consp(); expression = (Cons) expression.getCdr()) for (Cons expression = body; expression.consp(); expression = (Cons) expression.getCdr())
lastEvaluation = EVAL.eval(expression.getCar()); lastEvaluation = eval(expression.getCar());
executionContext.setScope(callingScope); executionContext.setScope(callingScope);
releaseParameterValues(); releaseParameterValues();

View File

@ -1,5 +1,7 @@
package function.builtin; package function.builtin;
import static function.builtin.EVAL.eval;
import java.io.*; import java.io.*;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -59,7 +61,7 @@ public class LOAD extends LispFunction {
private boolean isSuccessfulEvaluation(LispParser parser) { private boolean isSuccessfulEvaluation(LispParser parser) {
while (!parser.isEof()) { while (!parser.isEof()) {
try { try {
EVAL.eval(parser.getNextSExpression()); eval(parser.getNextSExpression());
} catch (LispException e) { } catch (LispException e) {
errorManager.handle(e); errorManager.handle(e);
return false; return false;

View File

@ -1,7 +1,8 @@
package function.builtin.special; package function.builtin.special;
import static function.builtin.EVAL.eval;
import function.*; import function.*;
import function.builtin.EVAL;
import sexpression.*; import sexpression.*;
public class AND extends LispFunction { public class AND extends LispFunction {
@ -19,7 +20,7 @@ public class AND extends LispFunction {
} }
private SExpression callTailRecursive(Cons argumentList, SExpression lastValue) { private SExpression callTailRecursive(Cons argumentList, SExpression lastValue) {
SExpression currentValue = EVAL.eval(argumentList.getCar()); SExpression currentValue = eval(argumentList.getCar());
Cons remainingValues = (Cons) argumentList.getCdr(); Cons remainingValues = (Cons) argumentList.getCdr();
if (argumentList.nullp()) if (argumentList.nullp())

View File

@ -1,7 +1,8 @@
package function.builtin.special; package function.builtin.special;
import static function.builtin.EVAL.eval;
import function.*; import function.*;
import function.builtin.EVAL;
import sexpression.*; import sexpression.*;
public class COND extends LispFunction { public class COND extends LispFunction {
@ -26,7 +27,7 @@ public class COND extends LispFunction {
Cons clause = (Cons) argumentList.getCar(); Cons clause = (Cons) argumentList.getCar();
Cons remainingClauses = (Cons) argumentList.getCdr(); Cons remainingClauses = (Cons) argumentList.getCdr();
SExpression test = EVAL.eval(clause.getCar()); SExpression test = eval(clause.getCar());
if (isTestSuccessful(test)) if (isTestSuccessful(test))
return evaluateResult(clause, test); return evaluateResult(clause, test);
@ -42,7 +43,7 @@ public class COND extends LispFunction {
SExpression lastResultValue = test; SExpression lastResultValue = test;
for (SExpression result = clause.getCdr(); result.consp(); result = advanceCons(result)) for (SExpression result = clause.getCdr(); result.consp(); result = advanceCons(result))
lastResultValue = EVAL.eval(getCar(result)); lastResultValue = eval(getCar(result));
return lastResultValue; return lastResultValue;
} }

View File

@ -1,7 +1,8 @@
package function.builtin.special; package function.builtin.special;
import static function.builtin.EVAL.eval;
import function.*; import function.*;
import function.builtin.EVAL;
import sexpression.*; import sexpression.*;
import table.*; import table.*;
@ -65,14 +66,14 @@ public class LET extends LispFunction {
SExpression symbol = symbolValuePair.getCar(); SExpression symbol = symbolValuePair.getCar();
SExpression value = restOfPair.getCar(); SExpression value = restOfPair.getCar();
scope.put(symbol.toString(), EVAL.eval(value)); scope.put(symbol.toString(), eval(value));
} }
private SExpression evaluateBody(Cons body) { private SExpression evaluateBody(Cons body) {
SExpression lastEvaluation = Nil.getInstance(); SExpression lastEvaluation = Nil.getInstance();
for (; body.consp(); body = (Cons) body.getCdr()) for (; body.consp(); body = (Cons) body.getCdr())
lastEvaluation = EVAL.eval(body.getCar()); lastEvaluation = eval(body.getCar());
return lastEvaluation; return lastEvaluation;
} }

View File

@ -1,7 +1,8 @@
package function.builtin.special; package function.builtin.special;
import static function.builtin.EVAL.eval;
import function.*; import function.*;
import function.builtin.EVAL;
import sexpression.*; import sexpression.*;
public class OR extends LispFunction { public class OR extends LispFunction {
@ -19,7 +20,7 @@ public class OR extends LispFunction {
} }
private SExpression callTailRecursive(Cons argumentList) { private SExpression callTailRecursive(Cons argumentList) {
SExpression currentValue = EVAL.eval(argumentList.getCar()); SExpression currentValue = eval(argumentList.getCar());
Cons remainingValues = (Cons) argumentList.getCdr(); Cons remainingValues = (Cons) argumentList.getCdr();
if (remainingValues.nullp() || !currentValue.nullp()) if (remainingValues.nullp() || !currentValue.nullp())

View File

@ -1,7 +1,8 @@
package function.builtin.special; package function.builtin.special;
import static function.builtin.EVAL.eval;
import function.*; import function.*;
import function.builtin.EVAL;
import sexpression.*; import sexpression.*;
import table.*; import table.*;
@ -22,7 +23,7 @@ public class SETF extends LispFunction {
Cons cdr = (Cons) argumentList.getCdr(); Cons cdr = (Cons) argumentList.getCdr();
SExpression symbol = argumentList.getCar(); SExpression symbol = argumentList.getCar();
SExpression value = EVAL.eval(cdr.getCar()); SExpression value = eval(cdr.getCar());
SymbolTable table = findScopeOfSymbol(symbol); SymbolTable table = findScopeOfSymbol(symbol);
table.put(symbol.toString(), value); table.put(symbol.toString(), value);

View File

@ -1,8 +1,9 @@
package interpreter; package interpreter;
import static function.builtin.EVAL.eval;
import environment.RuntimeEnvironment; import environment.RuntimeEnvironment;
import error.*; import error.*;
import function.builtin.EVAL;
import parser.LispParser; import parser.LispParser;
import sexpression.SExpression; import sexpression.SExpression;
@ -42,7 +43,7 @@ public class LispInterpreter {
private void printValueOfNextSExpressionWithException() { private void printValueOfNextSExpressionWithException() {
SExpression sExpression = parser.getNextSExpression(); SExpression sExpression = parser.getNextSExpression();
String result = environment.decorateValueOutput(String.valueOf(EVAL.eval(sExpression))); String result = environment.decorateValueOutput(String.valueOf(eval(sExpression)));
erasePrompt(); erasePrompt();
environment.getOutput().println(result); environment.getOutput().println(result);

View File

@ -1,10 +1,10 @@
package testutil; package testutil;
import static function.builtin.EVAL.eval;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.io.*; import java.io.*;
import function.builtin.EVAL;
import parser.LispParser; import parser.LispParser;
import sexpression.SExpression; import sexpression.SExpression;
@ -24,7 +24,7 @@ public final class TestUtilities {
} }
public static SExpression evaluateString(String input) { public static SExpression evaluateString(String input) {
return EVAL.eval(parseString(input)); return eval(parseString(input));
} }
public static SExpression parseString(String input) { public static SExpression parseString(String input) {