primop in compiler
This commit is contained in:
1
TODO.md
1
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.
|
- 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
|
- [ ] LSP and/or more editor support
|
||||||
|
- [ ] would be nice to have "add missing cases" and "case split"
|
||||||
- [ ] Probably need ranges for FC
|
- [ ] Probably need ranges for FC
|
||||||
- [ ] leave an interactive process running
|
- [ ] leave an interactive process running
|
||||||
- [ ] collect metadata or run through the serialization data
|
- [ ] collect metadata or run through the serialization data
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ data JSExp : U where
|
|||||||
Apply : JSExp -> List JSExp -> JSExp
|
Apply : JSExp -> List JSExp -> JSExp
|
||||||
Var : String -> JSExp
|
Var : String -> JSExp
|
||||||
JLam : List String -> JSStmt Return -> JSExp
|
JLam : List String -> JSStmt Return -> JSExp
|
||||||
|
JPrimOp : String → JSExp → JSExp → JSExp
|
||||||
JUndefined : JSExp
|
JUndefined : JSExp
|
||||||
Index : JSExp -> JSExp -> JSExp
|
Index : JSExp -> JSExp -> JSExp
|
||||||
Dot : JSExp -> String -> JSExp
|
Dot : JSExp -> String -> JSExp
|
||||||
@@ -134,6 +135,7 @@ termToJS env (CFun nms t) f =
|
|||||||
let (nms', env') = freshNames nms env
|
let (nms', env') = freshNames nms env
|
||||||
in f $ JLam nms' (termToJS env' t JReturn)
|
in f $ JLam nms' (termToJS env' t JReturn)
|
||||||
termToJS env (CRef nm) f = f $ Var (show nm)
|
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 (CMeta k) f = f $ LitString "META \{show k}"
|
||||||
termToJS env (CLit lit) f = f (litToJS lit)
|
termToJS env (CLit lit) f = f (litToJS lit)
|
||||||
-- if it's a var, just use the original
|
-- 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 JUndefined = text "null"
|
||||||
expToDoc (Index obj ix) = expToDoc obj ++ text "(" ++ expToDoc ix ++ text " :: Nil)"
|
expToDoc (Index obj ix) = expToDoc obj ++ text "(" ++ expToDoc ix ++ text " :: Nil)"
|
||||||
expToDoc (Dot obj nm) = expToDoc obj ++ text "." ++ jsIdent nm
|
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 : ∀ e. JSStmt e -> Doc
|
||||||
caseBody stmt@(JReturn x) = nest 2 (line ++ stmtToDoc stmt)
|
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 (CMeta _) = acc
|
||||||
getNames acc (CBnd _) = acc
|
getNames acc (CBnd _) = acc
|
||||||
getNames acc CErased = 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 : List QName → List QName → QName → List QName
|
||||||
go loop acc qn =
|
go loop acc qn =
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ data CExp : U where
|
|||||||
CConstr : Name -> List CExp -> CExp
|
CConstr : Name -> List CExp -> CExp
|
||||||
-- Raw javascript for `pfunc`
|
-- Raw javascript for `pfunc`
|
||||||
CRaw : String -> List QName -> CExp
|
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
|
-- I'm counting Lam in the term for arity. This matches what I need in
|
||||||
-- code gen.
|
-- code gen.
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ tailNames CErased = Nil
|
|||||||
tailNames (CLit _) = Nil
|
tailNames (CLit _) = Nil
|
||||||
tailNames (CMeta _) = Nil
|
tailNames (CMeta _) = Nil
|
||||||
tailNames (CRaw _ _) = Nil
|
tailNames (CRaw _ _) = Nil
|
||||||
|
tailNames (CPrimOp _ _ _) = Nil
|
||||||
|
|
||||||
-- rewrite tail calls to return an object
|
-- rewrite tail calls to return an object
|
||||||
rewriteTailCalls : List QName → CExp → CExp
|
rewriteTailCalls : List QName → CExp → CExp
|
||||||
|
|||||||
Reference in New Issue
Block a user