Load lisp language files automatically
This commit is contained in:
parent
3ef8712f2f
commit
568fce3c11
|
@ -1,8 +1,10 @@
|
||||||
|
|TranscendentalLisp.FinanceUnitTests||10:16:07 Sun, Jan 21, 2018|
|
||||||
|
|TranscendentalLisp.SetUp||10:15:35 Sun, Jan 21, 2018|
|
||||||
|
|TranscendentalLisp.SuiteSetUp||10:12:22 Sun, Jan 21, 2018|
|
||||||
|TranscendentalLisp.Recursion||15:06:26 Sun, Nov 26, 2017|
|
|TranscendentalLisp.Recursion||15:06:26 Sun, Nov 26, 2017|
|
||||||
|TranscendentalLisp||16:15:14 Fri, Mar 17, 2017|
|
|TranscendentalLisp||16:15:14 Fri, Mar 17, 2017|
|
||||||
|TranscendentalLisp.Macros||10:10:15 Mon, Mar 13, 2017|
|
|TranscendentalLisp.Macros||10:10:15 Mon, Mar 13, 2017|
|
||||||
|TranscendentalLisp.MacroTests||10:07:00 Mon, Mar 13, 2017|
|
|TranscendentalLisp.MacroTests||10:07:00 Mon, Mar 13, 2017|
|
||||||
|TranscendentalLisp.FinanceUnitTests||11:07:42 Thu, Mar 09, 2017|
|
|
||||||
|TranscendentalLisp.LangUnitTests||11:04:17 Thu, Mar 09, 2017|
|
|TranscendentalLisp.LangUnitTests||11:04:17 Thu, Mar 09, 2017|
|
||||||
|TranscendentalLisp.LexicalClosures||16:39:59 Tue, Mar 07, 2017|
|
|TranscendentalLisp.LexicalClosures||16:39:59 Tue, Mar 07, 2017|
|
||||||
|FrontPage||10:19:45 Tue, Mar 07, 2017|
|
|FrontPage||10:19:45 Tue, Mar 07, 2017|
|
||||||
|
|
|
@ -4,11 +4,11 @@ Test
|
||||||
Unit tests for the interest-compounder class.
|
Unit tests for the interest-compounder class.
|
||||||
|
|
||||||
| script | lisp interpreter fixture |
|
| script | lisp interpreter fixture |
|
||||||
| clear functions and symbols |
|
| refresh interpreter |
|
||||||
| check | evaluate file | lisp/finance/interest-compounder-test.lisp | =~/\nT$/ |
|
| check | evaluate file | lisp/finance/interest-compounder-test.lisp | =~/\nT$/ |
|
||||||
|
|
||||||
Unit tests for the compound-interest function.
|
Unit tests for the compound-interest function.
|
||||||
|
|
||||||
| script | lisp interpreter fixture |
|
| script | lisp interpreter fixture |
|
||||||
| clear functions and symbols |
|
| refresh interpreter |
|
||||||
| check | evaluate file | lisp/finance/compound-interest-test.lisp | =~/\nT$/ |
|
| check | evaluate file | lisp/finance/compound-interest-test.lisp | =~/\nT$/ |
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
Test
|
Test
|
||||||
---
|
---
|
||||||
| script | lisp interpreter fixture |
|
| script | lisp interpreter fixture |
|
||||||
| clear functions and symbols |
|
| refresh interpreter |
|
||||||
|
|
|
@ -3,6 +3,3 @@ Test
|
||||||
---
|
---
|
||||||
| import |
|
| import |
|
||||||
| acceptance.fixture |
|
| acceptance.fixture |
|
||||||
|
|
||||||
| script | lisp interpreter fixture |
|
|
||||||
| build interpreter |
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
(load "../lang/dlambda.lisp")
|
|
||||||
|
|
||||||
(let ((static))
|
(let ((static))
|
||||||
|
|
||||||
(setq static
|
(setq static
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
(load "../unit/unit-tester.lisp")
|
(load "../unit/unit-tester.lisp")
|
||||||
(load "dlambda.lisp")
|
|
||||||
|
|
||||||
(setq assertions (unit-tester-assertions))
|
(setq assertions (unit-tester-assertions))
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
(load "functions.lisp")
|
|
||||||
|
|
||||||
;; This is based on the dlambda macro presented in "Let Over Lambda" by Doug Hoyte.
|
;; This is based on the dlambda macro presented in "Let Over Lambda" by Doug Hoyte.
|
||||||
|
|
||||||
(defmacro dlambda (&rest methods)
|
(defmacro dlambda (&rest methods)
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
(load "../lang/dlambda.lisp")
|
|
||||||
|
|
||||||
(defun counter (initial-count)
|
(defun counter (initial-count)
|
||||||
(let ((count initial-count))
|
(let ((count initial-count))
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
(load "../lang/dlambda.lisp")
|
|
||||||
|
|
||||||
(defun counter (initial-count)
|
(defun counter (initial-count)
|
||||||
(let ((this) (name)
|
(let ((this) (name)
|
||||||
(count initial-count))
|
(count initial-count))
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
(load "../lang/dlambda.lisp")
|
|
||||||
(load "../lang/functions.lisp")
|
|
||||||
|
|
||||||
(defmacro keys (&rest fields)
|
(defmacro keys (&rest fields)
|
||||||
`(let ,(mapcar 'list fields)
|
`(let ,(mapcar 'list fields)
|
||||||
(dlambda
|
(dlambda
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
(load "../lang/dlambda.lisp")
|
|
||||||
|
|
||||||
(let ((private-static) (public-static))
|
(let ((private-static) (public-static))
|
||||||
|
|
||||||
(defun unit-tester-assertions ()
|
(defun unit-tester-assertions ()
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
(load "../lang/functions.lisp")
|
|
||||||
|
|
||||||
(defun list-doubler (seed times-to-double)
|
(defun list-doubler (seed times-to-double)
|
||||||
(if (< times-to-double 1) seed
|
(if (< times-to-double 1) seed
|
||||||
(recur (append seed seed) (- times-to-double 1))))
|
(recur (append seed seed) (- times-to-double 1))))
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -12,6 +12,12 @@
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
<testSourceDirectory>test</testSourceDirectory>
|
<testSourceDirectory>test</testSourceDirectory>
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>lisp/lang</directory>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
<testResources>
|
<testResources>
|
||||||
<testResource>
|
<testResource>
|
||||||
|
|
|
@ -2,6 +2,9 @@ package interpreter;
|
||||||
|
|
||||||
import static function.builtin.EVAL.eval;
|
import static function.builtin.EVAL.eval;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import environment.RuntimeEnvironment;
|
import environment.RuntimeEnvironment;
|
||||||
import error.LispException;
|
import error.LispException;
|
||||||
import parser.LispParser;
|
import parser.LispParser;
|
||||||
|
@ -16,6 +19,15 @@ public class LispInterpreter {
|
||||||
this.environment = RuntimeEnvironment.getInstance();
|
this.environment = RuntimeEnvironment.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void interpretLanguageFiles(List<LanguageFile> languageFiles) {
|
||||||
|
for (LanguageFile file : languageFiles) {
|
||||||
|
LispParser languageParser = new LispParser(file.getInputStream(), file.getName());
|
||||||
|
|
||||||
|
while (!languageParser.isEof())
|
||||||
|
eval(languageParser.getNextSExpression());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void interpret() {
|
public void interpret() {
|
||||||
createParser();
|
createParser();
|
||||||
|
|
||||||
|
@ -60,4 +72,23 @@ public class LispInterpreter {
|
||||||
environment.getOutput().flush();
|
environment.getOutput().flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class LanguageFile {
|
||||||
|
|
||||||
|
private InputStream inputStream;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public LanguageFile(InputStream inputStream, String name) {
|
||||||
|
this.inputStream = inputStream;
|
||||||
|
this.name = "lang:" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream getInputStream() {
|
||||||
|
return inputStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ public interface LispInterpreterBuilder {
|
||||||
|
|
||||||
void useFile(String fileName);
|
void useFile(String fileName);
|
||||||
|
|
||||||
|
void setLanguageFileNames(String... languageFiles);
|
||||||
|
|
||||||
void setPromptDecorator(Function<String, String> decorator);
|
void setPromptDecorator(Function<String, String> decorator);
|
||||||
|
|
||||||
void setValueOutputDecorator(Function<String, String> decorator);
|
void setValueOutputDecorator(Function<String, String> decorator);
|
||||||
|
|
|
@ -6,11 +6,14 @@ import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import environment.RuntimeEnvironment;
|
import environment.RuntimeEnvironment;
|
||||||
import error.CriticalLispException;
|
import error.CriticalLispException;
|
||||||
import error.ErrorManager;
|
import error.ErrorManager;
|
||||||
|
import interpreter.LispInterpreter.LanguageFile;
|
||||||
|
|
||||||
public class LispInterpreterBuilderImpl implements LispInterpreterBuilder {
|
public class LispInterpreterBuilderImpl implements LispInterpreterBuilder {
|
||||||
|
|
||||||
|
@ -26,6 +29,7 @@ public class LispInterpreterBuilderImpl implements LispInterpreterBuilder {
|
||||||
private PrintStream errorOutputStream;
|
private PrintStream errorOutputStream;
|
||||||
private Runnable terminationFunction;
|
private Runnable terminationFunction;
|
||||||
private Runnable errorTerminationFunction;
|
private Runnable errorTerminationFunction;
|
||||||
|
private List<LanguageFile> languageFiles;
|
||||||
private Function<String, String> promptDecorator;
|
private Function<String, String> promptDecorator;
|
||||||
private Function<String, String> valueOutputDecorator;
|
private Function<String, String> valueOutputDecorator;
|
||||||
private Function<String, String> warningOutputDecorator;
|
private Function<String, String> warningOutputDecorator;
|
||||||
|
@ -42,6 +46,7 @@ public class LispInterpreterBuilderImpl implements LispInterpreterBuilder {
|
||||||
this.isInteractive = true;
|
this.isInteractive = true;
|
||||||
this.isFileBased = false;
|
this.isFileBased = false;
|
||||||
this.isBuilt = false;
|
this.isBuilt = false;
|
||||||
|
this.languageFiles = new ArrayList<>();
|
||||||
this.promptDecorator = s -> s;
|
this.promptDecorator = s -> s;
|
||||||
this.valueOutputDecorator = s -> s;
|
this.valueOutputDecorator = s -> s;
|
||||||
this.warningOutputDecorator = s -> s;
|
this.warningOutputDecorator = s -> s;
|
||||||
|
@ -88,6 +93,15 @@ public class LispInterpreterBuilderImpl implements LispInterpreterBuilder {
|
||||||
this.setNotInteractive();
|
this.setNotInteractive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLanguageFileNames(String... languageFileNames) {
|
||||||
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
|
languageFiles = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String fileName : languageFileNames)
|
||||||
|
languageFiles.add(new LanguageFile(classLoader.getResourceAsStream(fileName), fileName));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPromptDecorator(Function<String, String> decorator) {
|
public void setPromptDecorator(Function<String, String> decorator) {
|
||||||
this.promptDecorator = decorator;
|
this.promptDecorator = decorator;
|
||||||
|
@ -126,6 +140,7 @@ public class LispInterpreterBuilderImpl implements LispInterpreterBuilder {
|
||||||
private LispInterpreter buildInterpreter() {
|
private LispInterpreter buildInterpreter() {
|
||||||
configureRuntimeEnvironment();
|
configureRuntimeEnvironment();
|
||||||
LispInterpreter lispInterpreter = createInterpreter();
|
LispInterpreter lispInterpreter = createInterpreter();
|
||||||
|
lispInterpreter.interpretLanguageFiles(languageFiles);
|
||||||
isBuilt = true;
|
isBuilt = true;
|
||||||
|
|
||||||
return lispInterpreter;
|
return lispInterpreter;
|
||||||
|
|
|
@ -31,6 +31,8 @@ public class LispMain {
|
||||||
public static final String ANSI_YELLOW = "\u001B[33m";
|
public static final String ANSI_YELLOW = "\u001B[33m";
|
||||||
public static final String ANSI_PURPLE = "\u001B[35m";
|
public static final String ANSI_PURPLE = "\u001B[35m";
|
||||||
|
|
||||||
|
public static final String[] LANGUAGE_FILE_NAMES = new String[] { "functions.lisp", "dlambda.lisp" };
|
||||||
|
|
||||||
public static void main(String[] arguments) {
|
public static void main(String[] arguments) {
|
||||||
LispMain lispMain = new LispMain();
|
LispMain lispMain = new LispMain();
|
||||||
|
|
||||||
|
@ -106,6 +108,7 @@ public class LispMain {
|
||||||
builder.setErrorOutput(output);
|
builder.setErrorOutput(output);
|
||||||
builder.setTerminationFunction(this::shutdownTerminal);
|
builder.setTerminationFunction(this::shutdownTerminal);
|
||||||
builder.setErrorTerminationFunction(this::shutdownTerminal);
|
builder.setErrorTerminationFunction(this::shutdownTerminal);
|
||||||
|
builder.setLanguageFileNames(LANGUAGE_FILE_NAMES);
|
||||||
builder.setPromptDecorator(s -> s + END_OF_SEGMENT);
|
builder.setPromptDecorator(s -> s + END_OF_SEGMENT);
|
||||||
builder.setValueOutputDecorator(makeColorDecorator(ANSI_GREEN));
|
builder.setValueOutputDecorator(makeColorDecorator(ANSI_GREEN));
|
||||||
builder.setWarningOutputDecorator(makeColorDecorator(ANSI_YELLOW));
|
builder.setWarningOutputDecorator(makeColorDecorator(ANSI_YELLOW));
|
||||||
|
@ -141,6 +144,7 @@ public class LispMain {
|
||||||
builder.setErrorOutput(System.err);
|
builder.setErrorOutput(System.err);
|
||||||
builder.setTerminationFunction(() -> System.exit(0));
|
builder.setTerminationFunction(() -> System.exit(0));
|
||||||
builder.setErrorTerminationFunction(() -> System.exit(1));
|
builder.setErrorTerminationFunction(() -> System.exit(1));
|
||||||
|
builder.setLanguageFileNames(LANGUAGE_FILE_NAMES);
|
||||||
builder.setValueOutputDecorator(makeColorDecorator(ANSI_GREEN));
|
builder.setValueOutputDecorator(makeColorDecorator(ANSI_GREEN));
|
||||||
builder.setWarningOutputDecorator(makeColorDecorator(ANSI_YELLOW));
|
builder.setWarningOutputDecorator(makeColorDecorator(ANSI_YELLOW));
|
||||||
builder.setErrorOutputDecorator(makeColorDecorator(ANSI_RED));
|
builder.setErrorOutputDecorator(makeColorDecorator(ANSI_RED));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package acceptance.fixture;
|
package acceptance.fixture;
|
||||||
|
|
||||||
|
import static main.LispMain.LANGUAGE_FILE_NAMES;
|
||||||
import static table.FunctionTable.resetFunctionTable;
|
import static table.FunctionTable.resetFunctionTable;
|
||||||
import static util.Path.getPathPrefix;
|
import static util.Path.getPathPrefix;
|
||||||
|
|
||||||
|
@ -22,11 +23,23 @@ public class LispInterpreterFixture {
|
||||||
private static RuntimeEnvironment environment = RuntimeEnvironment.getInstance();
|
private static RuntimeEnvironment environment = RuntimeEnvironment.getInstance();
|
||||||
private static LispInterpreter interpreter = null;
|
private static LispInterpreter interpreter = null;
|
||||||
|
|
||||||
|
public static void refreshInterpreter() {
|
||||||
|
cleanUp();
|
||||||
|
buildInterpreter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void cleanUp() {
|
||||||
|
resetFunctionTable();
|
||||||
|
executionContext.clearContext();
|
||||||
|
environment.reset();
|
||||||
|
}
|
||||||
|
|
||||||
public static void buildInterpreter() {
|
public static void buildInterpreter() {
|
||||||
LispInterpreterBuilder builder = new LispInterpreterBuilderImpl() {};
|
LispInterpreterBuilder builder = new LispInterpreterBuilderImpl() {};
|
||||||
builder.setOutput(new PrintStream(outputStream));
|
builder.setOutput(new PrintStream(outputStream));
|
||||||
builder.setErrorOutput(new PrintStream(outputStream));
|
builder.setErrorOutput(new PrintStream(outputStream));
|
||||||
builder.setNotInteractive();
|
builder.setNotInteractive();
|
||||||
|
builder.setLanguageFileNames(LANGUAGE_FILE_NAMES);
|
||||||
builder.setTerminationFunction(LispInterpreterFixture::terminate);
|
builder.setTerminationFunction(LispInterpreterFixture::terminate);
|
||||||
builder.setErrorTerminationFunction(LispInterpreterFixture::terminateFromError);
|
builder.setErrorTerminationFunction(LispInterpreterFixture::terminateFromError);
|
||||||
|
|
||||||
|
@ -39,16 +52,6 @@ public class LispInterpreterFixture {
|
||||||
throw new RuntimeException("Error Termination");
|
throw new RuntimeException("Error Termination");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanUp() {
|
|
||||||
clearFunctionsAndSymbols();
|
|
||||||
environment.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clearFunctionsAndSymbols() {
|
|
||||||
resetFunctionTable();
|
|
||||||
executionContext.clearContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String evaluateText(String input) {
|
public String evaluateText(String input) {
|
||||||
environment.setInputName("fitnesse");
|
environment.setInputName("fitnesse");
|
||||||
environment.setInput(new ByteArrayInputStream(input.getBytes()));
|
environment.setInput(new ByteArrayInputStream(input.getBytes()));
|
||||||
|
|
|
@ -12,8 +12,6 @@ import java.io.PipedInputStream;
|
||||||
import java.io.PipedOutputStream;
|
import java.io.PipedOutputStream;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.contrib.java.lang.system.ExpectedSystemExit;
|
import org.junit.contrib.java.lang.system.ExpectedSystemExit;
|
||||||
|
@ -26,8 +24,9 @@ import environment.RuntimeEnvironment;
|
||||||
import interpreter.LispInterpreterBuilderImpl;
|
import interpreter.LispInterpreterBuilderImpl;
|
||||||
import terminal.TerminalConfiguration;
|
import terminal.TerminalConfiguration;
|
||||||
import terminal.VirtualTerminalInteractor;
|
import terminal.VirtualTerminalInteractor;
|
||||||
|
import testutil.SymbolAndFunctionCleaner;
|
||||||
|
|
||||||
public class MainTest {
|
public class MainTest extends SymbolAndFunctionCleaner {
|
||||||
|
|
||||||
private RuntimeEnvironment environment;
|
private RuntimeEnvironment environment;
|
||||||
private CountDownLatch latch;
|
private CountDownLatch latch;
|
||||||
|
@ -89,13 +88,13 @@ public class MainTest {
|
||||||
@Rule
|
@Rule
|
||||||
public SystemOutRule systemOutRule = new SystemOutRule().enableLog().mute();
|
public SystemOutRule systemOutRule = new SystemOutRule().enableLog().mute();
|
||||||
|
|
||||||
@Before
|
@Override
|
||||||
public void setUp() {
|
public void additionalSetUp() {
|
||||||
environment.reset();
|
environment.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@Override
|
||||||
public void tearDown() {
|
public void additionalTearDown() {
|
||||||
environment.reset();
|
environment.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue