Merge branch 'idea-kotlin' into 'master'

Convert to intellij and kotlin

See merge request mike-cifelli/transcendental-lisp!1
This commit is contained in:
Mike Cifelli 2018-03-20 00:21:21 +00:00
commit 04a4164c1b
274 changed files with 2455 additions and 2608 deletions

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="test">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="lisp/lang">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

5
.gitignore vendored
View File

@ -1,7 +1,12 @@
.idea/**/libraries
.idea/**/tasks.xml
.idea/**/workspace.xml
.idea/dictionaries
fitnesse/FitNesseRoot/files
fitnesse/FitNesseRoot/FitNesse/UserGuide/
fitnesse/fitnesse-results
target/
*.iml
*.swp
*.zip
dependency-reduced-pom.xml

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ClojureProjectResolveSettings">
<currentScheme>IDE</currentScheme>
</component>
</project>

View File

@ -0,0 +1,92 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JavaCodeStyleSettings>
<option name="DO_NOT_WRAP_AFTER_SINGLE_ANNOTATION" value="true" />
<option name="ANNOTATION_PARAMETER_WRAP" value="5" />
<option name="ALIGN_MULTILINE_ANNOTATION_PARAMETERS" value="true" />
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<emptyLine />
<package name="" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="true" />
</value>
</option>
</JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value />
</option>
<option name="ALIGN_IN_COLUMNS_CASE_BRANCH" value="true" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
<option name="IMPORT_NESTED_CLASSES" value="true" />
<option name="CONTINUATION_INDENT_FOR_EXPRESSION_BODIES" value="false" />
<option name="CONTINUATION_INDENT_FOR_CHAINED_CALLS" value="false" />
<option name="WRAP_EXPRESSION_BODY_FUNCTIONS" value="1" />
</JetCodeStyleSettings>
<XML>
<option name="XML_ATTRIBUTE_WRAP" value="4" />
<option name="XML_KEEP_BLANK_LINES" value="1" />
<option name="XML_SPACE_INSIDE_EMPTY_TAG" value="true" />
</XML>
<codeStyleSettings language="JAVA">
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
<option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1" />
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
<option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" />
<option name="ALIGN_MULTILINE_TERNARY_OPERATION" value="true" />
<option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" />
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true" />
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
<option name="CALL_PARAMETERS_WRAP" value="5" />
<option name="METHOD_PARAMETERS_WRAP" value="5" />
<option name="RESOURCE_LIST_WRAP" value="5" />
<option name="EXTENDS_LIST_WRAP" value="5" />
<option name="THROWS_LIST_WRAP" value="5" />
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
<option name="THROWS_KEYWORD_WRAP" value="1" />
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
<option name="BINARY_OPERATION_WRAP" value="5" />
<option name="TERNARY_OPERATION_WRAP" value="1" />
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_CLASSES_IN_ONE_LINE" value="true" />
<option name="FOR_STATEMENT_WRAP" value="5" />
<option name="ARRAY_INITIALIZER_WRAP" value="5" />
<option name="ASSIGNMENT_WRAP" value="1" />
<option name="ENUM_CONSTANTS_WRAP" value="5" />
</codeStyleSettings>
<codeStyleSettings language="XML">
<indentOptions>
<option name="INDENT_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
<option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" />
<option name="CALL_PARAMETERS_WRAP" value="5" />
<option name="METHOD_PARAMETERS_WRAP" value="5" />
<option name="EXTENDS_LIST_WRAP" value="5" />
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
<option name="ASSIGNMENT_WRAP" value="1" />
<option name="FIELD_ANNOTATION_WRAP" value="1" />
<option name="ENUM_CONSTANTS_WRAP" value="5" />
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Mike" />
</state>
</component>

16
.idea/compiler.xml Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="transcendental-lisp" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="transcendental-lisp" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>

6
.idea/encodings.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$" charset="UTF-8" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="RemoveRedundantBackticks" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

7
.idea/kotlinc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JsCompilerArguments">
<option name="sourceMapEmbedSources" />
<option name="sourceMapPrefix" />
</component>
</project>

13
.idea/misc.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/classes" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/transcendental-lisp.iml" filepath="$PROJECT_DIR$/transcendental-lisp.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,27 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Build" type="MavenRunConfiguration" factoryName="Maven">
<MavenSettings>
<option name="myGeneralSettings" />
<option name="myRunnerSettings" />
<option name="myRunnerParameters">
<MavenRunnerParameters>
<option name="profiles">
<set />
</option>
<option name="goals">
<list>
<option value="clean" />
<option value="verify" />
</list>
</option>
<option name="profilesMap">
<map />
</option>
<option name="resolveToWorkspace" value="false" />
<option name="workingDirPath" value="$PROJECT_DIR$" />
</MavenRunnerParameters>
</option>
</MavenSettings>
<method />
</configuration>
</component>

View File

@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="FitNesse" type="JarApplication" factoryName="JAR Application" singleton="true">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<option name="JAR_PATH" value="$PROJECT_DIR$/fitnesse/fitnesse-standalone.jar" />
<option name="PROGRAM_PARAMETERS" value="-p 5150 -d fitnesse" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH" />
<envs />
<method />
</configuration>
</component>

View File

@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test" type="JUnit" factoryName="JUnit">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<module name="transcendental-lisp" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PACKAGE_NAME" value="" />
<option name="MAIN_CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="package" />
<option name="VM_PARAMETERS" value="-ea" />
<option name="PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="file://%MODULE_WORKING_DIR%" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="singleModule" />
</option>
<envs />
<dir value="$PROJECT_DIR$/src/test/java" />
<patterns />
<method />
</configuration>
</component>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Transcendental Lisp</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="/usr/bin/java"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="-jar fitnesse/fitnesse-standalone.jar -p 5150 -d fitnesse"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/Transcendental Lisp}"/>
</launchConfiguration>

