From 3c2615ecc1f8538c5d7df27d69061dfca84942f7 Mon Sep 17 00:00:00 2001 From: Steve Dunham Date: Sat, 15 Feb 2025 16:36:29 -0800 Subject: [PATCH] move idris version to orig and newt version to src. Development is being done on the newt version now. --- Makefile | 41 +++++++++++++++++++++++------- README.md | 18 ++++++++----- newt.ipkg | 2 +- {src => orig}/Lib/Common.idr | 0 {src => orig}/Lib/Compile.idr | 0 {src => orig}/Lib/CompileExp.idr | 0 {src => orig}/Lib/Elab.idr | 0 {src => orig}/Lib/Erasure.idr | 0 {src => orig}/Lib/Eval.idr | 0 {src => orig}/Lib/Parser.idr | 0 {src => orig}/Lib/Parser/Impl.idr | 0 {src => orig}/Lib/Prettier.idr | 0 {src => orig}/Lib/ProcessDecl.idr | 0 {src => orig}/Lib/Syntax.idr | 0 {src => orig}/Lib/Token.idr | 0 {src => orig}/Lib/Tokenizer.idr | 0 {src => orig}/Lib/TopContext.idr | 0 {src => orig}/Lib/Types.idr | 0 {src => orig}/Lib/Util.idr | 0 {src => orig}/Main.idr | 0 scripts/aoc | 3 ++- scripts/{aoc2 => orig_aoc} | 3 +-- scripts/orig_test | 31 ++++++++++++++++++++++ scripts/test | 8 +++++- serializer.ts | 2 +- {port => src}/Data/IORef.newt | 0 {port => src}/Data/Int.newt | 0 {port => src}/Data/List1.newt | 0 {port => src}/Data/SnocList.newt | 0 {port => src}/Data/SortedMap.newt | 0 {port => src}/Data/String.newt | 0 {port => src}/Lib/Common.newt | 0 {port => src}/Lib/Compile.newt | 0 {port => src}/Lib/CompileExp.newt | 0 {port => src}/Lib/Elab.newt | 0 {port => src}/Lib/Erasure.newt | 0 {port => src}/Lib/Eval.newt | 0 {port => src}/Lib/Parser.newt | 0 {port => src}/Lib/Parser/Impl.newt | 0 {port => src}/Lib/Prettier.newt | 0 {port => src}/Lib/ProcessDecl.newt | 0 {port => src}/Lib/Syntax.newt | 0 {port => src}/Lib/Token.newt | 0 {port => src}/Lib/Tokenizer.newt | 0 {port => src}/Lib/TopContext.newt | 0 {port => src}/Lib/Types.newt | 0 {port => src}/Lib/Util.newt | 0 {port => src}/Main.newt | 0 {port => src}/Node.newt | 0 {port => src}/Prelude.newt | 0 {port => src}/Serialize.newt | 0 {port => src}/Test/Parser.newt | 0 52 files changed, 86 insertions(+), 22 deletions(-) rename {src => orig}/Lib/Common.idr (100%) rename {src => orig}/Lib/Compile.idr (100%) rename {src => orig}/Lib/CompileExp.idr (100%) rename {src => orig}/Lib/Elab.idr (100%) rename {src => orig}/Lib/Erasure.idr (100%) rename {src => orig}/Lib/Eval.idr (100%) rename {src => orig}/Lib/Parser.idr (100%) rename {src => orig}/Lib/Parser/Impl.idr (100%) rename {src => orig}/Lib/Prettier.idr (100%) rename {src => orig}/Lib/ProcessDecl.idr (100%) rename {src => orig}/Lib/Syntax.idr (100%) rename {src => orig}/Lib/Token.idr (100%) rename {src => orig}/Lib/Tokenizer.idr (100%) rename {src => orig}/Lib/TopContext.idr (100%) rename {src => orig}/Lib/Types.idr (100%) rename {src => orig}/Lib/Util.idr (100%) rename {src => orig}/Main.idr (100%) rename scripts/{aoc2 => orig_aoc} (91%) create mode 100755 scripts/orig_test rename {port => src}/Data/IORef.newt (100%) rename {port => src}/Data/Int.newt (100%) rename {port => src}/Data/List1.newt (100%) rename {port => src}/Data/SnocList.newt (100%) rename {port => src}/Data/SortedMap.newt (100%) rename {port => src}/Data/String.newt (100%) rename {port => src}/Lib/Common.newt (100%) rename {port => src}/Lib/Compile.newt (100%) rename {port => src}/Lib/CompileExp.newt (100%) rename {port => src}/Lib/Elab.newt (100%) rename {port => src}/Lib/Erasure.newt (100%) rename {port => src}/Lib/Eval.newt (100%) rename {port => src}/Lib/Parser.newt (100%) rename {port => src}/Lib/Parser/Impl.newt (100%) rename {port => src}/Lib/Prettier.newt (100%) rename {port => src}/Lib/ProcessDecl.newt (100%) rename {port => src}/Lib/Syntax.newt (100%) rename {port => src}/Lib/Token.newt (100%) rename {port => src}/Lib/Tokenizer.newt (100%) rename {port => src}/Lib/TopContext.newt (100%) rename {port => src}/Lib/Types.newt (100%) rename {port => src}/Lib/Util.newt (100%) rename {port => src}/Main.newt (100%) rename {port => src}/Node.newt (100%) rename {port => src}/Prelude.newt (100%) rename {port => src}/Serialize.newt (100%) rename {port => src}/Test/Parser.newt (100%) diff --git a/Makefile b/Makefile index ac5e754..0966969 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,47 @@ -SRCS=$(shell find src -name "*.idr") +OSRCS=$(shell find orig -name "*.idr") +SRCS=$(shell find src -name "*.newt") .PHONY: -all: build/exec/newt build/exec/newt.js build/exec/newt.min.js +all: build/exec/newt build/exec/newt.js build/exec/newt.min.js newt.js -build/exec/newt: ${SRCS} +# Original idris version + +build/exec/newt: ${OSRCS} idris2 --build newt.ipkg -build/exec/newt.js: ${SRCS} - idris2 --cg node -o newt.js -p contrib -c src/Main.idr +build/exec/newt.js: ${OSRCS} + idris2 --cg node -o newt.js -p contrib -c orig/Main.idr -build/exec/newt.min.js: ${SRCS} - idris2 --cg node -o newt.min.js -p contrib -c src/Main.idr --directive minimal +build/exec/newt.min.js: ${OSRCS} + idris2 --cg node -o newt.min.js -p contrib -c orig/Main.idr --directive minimal -test: build/exec/newt +orig_aoctest: build/exec/newt + scripts/orig_aoc + +orig_test: build/exec/newt + scripts/orig_test + +# New version + +newt.js: ${SRCS} + bun run bootstrap/newt.js src/Main.newt -o newt.js + +newt2.js: newt.js + bun run newt.js src/Main.newt -o newt2.js + +newt3.js: newt2.js + bun run newt2.js src/Main.newt -o newt3.js + cmp newt2.js newt3.js + +test: newt.js scripts/test -aoctest: build/exec/newt +aoctest: newt.js scripts/aoc +# Misc + vscode: cd newt-vscode && vsce package && code --install-extension *.vsix diff --git a/README.md b/README.md index 34d91da..663ed4e 100644 --- a/README.md +++ b/README.md @@ -12,23 +12,27 @@ The web playground can be at https://dunhamsteve.github.io/newt. The top left co has a dropdown with some samples. Currently the web playground is using the Idris-built version of newt because most browsers lack tail call optimization. -The directory `port` contains a port of newt to itself. Currently it needs to be run by `bun` rather than `node` because `bun` does tail call optimization. +The directory `orig` contains the original version of newt written in Idris. It is used by the playground until TCO is added to newt. ## Sample code -- `port` contains a copy of newt written in newt -- `newt` contains miscellaneous files +- `src` contains a copy of newt written in newt +- `newt` contains miscellaneous samples - `aoc2024` contains solutions for 2024 Advent of Code in newt -- `tests` contains some test cases. +- `tests` contains test cases ## Building -There is a `Makefile` that builds both chez and javascript versions. They end up in -`build/exec` as usual. I've also added a `pack.toml`, so `pack build` also works. +The `Makefile` will build both the original Idris version of `newt`, which will end up in `build/exec` and the current version of newt, which will be `./newt.js`. There is a `pack.toml` file to allow building the original version of newt with `pack build`. + +Newt can also be built by running `bun run bootstrap/newt.js src/Main.newt -o newt.js`. There is a vscode extension in `newt-vscode`. Running `make vscode` will build and install it. The extension expects `build/exec/newt` to exist in the workspace. And `make test` will run a few black box tests. Currently it simply checks return codes, since the output format is in flux. -The web playground is in playground. +## Playground + +The web playground is found in the `playground` directory. It uses the original version of newt, which takes advantage of Idris' tail call optimization. + - `npm install` will pull down dependencies. - `./build` will build the web workers and install sample files (`make` must be run in root first). - `npx vite` will run the dev server. diff --git a/newt.ipkg b/newt.ipkg index e2db52e..5d0886b 100644 --- a/newt.ipkg +++ b/newt.ipkg @@ -36,7 +36,7 @@ main = Main -- name of executable executable = "newt" -- opts = -sourcedir = "src" +sourcedir = "orig" -- builddir = -- outputdir = diff --git a/src/Lib/Common.idr b/orig/Lib/Common.idr similarity index 100% rename from src/Lib/Common.idr rename to orig/Lib/Common.idr diff --git a/src/Lib/Compile.idr b/orig/Lib/Compile.idr similarity index 100% rename from src/Lib/Compile.idr rename to orig/Lib/Compile.idr diff --git a/src/Lib/CompileExp.idr b/orig/Lib/CompileExp.idr similarity index 100% rename from src/Lib/CompileExp.idr rename to orig/Lib/CompileExp.idr diff --git a/src/Lib/Elab.idr b/orig/Lib/Elab.idr similarity index 100% rename from src/Lib/Elab.idr rename to orig/Lib/Elab.idr diff --git a/src/Lib/Erasure.idr b/orig/Lib/Erasure.idr similarity index 100% rename from src/Lib/Erasure.idr rename to orig/Lib/Erasure.idr diff --git a/src/Lib/Eval.idr b/orig/Lib/Eval.idr similarity index 100% rename from src/Lib/Eval.idr rename to orig/Lib/Eval.idr diff --git a/src/Lib/Parser.idr b/orig/Lib/Parser.idr similarity index 100% rename from src/Lib/Parser.idr rename to orig/Lib/Parser.idr diff --git a/src/Lib/Parser/Impl.idr b/orig/Lib/Parser/Impl.idr similarity index 100% rename from src/Lib/Parser/Impl.idr rename to orig/Lib/Parser/Impl.idr diff --git a/src/Lib/Prettier.idr b/orig/Lib/Prettier.idr similarity index 100% rename from src/Lib/Prettier.idr rename to orig/Lib/Prettier.idr diff --git a/src/Lib/ProcessDecl.idr b/orig/Lib/ProcessDecl.idr similarity index 100% rename from src/Lib/ProcessDecl.idr rename to orig/Lib/ProcessDecl.idr diff --git a/src/Lib/Syntax.idr b/orig/Lib/Syntax.idr similarity index 100% rename from src/Lib/Syntax.idr rename to orig/Lib/Syntax.idr diff --git a/src/Lib/Token.idr b/orig/Lib/Token.idr similarity index 100% rename from src/Lib/Token.idr rename to orig/Lib/Token.idr diff --git a/src/Lib/Tokenizer.idr b/orig/Lib/Tokenizer.idr similarity index 100% rename from src/Lib/Tokenizer.idr rename to orig/Lib/Tokenizer.idr diff --git a/src/Lib/TopContext.idr b/orig/Lib/TopContext.idr similarity index 100% rename from src/Lib/TopContext.idr rename to orig/Lib/TopContext.idr diff --git a/src/Lib/Types.idr b/orig/Lib/Types.idr similarity index 100% rename from src/Lib/Types.idr rename to orig/Lib/Types.idr diff --git a/src/Lib/Util.idr b/orig/Lib/Util.idr similarity index 100% rename from src/Lib/Util.idr rename to orig/Lib/Util.idr diff --git a/src/Main.idr b/orig/Main.idr similarity index 100% rename from src/Main.idr rename to orig/Main.idr diff --git a/scripts/aoc b/scripts/aoc index e7c8842..85adbec 100755 --- a/scripts/aoc +++ b/scripts/aoc @@ -1,13 +1,14 @@ #!/bin/sh mkdir -p tmp echo "Test AoC 2024 solutions" +NCC="bun run newt.js" total=0 failed=0 for fn in aoc2024/Day*.newt; do total=$((total + 1)) echo Test $fn bn=$(basename $fn) - ./build/exec/newt $fn -o out.js > tmp/${bn}.compile + $NCC $fn -o out.js > tmp/${bn}.compile if [ $? != "0" ]; then echo Compile failed for $fn failed=$((failed + 1)) diff --git a/scripts/aoc2 b/scripts/orig_aoc similarity index 91% rename from scripts/aoc2 rename to scripts/orig_aoc index 85adbec..e7c8842 100755 --- a/scripts/aoc2 +++ b/scripts/orig_aoc @@ -1,14 +1,13 @@ #!/bin/sh mkdir -p tmp echo "Test AoC 2024 solutions" -NCC="bun run newt.js" total=0 failed=0 for fn in aoc2024/Day*.newt; do total=$((total + 1)) echo Test $fn bn=$(basename $fn) - $NCC $fn -o out.js > tmp/${bn}.compile + ./build/exec/newt $fn -o out.js > tmp/${bn}.compile if [ $? != "0" ]; then echo Compile failed for $fn failed=$((failed + 1)) diff --git a/scripts/orig_test b/scripts/orig_test new file mode 100755 index 0000000..d0bfd92 --- /dev/null +++ b/scripts/orig_test @@ -0,0 +1,31 @@ +#!/bin/sh +SAMPLES=$(find playground/samples -name "*.newt") +total=0 +failed=0 +for fn in tests/*.newt ; do + total=$((total + 1)) + echo Test $fn + bn=$(basename $fn) + ./build/exec/newt $fn -o out.js > tmp/${bn}.compile + if [ $? != "0" ]; then + echo Compile failed for $fn + failed=$((failed + 1)) + continue + fi + # if there is a golden file, run the code and compare output + if [ -f ${fn}.golden ]; then + bun run out.js > tmp/${bn}.out + if [ $? != "0" ]; then + echo Run failed for $fn + failed=$((failed + 1)) + continue + fi + if ! diff -q tmp/${bn}.out ${fn}.golden; then + echo "Output mismatch for $fn" + failed=$((failed + 1)) + fi + fi +done +echo "Total tests: $total" +echo "Failed tests: $failed" + diff --git a/scripts/test b/scripts/test index d0bfd92..f4d27a2 100755 --- a/scripts/test +++ b/scripts/test @@ -1,12 +1,18 @@ #!/bin/sh SAMPLES=$(find playground/samples -name "*.newt") +NCC="bun run newt.js" total=0 failed=0 for fn in tests/*.newt ; do total=$((total + 1)) echo Test $fn bn=$(basename $fn) - ./build/exec/newt $fn -o out.js > tmp/${bn}.compile + if [ -f ${fn}.golden ]; then + $NCC $fn -o out.js > tmp/${bn}.compile + else + # we've dropped support for compiling things without main for now. + $NCC $fn > tmp/${bn}.compile + fi if [ $? != "0" ]; then echo Compile failed for $fn failed=$((failed + 1)) diff --git a/serializer.ts b/serializer.ts index 7333ce6..161a58d 100644 --- a/serializer.ts +++ b/serializer.ts @@ -1,5 +1,5 @@ // Experimental serializer / deserializer for modules -// not completely wired in yet, serialization is running. +// not completely wired in yet, serialization is running, deserialization is not const END = 0; const LIST = 1; diff --git a/port/Data/IORef.newt b/src/Data/IORef.newt similarity index 100% rename from port/Data/IORef.newt rename to src/Data/IORef.newt diff --git a/port/Data/Int.newt b/src/Data/Int.newt similarity index 100% rename from port/Data/Int.newt rename to src/Data/Int.newt diff --git a/port/Data/List1.newt b/src/Data/List1.newt similarity index 100% rename from port/Data/List1.newt rename to src/Data/List1.newt diff --git a/port/Data/SnocList.newt b/src/Data/SnocList.newt similarity index 100% rename from port/Data/SnocList.newt rename to src/Data/SnocList.newt diff --git a/port/Data/SortedMap.newt b/src/Data/SortedMap.newt similarity index 100% rename from port/Data/SortedMap.newt rename to src/Data/SortedMap.newt diff --git a/port/Data/String.newt b/src/Data/String.newt similarity index 100% rename from port/Data/String.newt rename to src/Data/String.newt diff --git a/port/Lib/Common.newt b/src/Lib/Common.newt similarity index 100% rename from port/Lib/Common.newt rename to src/Lib/Common.newt diff --git a/port/Lib/Compile.newt b/src/Lib/Compile.newt similarity index 100% rename from port/Lib/Compile.newt rename to src/Lib/Compile.newt diff --git a/port/Lib/CompileExp.newt b/src/Lib/CompileExp.newt similarity index 100% rename from port/Lib/CompileExp.newt rename to src/Lib/CompileExp.newt diff --git a/port/Lib/Elab.newt b/src/Lib/Elab.newt similarity index 100% rename from port/Lib/Elab.newt rename to src/Lib/Elab.newt diff --git a/port/Lib/Erasure.newt b/src/Lib/Erasure.newt similarity index 100% rename from port/Lib/Erasure.newt rename to src/Lib/Erasure.newt diff --git a/port/Lib/Eval.newt b/src/Lib/Eval.newt similarity index 100% rename from port/Lib/Eval.newt rename to src/Lib/Eval.newt diff --git a/port/Lib/Parser.newt b/src/Lib/Parser.newt similarity index 100% rename from port/Lib/Parser.newt rename to src/Lib/Parser.newt diff --git a/port/Lib/Parser/Impl.newt b/src/Lib/Parser/Impl.newt similarity index 100% rename from port/Lib/Parser/Impl.newt rename to src/Lib/Parser/Impl.newt diff --git a/port/Lib/Prettier.newt b/src/Lib/Prettier.newt similarity index 100% rename from port/Lib/Prettier.newt rename to src/Lib/Prettier.newt diff --git a/port/Lib/ProcessDecl.newt b/src/Lib/ProcessDecl.newt similarity index 100% rename from port/Lib/ProcessDecl.newt rename to src/Lib/ProcessDecl.newt diff --git a/port/Lib/Syntax.newt b/src/Lib/Syntax.newt similarity index 100% rename from port/Lib/Syntax.newt rename to src/Lib/Syntax.newt diff --git a/port/Lib/Token.newt b/src/Lib/Token.newt similarity index 100% rename from port/Lib/Token.newt rename to src/Lib/Token.newt diff --git a/port/Lib/Tokenizer.newt b/src/Lib/Tokenizer.newt similarity index 100% rename from port/Lib/Tokenizer.newt rename to src/Lib/Tokenizer.newt diff --git a/port/Lib/TopContext.newt b/src/Lib/TopContext.newt similarity index 100% rename from port/Lib/TopContext.newt rename to src/Lib/TopContext.newt diff --git a/port/Lib/Types.newt b/src/Lib/Types.newt similarity index 100% rename from port/Lib/Types.newt rename to src/Lib/Types.newt diff --git a/port/Lib/Util.newt b/src/Lib/Util.newt similarity index 100% rename from port/Lib/Util.newt rename to src/Lib/Util.newt diff --git a/port/Main.newt b/src/Main.newt similarity index 100% rename from port/Main.newt rename to src/Main.newt diff --git a/port/Node.newt b/src/Node.newt similarity index 100% rename from port/Node.newt rename to src/Node.newt diff --git a/port/Prelude.newt b/src/Prelude.newt similarity index 100% rename from port/Prelude.newt rename to src/Prelude.newt diff --git a/port/Serialize.newt b/src/Serialize.newt similarity index 100% rename from port/Serialize.newt rename to src/Serialize.newt diff --git a/port/Test/Parser.newt b/src/Test/Parser.newt similarity index 100% rename from port/Test/Parser.newt rename to src/Test/Parser.newt