mirror of
https://github.com/gren-lang/compiler.git
synced 2024-09-11 08:45:42 +03:00
Add support for compiling simple nodejs applications.
This commit is contained in:
parent
ed863615d2
commit
71f4fd97f3
@ -117,7 +117,8 @@ data LocalGraph = LocalGraph
|
||||
}
|
||||
|
||||
data Main
|
||||
= Static
|
||||
= StaticString
|
||||
| StaticVDom
|
||||
| Dynamic
|
||||
{ _message :: Can.Type,
|
||||
_decoder :: Expr
|
||||
@ -339,15 +340,17 @@ instance Binary LocalGraph where
|
||||
instance Binary Main where
|
||||
put main =
|
||||
case main of
|
||||
Static -> putWord8 0
|
||||
Dynamic a b -> putWord8 1 >> put a >> put b
|
||||
StaticString -> putWord8 0
|
||||
StaticVDom -> putWord8 1
|
||||
Dynamic a b -> putWord8 2 >> put a >> put b
|
||||
|
||||
get =
|
||||
do
|
||||
word <- getWord8
|
||||
case word of
|
||||
0 -> return Static
|
||||
1 -> liftM2 Dynamic get get
|
||||
0 -> return StaticString
|
||||
1 -> return StaticVDom
|
||||
2 -> liftM2 Dynamic get get
|
||||
_ -> fail "problem getting Opt.Main binary"
|
||||
|
||||
instance Binary Node where
|
||||
|
@ -492,8 +492,8 @@ generateTailCall mode name args =
|
||||
toRealVars (argName, _) =
|
||||
JS.ExprStmt $
|
||||
JS.Assign (JS.LRef (JsName.fromLocal argName)) (JS.Ref (JsName.makeTemp argName))
|
||||
in JS.Vars (map toTempVars args)
|
||||
: map toRealVars args
|
||||
in JS.Vars (map toTempVars args) :
|
||||
map toRealVars args
|
||||
++ [JS.Continue (Just (JsName.fromLocal name))]
|
||||
|
||||
-- DEFINITIONS
|
||||
@ -749,7 +749,10 @@ pathToJsExpr mode root path =
|
||||
generateMain :: Mode.Mode -> ModuleName.Canonical -> Opt.Main -> JS.Expr
|
||||
generateMain mode home main =
|
||||
case main of
|
||||
Opt.Static ->
|
||||
Opt.StaticString ->
|
||||
JS.Ref (JsName.fromKernel Name.node "log")
|
||||
# JS.Ref (JsName.fromGlobal home "main")
|
||||
Opt.StaticVDom ->
|
||||
JS.Ref (JsName.fromKernel Name.virtualDom "init")
|
||||
# JS.Ref (JsName.fromGlobal home "main")
|
||||
# JS.Int 0
|
||||
|
@ -177,13 +177,13 @@ addDefHelp platform region annotations home name args body graph@(Opt.LocalGraph
|
||||
Result.ok $
|
||||
addMain $
|
||||
Names.run $
|
||||
Names.registerKernel Name.virtualDom Opt.Static
|
||||
Names.registerKernel Name.node Opt.StaticString
|
||||
Can.TType hm nm [_]
|
||||
| platform == P.Browser && hm == ModuleName.virtualDom && nm == Name.node ->
|
||||
Result.ok $
|
||||
addMain $
|
||||
Names.run $
|
||||
Names.registerKernel Name.virtualDom Opt.Static
|
||||
Names.registerKernel Name.virtualDom Opt.StaticVDom
|
||||
Can.TType hm nm [flags, _, message] | hm == ModuleName.platform && nm == Name.program ->
|
||||
case Effects.checkPayload flags of
|
||||
Right () ->
|
||||
|
Loading…
Reference in New Issue
Block a user