View File

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/Transcendental Lisp"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<listAttribute key="org.eclipse.eclemma.core.SCOPE_IDS">
<listEntry value="=Transcendental Lisp/src"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=Transcendental Lisp"/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Transcendental Lisp"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/>
</launchConfiguration>

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
<booleanAttribute key="M2_DEBUG_OUTPUT" value="false"/>
<stringAttribute key="M2_GOALS" value="clean verify"/>
<booleanAttribute key="M2_NON_RECURSIVE" value="false"/>
<booleanAttribute key="M2_OFFLINE" value="false"/>
<stringAttribute key="M2_PROFILES" value=""/>
<listAttribute key="M2_PROPERTIES"/>
<stringAttribute key="M2_RUNTIME" value="EMBEDDED"/>
<booleanAttribute key="M2_SKIP_TESTS" value="false"/>
<intAttribute key="M2_THREADS" value="1"/>
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/>
<stringAttribute key="M2_USER_SETTINGS" value=""/>
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc:Transcendental Lisp}"/>
</launchConfiguration>

View File

@ -1,5 +0,0 @@
eclipse.preferences.version=1
encoding//lisp/lang=UTF-8
encoding/<project>=UTF-8
encoding/src=UTF-8
encoding/test=UTF-8

View File

@ -1,13 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -1,4 +0,0 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

141
pom.xml
View File

@ -1,5 +1,4 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@ -9,24 +8,17 @@
<artifactId>transcendental-lisp</artifactId>
<version>1.2.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.2.30</kotlin.version>
<junit5.version>5.1.0</junit5.version>
<skipTests>false</skipTests>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
<directory>lisp/lang</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>test</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<!-- TODO - when everything is converted to kotlin -->
<!--<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>-->
<!--<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>-->
<plugins>
<plugin>
@ -41,10 +33,62 @@
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<!-- TODO - remove when everything is converted to kotlin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>1.8</source>
<target>1.8</target>
@ -54,7 +98,29 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit5.version}</version>
</dependency>
<!-- TODO - remove when all test cases converted to junit 5 -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit5.version}</version>
</dependency>
</dependencies>
<configuration>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
<plugin>
@ -84,7 +150,7 @@
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>main.LispMain</mainClass>
<mainClass>application.LispMain</mainClass>
</transformer>
</transformers>
</configuration>
@ -95,12 +161,40 @@
</build>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.lanterna</groupId>
<artifactId>lanterna</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<!-- TODO - remove when test cases all converted to junit 5 and assertj-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -108,6 +202,7 @@
<scope>test</scope>
</dependency>
<!-- TODO - remove when test cases all converted to junit 5 and assertj-->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
@ -130,8 +225,4 @@
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -1,21 +0,0 @@
package error;
import static error.ErrorManager.Severity.CRITICAL;
import error.ErrorManager.Severity;
import file.FilePosition;
public abstract class CriticalLineColumnException extends LineColumnException {
private static final long serialVersionUID = 1L;
public CriticalLineColumnException(FilePosition position) {
super(position);
}
@Override
public Severity getSeverity() {
return CRITICAL;
}
}

View File

@ -1,16 +0,0 @@
package error;
import static error.ErrorManager.Severity.CRITICAL;
import error.ErrorManager.Severity;
public abstract class CriticalLispException extends LispException {
private static final long serialVersionUID = 1L;
@Override
public Severity getSeverity() {
return CRITICAL;
}
}

View File

@ -1,99 +0,0 @@
package error;
import static error.ErrorManager.Severity.CRITICAL;
import static error.ErrorManager.Severity.WARNING;
import static java.text.MessageFormat.format;
import java.io.PrintStream;
import environment.RuntimeEnvironment;
/**
* Prints error messages and potentially terminates the application.
*/
public class ErrorManager {
private RuntimeEnvironment environment;
public ErrorManager() {
this.environment = RuntimeEnvironment.getInstance();
}
public void handle(LispException lispException) {
printMessage(lispException);
if (isCritical(lispException))
environment.terminateExceptionally();
}
private void printMessage(LispException lispException) {
PrintStream output = selectOutputStream(lispException.getSeverity());
output.println(formatMessage(lispException));
}
private PrintStream selectOutputStream(Severity severity) {
if (severity == WARNING)
return environment.getOutput();
return environment.getErrorOutput();
}
private String formatMessage(LispException lispException) {
Severity severity = lispException.getSeverity();
String prefix = severity.toDisplayString();
String message = format("[{0}] {1}", prefix, lispException.getMessage());
return severity.decorate(message, environment);
}
private boolean isCritical(LispException lispException) {
return lispException.getSeverity() == CRITICAL;
}
public static enum Severity {
WARNING {
@Override
public String decorate(String warningOutput, RuntimeEnvironment environment) {
return environment.decorateWarningOutput(warningOutput);
}
@Override
public String toDisplayString() {
return "warning";
}
},
ERROR {
@Override
public String decorate(String errorOutput, RuntimeEnvironment environment) {
return environment.decorateErrorOutput(errorOutput);
}
@Override
public String toDisplayString() {
return "error";
}
},
CRITICAL {
@Override
public String decorate(String criticalOutput, RuntimeEnvironment environment) {
return environment.decorateCriticalOutput(criticalOutput);
}
@Override
public String toDisplayString() {
return "critical";
}
};
public abstract String decorate(String output, RuntimeEnvironment environment);
public abstract String toDisplayString();
}
}

View File

@ -1,26 +0,0 @@
package error;
import static java.text.MessageFormat.format;
import file.FilePosition;
public abstract class LineColumnException extends LispException {
private static final long serialVersionUID = 1L;
private FilePosition position;
public LineColumnException(FilePosition position) {
this.position = position;
}
@Override
public String getMessage() {
return format("{0} - line {1}, column {2}",
getMessagePrefix(),
position.getLineNumber(),
position.getColumnNumber());
}
public abstract String getMessagePrefix();
}

View File

