summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2024-05-27 00:11:26 -0300
committerSoniEx2 <endermoneymod@gmail.com>2024-05-27 00:11:26 -0300
commite62ec5ac36188cb12411a8c720daebce77ecf645 (patch)
treeb1a2ce8e95ffc6e92ee31c1e271b0fcafe8a0b2f
parent9dea1c26b487ae723d99ba1e5e5887b09aec87dd (diff)
Set up a "build system"
-rw-r--r--.gitignore1
-rw-r--r--README.md2
-rwxr-xr-xbuild.sh63
-rw-r--r--src/bin/cratera.lua21
-rw-r--r--src/bin/printtokens.lua (renamed from printtokens.lua)3
-rw-r--r--src/cratera/compiler.lua (renamed from cratera/compiler.lua)0
-rw-r--r--src/cratera/init.lua (renamed from cratera.lua)2
-rw-r--r--src/cratera/loader.lua19
-rw-r--r--src/cratera/luatokens.lua (renamed from cratera/luatokens.lua)0
-rw-r--r--src/cratera/parser.lua (renamed from cratera/parser.lua)0
-rw-r--r--test/testbc.lua (renamed from testbc.lua)6
-rw-r--r--test/testc.lua (renamed from testc.lua)4
-rw-r--r--test/testp.lua (renamed from testp.lua)2
-rw-r--r--test/tests.cratera (renamed from tests.cratera)0
14 files changed, 110 insertions, 13 deletions
diff --git a/.gitignore b/.gitignore
index 731e4eb..6a3417b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1 @@
 /out/
-/testsdump.cratera
diff --git a/README.md b/README.md
index 30f6946..dd99d84 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ and, indeed, `mytable` is only evaluated once.
 Usage
 -----
 
-To use the Cratera Compiler, simply put the cratera directory somewhere in the Lua search path, and `require "cratera"`. It's compatible with Lua 5.1, Lua 5.2, and Lua 5.3.
+To use Cratera Compiler, simply put the cratera directory somewhere in the Lua search path, and `require "cratera"`. It's compatible with Lua 5.1, Lua 5.2, and Lua 5.3.
 It returns a table with the following API functions:
 
 ### `cratera.load(chunk, [chunkname, ...])`
diff --git a/build.sh b/build.sh
index 173fe8c..cdff7bd 100755
--- a/build.sh
+++ b/build.sh
@@ -1,5 +1,60 @@
 #!/bin/sh
