diff --git a/TODO.md b/TODO.md index 5c29851..534dd0c 100644 --- a/TODO.md +++ b/TODO.md @@ -24,6 +24,7 @@ Syntax -> Parser.Impl ? - It would be nice if IO looked like imperative JS, but that might be a bit of a stretch. - [ ] LSP and/or more editor support + - [ ] would be nice to have "add missing cases" and "case split" - [ ] Probably need ranges for FC - [ ] leave an interactive process running - [ ] collect metadata or run through the serialization data diff --git a/src/Lib/Compile.newt b/src/Lib/Compile.newt index 452b080..1f3085d 100644 --- a/src/Lib/Compile.newt +++ b/src/Lib/Compile.newt @@ -36,6 +36,7 @@ data JSExp : U where Apply : JSExp -> List JSExp -> JSExp Var : String -> JSExp JLam : List String -> JSStmt Return -> JSExp + JPrimOp : String → JSExp → JSExp → JSExp JUndefined : JSExp Index : JSExp -> JSExp -> JSExp Dot : JSExp -> String -> JSExp @@ -134,6 +135,7 @@ termToJS env (CFun nms t) f = let (nms', env') = freshNames nms env in f $ JLam nms' (termToJS env' t JReturn) termToJS env (CRef nm) f = f $ Var (show nm) +termToJS env (CPrimOp op t u) f = termToJS env t $ \ t => termToJS env u $ \ u => f $ JPrimOp op t u termToJS env (CMeta k) f = f $ LitString "META \{show k}" termToJS env (CLit lit) f = f (litToJS lit) -- if it's a var, just use the original @@ -258,6 +260,7 @@ expToDoc (JLam nms body) = text "(" <+> commaSep (map jsIdent nms) <+> text ") = expToDoc JUndefined = text "null" expToDoc (Index obj ix) = expToDoc obj ++ text "(" ++ expToDoc ix ++ text " :: Nil)" expToDoc (Dot obj nm) = expToDoc obj ++ text "." ++ jsIdent nm +expToDoc (JPrimOp op t u) = text "(" ++ expToDoc t <+> text op <+> expToDoc u ++ text ")" caseBody : ∀ e. JSStmt e -> Doc caseBody stmt@(JReturn x) = nest 2 (line ++ stmtToDoc stmt) @@ -357,6 +360,7 @@ sortedNames defs qn = go Nil Nil qn getNames acc (CMeta _) = acc getNames acc (CBnd _) = acc getNames acc CErased = acc + getNames acc (CPrimOp op t u) = getNames (getNames acc t) u go : List QName → List QName → QName → List QName go loop acc qn = diff --git a/src/Lib/CompileExp.newt b/src/Lib/CompileExp.newt index f4bf75c..d79de36 100644 --- a/src/Lib/CompileExp.newt +++ b/src/Lib/CompileExp.newt @@ -42,6 +42,9 @@ data CExp : U where CConstr : Name -> List CExp -> CExp -- Raw javascript for `pfunc` CRaw : String -> List QName -> CExp + -- Need this for magic Nat + -- TODO - use for primitives too + CPrimOp : String → CExp → CExp -> CExp -- I'm counting Lam in the term for arity. This matches what I need in -- code gen. diff --git a/src/Lib/TCO.newt b/src/Lib/TCO.newt index a591892..dc61dba 100644 --- a/src/Lib/TCO.newt +++ b/src/Lib/TCO.newt @@ -39,6 +39,7 @@ tailNames CErased = Nil tailNames (CLit _) = Nil tailNames (CMeta _) = Nil tailNames (CRaw _ _) = Nil +tailNames (CPrimOp _ _ _) = Nil -- rewrite tail calls to return an object rewriteTailCalls : List QName → CExp → CExp