diff --git a/done/Lib/Parser/Impl.newt b/done/Lib/Parser/Impl.newt index 90f4132..7cbecee 100644 --- a/done/Lib/Parser/Impl.newt +++ b/done/Lib/Parser/Impl.newt @@ -84,7 +84,7 @@ getOps = P $ \ toks com ops col => OK ops toks com ops addOp : String -> Int -> Fixity -> Parser Unit addOp nm prec fix = P $ \ toks com ops col => - let parts = split "_" nm in + let parts = split nm "_" in case parts of "" :: key :: rule => OK MkUnit toks com (updateMap key (MkOp nm prec fix False rule) ops) key :: rule => OK MkUnit toks com (updateMap key (MkOp nm prec fix True rule) ops) diff --git a/done/Lib/Prettier.newt b/done/Lib/Prettier.newt index 91c980d..469bed2 100644 --- a/done/Lib/Prettier.newt +++ b/done/Lib/Prettier.newt @@ -29,6 +29,14 @@ flatten Line = Text " " flatten (Text str) = Text str flatten (Alt x y) = flatten x +noAlt : Doc -> Doc +noAlt Empty = Empty +noAlt (Seq x y) = Seq (noAlt x) (noAlt y) +noAlt (Nest i x) = noAlt x +noAlt Line = Line +noAlt (Text str) = Text str +noAlt (Alt x y) = noAlt x + group : Doc -> Doc group x = Alt (flatten x) x diff --git a/done/Main.newt b/done/Main.newt index 3692c70..4f4116d 100644 --- a/done/Main.newt +++ b/done/Main.newt @@ -55,7 +55,7 @@ writeSource fn = do ( "\"use strict\";" :: "const PiType = (h0, h1) => ({ tag: \"PiType\", h0, h1 })" :: Nil) - ++ map (render 90) docs + ++ map (render 90 ∘ noAlt) docs (Right _) <- liftIO {M} $ writeFile fn src | Left err => exitFailure (show err) -- (Right _) <- chmodRaw fn 493 | Left err => exitFailure (show err) @@ -150,6 +150,19 @@ baseDir (dirs :< d) (ns :< n) = if d == n else Left "module path doesn't match directory" baseDir Lin _ = Left "module path doesn't match directory" +showErrors : String -> String -> M Unit +showErrors fn src = do + top <- get + (Nil) <- liftIO {M} $ readIORef top.errors + | errors => do + ignore $ for errors $ \err => + putStrLn (showError src err) + -- if err.file == fn + -- then putStrLn (showError src err) + -- else putStrLn (showError "" err) + exitFailure "Compile failed" + pure MkUnit + processFile : String -> M Unit processFile fn = do @@ -180,7 +193,7 @@ processFile fn = do processDecl ("Prim" :: Nil) (PType emptyFC "Int" Nothing) processDecl ("Prim" :: Nil) (PType emptyFC "String" Nothing) processDecl ("Prim" :: Nil) (PType emptyFC "Char" Nothing) - let base = "port" -- FIXME + let base = "aoc2024" -- FIXME src <- processModule emptyFC base Nil (QN path modName') top <- get -- -- dumpContext top @@ -190,6 +203,7 @@ processFile fn = do -- for_ errors $ \err => -- putStrLn (showError src err) -- exitFailure "Compile failed" + showErrors fn src pure MkUnit diff --git a/done/Node.newt b/done/Node.newt index bb04eb6..e100881 100644 --- a/done/Node.newt +++ b/done/Node.newt @@ -30,5 +30,8 @@ pfunc writeFile uses (fs MkIORes MkUnit) : String → String → IO (Either Stri }` -- maybe System.exit or something, like the original putStrLn msg >> exitFailure -pfunc exitFailure : ∀ a. String → a := `(_, msg) => { throw new Error(msg) }` +pfunc exitFailure : ∀ a. String → a := `(_, msg) => { + console.log(msg); + process.exit(1); +}` diff --git a/scripts/aoc2 b/scripts/aoc2 new file mode 100755 index 0000000..85adbec --- /dev/null +++ b/scripts/aoc2 @@ -0,0 +1,35 @@ +#!/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 + 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" + +