diff --git a/newt/Prelude.newt b/newt/Prelude.newt index 76b58ea..a920f47 100644 --- a/newt/Prelude.newt +++ b/newt/Prelude.newt @@ -532,9 +532,11 @@ drop Z xs = xs drop (S k) (x :: xs) = drop k xs take : ∀ a. Nat -> List a -> List a -take Z xs = Nil -take _ Nil = Nil -take (S k) (x :: xs) = x :: take k xs +take {a} n xs = go n xs Lin + where + go : Nat → List a → SnocList a → List a + go (S k) (x :: xs) acc = go k xs (acc :< x) + go _ _ acc = acc <>> Nil getAt : ∀ a. Nat → List a → Maybe a getAt _ Nil = Nothing @@ -880,8 +882,11 @@ getAt' : ∀ a. Int → List a → Maybe a getAt' i xs = getAt (cast i) xs length' : ∀ a. List a → Int -length' Nil = 0 -length' (x :: xs) = 1 + length' xs +length' xs = go xs 0 + where + go : ∀ a. List a → Int → Int + go Nil acc = acc + go (x :: xs) acc = go xs (acc + 1) unlines : List String → String unlines lines = joinBy "\n" lines diff --git a/port/Lib/CompileExp.newt b/port/Lib/CompileExp.newt index 0283008..acdc900 100644 --- a/port/Lib/CompileExp.newt +++ b/port/Lib/CompileExp.newt @@ -138,7 +138,7 @@ compileTerm (UU _) = pure $ CRef "U" compileTerm (Pi _ nm icit rig t u) = do t' <- compileTerm t u' <- compileTerm u - pure $ CApp (CRef "PiType") (t' :: u' :: Nil) 0 + pure $ CApp (CRef "PiType") (t' :: CLam nm u' :: Nil) 0 compileTerm (Case _ t alts) = do t' <- compileTerm t alts' <- for alts $ \case diff --git a/port/Lib/Elab.newt b/port/Lib/Elab.newt index 8e99bc8..b4b0513 100644 --- a/port/Lib/Elab.newt +++ b/port/Lib/Elab.newt @@ -257,7 +257,7 @@ solveAutos mstart = do top <- get mc <- readIORef top.metaCtx let mlen = length' mc.metas - mstart - res <- run $ filter isAuto (take (cast mlen) mc.metas) + res <- run $ filter isAuto (ite (mstart == 0) mc.metas $ take (cast mlen) mc.metas) if res then solveAutos mstart else pure MkUnit where isAuto : MetaEntry -> Bool diff --git a/port/Lib/Prettier.newt b/port/Lib/Prettier.newt index 469bed2..700c893 100644 --- a/port/Lib/Prettier.newt +++ b/port/Lib/Prettier.newt @@ -80,7 +80,7 @@ class Pretty a where render : Int -> Doc -> String -render w x = layout (best w 0 x) Lin +render w x = layout (best w 0 (noAlt x)) Lin instance Semigroup Doc where x <+> y = Seq x (Seq (Text " ") y) diff --git a/port/Main.newt b/port/Main.newt index 4f4116d..a5cb62d 100644 --- a/port/Main.newt +++ b/port/Main.newt @@ -193,7 +193,8 @@ 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 = "aoc2024" -- FIXME + -- let base = "aoc2024" -- FIXME + let base = "port" -- FIXME src <- processModule emptyFC base Nil (QN path modName') top <- get -- -- dumpContext top diff --git a/scripts/translate.sh b/scripts/translate.sh index d942c88..00b1df4 100755 --- a/scripts/translate.sh +++ b/scripts/translate.sh @@ -2,10 +2,10 @@ # script to translate a file from idris to newt # this is just a first pass, hopefully -mkdir -p port +mkdir -p xlate find src -type f -name '*.idr' | while read -r file; do - output_file="port/${file#src/}" + output_file="xlate/${file#src/}" output_file="${output_file%.idr}.newt" mkdir -p "$(dirname "$output_file")" if [[ ! -f "$output_file" ]]; then @@ -49,4 +49,4 @@ find src -type f -name '*.idr' | while read -r file; do ' "$file" > "$output_file" fi done -rsync -av done/ port +#rsync -av done/ xlate