diff --git a/Makefile b/Makefile index 8d78eaa..8daa635 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ orig_test: build/exec/newt # New version newt.js: ${SRCS} - -rm build/* + -rm build/* >/dev/null $(RUNJS) bootstrap/newt.js src/Main.newt -o newt.js newt2.js: newt.js diff --git a/TODO.md b/TODO.md index c2b0e49..271e8c8 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,9 @@ ## TODO +- [ ] Increment row/col in printing, so vscode can click on compiler output - [ ] Raw is duplicated between Lib.Syntax and Lib.Compile, but not detected + - Maybe add qualified names - [ ] vscode - run newt when switching editors - [ ] who calls X? We can only do this scoped to the current context for now. Someday whole source dir - [ ] case split diff --git a/playground/TODO.md b/playground/TODO.md index 42778a1..8f8b586 100644 --- a/playground/TODO.md +++ b/playground/TODO.md @@ -1,6 +1,7 @@ ## Todo items for the playground +- [ ] switch to oxlint (dependency reduction) - [x] sample files - [x] codemirror migration - [ ] make sample files available for import diff --git a/src/Lib/CompileExp.newt b/src/Lib/CompileExp.newt index deaa062..54e72fb 100644 --- a/src/Lib/CompileExp.newt +++ b/src/Lib/CompileExp.newt @@ -52,6 +52,14 @@ lamArity : Tm -> Nat lamArity (Lam _ _ _ _ t) = S (lamArity t) lamArity _ = Z +compilePrimOp : String → List CExp → Maybe CExp +compilePrimOp "Prelude.addString" (x :: y :: Nil) = Just (CPrimOp "+" x y) +compilePrimOp "Prelude.addInt" (x :: y :: Nil) = Just (CPrimOp "+" x y) +compilePrimOp "Prelude.mulInt" (x :: y :: Nil) = Just (CPrimOp "*" x y) +compilePrimOp "Prelude.subInt" (x :: y :: Nil) = Just (CPrimOp "-" x y) +compilePrimOp "Prelude.divInt" (x :: y :: Nil) = Just (CPrimOp "|" (CPrimOp "/" x y) (CLit $ LInt 0)) +compilePrimOp _ _ = Nothing + -- This is how much we want to curry at top level -- leading lambda Arity is used for function defs and metas -- TODO - figure out how this will work with erasure @@ -125,6 +133,8 @@ compileTerm tm@(App _ _ _) = case funArgs tm of defs <- getRef Defs args' <- traverse compileTerm args arity <- arityForName fc nm + let (Nothing) = compilePrimOp (show nm) args' + | Just cexp => pure cexp case the (Maybe Def) $ lookupMap' nm defs of Just (DCon SuccCon _ _) => applySucc args' _ => apply nm args' Lin arity diff --git a/src/Prelude.newt b/src/Prelude.newt index bc41633..3edd424 100644 --- a/src/Prelude.newt +++ b/src/Prelude.newt @@ -259,9 +259,9 @@ infixr 7 _++_ class Concat a where _++_ : a → a → a -pfunc sconcat : String → String → String := `(x,y) => x + y` +pfunc addString : String → String → String := `(x,y) => x + y` instance Concat String where - _++_ = sconcat + _++_ = addString pfunc jsEq uses (True False) : ∀ a. a → a → Bool := `(_, a, b) => a == b ? Prelude_True : Prelude_False` @@ -872,14 +872,10 @@ instance ∀ a. {{Show a}} → Show (Maybe a) where show Nothing = "Nothing" show (Just a) = "Just {show a}" - --- TODO - pfunc isPrefixOf uses (True False): String → String → Bool := `(pfx, s) => s.startsWith(pfx) ? Prelude_True : Prelude_False` pfunc isSuffixOf uses (True False): String → String → Bool := `(pfx, s) => s.endsWith(pfx) ? Prelude_True : Prelude_False` pfunc strIndex : String → Int → Char := `(s, ix) => s[ix]` - instance ∀ a. {{Show a}} → Show (SnocList a) where show xs = show (xs <>> Nil)