@ -1,15 +0,0 @@
package error;
import static error.ErrorManager.Severity.ERROR;
import error.ErrorManager.Severity;
public abstract class LispException extends RuntimeException {
private static final long serialVersionUID = 1L;
public Severity getSeverity() {
return ERROR;
}
}

View File

@ -1,16 +0,0 @@
package error;
import static error.ErrorManager.Severity.WARNING;
import error.ErrorManager.Severity;
public abstract class LispWarning extends LispException {
private static final long serialVersionUID = 1L;
@Override
public Severity getSeverity() {
return WARNING;
}
}

View File

@ -1,70 +0,0 @@
package function.builtin.special;
import static function.builtin.cons.LIST.makeList;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispSpecialFunction;
import function.UserDefinedFunction;
import sexpression.Cons;
import sexpression.LambdaExpression;
import sexpression.SExpression;
import sexpression.Symbol;
@FunctionNames({ "LAMBDA", "Λ" })
public class LAMBDA extends LispSpecialFunction {
public static boolean isLambdaExpression(SExpression sexpr) {
if (sexpr.isCons()) {
String first = ((Cons) sexpr).getFirst().toString();
return "LAMBDA".equals(first) || "Λ".equals(first);
}
return false;
}
public static UserDefinedFunction createFunction(Cons lambdaExpression) {
SExpression rest = lambdaExpression.getRest();
ArgumentValidator lambdaValidator = new ArgumentValidator("LAMBDA|create|");
lambdaValidator.setEveryArgumentExpectedType(Cons.class);
lambdaValidator.validate(makeList(rest));
LambdaExpression lambda = new LAMBDA("LAMBDA").call((Cons) rest);
return lambda.getFunction();
}
private ArgumentValidator argumentValidator;
private ArgumentValidator lambdaListValidator;
public LAMBDA(String name) {
this.argumentValidator = new ArgumentValidator(name);
this.argumentValidator.setFirstArgumentExpectedType(Cons.class);
this.argumentValidator.setMinimumNumberOfArguments(1);
this.lambdaListValidator = new ArgumentValidator(name + "|lambda-list|");
this.lambdaListValidator.setEveryArgumentExpectedType(Symbol.class);
}
@Override
public LambdaExpression call(Cons argumentList) {
argumentValidator.validate(argumentList);
SExpression first = argumentList.getFirst();
Cons lambdaList = (Cons) first;
Cons body = (Cons) argumentList.getRest();
lambdaListValidator.validate(lambdaList);
UserDefinedFunction function = new UserDefinedFunction(":LAMBDA", lambdaList, body);
return new LambdaExpression(makeOriginalLambdaExpression(argumentList), function);
}
private Cons makeOriginalLambdaExpression(Cons argumentList) {
return new Cons(new Symbol("LAMBDA"), argumentList);
}
}

View File

@ -1,8 +1,14 @@
package main;
package application;
import static com.googlecode.lanterna.terminal.IOSafeTerminalAdapter.createRuntimeExceptionConvertingAdapter;
import static java.text.MessageFormat.format;
import static terminal.LispTerminal.END_OF_SEGMENT;
import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
import com.googlecode.lanterna.terminal.IOSafeTerminal;
import com.googlecode.lanterna.terminal.Terminal;
import interpreter.LispInterpreter;
import interpreter.LispInterpreterBuilder;
import interpreter.LispInterpreterBuilderImpl;
import stream.UncheckedIOException;
import terminal.LispTerminal;
import terminal.TerminalConfiguration;
import java.io.IOException;
import java.io.PipedInputStream;
@ -10,16 +16,9 @@ import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.util.function.Function;
import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
import com.googlecode.lanterna.terminal.IOSafeTerminal;
import com.googlecode.lanterna.terminal.Terminal;
import interpreter.LispInterpreter;
import interpreter.LispInterpreterBuilder;
import interpreter.LispInterpreterBuilderImpl;
import stream.UncheckedIOException;
import terminal.LispTerminal;
import terminal.TerminalConfiguration;
import static com.googlecode.lanterna.terminal.IOSafeTerminalAdapter.createRuntimeExceptionConvertingAdapter;
import static java.text.MessageFormat.format;
import static terminal.LispTerminal.END_OF_SEGMENT;
public class LispMain {
@ -152,5 +151,4 @@ public class LispMain {
return builder.build();
}
}

View File