-mkdir -p out/cratera/
-# worst tool for this job
-cp -r cratera/* out/cratera/
-cp cratera.lua out/cratera/init.lua
+
+LUA_INTERPRETER=${LUA_INTERPRETER:=lua}
+case "$LUA_INTERPRETER" in
+	/*)
+		;;
+	*)
+		ENV_WRAPPER=${ENV_WRAPPER:="$(command -v env)"}
+		;;
+esac
+
+do_build() {
+	mkdir -p out/lua/cratera/ || exit 1
+	mkdir -p out/bin || exit 1
+	# worst tool for this job
+	cp -r src/cratera/* out/lua/cratera/ || exit 1
+	if [ "$ENV_WRAPPER" = '' ]; then
+		printf "#!%s\n" "$LUA_INTERPRETER" >out/bin/cratera || exit 1
+	else
+		printf "#!%s %s\n" "$ENV_WRAPPER" "$LUA_INTERPRETER" >out/bin/cratera || exit 1
+	fi
+	cat src/bin/cratera.lua >>out/bin/cratera || exit 1
+	chmod +x out/bin/cratera || exit 1
+}
+
+do_test() {
+	# FIXME this does NOT handle LUA_PATH correctly.
+	# FIXME nor LUA_INIT.
+	do_build || exit 1
+	mkdir -p out/test || exit 2
+	# these tests use the regular lua interpreter
+	LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' "$LUA_INTERPRETER" test/testp.lua || exit 2
+	LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' "$LUA_INTERPRETER" test/testc.lua || exit 2
+	LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' "$LUA_INTERPRETER" test/testbc.lua || exit 2
+	# these tests use the cratera interpreter
+	LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' out/bin/cratera test/tests.cratera || exit 2
+}
+
+case "$1" in
+	-h|--help|help)
+		echo 'The Cratera "Build System"'
+		echo 'To build, use './build.sh build'. Files will be put in out/.'
+		echo 'To run tests, use './build.sh test'.'
+		echo 'The currently selected Lua interpreter is:'
+		printf '    LUA_INTERPRETER=%s' "$LUA_INTERPRETER"
+		echo ''
+		echo 'The currently selected env wrapper is:'
+		printf '    ENV_WRAPPER=%s' "$ENV_WRAPPER"
+		echo ''
+		;;
+	test)
+		do_test || exit $?
+		;;
+	build|'')
+		do_build || exit $?
+		;;
+	*)
+		echo 'sorry'
+		;;
+esac
diff --git a/src/bin/cratera.lua b/src/bin/cratera.lua
new file mode 100644
index 0000000..fa94e96
--- /dev/null
+++ b/src/bin/cratera.lua
@@ -0,0 +1,21 @@
+--[[
+    Cratera Interpreter
+    Copyright (C) 2024  Soni L.
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
+--]]
+
+local cratera = require "cratera"
+
+error("not implemented")
diff --git a/printtokens.lua b/src/bin/printtokens.lua
index 2cc6125..49827da 100644
--- a/printtokens.lua
+++ b/src/bin/printtokens.lua
@@ -16,6 +16,9 @@
     along with this program.  If not, see <https://www.gnu.org/licenses/>.
 --]]
 
+-- this isn't supposed to be installed or anything it's just a basic CLI to
+-- print a lua or cratera file as a token stream.
+
 local parser = require "cratera.parser"
 
 -- CLI argument rules
diff --git a/cratera/compiler.lua b/src/cratera/compiler.lua
index 2f4a998..2f4a998 100644
--- a/cratera/compiler.lua
+++ b/src/cratera/compiler.lua
diff --git a/cratera.lua b/src/cratera/init.lua
index 6c0335b..bac3f53 100644
--- a/cratera.lua
+++ b/src/cratera/init.lua
@@ -1,6 +1,6 @@
 --[[
     Cratera Compiler - pure-Lua Cratera-to-Lua transpiler
-    Copyright (C) 2019  Soni L.
+    Copyright (C) 2019, 2024  Soni L.
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU Affero General Public License as published by
diff --git a/src/cratera/loader.lua b/src/cratera/loader.lua
new file mode 100644
index 0000000..02697ac
--- /dev/null
+++ b/src/cratera/loader.lua
@@ -0,0 +1,19 @@
+--[[
+    The Cratera Loader
+    Copyright (C) 2024  Soni L.
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
+--]]
+
+-- TODO
diff --git a/cratera/luatokens.lua b/src/cratera/luatokens.lua
index 90d0c61..90d0c61 100644
--- a/cratera/luatokens.lua
+++ b/src/cratera/luatokens.lua
diff --git a/cratera/parser.lua b/src/cratera/parser.lua
index ade568c..ade568c 100644
--- a/cratera/parser.lua
+++ b/src/cratera/parser.lua
diff --git a/testbc.lua b/test/testbc.lua
index 7b4a6e2..05a36cc 100644
--- a/testbc.lua
+++ b/test/testbc.lua
@@ -11,7 +11,7 @@ local function stream(filename, mode)
 end
 
 -- load tests, streaming
-local tests = assert(cratera.load(stream("tests.cratera", "rb")))
+local tests = assert(cratera.load(stream("test/tests.cratera", "rb")))
 
 -- dump tests
 local testsdump = string.dump(tests)
@@ -20,10 +20,10 @@ local testsdump = string.dump(tests)
 assert(cratera.load(testsdump))()
 
 -- output to a file
-local file = io.open("testsdump.cratera", "wb")
+local file = io.open("out/test/testsdump.cratera", "wb")
 assert(file:write(testsdump))
 assert(file:flush())
 assert(file:close())
 
 -- load again, streaming, precompiled, and from a file
-assert(cratera.load(stream("testsdump.cratera", "rb")))()
+assert(cratera.load(stream("out/test/testsdump.cratera", "rb")))()
diff --git a/testc.lua b/test/testc.lua
index e9a793c..72ed393 100644
--- a/testc.lua
+++ b/test/testc.lua
@@ -27,7 +27,7 @@ local cratera = require "cratera"
 assert(printr(cratera.load("")))()
 
 -- second test: does it handle lua code properly?
-assert(printr(cratera.load(io.open("cratera/compiler.lua"):read("*a"))))()
+assert(printr(cratera.load(io.open("src/cratera/compiler.lua"):read("*a"))))()
 
 print("-----------------------------------------------------------------------------------------------------------------------")
 print(table.concat(collect))
@@ -35,7 +35,7 @@ print(table.concat(collect))
 collect = {}
 
 -- third test: does it handle cratera tests properly?
-assert(printr(cratera.load(io.open("tests.cratera"):read("*a"))))()
+assert(printr(cratera.load(io.open("test/tests.cratera"):read("*a"))))()
 
 print("-----------------------------------------------------------------------------------------------------------------------")
 print(table.concat(collect))
diff --git a/testp.lua b/test/testp.lua
index 4b6434a..1ab5304 100644
--- a/testp.lua
+++ b/test/testp.lua
@@ -454,7 +454,7 @@ end -- numbers
 
 do -- FUCK
     local luatokens = require "cratera.luatokens"
-    local luatokens_file = io.open("./cratera/luatokens.lua", "r")
+    local luatokens_file = io.open("./src/cratera/luatokens.lua", "r")
     local tokens = luatokens.defs
     local state, err, etoken, estate = parser.parse(tokens, function() return luatokens_file:read(8192) end)
     local case = case()
diff --git a/tests.cratera b/test/tests.cratera
index fd97917..fd97917 100644
--- a/tests.cratera
+++ b/test/tests.cratera