Skip to content

Commit

Permalink
C-like assignments for constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorTaelin committed Nov 2, 2024
1 parent 431bb1e commit beae458
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Kind/CompileJS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,13 @@ fnToJS book fnName (getArguments -> (fnArgs, fnBody)) = do
retStmt <- set var $ concat ["(", funName, ")(", argName, ")"]
return $ concat [funStmt, argStmt, retStmt]
go (CCon nam fields) = do
fieldNamesStmts <- forM fields $ \ (nm, tm) -> do
fieldName <- fresh
fieldStmt <- ctToJS False fieldName tm dep
return ((nm, fieldName), fieldStmt)
let fields' = concatMap (\ (nm, fieldName) -> ", " ++ nm ++ ": " ++ fieldName) (map fst fieldNamesStmts)
retStmt <- set var $ concat ["({$: \"", nam, "\"", fields', "})"]
return $ concat (map snd fieldNamesStmts ++ [retStmt])

objStmt <- set var $ concat ["({$: \"", nam, "\"})"]
setStmts <- forM fields $ \ (nm, tm) -> do
fldName <- fresh
fldStmt <- ctToJS False fldName tm dep
setStmt <- return $ concat [var ++ "." ++ nm ++ " = " ++ fldName ++ ";"]
return $ concat [fldStmt, setStmt]
return $ concat $ [objStmt] ++ setStmts
go (CMat val cses) = do
let isRecord = length cses == 1 && not (any (\ (nm,_,_) -> nm == "_") cses)
valName <- fresh
Expand Down

0 comments on commit beae458

Please sign in to comment.