@ -1,11 +1,11 @@
package environment;
import error.ErrorManager;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.function.Function;
import error.ErrorManager;
public class RuntimeEnvironment {
private static RuntimeEnvironment uniqueInstance = new RuntimeEnvironment();
@ -151,5 +151,4 @@ public class RuntimeEnvironment {
public String decorateCriticalOutput(String criticalOutput) {
return criticalOutputDecorator.apply(criticalOutput);
}
}

View File

@ -0,0 +1,9 @@
package error
import error.Severity.CRITICAL
import file.FilePosition
abstract class CriticalLineColumnException(position: FilePosition) : LineColumnException(position) {
override val severity = CRITICAL
}

View File

@ -0,0 +1,8 @@
package error
import error.Severity.CRITICAL
abstract class CriticalLispException : LispException() {
override val severity = CRITICAL
}

View File

@ -0,0 +1,41 @@
package error
import environment.RuntimeEnvironment
import error.Severity.CRITICAL
import error.Severity.WARNING
import java.io.PrintStream
import java.text.MessageFormat.format
/**
* Prints error messages and potentially terminates the application.
*/
class ErrorManager {
private val environment: RuntimeEnvironment = RuntimeEnvironment.getInstance()
fun handle(lispException: LispException) {
printMessage(lispException)
if (isCritical(lispException))
environment.terminateExceptionally()
}
private fun printMessage(lispException: LispException) {
val output = selectOutputStream(lispException.severity)
output.println(formatMessage(lispException))
}
private fun selectOutputStream(severity: Severity): PrintStream {
return if (severity === WARNING) environment.output else environment.errorOutput
}
private fun formatMessage(lispException: LispException): String {
val severity = lispException.severity
val prefix = severity.toDisplayString()
val message = format("[{0}] {1}", prefix, lispException.message)
return severity.decorate(message, environment)
}
private fun isCritical(lispException: LispException) = lispException.severity == CRITICAL
}

View File

@ -0,0 +1,12 @@
package error
import file.FilePosition
import java.text.MessageFormat.format
abstract class LineColumnException(private val position: FilePosition) : LispException() {
abstract val messagePrefix: String
override val message: String
get() = format("{0} - line {1}, column {2}", messagePrefix, position.lineNumber, position.columnNumber)
}

View File

@ -0,0 +1,8 @@
package error
import error.Severity.ERROR
abstract class LispException : RuntimeException() {
open val severity = ERROR
}

View File

@ -0,0 +1,8 @@
package error
import error.Severity.WARNING
abstract class LispWarning : LispException() {
override val severity = WARNING
}

View File

@ -0,0 +1,31 @@
package error
import environment.RuntimeEnvironment
enum class Severity {
WARNING {
override fun decorate(output: String, environment: RuntimeEnvironment): String =
environment.decorateWarningOutput(output)
override fun toDisplayString() = "warning"
},
ERROR {
override fun decorate(output: String, environment: RuntimeEnvironment): String =
environment.decorateErrorOutput(output)
override fun toDisplayString() = "error"
},
CRITICAL {
override fun decorate(output: String, environment: RuntimeEnvironment): String =
environment.decorateCriticalOutput(output)
override fun toDisplayString() = "critical"
};
abstract fun decorate(output: String, environment: RuntimeEnvironment): String
abstract fun toDisplayString(): String
}

View File

@ -29,5 +29,4 @@ public class FilePosition {
public void setColumnNumber(int columnNumber) {
this.columnNumber = columnNumber;
}
}

View File

@ -28,5 +28,4 @@ public class FilePositionTracker {
lineNumber++;
columnNumber = 0;
}
}

View File

@ -1,15 +1,15 @@
package function;
import static function.builtin.cons.LENGTH.getLength;
import static java.text.MessageFormat.format;
import java.math.BigInteger;
import error.LispException;
import sexpression.Cons;
import sexpression.DisplayName;
import sexpression.SExpression;
import java.math.BigInteger;
import static function.builtin.cons.LENGTH.getLength;
import static java.text.MessageFormat.format;
public class ArgumentValidator {
private Class<? extends SExpression> firstArgumentType;
@ -231,5 +231,4 @@ public class ArgumentValidator {
return (displayName == null) ? "unknown" : displayName.value();
}
}
}

View File

@ -10,5 +10,4 @@ import java.lang.annotation.Target;
public @interface FunctionNames {
String[] value();
}

View File

@ -14,5 +14,4 @@ public abstract class LispFunction {
public boolean isMacro() {
return false;
}
}

View File

@ -6,5 +6,4 @@ public abstract class LispSpecialFunction extends LispFunction {
public boolean isArgumentListEvaluated() {
return false;
}
}

View File

@ -1,12 +1,5 @@
package function;
import static function.builtin.EVAL.eval;
import static java.text.MessageFormat.format;
import static recursion.TailCalls.done;
import static sexpression.Nil.NIL;
import java.util.ArrayList;
import error.LispException;
import recursion.TailCall;
import recursion.TailCalls;
@ -16,6 +9,13 @@ import sexpression.Symbol;
import table.ExecutionContext;
import table.SymbolTable;
import java.util.ArrayList;
import static function.builtin.EVAL.eval;
import static java.text.MessageFormat.format;
import static recursion.TailCalls.done;
import static sexpression.Nil.NIL;
public class UserDefinedFunction extends LispFunction {
private static final String KEYWORD_REST = "&REST";
@ -166,5 +166,4 @@ public class UserDefinedFunction extends LispFunction {
parameters);
}
}
}

View File

@ -12,5 +12,4 @@ public class UserDefinedMacro extends UserDefinedSpecialFunction {
public boolean isMacro() {
return true;
}
}

View File

@ -12,5 +12,4 @@ public class UserDefinedSpecialFunction extends UserDefinedFunction {
public boolean isArgumentListEvaluated() {
return false;
}
}

View File

@ -1,15 +1,15 @@
package function.builtin;
import static function.builtin.EVAL.applyFunction;
import static function.builtin.EVAL.lookupFunctionOrLambda;
import static table.FunctionTable.lookupFunction;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;
import static function.builtin.EVAL.applyFunction;
import static function.builtin.EVAL.lookupFunctionOrLambda;
import static table.FunctionTable.lookupFunction;
@FunctionNames({ "APPLY" })
public class APPLY extends LispFunction {
@ -36,5 +36,4 @@ public class APPLY extends LispFunction {
return applyFunction(function, functionArguments);
}
}

View File

@ -1,8 +1,5 @@
package function.builtin;
import static function.builtin.EVAL.eval;
import static sexpression.Nil.NIL;
import error.LispException;
import function.ArgumentValidator;
import sexpression.AtSignExpression;
@ -11,6 +8,9 @@ import sexpression.CommaExpression;
import sexpression.Cons;
import sexpression.SExpression;
import static function.builtin.EVAL.eval;
import static sexpression.Nil.NIL;
class BackquoteEvaluator {
private ArgumentValidator listValidator;
@ -201,5 +201,4 @@ class BackquoteEvaluator {
return "at sign did not evaluate to a list";
}
}
}

View File

