port compiles hello world

This commit is contained in:
2025-01-04 21:07:25 -08:00
parent 6b1eef86a7
commit 0dbc5d5ee7
7 changed files with 26 additions and 14 deletions

View File

@@ -1,6 +1,11 @@
## TODO ## TODO
- [x] get port to run
- [ ] something goes terribly wrong with traverse_ and for_ (related to erasure, I think)
- [ ] sort through issues that came up during port
- [ ] don't use `take` - it's not stack safe
More comments in code! This is getting big enough that I need to re-find my bearings when fixing stuff. More comments in code! This is getting big enough that I need to re-find my bearings when fixing stuff.
- [ ] report info in case of error - [ ] report info in case of error

View File

@@ -7,7 +7,7 @@ import Prelude
ptype IORef : U U ptype IORef : U U
pfunc primNewIORef uses (MkIORes MkUnit) : a. a IO (IORef a) := `(_, a) => (w) => MkIORes(undefined, [a], w)` pfunc primNewIORef uses (MkIORes MkUnit) : a. a IO (IORef a) := `(_, a) => (w) => MkIORes(undefined, [a], w)`
pfunc primReadIORef uses (MkIORes MkUnit) : a. IORef a IO a := `(_, ref) => (w) => MkIORes(undefined, ref[0], w)` pfunc primReadIORef uses (MkIORes MkUnit) : a. IORef a IO a := `(_, ref) => (w) => MkIORes(undefined, ref[0], w)`
pfunc primWriteIORef uses (MkIORes MkUnit) : a. IORef a a IO a := `(_, ref, a) => (w) => { pfunc primWriteIORef uses (MkIORes MkUnit) : a. IORef a a IO Unit := `(_, ref, a) => (w) => {
ref[0] = a ref[0] = a
return MkIORes(undefined,MkUnit,w) return MkIORes(undefined,MkUnit,w)
}` }`
@@ -19,7 +19,7 @@ readIORef : ∀ io a. {{HasIO io}} → IORef a → io a
readIORef ref = liftIO $ primReadIORef ref readIORef ref = liftIO $ primReadIORef ref
writeIORef : io a. {{HasIO io}} IORef a -> a -> io Unit writeIORef : io a. {{HasIO io}} IORef a -> a -> io Unit
writeIORef ref a = liftIO $ writeIORef ref a writeIORef ref a = liftIO $ primWriteIORef ref a
-- Idris HasIO constraints to monad, we don't have those constraints yet -- Idris HasIO constraints to monad, we don't have those constraints yet
modifyIORef : io a. {{Monad io}} {{HasIO io}} IORef a -> (a -> a) -> io Unit modifyIORef : io a. {{Monad io}} {{HasIO io}} IORef a -> (a -> a) -> io Unit

7
done/Hello.newt Normal file
View File

@@ -0,0 +1,7 @@
module Hello
import Prelude
main : IO Unit
main = do
putStrLn "hello, world"

View File

@@ -122,7 +122,7 @@ processDecl ns (TypeSig fc names tm) = do
ty <- check (mkCtx fc) tm (VU fc) ty <- check (mkCtx fc) tm (VU fc)
ty <- zonk top 0 Nil ty ty <- zonk top 0 Nil ty
putStrLn "TypeSig \{unwords names} : \{render 90 $ pprint Nil ty}" putStrLn "TypeSig \{unwords names} : \{render 90 $ pprint Nil ty}"
for_ names $ \nm => setDef (QN ns nm) fc ty Axiom ignore $ for names $ \nm => setDef (QN ns nm) fc ty Axiom
-- Zoo4eg has metas in TypeSig, need to decide if I want to support leaving them unsolved here -- Zoo4eg has metas in TypeSig, need to decide if I want to support leaving them unsolved here
-- logMetas mstart -- logMetas mstart
@@ -444,7 +444,7 @@ processDecl ns (Record recordFC nm tele cname decls) = do
putStrLn "Decl:" putStrLn "Decl:"
putStrLn $ render 90 $ pretty decl putStrLn $ render 90 $ pretty decl
processDecl ns decl processDecl ns decl
for_ fields $ \case ignore $ for fields $ \case
(fc,name,ty) => do (fc,name,ty) => do
-- TODO dependency isn't handled yet -- TODO dependency isn't handled yet
-- we'll need to replace stuff like `len` with `len self`. -- we'll need to replace stuff like `len` with `len self`.

