encode enum as string
This commit is contained in:
4
Makefile
4
Makefile
@@ -16,7 +16,7 @@ build/exec/newt: ${OSRCS}
|
|||||||
idris2 --build newt.ipkg
|
idris2 --build newt.ipkg
|
||||||
|
|
||||||
build/exec/newt.js: ${OSRCS}
|
build/exec/newt.js: ${OSRCS}
|
||||||
rm build/*
|
-rm build/*
|
||||||
idris2 --cg node -o newt.js -p contrib -c orig/Main.idr
|
idris2 --cg node -o newt.js -p contrib -c orig/Main.idr
|
||||||
|
|
||||||
build/exec/newt.min.js: ${OSRCS}
|
build/exec/newt.min.js: ${OSRCS}
|
||||||
@@ -34,7 +34,7 @@ newt.js: ${SRCS}
|
|||||||
$(RUNJS) bootstrap/newt.js src/Main.newt -o newt.js
|
$(RUNJS) bootstrap/newt.js src/Main.newt -o newt.js
|
||||||
|
|
||||||
newt2.js: newt.js
|
newt2.js: newt.js
|
||||||
rm build/*
|
-rm build/*
|
||||||
$(RUNJS) newt.js src/Main.newt -o newt2.js
|
$(RUNJS) newt.js src/Main.newt -o newt2.js
|
||||||
|
|
||||||
newt3.js: newt2.js
|
newt3.js: newt2.js
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -91,11 +91,16 @@ apply t ts acc Z = go (CApp t (acc <>> Nil) 0) ts
|
|||||||
|
|
||||||
compileTerm (Bnd _ k) = pure $ CBnd k
|
compileTerm (Bnd _ k) = pure $ CBnd k
|
||||||
-- need to eta expand to arity
|
-- need to eta expand to arity
|
||||||
compileTerm t@(Ref fc nm) = do
|
compileTerm t@(Ref fc nm@(QN _ tag)) = do
|
||||||
arity <- arityForName fc nm
|
arity <- arityForName fc nm
|
||||||
|
defs <- getRef Defs
|
||||||
case arity of
|
case arity of
|
||||||
-- we don't need to curry functions that take one argument
|
-- we don't need to curry functions that take one argument
|
||||||
(S Z) => pure $ CRef nm
|
(S Z) => pure $ CRef nm
|
||||||
|
Z =>
|
||||||
|
case the (Maybe Def) $ lookupMap' nm defs of
|
||||||
|
(Just (DCon EnumCon _ _)) => pure $ CLit $ LString tag
|
||||||
|
_ => pure $ CRef nm
|
||||||
_ => apply (CRef nm) Nil Lin arity
|
_ => apply (CRef nm) Nil Lin arity
|
||||||
|
|
||||||
compileTerm (Meta _ k) = pure $ CRef (QN Nil "meta$\{show k}") -- FIXME should be exception
|
compileTerm (Meta _ k) = pure $ CRef (QN Nil "meta$\{show k}") -- FIXME should be exception
|
||||||
@@ -125,7 +130,11 @@ compileTerm (Case _ t alts) = do
|
|||||||
alts' <- for alts $ \case
|
alts' <- for alts $ \case
|
||||||
CaseDefault tm => CDefAlt <$> compileTerm tm
|
CaseDefault tm => CDefAlt <$> compileTerm tm
|
||||||
-- we use the base name for the tag, some primitives assume this
|
-- we use the base name for the tag, some primitives assume this
|
||||||
CaseCons (QN ns nm) args tm => CConAlt nm args <$> compileTerm tm
|
CaseCons qn@(QN ns nm) args tm => do
|
||||||
|
defs <- getRef Defs
|
||||||
|
case the (Maybe Def) $ lookupMap' qn defs of
|
||||||
|
Just (DCon EnumCon _ _) => CLitAlt (LString nm) <$> compileTerm tm
|
||||||
|
_ => CConAlt nm args <$> compileTerm tm
|
||||||
CaseLit lit tm => CLitAlt lit <$> compileTerm tm
|
CaseLit lit tm => CLitAlt lit <$> compileTerm tm
|
||||||
pure $ CCase t' alts'
|
pure $ CCase t' alts'
|
||||||
compileTerm (Lit _ lit) = pure $ CLit lit
|
compileTerm (Lit _ lit) = pure $ CLit lit
|
||||||
@@ -149,6 +158,7 @@ compileFun tm = go tm Lin
|
|||||||
|
|
||||||
-- What are the Defs used for above? (Arity for name)
|
-- What are the Defs used for above? (Arity for name)
|
||||||
compileDCon : QName → ConInfo → Int → CExp
|
compileDCon : QName → ConInfo → Int → CExp
|
||||||
|
compileDCon (QN _ nm) EnumCon 0 = CLit $ LString nm
|
||||||
compileDCon (QN _ nm) info 0 = CConstr nm Nil
|
compileDCon (QN _ nm) info 0 = CConstr nm Nil
|
||||||
compileDCon (QN _ nm) info arity =
|
compileDCon (QN _ nm) info arity =
|
||||||
let args = map (\k => "h\{show k}") (range 0 arity) in
|
let args = map (\k => "h\{show k}") (range 0 arity) in
|
||||||
|
|||||||
@@ -435,8 +435,8 @@ processData ns fc nm ty cons = do
|
|||||||
error (getFC codomain) "Constructor codomain is \{render 90 $ pprint tnames codomain} rather than \{nm}"
|
error (getFC codomain) "Constructor codomain is \{render 90 $ pprint tnames codomain} rather than \{nm}"
|
||||||
pure $ map (\ nm' => (MkEntry fc (QN ns nm') dty (DCon NormalCon (getArity dty) hn))) names
|
pure $ map (\ nm' => (MkEntry fc (QN ns nm') dty (DCon NormalCon (getArity dty) hn))) names
|
||||||
decl => throwError $ E (getFC decl) "expected constructor declaration")
|
decl => throwError $ E (getFC decl) "expected constructor declaration")
|
||||||
for entries $ \case (MkEntry name fc dty def) => setDef fc name dty def
|
|
||||||
let entries = populateConInfo entries
|
let entries = populateConInfo entries
|
||||||
|
for entries $ \case (MkEntry name fc dty def) => setDef fc name dty def
|
||||||
let cnames = map (\x => x.name) entries
|
let cnames = map (\x => x.name) entries
|
||||||
|
|
||||||
log 1 $ \ _ => "setDef \{nm} TCon \{show cnames}"
|
log 1 $ \ _ => "setDef \{nm} TCon \{show cnames}"
|
||||||
|
|||||||
@@ -162,7 +162,9 @@ processModule importFC base stk qn@(QN ns nm) = do
|
|||||||
|
|
||||||
let mod = MkModCtx csum top.defs mc top.ops
|
let mod = MkModCtx csum top.defs mc top.ops
|
||||||
errors <- liftIO {M} $ readIORef top.errors
|
errors <- liftIO {M} $ readIORef top.errors
|
||||||
if stk == Nil || length' errors == 0 then pure MkUnit else dumpModule qn src mod
|
if stk /= Nil && length' errors == 0
|
||||||
|
then dumpModule qn src mod
|
||||||
|
else pure MkUnit
|
||||||
|
|
||||||
let modules = updateMap modns mod top.modules
|
let modules = updateMap modns mod top.modules
|
||||||
modifyTop (\ top => MkTop modules top.imported top.ns top.defs top.metaCtx top.verbose top.errors top.ops)
|
modifyTop (\ top => MkTop modules top.imported top.ns top.defs top.metaCtx top.verbose top.errors top.ops)
|
||||||
|
|||||||
Reference in New Issue
Block a user