@ -1,17 +1,10 @@
package function.builtin;
import static function.builtin.cons.LIST.makeList;
import static function.builtin.special.LAMBDA.createFunction;
import static function.builtin.special.LAMBDA.isLambdaExpression;
import static java.text.MessageFormat.format;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import static table.FunctionTable.lookupFunction;
import error.LispException;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import function.builtin.special.LAMBDA;
import function.builtin.special.RECUR.RecurNotInTailPositionException;
import sexpression.BackquoteExpression;
import sexpression.Cons;
@ -20,6 +13,12 @@ import sexpression.SExpression;
import sexpression.Symbol;
import table.ExecutionContext;
import static function.builtin.cons.LIST.makeList;
import static java.text.MessageFormat.format;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import static table.FunctionTable.lookupFunction;
@FunctionNames({ "EVAL" })
public class EVAL extends LispFunction {
@ -60,8 +59,8 @@ public class EVAL extends LispFunction {
private static LispFunction createLambdaFunction(SExpression lambdaExpression) {
if (lambdaExpression.isFunction())
return ((LambdaExpression) lambdaExpression).getFunction();
else if (isLambdaExpression(lambdaExpression))
return createFunction((Cons) lambdaExpression);
else if (LAMBDA.Companion.isLambdaExpression(lambdaExpression))
return LAMBDA.Companion.createFunction((Cons) lambdaExpression);
else
throw new UndefinedFunctionException(lambdaExpression);
}
@ -228,5 +227,4 @@ public class EVAL extends LispFunction {
return "unmatched at sign";
}
}
}

View File

@ -1,7 +1,5 @@
package function.builtin;
import static sexpression.Nil.NIL;
import environment.RuntimeEnvironment;
import function.ArgumentValidator;
import function.FunctionNames;
@ -9,6 +7,8 @@ import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;
import static sexpression.Nil.NIL;
@FunctionNames({ "EXIT" })
public class EXIT extends LispFunction {
@ -28,5 +28,4 @@ public class EXIT extends LispFunction {
return NIL;
}
}

View File

@ -1,14 +1,14 @@
package function.builtin;
import static function.builtin.APPLY.apply;
import static function.builtin.cons.LIST.makeList;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;
import static function.builtin.APPLY.apply;
import static function.builtin.cons.LIST.makeList;
@FunctionNames({ "FUNCALL", "CALL" })
public class FUNCALL extends LispFunction {
@ -26,5 +26,4 @@ public class FUNCALL extends LispFunction {
return apply(applyArgs);
}
}

View File

@ -32,5 +32,4 @@ public class FUSE extends LispFunction {
return new Symbol(left.toString() + SEPARATOR + right.toString());
}
}

View File

@ -1,7 +1,5 @@
package function.builtin;
import java.math.BigInteger;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
@ -9,6 +7,8 @@ import sexpression.Cons;
import sexpression.SExpression;
import sexpression.Symbol;
import java.math.BigInteger;
@FunctionNames({ "GENSYM" })
public class GENSYM extends LispFunction {
@ -39,5 +39,4 @@ public class GENSYM extends LispFunction {
return generateSymbol();
}
}

View File

@ -1,15 +1,5 @@
package function.builtin;
import static function.builtin.EVAL.eval;
import static java.text.MessageFormat.format;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import static util.Path.getPathPrefix;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Stack;
import environment.RuntimeEnvironment;
import error.LispException;
import error.LispWarning;
@ -21,6 +11,16 @@ import sexpression.Cons;
import sexpression.LispString;
import sexpression.SExpression;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Stack;
import static function.builtin.EVAL.eval;
import static java.text.MessageFormat.format;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import static util.Path.getPathPrefix;
@FunctionNames({ "LOAD" })
public class LOAD extends LispFunction {
@ -114,5 +114,4 @@ public class LOAD extends LispFunction {
return format("could not load ''{0}''", fileName);
}
}
}

View File

@ -27,5 +27,4 @@ public class PRINT extends LispFunction {
return argument;
}
}

View File

@ -1,7 +1,5 @@
package function.builtin;
import static table.FunctionTable.lookupFunction;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
@ -11,6 +9,8 @@ import sexpression.Symbol;
import table.ExecutionContext;
import table.SymbolTable;
import static table.FunctionTable.lookupFunction;
@FunctionNames({ "SET" })
public class SET extends LispFunction {
@ -54,5 +54,4 @@ public class SET extends LispFunction {
private boolean isSymbolInTable(SExpression symbol, SymbolTable table) {
return table.contains(symbol.toString());
}
}

View File

@ -25,5 +25,4 @@ public class SYMBOLS extends LispFunction {
return executionContext.toList();
}
}

View File

@ -1,8 +1,5 @@
package function.builtin;
import static java.text.MessageFormat.format;
import static table.FunctionTable.lookupFunction;
import error.LispException;
import function.ArgumentValidator;
import function.FunctionNames;
@ -13,6 +10,9 @@ import sexpression.Cons;
import sexpression.SExpression;
import sexpression.Symbol;
import static java.text.MessageFormat.format;
import static table.FunctionTable.lookupFunction;
@FunctionNames({ "SYMBOL-FUNCTION" })
public class SYMBOL_FUNCTION extends LispFunction {
@ -60,5 +60,4 @@ public class SYMBOL_FUNCTION extends LispFunction {
return format("SYMBOL-FUNCTION: undefined function: {0}", function);
}
}
}

View File

@ -1,13 +1,13 @@
package function.builtin.cons;
import static sexpression.Nil.NIL;
import static table.FunctionTable.lookupFunction;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import static sexpression.Nil.NIL;
import static table.FunctionTable.lookupFunction;
@FunctionNames({ "APPEND" })
public class APPEND extends LispFunction {

View File

@ -26,5 +26,4 @@ public class CONS extends LispFunction {
return new Cons(firstArgument, secondArgument);
}
}

View File

@ -24,5 +24,4 @@ public class FIRST extends LispFunction {
return argument.getFirst();
}
}

View File