View File

@@ -106,7 +106,7 @@ processModule importFC base stk qn@(QN ns nm) = do
let (Right (imports, ops, toks)) = partialParse fn parseImports ops toks let (Right (imports, ops, toks)) = partialParse fn parseImports ops toks
| Left (err, toks) => exitFailure (showError src err) | Left (err, toks) => exitFailure (showError src err)
for_ imports $ \case for imports $ \case
MkImport fc name' => do MkImport fc name' => do
let (a,b) = unsnoc $ split1 name' "." let (a,b) = unsnoc $ split1 name' "."
let qname = QN a b let qname = QN a b
@@ -214,7 +214,7 @@ main' = do
let (arg0 :: args) = getArgs let (arg0 :: args) = getArgs
| _ => error emptyFC "error reading args" | _ => error emptyFC "error reading args"
(out, files) <- cmdLine args (out, files) <- cmdLine args
traverse_ processFile files traverse processFile files
when (elem "--top" args) $ \ _ => do when (elem "--top" args) $ \ _ => do
json <- jsonTopContext json <- jsonTopContext

View File

@@ -17,7 +17,7 @@ pfunc readFile uses (fs MkIORes Left Right) : (fn : String) -> IO (Either String
}` }`
-- I wonder if I should automatically `uses` the constructors in the types -- I wonder if I should automatically `uses` the constructors in the types
pfunc writeFile uses (fs MkIORes MkUnit) : String String IO (Either String Unit) := `(fn, content) => { pfunc writeFile uses (fs MkIORes MkUnit) : String String IO (Either String Unit) := `(fn, content) => (w) => {
let result let result
try { try {
fs.writeFileSync(fn, content, 'utf8') fs.writeFileSync(fn, content, 'utf8')

View File

@@ -185,15 +185,15 @@ instance Traversable List where
traverse f Nil = return Nil traverse f Nil = return Nil
traverse f (x :: xs) = return _::_ <*> f x <*> traverse f xs traverse f (x :: xs) = return _::_ <*> f x <*> traverse f xs
-- something goes madly wrong with erasure in here.
traverse_ : t f a b. {{Traversable t}} {{Applicative f}} (a f b) t a f Unit -- traverse_ : ∀ t f a b. {{Traversable t}} {{Applicative f}} → (a → f b) → t a → f Unit
traverse_ f xs = return (const MkUnit) <*> traverse f xs -- traverse_ f xs = return (const MkUnit) <*> traverse f xs
for : {t : U U} {f : U U} {{Traversable t}} {{appf : Applicative f}} {a : U} {b : U} t a (a f b) f (t b) for : {t : U U} {f : U U} {{Traversable t}} {{appf : Applicative f}} {a : U} {b : U} t a (a f b) f (t b)
for stuff fun = traverse fun stuff for stuff fun = traverse fun stuff
for_ : {t : U U} {f : U U} {{Traversable t}} {{appf : Applicative f}} {a : U} {b : U} t a (a f b) f Unit -- for_ : {t : U → U} {f : U → U} → {{Traversable t}} {{appf : Applicative f}} → {a : U} → {b : U} → t a → (a → f b) → f Unit
for_ stuff fun = return (const MkUnit) <*> traverse fun stuff -- for_ stuff fun = return (const MkUnit) <*> traverse fun stuff
instance Applicative Maybe where instance Applicative Maybe where
return a = Just a return a = Just a
@@ -330,8 +330,8 @@ pfunc intToNat uses (Z S) : Int -> Nat := `(n) => {
pfunc fastConcat : List String String := `(xs) => listToArray(undefined, xs).join('')` pfunc fastConcat uses (listToArray) : List String String := `(xs) => listToArray(undefined, xs).join('')`
pfunc replicate : Nat -> Char String := `(n,c) => c.repeat(natToInt(n))` pfunc replicate uses (natToInt) : Nat -> Char String := `(n,c) => c.repeat(natToInt(n))`
-- I don't want to use an empty type because it would be a proof of void -- I don't want to use an empty type because it would be a proof of void
ptype World ptype World