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