@ -1,12 +1,5 @@
package function.builtin.cons;
import static function.builtin.cons.LIST.makeList;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static table.FunctionTable.lookupFunction;
import java.math.BigInteger;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
@ -14,6 +7,13 @@ import recursion.TailCall;
import sexpression.Cons;
import sexpression.LispNumber;
import java.math.BigInteger;
import static function.builtin.cons.LIST.makeList;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static table.FunctionTable.lookupFunction;
@FunctionNames({ "LENGTH" })
public class LENGTH extends LispFunction {
@ -62,5 +62,4 @@ public class LENGTH extends LispFunction {
private BigInteger increment(BigInteger number) {
return number.add(BigInteger.ONE);
}
}

View File

@ -1,13 +1,13 @@
package function.builtin.cons;
import static sexpression.Nil.NIL;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;
import static sexpression.Nil.NIL;
@FunctionNames({ "LIST" })
public class LIST extends LispFunction {
@ -27,5 +27,4 @@ public class LIST extends LispFunction {
return argumentList;
}
}

View File

@ -24,5 +24,4 @@ public class REST extends LispFunction {
return argument.getRest();
}
}

View File

@ -1,7 +1,5 @@
package function.builtin.math;
import java.math.BigInteger;
import error.LispException;
import function.ArgumentValidator;
import function.FunctionNames;
@ -9,6 +7,8 @@ import function.LispFunction;
import sexpression.Cons;
import sexpression.LispNumber;
import java.math.BigInteger;
@FunctionNames({ "/" })
public class DIVIDE extends LispFunction {
@ -50,5 +50,4 @@ public class DIVIDE extends LispFunction {
return "divide by zero";
}
}
}

View File

@ -1,13 +1,13 @@
package function.builtin.math;
import java.math.BigInteger;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.LispNumber;
import java.math.BigInteger;
@FunctionNames({ "-" })
public class MINUS extends LispFunction {
@ -35,5 +35,4 @@ public class MINUS extends LispFunction {
private LispNumber subtract(LispNumber number1, LispNumber number2) {
return new LispNumber(number1.getValue().subtract(number2.getValue()));
}
}

View File

@ -41,5 +41,4 @@ public class MODULO extends LispFunction {
return "modulus not positive";
}
}
}

View File

@ -1,13 +1,13 @@
package function.builtin.math;
import static sexpression.LispNumber.ONE;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.LispNumber;
import static sexpression.LispNumber.ONE;
@FunctionNames({ "*" })
public class MULTIPLY extends LispFunction {
@ -30,5 +30,4 @@ public class MULTIPLY extends LispFunction {
private LispNumber multiply(LispNumber number1, LispNumber number2) {
return new LispNumber(number1.getValue().multiply(number2.getValue()));
}
}

View File

@ -1,16 +1,16 @@
package function.builtin.math;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import java.util.function.BiFunction;
import java.util.function.Function;
import recursion.TailCall;
import sexpression.Cons;
import sexpression.LispNumber;
import sexpression.SExpression;
import java.util.function.BiFunction;
import java.util.function.Function;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
class MathFunction {
Function<LispNumber, LispNumber> singleValueOperation;
@ -40,5 +40,4 @@ class MathFunction {
return tailCall(() -> callTailRecursive(new Cons(operationResult, remainingNumbers)));
}
}

View File

@ -1,13 +1,13 @@
package function.builtin.math;
import static sexpression.LispNumber.ZERO;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.LispNumber;
import static sexpression.LispNumber.ZERO;
@FunctionNames({ "+" })
public class PLUS extends LispFunction {
@ -30,5 +30,4 @@ public class PLUS extends LispFunction {
private LispNumber add(LispNumber number1, LispNumber number2) {
return new LispNumber(number1.getValue().add(number2.getValue()));
}
}

View File

@ -31,5 +31,4 @@ public class REMAINDER extends LispFunction {
throw new DivideByZeroException();
}
}
}

View File

@ -1,14 +1,14 @@
package function.builtin.predicate;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
@FunctionNames({ "ATOM", "ATOM?" })
public class ATOM extends LispFunction {
@ -26,5 +26,4 @@ public class ATOM extends LispFunction {
return argument.isAtom() ? T : NIL;
}
}

View File

