From 68a2ebd34fc94488e89ffb82b359ec6e7e152ae9 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 8 Jul 2021 00:14:31 -0700 Subject: [PATCH] Restructure project to make room for clox --- .gitignore | 2 ++ Jenkinsfile | 4 ++-- jlox | 3 --- {src => jlox}/.gitignore | 0 {src => jlox}/CMakeLists.txt | 2 +- {src => jlox}/CMakePresets.json | 0 jlox/jlox | 3 +++ .../src}/com/craftinginterpreters/CMakeLists.txt | 0 .../src}/com/craftinginterpreters/lox/.gitignore | 0 .../lox/.settings/org.eclipse.jdt.core.prefs | 2 ++ .../src}/com/craftinginterpreters/lox/AstPrinter.java | 0 .../src}/com/craftinginterpreters/lox/CMakeLists.txt | 0 .../src}/com/craftinginterpreters/lox/Environment.java | 0 .../src}/com/craftinginterpreters/lox/Interpreter.java | 0 {src => jlox/src}/com/craftinginterpreters/lox/Lox.java | 0 .../src}/com/craftinginterpreters/lox/LoxCallable.java | 0 .../src}/com/craftinginterpreters/lox/LoxClass.java | 0 .../src}/com/craftinginterpreters/lox/LoxFunction.java | 0 .../src}/com/craftinginterpreters/lox/LoxInstance.java | 0 .../src}/com/craftinginterpreters/lox/Parser.java | 0 .../src}/com/craftinginterpreters/lox/Resolver.java | 0 .../src}/com/craftinginterpreters/lox/Return.java | 0 .../src}/com/craftinginterpreters/lox/RuntimeError.java | 0 .../src}/com/craftinginterpreters/lox/Scanner.java | 0 .../src}/com/craftinginterpreters/lox/Token.java | 0 .../src}/com/craftinginterpreters/lox/TokenType.java | 0 .../src}/com/craftinginterpreters/tool/CMakeLists.txt | 0 .../src}/com/craftinginterpreters/tool/GenerateAst.java | 0 src/fib.lox | 9 +++++++++ src/test.lox | 7 +++++++ testsuite/jlox.tests/tests.exp | 2 +- 31 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 .gitignore delete mode 100755 jlox rename {src => jlox}/.gitignore (100%) rename {src => jlox}/CMakeLists.txt (68%) rename {src => jlox}/CMakePresets.json (100%) create mode 100755 jlox/jlox rename {src => jlox/src}/com/craftinginterpreters/CMakeLists.txt (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/.gitignore (100%) create mode 100644 jlox/src/com/craftinginterpreters/lox/.settings/org.eclipse.jdt.core.prefs rename {src => jlox/src}/com/craftinginterpreters/lox/AstPrinter.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/CMakeLists.txt (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/Environment.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/Interpreter.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/Lox.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/LoxCallable.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/LoxClass.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/LoxFunction.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/LoxInstance.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/Parser.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/Resolver.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/Return.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/RuntimeError.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/Scanner.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/Token.java (100%) rename {src => jlox/src}/com/craftinginterpreters/lox/TokenType.java (100%) rename {src => jlox/src}/com/craftinginterpreters/tool/CMakeLists.txt (100%) rename {src => jlox/src}/com/craftinginterpreters/tool/GenerateAst.java (100%) create mode 100644 src/fib.lox create mode 100644 src/test.lox diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4b8e4b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +jlox.sum +jlox.log diff --git a/Jenkinsfile b/Jenkinsfile index 24b123f..ef408d8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,10 +10,10 @@ pipeline { steps { cmakeBuild installation: 'InSearchPath', buildDir: 'build', - sourceDir: 'src', + sourceDir: 'jlox', steps: [[args: 'all']] - archiveArtifacts artifacts: 'build/com/craftinginterpreters/lox/Lox.jar', + archiveArtifacts artifacts: 'jlox/_build/com/craftinginterpreters/lox/Lox.jar', fingerprint: false, onlyIfSuccessful: true } diff --git a/jlox b/jlox deleted file mode 100755 index c6be2ea..0000000 --- a/jlox +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -/usr/bin/java -jar src/_build/com/craftinginterpreters/lox/Lox.jar "$@" diff --git a/src/.gitignore b/jlox/.gitignore similarity index 100% rename from src/.gitignore rename to jlox/.gitignore diff --git a/src/CMakeLists.txt b/jlox/CMakeLists.txt similarity index 68% rename from src/CMakeLists.txt rename to jlox/CMakeLists.txt index 52a7d57..da162c1 100644 --- a/src/CMakeLists.txt +++ b/jlox/CMakeLists.txt @@ -5,4 +5,4 @@ include(UseJava) project(Lox NONE) -add_subdirectory(com/craftinginterpreters) +add_subdirectory(src/com/craftinginterpreters) diff --git a/src/CMakePresets.json b/jlox/CMakePresets.json similarity index 100% rename from src/CMakePresets.json rename to jlox/CMakePresets.json diff --git a/jlox/jlox b/jlox/jlox new file mode 100755 index 0000000..6798309 --- /dev/null +++ b/jlox/jlox @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +java -jar "$(dirname "$0")/_build/src/com/craftinginterpreters/lox/Lox.jar" "$@" diff --git a/src/com/craftinginterpreters/CMakeLists.txt b/jlox/src/com/craftinginterpreters/CMakeLists.txt similarity index 100% rename from src/com/craftinginterpreters/CMakeLists.txt rename to jlox/src/com/craftinginterpreters/CMakeLists.txt diff --git a/src/com/craftinginterpreters/lox/.gitignore b/jlox/src/com/craftinginterpreters/lox/.gitignore similarity index 100% rename from src/com/craftinginterpreters/lox/.gitignore rename to jlox/src/com/craftinginterpreters/lox/.gitignore diff --git a/jlox/src/com/craftinginterpreters/lox/.settings/org.eclipse.jdt.core.prefs b/jlox/src/com/craftinginterpreters/lox/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..479bf4d --- /dev/null +++ b/jlox/src/com/craftinginterpreters/lox/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.formatter.lineSplit=80 diff --git a/src/com/craftinginterpreters/lox/AstPrinter.java b/jlox/src/com/craftinginterpreters/lox/AstPrinter.java similarity index 100% rename from src/com/craftinginterpreters/lox/AstPrinter.java rename to jlox/src/com/craftinginterpreters/lox/AstPrinter.java diff --git a/src/com/craftinginterpreters/lox/CMakeLists.txt b/jlox/src/com/craftinginterpreters/lox/CMakeLists.txt similarity index 100% rename from src/com/craftinginterpreters/lox/CMakeLists.txt rename to jlox/src/com/craftinginterpreters/lox/CMakeLists.txt diff --git a/src/com/craftinginterpreters/lox/Environment.java b/jlox/src/com/craftinginterpreters/lox/Environment.java similarity index 100% rename from src/com/craftinginterpreters/lox/Environment.java rename to jlox/src/com/craftinginterpreters/lox/Environment.java diff --git a/src/com/craftinginterpreters/lox/Interpreter.java b/jlox/src/com/craftinginterpreters/lox/Interpreter.java similarity index 100% rename from src/com/craftinginterpreters/lox/Interpreter.java rename to jlox/src/com/craftinginterpreters/lox/Interpreter.java diff --git a/src/com/craftinginterpreters/lox/Lox.java b/jlox/src/com/craftinginterpreters/lox/Lox.java similarity index 100% rename from src/com/craftinginterpreters/lox/Lox.java rename to jlox/src/com/craftinginterpreters/lox/Lox.java diff --git a/src/com/craftinginterpreters/lox/LoxCallable.java b/jlox/src/com/craftinginterpreters/lox/LoxCallable.java similarity index 100% rename from src/com/craftinginterpreters/lox/LoxCallable.java rename to jlox/src/com/craftinginterpreters/lox/LoxCallable.java diff --git a/src/com/craftinginterpreters/lox/LoxClass.java b/jlox/src/com/craftinginterpreters/lox/LoxClass.java similarity index 100% rename from src/com/craftinginterpreters/lox/LoxClass.java rename to jlox/src/com/craftinginterpreters/lox/LoxClass.java diff --git a/src/com/craftinginterpreters/lox/LoxFunction.java b/jlox/src/com/craftinginterpreters/lox/LoxFunction.java similarity index 100% rename from src/com/craftinginterpreters/lox/LoxFunction.java rename to jlox/src/com/craftinginterpreters/lox/LoxFunction.java diff --git a/src/com/craftinginterpreters/lox/LoxInstance.java b/jlox/src/com/craftinginterpreters/lox/LoxInstance.java similarity index 100% rename from src/com/craftinginterpreters/lox/LoxInstance.java rename to jlox/src/com/craftinginterpreters/lox/LoxInstance.java diff --git a/src/com/craftinginterpreters/lox/Parser.java b/jlox/src/com/craftinginterpreters/lox/Parser.java similarity index 100% rename from src/com/craftinginterpreters/lox/Parser.java rename to jlox/src/com/craftinginterpreters/lox/Parser.java diff --git a/src/com/craftinginterpreters/lox/Resolver.java b/jlox/src/com/craftinginterpreters/lox/Resolver.java similarity index 100% rename from src/com/craftinginterpreters/lox/Resolver.java rename to jlox/src/com/craftinginterpreters/lox/Resolver.java diff --git a/src/com/craftinginterpreters/lox/Return.java b/jlox/src/com/craftinginterpreters/lox/Return.java similarity index 100% rename from src/com/craftinginterpreters/lox/Return.java rename to jlox/src/com/craftinginterpreters/lox/Return.java diff --git a/src/com/craftinginterpreters/lox/RuntimeError.java b/jlox/src/com/craftinginterpreters/lox/RuntimeError.java similarity index 100% rename from src/com/craftinginterpreters/lox/RuntimeError.java rename to jlox/src/com/craftinginterpreters/lox/RuntimeError.java diff --git a/src/com/craftinginterpreters/lox/Scanner.java b/jlox/src/com/craftinginterpreters/lox/Scanner.java similarity index 100% rename from src/com/craftinginterpreters/lox/Scanner.java rename to jlox/src/com/craftinginterpreters/lox/Scanner.java diff --git a/src/com/craftinginterpreters/lox/Token.java b/jlox/src/com/craftinginterpreters/lox/Token.java similarity index 100% rename from src/com/craftinginterpreters/lox/Token.java rename to jlox/src/com/craftinginterpreters/lox/Token.java diff --git a/src/com/craftinginterpreters/lox/TokenType.java b/jlox/src/com/craftinginterpreters/lox/TokenType.java similarity index 100% rename from src/com/craftinginterpreters/lox/TokenType.java rename to jlox/src/com/craftinginterpreters/lox/TokenType.java diff --git a/src/com/craftinginterpreters/tool/CMakeLists.txt b/jlox/src/com/craftinginterpreters/tool/CMakeLists.txt similarity index 100% rename from src/com/craftinginterpreters/tool/CMakeLists.txt rename to jlox/src/com/craftinginterpreters/tool/CMakeLists.txt diff --git a/src/com/craftinginterpreters/tool/GenerateAst.java b/jlox/src/com/craftinginterpreters/tool/GenerateAst.java similarity index 100% rename from src/com/craftinginterpreters/tool/GenerateAst.java rename to jlox/src/com/craftinginterpreters/tool/GenerateAst.java diff --git a/src/fib.lox b/src/fib.lox new file mode 100644 index 0000000..dd6fb5e --- /dev/null +++ b/src/fib.lox @@ -0,0 +1,9 @@ +fun fib(n) { + if (n < 2) return n; + return fib(n - 1) + fib(n - 2); +} + +var before = clock(); +print fib(40); +var after = clock(); +print after - before; diff --git a/src/test.lox b/src/test.lox new file mode 100644 index 0000000..8810767 --- /dev/null +++ b/src/test.lox @@ -0,0 +1,7 @@ +class Bacon { +eat() { +print "Crunch crunch crunch!"; +} +} + +Bacon().eat(); diff --git a/testsuite/jlox.tests/tests.exp b/testsuite/jlox.tests/tests.exp index 9b9f620..bd41cfb 100644 --- a/testsuite/jlox.tests/tests.exp +++ b/testsuite/jlox.tests/tests.exp @@ -1,5 +1,5 @@ set test_name "Printing" -set command_line "./jlox" +set command_line "jlox/jlox" spawn $command_line send "print \"Hello, world!\";\n"