diff --git a/src/Lib/CompileJS.newt b/src/Lib/CompileJS.newt index 0b59dc6..4de494a 100644 --- a/src/Lib/CompileJS.newt +++ b/src/Lib/CompileJS.newt @@ -309,6 +309,8 @@ termToJS {e} env (CCase t alts) f = getArgs (CConAlt _ _ _ args _) = args maybeCaseStmt : JSEnv -> JSExp -> List CAlt -> JSStmt e + -- deleteT23 does this... + maybeCaseStmt env sc (CDefAlt u :: Nil) = (termToJS env u f) -- If there is a single alt, assume it matched maybeCaseStmt env sc ((CConAlt _ _ info args u) :: Nil) = (termToJS (conAltEnv sc 0 env args) u f) maybeCaseStmt env sc alts@(CLitAlt _ _ :: _) = diff --git a/src/Lib/CompileScheme.newt b/src/Lib/CompileScheme.newt index 820beee..147b245 100644 --- a/src/Lib/CompileScheme.newt +++ b/src/Lib/CompileScheme.newt @@ -65,8 +65,8 @@ scmName qn = scmIdent $ show qn cexpToScm : SCEnv → CExp → String withVar : SCEnv → CExp → (String → String) → String --- withVar env (CBnd _) f = ? --- withVar env (CLit _) f = ? +-- don't rebind a variable +withVar env (CBnd n) f = f $ getEnv n env withVar env t f = let nm = "wv$\{show $ length' env}" in "(let ((\{nm} \{cexpToScm env t})) \{f nm})" @@ -123,6 +123,9 @@ cexpToScm env (CCase sc alts) = do doAlt nm (CLitAlt lit body) = "((\{scmLit lit}) \{cexpToScm env body})" doCase : String → List CAlt → String + -- I'm not sure the case tree should be generating this, c.f. deleteT23 + doCase nm (CDefAlt body :: Nil) = cexpToScm env body + doCase nm (CConAlt tag cname _ args body :: Nil) = conAlt env nm Lin args body doCase nm alts@(CLitAlt _ _ :: _) = "(case \{nm} \{joinBy " " $ map (doAlt nm) alts})" doCase nm alts = "(case (vector-ref \{cexpToScm env sc} 0) \{joinBy " " $ map (doAlt nm) alts})"