@ -1,14 +1,14 @@
package function.builtin.predicate;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
@FunctionNames({ "EQ", "EQ?" })
public class EQ extends LispFunction {
@ -52,5 +52,4 @@ public class EQ extends LispFunction {
private SExpression listEq(SExpression firstArgument, SExpression secondArgument) {
return (firstArgument == secondArgument) ? T : NIL;
}
}

View File

@ -1,14 +1,14 @@
package function.builtin.predicate;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
@FunctionNames({ "EQUAL", "EQUAL?" })
public class EQUAL extends LispFunction {
@ -37,5 +37,4 @@ public class EQUAL extends LispFunction {
private SExpression equal(SExpression firstArgument, SExpression secondArgument) {
return isEqual(firstArgument, secondArgument) ? T : NIL;
}
}

View File

@ -1,8 +1,10 @@
package function.builtin.predicate;
import static function.builtin.GENSYM.GENSYM_PREFIX;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;
import java.util.HashMap;
import java.util.Map;
@ -10,11 +12,9 @@ import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;
import static function.builtin.GENSYM.GENSYM_PREFIX;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
@FunctionNames({ "GENSYM-EQUAL", "GENSYM-EQUAL?" })
public class GENSYM_EQUAL extends LispFunction {
@ -97,5 +97,4 @@ public class GENSYM_EQUAL extends LispFunction {
return equalizedExpression;
}
}
}

View File

@ -1,14 +1,14 @@
package function.builtin.predicate;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
@FunctionNames({ "LISTP", "LIST?" })
public class LISTP extends LispFunction {
@ -25,5 +25,4 @@ public class LISTP extends LispFunction {
return argumentList.getFirst().isList() ? T : NIL;
}
}

View File

@ -1,14 +1,14 @@
package function.builtin.predicate;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Cons;
import sexpression.SExpression;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
@FunctionNames({ "NULL", "NULL?" })
public class NULL extends LispFunction {
@ -25,5 +25,4 @@ public class NULL extends LispFunction {
return argumentList.getFirst().isNull() ? T : NIL;
}
}

View File

@ -1,10 +1,5 @@
package function.builtin.predicate;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
@ -13,6 +8,11 @@ import sexpression.Cons;
import sexpression.LispNumber;
import sexpression.SExpression;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
@FunctionNames({ "=" })
public class NUMERIC_EQUAL extends LispFunction {
@ -51,5 +51,4 @@ public class NUMERIC_EQUAL extends LispFunction {
private boolean isEqual(LispNumber number1, LispNumber number2) {
return number1.getValue().equals(number2.getValue());
}
}

View File

@ -1,10 +1,5 @@
package function.builtin.predicate;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
@ -13,6 +8,11 @@ import sexpression.Cons;
import sexpression.LispNumber;
import sexpression.SExpression;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
@FunctionNames({ ">" })
public class NUMERIC_GREATER extends LispFunction {
@ -51,5 +51,4 @@ public class NUMERIC_GREATER extends LispFunction {
private boolean isFirstGreater(LispNumber number1, LispNumber number2) {
return number1.getValue().compareTo(number2.getValue()) > 0;
}
}

View File

@ -1,10 +1,5 @@
package function.builtin.predicate;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
@ -13,6 +8,11 @@ import sexpression.Cons;
import sexpression.LispNumber;
import sexpression.SExpression;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
@FunctionNames({ "<" })
public class NUMERIC_LESS extends LispFunction {
@ -51,5 +51,4 @@ public class NUMERIC_LESS extends LispFunction {
private boolean isFirstLesser(LispNumber number1, LispNumber number2) {
return number1.getValue().compareTo(number2.getValue()) < 0;
}
}

View File

@ -1,10 +1,5 @@
package function.builtin.special;
import static function.builtin.EVAL.eval;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Symbol.T;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispSpecialFunction;
@ -12,6 +7,11 @@ import recursion.TailCall;
import sexpression.Cons;
import sexpression.SExpression;
import static function.builtin.EVAL.eval;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Symbol.T;
@FunctionNames({ "AND" })
public class AND extends LispSpecialFunction {
@ -40,5 +40,4 @@ public class AND extends LispSpecialFunction {
return tailCall(() -> callTailRecursive(remainingValues, currentValue));
}
}

View File

@ -1,12 +1,5 @@
package function.builtin.special;
import static function.builtin.EVAL.eval;
import static function.builtin.predicate.EQUAL.isEqual;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispSpecialFunction;
@ -15,6 +8,13 @@ import sexpression.Cons;
import sexpression.Nil;
import sexpression.SExpression;
import static function.builtin.EVAL.eval;
import static function.builtin.predicate.EQUAL.isEqual;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Nil.NIL;
import static sexpression.Symbol.T;
@FunctionNames({ "CASE" })
public class CASE extends LispSpecialFunction {
@ -82,5 +82,4 @@ public class CASE extends LispSpecialFunction {
return lastConsequentValue;
}
}

View File

@ -1,10 +1,5 @@
package function.builtin.special;
import static function.builtin.EVAL.eval;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Nil.NIL;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispSpecialFunction;
@ -13,6 +8,11 @@ import sexpression.Cons;
import sexpression.Nil;
import sexpression.SExpression;
import static function.builtin.EVAL.eval;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Nil.NIL;
@FunctionNames({ "COND" })
public class COND extends LispSpecialFunction {
@ -65,5 +65,4 @@ public class COND extends LispSpecialFunction {
private SExpression getFirst(SExpression knownCons) {
return ((Cons) knownCons).getFirst();
}
}

View File

@ -17,5 +17,4 @@ public class DEFINE_SPECIAL extends Define {
protected UserDefinedFunction createFunction(SExpression functionName, Cons lambdaList, Cons functionBody) {
return new UserDefinedSpecialFunction(functionName.toString(), lambdaList, functionBody);
}
}

View File

@ -17,5 +17,4 @@ public class DEFMACRO extends Define {
protected UserDefinedFunction createFunction(SExpression functionName, Cons lambdaList, Cons functionBody) {
return new UserDefinedMacro(functionName.toString(), lambdaList, functionBody);
}
}

View File

@ -16,5 +16,4 @@ public class DEFUN extends Define {
protected UserDefinedFunction createFunction(SExpression functionName, Cons lambdaList, Cons functionBody) {
return new UserDefinedFunction(functionName.toString(), lambdaList, functionBody);
}
}

View File

@ -1,10 +1,5 @@
package function.builtin.special;
import static function.builtin.cons.LIST.makeList;
import static java.text.MessageFormat.format;
import static table.FunctionTable.defineFunction;
import static table.FunctionTable.isAlreadyDefined;
import environment.RuntimeEnvironment;
import error.LispWarning;
import function.ArgumentValidator;
@ -14,6 +9,11 @@ import sexpression.Cons;
import sexpression.SExpression;
import sexpression.Symbol;
import static function.builtin.cons.LIST.makeList;
import static java.text.MessageFormat.format;
import static table.FunctionTable.defineFunction;
import static table.FunctionTable.isAlreadyDefined;
public abstract class Define extends LispSpecialFunction {
private ArgumentValidator argumentValidator;
@ -74,5 +74,4 @@ public abstract class Define extends LispSpecialFunction {
return format("redefining function {0}", functionName);
}
}
}

View File

@ -1,13 +1,13 @@
package function.builtin.special;
import static function.builtin.EVAL.eval;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispSpecialFunction;
import sexpression.Cons;
import sexpression.SExpression;
import static function.builtin.EVAL.eval;
@FunctionNames({ "IF" })
public class IF extends LispSpecialFunction {
@ -49,5 +49,4 @@ public class IF extends LispSpecialFunction {
return getRestOfList(expressions).getFirst();
}
}

View File

@ -0,0 +1,67 @@
package function.builtin.special
import function.ArgumentValidator
import function.FunctionNames
import function.LispSpecialFunction
import function.UserDefinedFunction
import function.builtin.cons.LIST.makeList
import sexpression.Cons
import sexpression.LambdaExpression
import sexpression.SExpression
import sexpression.Symbol
@FunctionNames("LAMBDA", "Λ")
class LAMBDA(name: String) : LispSpecialFunction() {
private val argumentValidator: ArgumentValidator = ArgumentValidator(name)
private val lambdaListValidator: ArgumentValidator = ArgumentValidator("$name|lambda-list|")
init {
this.argumentValidator.setFirstArgumentExpectedType(Cons::class.java)
this.argumentValidator.setMinimumNumberOfArguments(1)
this.lambdaListValidator.setEveryArgumentExpectedType(Symbol::class.java)
}
override fun call(argumentList: Cons): LambdaExpression {
argumentValidator.validate(argumentList)
val first = argumentList.first
val lambdaList = first as Cons
val body = argumentList.rest as Cons
lambdaListValidator.validate(lambdaList)
val function = UserDefinedFunction(":LAMBDA", lambdaList, body)
return LambdaExpression(makeOriginalLambdaExpression(argumentList), function)
}
private fun makeOriginalLambdaExpression(argumentList: Cons): Cons {
return Cons(Symbol("LAMBDA"), argumentList)
}
companion object {
fun isLambdaExpression(sexpr: SExpression): Boolean {
if (sexpr.isCons) {
val first = (sexpr as Cons).first.toString()
return "LAMBDA" == first || "Λ" == first
}
return false
}
fun createFunction(lambdaExpression: Cons): UserDefinedFunction {
val rest = lambdaExpression.rest
val lambdaValidator = ArgumentValidator("LAMBDA|create|")
lambdaValidator.setEveryArgumentExpectedType(Cons::class.java)
lambdaValidator.validate(makeList(rest))
val lambda = LAMBDA("LAMBDA").call(rest as Cons)
return lambda.function
}
}
}

View File

@ -1,8 +1,5 @@
package function.builtin.special;
import static function.builtin.EVAL.eval;
import static sexpression.Nil.NIL;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispSpecialFunction;
@ -12,6 +9,9 @@ import sexpression.Symbol;
import table.ExecutionContext;
import table.SymbolTable;
import static function.builtin.EVAL.eval;
import static sexpression.Nil.NIL;
@FunctionNames({ "LET" })
public class LET extends LispSpecialFunction {
@ -90,5 +90,4 @@ public class LET extends LispSpecialFunction {
private void restorePreviousScope(SymbolTable localScope) {
executionContext.setScope(localScope.getParent());
}
}

View File

@ -19,5 +19,4 @@ public class LET_STAR extends LET {
return localScope;
}
}

View File

@ -1,9 +1,5 @@
package function.builtin.special;
import static function.builtin.EVAL.eval;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispSpecialFunction;
@ -11,6 +7,10 @@ import recursion.TailCall;
import sexpression.Cons;
import sexpression.SExpression;
import static function.builtin.EVAL.eval;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
@FunctionNames({ "OR" })
public class OR extends LispSpecialFunction {
@ -36,5 +36,4 @@ public class OR extends LispSpecialFunction {
return tailCall(() -> callTailRecursive(remainingValues));
}
}

View File

@ -1,10 +1,5 @@
package function.builtin.special;
import static function.builtin.EVAL.eval;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Nil.NIL;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispSpecialFunction;
@ -12,6 +7,11 @@ import recursion.TailCall;
import sexpression.Cons;
import sexpression.SExpression;
import static function.builtin.EVAL.eval;
import static recursion.TailCalls.done;
import static recursion.TailCalls.tailCall;
import static sexpression.Nil.NIL;
@FunctionNames({ "PROGN", "BEGIN" })
public class PROGN extends LispSpecialFunction {
@ -37,5 +37,4 @@ public class PROGN extends LispSpecialFunction {
return tailCall(() -> callTailRecursive(remainingValues, currentValue));
}
}

View File

@ -22,5 +22,4 @@ public class QUOTE extends LispSpecialFunction {
return argumentList.getFirst();
}
}

View File

@ -1,7 +1,5 @@
package function.builtin.special;
import static function.builtin.EVAL.evaluateFunctionArgumentList;
import error.LispException;
import function.ArgumentValidator;
import function.FunctionNames;
@ -10,6 +8,8 @@ import sexpression.Cons;
import sexpression.SExpression;
import table.ExecutionContext;
import static function.builtin.EVAL.evaluateFunctionArgumentList;
@FunctionNames({ "RECUR" })
public class RECUR extends LispSpecialFunction {
@ -87,5 +87,4 @@ public class RECUR extends LispSpecialFunction {
return "recur not in tail position";
}
}
}

View File

@ -1,9 +1,5 @@
package function.builtin.special;
import static function.builtin.EVAL.eval;
import static function.builtin.SET.set;
import static function.builtin.cons.LIST.makeList;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispSpecialFunction;
@ -11,6 +7,10 @@ import sexpression.Cons;
import sexpression.SExpression;
import sexpression.Symbol;
import static function.builtin.EVAL.eval;
import static function.builtin.SET.set;
import static function.builtin.cons.LIST.makeList;
@FunctionNames({ "SETQ" })
public class SETQ extends LispSpecialFunction {
@ -35,5 +35,4 @@ public class SETQ extends LispSpecialFunction {
return new Cons(argumentList.getFirst(), makeList(value));
}
}

View File

@ -25,5 +25,4 @@ public class FileLispInterpreter extends LispInterpreter {
super.applyFinishingTouches();
}
}

View File

@ -21,5 +21,4 @@ public class InteractiveLispInterpreter extends LispInterpreter {
environment.getOutput().println(environment.decoratePrompt(""));
environment.getOutput().flush();
}
}

Some files were not shown because too many files have changed in this diff Show More