diff --git a/compiler/src/AST/Optimized.hs b/compiler/src/AST/Optimized.hs index d87d8a7d..c199c76d 100644 --- a/compiler/src/AST/Optimized.hs +++ b/compiler/src/AST/Optimized.hs @@ -53,7 +53,7 @@ data Expr | VarDebug A.Region Name ModuleName.Canonical (Maybe Name) | VarKernel A.Region Name Name | Array A.Region [Expr] - | Function [A.Located Name] Expr + | Function A.Region [A.Located Name] Expr | Call A.Region Expr [Expr] | TailCall Name [(Name, Expr)] | If [(Expr, Expr)] Expr @@ -64,17 +64,21 @@ data Expr | Access Expr A.Region Name | Update A.Region Expr (Map.Map (A.Located Name) Expr) | Record A.Region (Map.Map (A.Located Name) Expr) + deriving (Show) data Global = Global ModuleName.Canonical Name + deriving (Show) -- DEFINITIONS data Def = Def A.Region Name Expr | TailDef A.Region Name [A.Located Name] Expr + deriving (Show) data Destructor = Destructor Name Path + deriving (Show) data Path = Index Index.ZeroBased Path @@ -82,6 +86,7 @@ data Path | Field Name Path | Unbox Path | Root Name + deriving (Show) -- BRANCHING @@ -97,11 +102,12 @@ data Decider a _tests :: [(DT.Test, Decider a)], _fallback :: Decider a } - deriving (Eq) + deriving (Show, Eq) data Choice = Inline Expr | Jump Int + deriving (Show) -- OBJECT GRAPH @@ -219,7 +225,7 @@ instance Binary Expr where VarDebug a b c d -> putWord8 10 >> put a >> put b >> put c >> put d VarKernel a b c -> putWord8 11 >> put a >> put b >> put c Array a b -> putWord8 12 >> put a >> put b - Function a b -> putWord8 13 >> put a >> put b + Function a b c -> putWord8 13 >> put a >> put b >> put c Call a b c -> putWord8 14 >> put a >> put b >> put c TailCall a b -> putWord8 15 >> put a >> put b If a b -> putWord8 16 >> put a >> put b @@ -248,7 +254,7 @@ instance Binary Expr where 10 -> liftM4 VarDebug get get get get 11 -> liftM3 VarKernel get get get 12 -> liftM2 Array get get - 13 -> liftM2 Function get get + 13 -> liftM3 Function get get get 14 -> liftM3 Call get get get 15 -> liftM2 TailCall get get 16 -> liftM2 If get get diff --git a/compiler/src/Generate/JavaScript.hs b/compiler/src/Generate/JavaScript.hs index 09db94e5..73d3cf67 100644 --- a/compiler/src/Generate/JavaScript.hs +++ b/compiler/src/Generate/JavaScript.hs @@ -36,6 +36,8 @@ import Prelude hiding (cycle, print) type Graph = Map.Map Opt.Global Opt.Node +type FnArgLookup = ModuleName.Canonical -> Name.Name -> Maybe Int + type Mains = Map.Map ModuleName.Canonical Opt.Main data GeneratedResult = GeneratedResult @@ -43,6 +45,32 @@ data GeneratedResult = GeneratedResult _sourceMap :: SourceMap.SourceMap } +makeArgLookup :: Graph -> ModuleName.Canonical -> Name.Name -> Maybe Int +makeArgLookup graph home name = + case Map.lookup (Opt.Global home name) graph of + Just (Opt.Define _ (Opt.Function _ args _) _) -> + Just (length args) + Just (Opt.Ctor _ arity) -> + Just arity + Just (Opt.Link global) -> + case Map.lookup global graph of + Just (Opt.Cycle names _ defs _) -> + case List.find (\d -> defName d == name) defs of + Just (Opt.Def _ _ (Opt.Function _ args _)) -> + Just (length args) + Just (Opt.TailDef _ _ args _) -> + Just (length args) + _ -> + error (show names) + _ -> + Nothing + _ -> + Nothing + +defName :: Opt.Def -> Name.Name +defName (Opt.Def _ name _) = name +defName (Opt.TailDef _ name _ _) = name + prelude :: B.Builder prelude = "(function(scope){\n'use strict';" @@ -140,18 +168,32 @@ addGlobalHelp :: Mode.Mode -> Graph -> Opt.Global -> State -> State addGlobalHelp mode graph global@(Opt.Global home _) state = let addDeps deps someState = Set.foldl' (addGlobal mode graph) someState deps + + argLookup = makeArgLookup graph in case graph ! global of + Opt.Define region (Opt.Function (A.Region funcStart _) args body) deps + | length args > 1 -> + addStmt + (addDeps deps state) + ( trackedFn region global args (Expr.generateFunctionImplementation mode argLookup home funcStart args body) + ) Opt.Define region expr deps -> addStmt (addDeps deps state) - ( trackedVar region global (Expr.generate mode home expr) + ( trackedVar region global (Expr.generate mode argLookup home expr) ) Opt.DefineTailFunc region argNames body deps -> addStmt (addDeps deps state) ( let (Opt.Global _ name) = global - in trackedVar region global (Expr.generateTailDef mode home name argNames body) + in trackedVar region global (Expr.generateTailDef mode argLookup home name argNames body) ) + Opt.Ctor index arity + | arity > 1 -> + addStmt + state + ( ctor global arity (Expr.generateCtorImplementation mode global index arity) + ) Opt.Ctor index arity -> addStmt state @@ -162,7 +204,7 @@ addGlobalHelp mode graph global@(Opt.Global home _) state = Opt.Cycle names values functions deps -> addStmt (addDeps deps state) - ( generateCycle mode global names values functions + ( generateCycle mode argLookup global names values functions ) Opt.Manager effectsType -> generateManager mode graph global effectsType state @@ -207,17 +249,35 @@ trackedVar :: A.Region -> Opt.Global -> Expr.Code -> JS.Stmt trackedVar (A.Region startPos _) (Opt.Global home name) code = JS.TrackedVar home startPos (JsName.fromGlobalHumanReadable home name) (JsName.fromGlobal home name) (Expr.codeToExpr code) +trackedFn :: A.Region -> Opt.Global -> [A.Located Name.Name] -> Expr.Code -> JS.Stmt +trackedFn (A.Region startPos _) (Opt.Global home name) args code = + let directFnName = JsName.fromGlobalDirectFn home name + argNames = map (\(A.At _ arg) -> JsName.fromLocal arg) args + in JS.Block + [ JS.TrackedVar home startPos (JsName.fromGlobalHumanReadable home name) directFnName (Expr.codeToExpr code), + JS.Var (JsName.fromGlobal home name) $ Expr.codeToExpr (Expr.generateCurriedFunctionRef argNames directFnName) + ] + +ctor :: Opt.Global -> Int -> Expr.Code -> JS.Stmt +ctor (Opt.Global home name) arity code = + let directFnName = JsName.fromGlobalDirectFn home name + argNames = Index.indexedMap (\i _ -> JsName.fromIndex i) [1 .. arity] + in JS.Block + [ JS.Var directFnName (Expr.codeToExpr code), + JS.Var (JsName.fromGlobal home name) $ Expr.codeToExpr (Expr.generateCurriedFunctionRef argNames directFnName) + ] + isDebugger :: Opt.Global -> Bool isDebugger (Opt.Global (ModuleName.Canonical _ home) _) = home == Name.debugger -- GENERATE CYCLES -generateCycle :: Mode.Mode -> Opt.Global -> [Name.Name] -> [(Name.Name, Opt.Expr)] -> [Opt.Def] -> JS.Stmt -generateCycle mode (Opt.Global home _) names values functions = +generateCycle :: Mode.Mode -> FnArgLookup -> Opt.Global -> [Name.Name] -> [(Name.Name, Opt.Expr)] -> [Opt.Def] -> JS.Stmt +generateCycle mode argLookup (Opt.Global home _) names values functions = JS.Block - [ JS.Block $ map (generateCycleFunc mode home) functions, - JS.Block $ map (generateSafeCycle mode home) values, + [ JS.Block $ map (generateCycleFunc mode argLookup home) functions, + JS.Block $ map (generateSafeCycle mode argLookup home) values, case map (generateRealCycle home) values of [] -> JS.EmptyStmt @@ -238,18 +298,29 @@ generateCycle mode (Opt.Global home _) names values functions = <> " to learn how to fix it!" ] -generateCycleFunc :: Mode.Mode -> ModuleName.Canonical -> Opt.Def -> JS.Stmt -generateCycleFunc mode home def = +generateCycleFunc :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Opt.Def -> JS.Stmt +generateCycleFunc mode argLookup home def = case def of - Opt.Def _ name expr -> - JS.Var (JsName.fromGlobal home name) (Expr.codeToExpr (Expr.generate mode home expr)) - Opt.TailDef _ name args expr -> - JS.Var (JsName.fromGlobal home name) (Expr.codeToExpr (Expr.generateTailDef mode home name args expr)) - -generateSafeCycle :: Mode.Mode -> ModuleName.Canonical -> (Name.Name, Opt.Expr) -> JS.Stmt -generateSafeCycle mode home (name, expr) = + Opt.Def region name (Opt.Function (A.Region funcStartPos _) args body) + | length args > 1 -> + trackedFn region (Opt.Global home name) args (Expr.generateFunctionImplementation mode argLookup home funcStartPos args body) + Opt.Def (A.Region startPos _) name expr -> + JS.TrackedVar home startPos (JsName.fromGlobalHumanReadable home name) (JsName.fromGlobal home name) (Expr.codeToExpr (Expr.generate mode argLookup home expr)) + Opt.TailDef (A.Region startPos _) name args expr + | length args > 1 -> + let directFnName = JsName.fromGlobalDirectFn home name + argNames = map (\(A.At _ arg) -> JsName.fromLocal arg) args + in JS.Block + [ JS.TrackedVar home startPos (JsName.fromGlobalHumanReadable home name) directFnName (Expr.codeToExpr (Expr.generateTailDefImplementation mode argLookup home name args expr)), + JS.Var (JsName.fromGlobal home name) (Expr.codeToExpr (Expr.generateCurriedFunctionRef argNames directFnName)) + ] + Opt.TailDef (A.Region startPos _) name args expr -> + JS.TrackedVar home startPos (JsName.fromGlobalHumanReadable home name) (JsName.fromGlobal home name) (Expr.codeToExpr (Expr.generateTailDef mode argLookup home name args expr)) + +generateSafeCycle :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> (Name.Name, Opt.Expr) -> JS.Stmt +generateSafeCycle mode argLookup home (name, expr) = JS.FunctionStmt (JsName.fromCycle home name) [] $ - Expr.codeToStmtList (Expr.generate mode home expr) + Expr.codeToStmtList (Expr.generate mode argLookup home expr) generateRealCycle :: ModuleName.Canonical -> (Name.Name, expr) -> JS.Stmt generateRealCycle home (name, _) = @@ -338,7 +409,7 @@ generatePort mode (Opt.Global home name) makePort converter = JS.Call (JS.Ref (JsName.fromKernel Name.platform makePort)) [ JS.String (Name.toBuilder name), - Expr.codeToExpr (Expr.generate mode home converter) + Expr.codeToExpr (Expr.generate mode (\_ _ -> Nothing) home converter) ] -- GENERATE MANAGER @@ -408,7 +479,7 @@ generateExports mode (Trie maybeMain subs) = "{" Just (home, main) -> "{'init':" - <> JS._code (JS.exprToBuilder (Expr.generateMain mode home main) (JS.emptyBuilder 0)) + <> JS._code (JS.exprToBuilder (Expr.generateMain mode (\_ _ -> Nothing) home main) (JS.emptyBuilder 0)) <> end in case Map.toList subs of [] -> diff --git a/compiler/src/Generate/JavaScript/Builder.hs b/compiler/src/Generate/JavaScript/Builder.hs index 6f9c9571..b43a41dd 100644 --- a/compiler/src/Generate/JavaScript/Builder.hs +++ b/compiler/src/Generate/JavaScript/Builder.hs @@ -63,7 +63,7 @@ data Expr | Call Expr [Expr] | TrackedNormalCall ModuleName.Canonical A.Position Expr Expr [Expr] | Function (Maybe Name) [Name] [Stmt] - | TrackedFunction ModuleName.Canonical [A.Located Name] [Stmt] + | TrackedFunction ModuleName.Canonical A.Position [A.Located Name] [Stmt] data LValue = LRef Name @@ -627,9 +627,12 @@ fromExpr level@(Level indent nextLevel) grouping expression builder = & fromStmtBlock nextLevel stmts & addByteString indent & addAscii "}" - TrackedFunction moduleName args stmts -> + TrackedFunction moduleName startPos args stmts -> builder - & addAscii "function" + & ( if startPos == A.zeroPosition + then addAscii "function" + else addTrackedByteString moduleName startPos "function" + ) & addAscii "(" & commaSepExpr (\(A.At (A.Region start _) name) -> addName moduleName start name name) args & addAscii ") {" diff --git a/compiler/src/Generate/JavaScript/Expression.hs b/compiler/src/Generate/JavaScript/Expression.hs index dcedfbfc..543306f4 100644 --- a/compiler/src/Generate/JavaScript/Expression.hs +++ b/compiler/src/Generate/JavaScript/Expression.hs @@ -3,10 +3,14 @@ module Generate.JavaScript.Expression ( generate, generateCtor, + generateCtorImplementation, generateField, + generateFunctionImplementation, + generateCurriedFunctionRef, generateTailDef, + generateTailDefImplementation, generateMain, - Code, + Code (..), codeToExpr, codeToStmtList, ) @@ -37,12 +41,14 @@ import Reporting.Annotation qualified as A -- EXPRESSIONS -generateJsExpr :: Mode.Mode -> ModuleName.Canonical -> Opt.Expr -> JS.Expr -generateJsExpr mode parentModule expression = - codeToExpr (generate mode parentModule expression) +type FnArgLookup = ModuleName.Canonical -> Name.Name -> Maybe Int -generate :: Mode.Mode -> ModuleName.Canonical -> Opt.Expr -> Code -generate mode parentModule expression = +generateJsExpr :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Opt.Expr -> JS.Expr +generateJsExpr mode argLookup parentModule expression = + codeToExpr (generate mode argLookup parentModule expression) + +generate :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Opt.Expr -> Code +generate mode argLookup parentModule expression = case expression of Opt.Bool (A.Region start _) bool -> JsExpr $ JS.TrackedBool parentModule start bool @@ -77,32 +83,32 @@ generate mode parentModule expression = Opt.VarCycle (A.Region startPos _) home name -> JsExpr $ JS.Call (JS.TrackedRef parentModule startPos (JsName.fromGlobalHumanReadable home name) (JsName.fromCycle home name)) [] Opt.VarDebug region name home unhandledValueName -> - JsExpr $ generateDebug name home region unhandledValueName + JsExpr $ generateDebug parentModule name home region unhandledValueName Opt.VarKernel (A.Region startPos _) home name -> JsExpr $ JS.TrackedRef parentModule startPos (JsName.fromKernel home name) (JsName.fromKernel home name) Opt.Array region entries -> - let generatedEntries = map (generateJsExpr mode parentModule) entries + let generatedEntries = map (generateJsExpr mode argLookup parentModule) entries in JsExpr $ if region == A.zero then JS.Array generatedEntries else JS.TrackedArray parentModule region generatedEntries - Opt.Function args body -> + Opt.Function (A.Region startPos _) args body -> let argNames = map (\(A.At region name) -> A.At region (JsName.fromLocal name)) args - in generateTrackedFunction parentModule argNames (generate mode parentModule body) + in generateTrackedFunction parentModule startPos argNames (generate mode argLookup parentModule body) Opt.Call (A.Region startPos _) func args -> - JsExpr $ generateCall mode parentModule startPos func args + JsExpr $ generateCall mode argLookup parentModule startPos func args Opt.TailCall name args -> - JsBlock $ generateTailCall mode parentModule name args + JsBlock $ generateTailCall mode argLookup parentModule name args Opt.If branches final -> - generateIf mode parentModule branches final + generateIf mode argLookup parentModule branches final Opt.Let def body -> JsBlock $ - generateDef mode parentModule def : codeToStmtList (generate mode parentModule body) + generateDef mode argLookup parentModule def : codeToStmtList (generate mode argLookup parentModule body) Opt.Destruct (Opt.Destructor name path) body -> let pathDef = JS.Var (JsName.fromLocal name) (generatePath mode path) - in JsBlock $ pathDef : codeToStmtList (generate mode parentModule body) + in JsBlock $ pathDef : codeToStmtList (generate mode argLookup parentModule body) Opt.Case label root decider jumps -> - JsBlock $ generateCase mode parentModule label root decider jumps + JsBlock $ generateCase mode argLookup parentModule label root decider jumps Opt.Accessor _ field -> JsExpr $ JS.Function @@ -112,16 +118,16 @@ generate mode parentModule expression = JS.Access (JS.Ref JsName.dollar) (generateField mode field) ] Opt.Access record (A.Region startPos _) field -> - JsExpr $ JS.TrackedAccess (generateJsExpr mode parentModule record) parentModule startPos (generateField mode field) + JsExpr $ JS.TrackedAccess (generateJsExpr mode argLookup parentModule record) parentModule startPos (generateField mode field) Opt.Update region record fields -> JsExpr $ JS.Call (JS.Ref (JsName.fromKernel Name.utils "update")) - [ generateJsExpr mode parentModule record, - generateRecord mode parentModule region fields + [ generateJsExpr mode argLookup parentModule record, + generateRecord mode argLookup parentModule region fields ] Opt.Record region fields -> - JsExpr $ generateRecord mode parentModule region fields + JsExpr $ generateRecord mode argLookup parentModule region fields -- CODE CHUNKS @@ -183,6 +189,22 @@ generateCtor mode (Opt.Global home name) index arity = JS.Object $ (JsName.dollar, ctorTag) : map (\n -> (n, JS.Ref n)) argNames +generateCtorImplementation :: Mode.Mode -> Opt.Global -> Index.ZeroBased -> Int -> Code +generateCtorImplementation mode (Opt.Global home name) index arity = + let argNames = + Index.indexedMap (\i _ -> JsName.fromIndex i) [1 .. arity] + + ctorTag = + case mode of + Mode.Dev _ -> JS.String (Name.toBuilder name) + Mode.Prod _ -> JS.Int (ctorToInt home name index) + in JsExpr $ + JS.Function Nothing argNames $ + codeToStmtList $ + JsExpr $ + JS.Object $ + (JsName.dollar, ctorTag) : map (\n -> (n, JS.Ref n)) argNames + ctorToInt :: ModuleName.Canonical -> Name.Name -> Index.ZeroBased -> Int ctorToInt home name index = if home == ModuleName.dict && name == "RBNode_gren_builtin" || name == "RBEmpty_gren_builtin" @@ -191,10 +213,10 @@ ctorToInt home name index = -- RECORDS -generateRecord :: Mode.Mode -> ModuleName.Canonical -> A.Region -> Map.Map (A.Located Name.Name) Opt.Expr -> JS.Expr -generateRecord mode parentModule region fields = +generateRecord :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> A.Region -> Map.Map (A.Located Name.Name) Opt.Expr -> JS.Expr +generateRecord mode argLookup parentModule region fields = let toPair (A.At fieldRegion field, value) = - (A.At fieldRegion $ generateField mode field, generateJsExpr mode parentModule value) + (A.At fieldRegion $ generateField mode field, generateJsExpr mode argLookup parentModule value) in JS.TrackedObject parentModule region (map toPair (Map.toList fields)) generateField :: Mode.Mode -> Name.Name -> JsName.Name @@ -207,22 +229,23 @@ generateField mode name = -- DEBUG -generateDebug :: Name.Name -> ModuleName.Canonical -> A.Region -> Maybe Name.Name -> JS.Expr -generateDebug name (ModuleName.Canonical _ home) region unhandledValueName = - if name /= "todo" - then JS.Ref (JsName.fromGlobal ModuleName.debug name) - else case unhandledValueName of - Nothing -> - JS.Call (JS.Ref (JsName.fromKernel Name.debug "todo")) $ - [ JS.String (Name.toBuilder home), - regionToJsExpr region - ] - Just valueName -> - JS.Call (JS.Ref (JsName.fromKernel Name.debug "todoCase")) $ - [ JS.String (Name.toBuilder home), - regionToJsExpr region, - JS.Ref (JsName.fromLocal valueName) - ] +generateDebug :: ModuleName.Canonical -> Name.Name -> ModuleName.Canonical -> A.Region -> Maybe Name.Name -> JS.Expr +generateDebug parentMod name (ModuleName.Canonical _ home) region@(A.Region startPos _) unhandledValueName = + let trackedRef = JS.TrackedRef parentMod startPos (JsName.fromGlobalHumanReadable ModuleName.debug name) (JsName.fromGlobal ModuleName.debug name) + in if name /= "todo" + then trackedRef + else case unhandledValueName of + Nothing -> + JS.Call trackedRef $ + [ JS.String (Name.toBuilder home), + regionToJsExpr region + ] + Just valueName -> + JS.Call (JS.Ref (JsName.fromKernel Name.debug "todoCase")) $ + [ JS.String (Name.toBuilder home), + regionToJsExpr region, + JS.Ref (JsName.fromLocal valueName) + ] regionToJsExpr :: A.Region -> JS.Expr regionToJsExpr (A.Region start end) = @@ -257,21 +280,37 @@ generateFunction args body = codeToStmtList code in foldr addArg body args -generateTrackedFunction :: ModuleName.Canonical -> [A.Located JsName.Name] -> Code -> Code -generateTrackedFunction parentModule args body = +generateCurriedFunctionRef :: [JsName.Name] -> JsName.Name -> Code +generateCurriedFunctionRef args ref = case IntMap.lookup (length args) funcHelpers of Just helper -> JsExpr $ JS.Call helper - [ JS.TrackedFunction parentModule args $ + [ JS.Ref ref + ] + Nothing -> + let addArg arg code = + JsExpr $ + JS.Function Nothing [arg] $ + codeToStmtList code + in foldr addArg (JsExpr $ JS.Call (JS.Ref ref) (map JS.Ref args)) args + +generateTrackedFunction :: ModuleName.Canonical -> A.Position -> [A.Located JsName.Name] -> Code -> Code +generateTrackedFunction parentModule pos args body = + case IntMap.lookup (length args) funcHelpers of + Just helper -> + JsExpr $ + JS.Call + helper + [ JS.TrackedFunction parentModule pos args $ codeToStmtList body ] Nothing -> case args of [_] -> JsExpr $ - JS.TrackedFunction parentModule args $ + JS.TrackedFunction parentModule pos args $ codeToStmtList body _ -> let addArg arg code = @@ -287,40 +326,47 @@ funcHelpers = -- CALLS -generateCall :: Mode.Mode -> ModuleName.Canonical -> A.Position -> Opt.Expr -> [Opt.Expr] -> JS.Expr -generateCall mode parentModule pos func args = +generateCall :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> A.Position -> Opt.Expr -> [Opt.Expr] -> JS.Expr +generateCall mode argLookup parentModule pos func args = case func of Opt.VarGlobal _ global@(Opt.Global (ModuleName.Canonical pkg _) _) | pkg == Pkg.core -> - generateCoreCall mode parentModule pos global args - Opt.VarBox _ _ -> + generateCoreCall mode argLookup parentModule pos global args + Opt.VarGlobal _ (Opt.Global home name) -> + generateGlobalCall argLookup parentModule pos home name (map (generateJsExpr mode argLookup parentModule) args) + Opt.VarBox _ (Opt.Global home name) -> case mode of Mode.Dev _ -> - generateCallHelp mode parentModule pos func args + generateGlobalCall argLookup parentModule pos home name (map (generateJsExpr mode argLookup parentModule) args) Mode.Prod _ -> case args of [arg] -> - generateJsExpr mode parentModule arg + generateJsExpr mode argLookup parentModule arg _ -> - generateCallHelp mode parentModule pos func args + generateGlobalCall argLookup parentModule pos home name (map (generateJsExpr mode argLookup parentModule) args) _ -> - generateCallHelp mode parentModule pos func args + generateCallHelp mode argLookup parentModule pos func args -generateCallHelp :: Mode.Mode -> ModuleName.Canonical -> A.Position -> Opt.Expr -> [Opt.Expr] -> JS.Expr -generateCallHelp mode parentModule pos func args = +generateCallHelp :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> A.Position -> Opt.Expr -> [Opt.Expr] -> JS.Expr +generateCallHelp mode argLookup parentModule pos func args = generateNormalCall parentModule pos - (generateJsExpr mode parentModule func) - (map (generateJsExpr mode parentModule) args) - -generateGlobalCall :: ModuleName.Canonical -> A.Position -> ModuleName.Canonical -> Name.Name -> [JS.Expr] -> JS.Expr -generateGlobalCall parentModule pos@(A.Position line col) home name args = - let ref = - if line == 0 && col == 0 - then JS.Ref (JsName.fromGlobal home name) - else JS.TrackedRef parentModule pos (JsName.fromGlobalHumanReadable home name) (JsName.fromGlobal home name) - in generateNormalCall parentModule pos ref args + (generateJsExpr mode argLookup parentModule func) + (map (generateJsExpr mode argLookup parentModule) args) + +generateGlobalCall :: FnArgLookup -> ModuleName.Canonical -> A.Position -> ModuleName.Canonical -> Name.Name -> [JS.Expr] -> JS.Expr +generateGlobalCall argLookup parentModule pos home name args = + case argLookup home name of + Just n + | n > 1 && n == (length args) -> + JS.Call (JS.TrackedRef parentModule pos (JsName.fromGlobalHumanReadable home name) (JsName.fromGlobalDirectFn home name)) args + _ -> + let ref = + if pos == A.zeroPosition + then JS.Ref (JsName.fromGlobal home name) + else JS.TrackedRef parentModule pos (JsName.fromGlobalHumanReadable home name) (JsName.fromGlobal home name) + in generateNormalCall parentModule pos ref args generateNormalCall :: ModuleName.Canonical -> A.Position -> JS.Expr -> [JS.Expr] -> JS.Expr generateNormalCall parentModule pos func args = @@ -337,25 +383,25 @@ callHelpers = -- CORE CALLS -generateCoreCall :: Mode.Mode -> ModuleName.Canonical -> A.Position -> Opt.Global -> [Opt.Expr] -> JS.Expr -generateCoreCall mode parentModule pos (Opt.Global home@(ModuleName.Canonical _ moduleName) name) args = +generateCoreCall :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> A.Position -> Opt.Global -> [Opt.Expr] -> JS.Expr +generateCoreCall mode argLookup parentModule pos (Opt.Global home@(ModuleName.Canonical _ moduleName) name) args = if moduleName == Name.basics - then generateBasicsCall mode parentModule pos home name args + then generateBasicsCall mode argLookup parentModule pos home name args else if moduleName == Name.bitwise - then generateBitwiseCall parentModule pos home name (map (generateJsExpr mode parentModule) args) + then generateBitwiseCall argLookup parentModule pos home name (map (generateJsExpr mode argLookup parentModule) args) else if moduleName == Name.math - then generateMathCall parentModule pos home name (map (generateJsExpr mode parentModule) args) - else generateGlobalCall parentModule pos home name (map (generateJsExpr mode parentModule) args) + then generateMathCall argLookup parentModule pos home name (map (generateJsExpr mode argLookup parentModule) args) + else generateGlobalCall argLookup parentModule pos home name (map (generateJsExpr mode argLookup parentModule) args) -generateBitwiseCall :: ModuleName.Canonical -> A.Position -> ModuleName.Canonical -> Name.Name -> [JS.Expr] -> JS.Expr -generateBitwiseCall parentModule pos home name args = +generateBitwiseCall :: FnArgLookup -> ModuleName.Canonical -> A.Position -> ModuleName.Canonical -> Name.Name -> [JS.Expr] -> JS.Expr +generateBitwiseCall argLookup parentModule pos home name args = case args of [arg] -> case name of "complement" -> JS.Prefix JS.PrefixComplement arg - _ -> generateGlobalCall parentModule pos home name args + _ -> generateGlobalCall argLookup parentModule pos home name args [left, right] -> case name of "and" -> JS.Infix JS.OpBitwiseAnd left right @@ -364,30 +410,28 @@ generateBitwiseCall parentModule pos home name args = "shiftLeftBy" -> JS.Infix JS.OpLShift right left "shiftRightBy" -> JS.Infix JS.OpSpRShift right left "shiftRightZfBy" -> JS.Infix JS.OpZfRShift right left - _ -> generateGlobalCall parentModule pos home name args + _ -> generateGlobalCall argLookup parentModule pos home name args _ -> - generateGlobalCall parentModule pos home name args + generateGlobalCall argLookup parentModule pos home name args -generateBasicsCall :: Mode.Mode -> ModuleName.Canonical -> A.Position -> ModuleName.Canonical -> Name.Name -> [Opt.Expr] -> JS.Expr -generateBasicsCall mode parentModule pos home name args = +generateBasicsCall :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> A.Position -> ModuleName.Canonical -> Name.Name -> [Opt.Expr] -> JS.Expr +generateBasicsCall mode argLookup parentModule pos home name args = case args of [grenArg] -> - let arg = generateJsExpr mode parentModule grenArg + let arg = generateJsExpr mode argLookup parentModule grenArg in case name of "not" -> JS.Prefix JS.PrefixNot arg "negate" -> JS.Prefix JS.PrefixNegate arg "toFloat" -> arg - _ -> generateGlobalCall parentModule pos home name [arg] + _ -> generateGlobalCall argLookup parentModule pos home name [arg] [grenLeft, grenRight] -> case name of - -- NOTE: removed "composeL" and "composeR" because of this issue: - -- https://github.com/elm-lang/compiler/issues/1722 - "append" -> append mode parentModule grenLeft grenRight - "apL" -> generateJsExpr mode parentModule $ apply grenLeft grenRight - "apR" -> generateJsExpr mode parentModule $ apply grenRight grenLeft + "append" -> append mode argLookup parentModule grenLeft grenRight + "apL" -> generateJsExpr mode argLookup parentModule $ apply grenLeft grenRight + "apR" -> generateJsExpr mode argLookup parentModule $ apply grenRight grenLeft _ -> - let left = generateJsExpr mode parentModule grenLeft - right = generateJsExpr mode parentModule grenRight + let left = generateJsExpr mode argLookup parentModule grenLeft + right = generateJsExpr mode argLookup parentModule grenRight in case name of "add" -> JS.Infix JS.OpAdd left right "sub" -> JS.Infix JS.OpSub left right @@ -403,23 +447,19 @@ generateBasicsCall mode parentModule pos home name args = "or" -> JS.Infix JS.OpOr left right "and" -> JS.Infix JS.OpAnd left right "xor" -> JS.Infix JS.OpNe left right - _ -> generateGlobalCall parentModule pos home name [left, right] + _ -> generateGlobalCall argLookup parentModule pos home name [left, right] _ -> - generateGlobalCall parentModule pos home name (map (generateJsExpr mode parentModule) args) + generateGlobalCall argLookup parentModule pos home name (map (generateJsExpr mode argLookup parentModule) args) -generateMathCall :: ModuleName.Canonical -> A.Position -> ModuleName.Canonical -> Name.Name -> [JS.Expr] -> JS.Expr -generateMathCall parentModule pos home name args = +generateMathCall :: FnArgLookup -> ModuleName.Canonical -> A.Position -> ModuleName.Canonical -> Name.Name -> [JS.Expr] -> JS.Expr +generateMathCall argLookup parentModule pos home name args = case args of - [arg] -> - case name of - "truncate" -> JS.Infix JS.OpBitwiseOr arg (JS.Int 0) - _ -> generateGlobalCall parentModule pos home name [arg] [left, right] -> case name of "remainderBy" -> JS.Infix JS.OpMod right left - _ -> generateGlobalCall parentModule pos home name [left, right] + _ -> generateGlobalCall argLookup parentModule pos home name [left, right] _ -> - generateGlobalCall parentModule pos home name args + generateGlobalCall argLookup parentModule pos home name args equal :: JS.Expr -> JS.Expr -> JS.Expr equal left right = @@ -448,14 +488,14 @@ cmp idealOp backupOp backupInt left right = isLiteral :: JS.Expr -> Bool isLiteral expr = case expr of - JS.String _ -> - True - JS.Float _ -> - True - JS.Int _ -> - True - JS.Bool _ -> - True + JS.String _ -> True + JS.TrackedString _ _ _ -> True + JS.Float _ -> True + JS.TrackedFloat _ _ _ -> True + JS.Int _ -> True + JS.TrackedInt _ _ _ -> True + JS.Bool _ -> True + JS.TrackedBool _ _ _ -> True _ -> False @@ -485,7 +525,7 @@ exprRegion expr = Opt.VarDebug region _ _ _ -> Just region Opt.VarKernel region _ _ -> Just region Opt.Array region _ -> Just region - Opt.Function _ _ -> Nothing + Opt.Function _ _ _ -> Nothing Opt.Call region _ _ -> Just region Opt.TailCall _ _ -> Nothing Opt.If _ _ -> Nothing @@ -497,9 +537,9 @@ exprRegion expr = Opt.Update region _ _ -> Just region Opt.Record region _ -> Just region -append :: Mode.Mode -> ModuleName.Canonical -> Opt.Expr -> Opt.Expr -> JS.Expr -append mode parentModule left right = - let seqs = generateJsExpr mode parentModule left : toSeqs mode parentModule right +append :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Opt.Expr -> Opt.Expr -> JS.Expr +append mode argLookup parentModule left right = + let seqs = generateJsExpr mode argLookup parentModule left : toSeqs mode argLookup parentModule right in if any isStringLiteral seqs then foldr1 (JS.Infix JS.OpAdd) seqs else foldr1 jsAppend seqs @@ -508,20 +548,22 @@ jsAppend :: JS.Expr -> JS.Expr -> JS.Expr jsAppend a b = JS.Call (JS.Ref (JsName.fromKernel Name.utils "ap")) [a, b] -toSeqs :: Mode.Mode -> ModuleName.Canonical -> Opt.Expr -> [JS.Expr] -toSeqs mode parentModule expr = +toSeqs :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Opt.Expr -> [JS.Expr] +toSeqs mode argLookup parentModule expr = case expr of Opt.Call _ (Opt.VarGlobal _ (Opt.Global home "append")) [left, right] | home == ModuleName.basics -> - generateJsExpr mode parentModule left : toSeqs mode parentModule right + generateJsExpr mode argLookup parentModule left : toSeqs mode argLookup parentModule right _ -> - [generateJsExpr mode parentModule expr] + [generateJsExpr mode argLookup parentModule expr] isStringLiteral :: JS.Expr -> Bool isStringLiteral expr = case expr of JS.String _ -> True + JS.TrackedString _ _ _ -> + True _ -> False @@ -561,10 +603,10 @@ strictNEq left right = -- TAIL CALL -generateTailCall :: Mode.Mode -> ModuleName.Canonical -> Name.Name -> [(Name.Name, Opt.Expr)] -> [JS.Stmt] -generateTailCall mode parentModule name args = +generateTailCall :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Name.Name -> [(Name.Name, Opt.Expr)] -> [JS.Stmt] +generateTailCall mode argLookup parentModule name args = let toTempVars (argName, arg) = - (JsName.makeTemp argName, generateJsExpr mode parentModule arg) + (JsName.makeTemp argName, generateJsExpr mode argLookup parentModule arg) toRealVars (argName, _) = JS.ExprStmt $ @@ -575,26 +617,45 @@ generateTailCall mode parentModule name args = -- DEFINITIONS -generateDef :: Mode.Mode -> ModuleName.Canonical -> Opt.Def -> JS.Stmt -generateDef mode parentModule def = +generateDef :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Opt.Def -> JS.Stmt +generateDef mode argLookup parentModule def = case def of Opt.Def (A.Region start _) name body -> JS.TrackedVar parentModule start (JsName.fromLocal name) (JsName.fromLocal name) $ - generateJsExpr mode parentModule body + generateJsExpr mode argLookup parentModule body Opt.TailDef (A.Region start _) name argNames body -> JS.TrackedVar parentModule start (JsName.fromLocal name) (JsName.fromLocal name) $ - codeToExpr (generateTailDef mode parentModule name argNames body) - -generateTailDef :: Mode.Mode -> ModuleName.Canonical -> Name.Name -> [A.Located Name.Name] -> Opt.Expr -> Code -generateTailDef mode parentModule name argNames body = - generateTrackedFunction parentModule (map (\(A.At region argName) -> A.At region (JsName.fromLocal argName)) argNames) $ + codeToExpr (generateTailDef mode argLookup parentModule name argNames body) + +generateFunctionImplementation :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> A.Position -> [A.Located Name.Name] -> Opt.Expr -> Code +generateFunctionImplementation mode argLookup parentModule funcPos argNames body = + JsExpr $ + JS.TrackedFunction parentModule funcPos (map (\(A.At region argName) -> A.At region (JsName.fromLocal argName)) argNames) $ + codeToStmtList $ + generate mode argLookup parentModule body + +generateTailDef :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Name.Name -> [A.Located Name.Name] -> Opt.Expr -> Code +generateTailDef mode argLookup parentModule name argNames body = + generateTrackedFunction parentModule A.zeroPosition (map (\(A.At region argName) -> A.At region (JsName.fromLocal argName)) argNames) $ JsBlock [ JS.Labelled (JsName.fromLocal name) $ JS.While (JS.Bool True) $ codeToStmt $ - generate mode parentModule body + generate mode argLookup parentModule body ] +generateTailDefImplementation :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Name.Name -> [A.Located Name.Name] -> Opt.Expr -> Code +generateTailDefImplementation mode argLookup parentModule name argNames body = + JsExpr $ + JS.TrackedFunction parentModule A.zeroPosition (map (\(A.At region argName) -> A.At region (JsName.fromLocal argName)) argNames) $ + codeToStmtList $ + JsBlock + [ JS.Labelled (JsName.fromLocal name) $ + JS.While (JS.Bool True) $ + codeToStmt $ + generate mode argLookup parentModule body + ] + -- PATHS generatePath :: Mode.Mode -> Opt.Path -> JS.Expr @@ -617,18 +678,18 @@ generatePath mode path = -- GENERATE IFS -generateIf :: Mode.Mode -> ModuleName.Canonical -> [(Opt.Expr, Opt.Expr)] -> Opt.Expr -> Code -generateIf mode parentModule givenBranches givenFinal = +generateIf :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> [(Opt.Expr, Opt.Expr)] -> Opt.Expr -> Code +generateIf mode argLookup parentModule givenBranches givenFinal = let (branches, final) = crushIfs givenBranches givenFinal convertBranch (condition, expr) = - ( generateJsExpr mode parentModule condition, - generate mode parentModule expr + ( generateJsExpr mode argLookup parentModule condition, + generate mode argLookup parentModule expr ) branchExprs = map convertBranch branches - finalCode = generate mode parentModule final + finalCode = generate mode argLookup parentModule final in if isBlock finalCode || any (isBlock . snd) branchExprs then JsBlock [foldr addStmtIf (codeToStmt finalCode) branchExprs] else JsExpr $ foldr addExprIf (codeToExpr finalCode) branchExprs @@ -669,37 +730,37 @@ crushIfsHelp visitedBranches unvisitedBranches final = -- CASE EXPRESSIONS -generateCase :: Mode.Mode -> ModuleName.Canonical -> Name.Name -> Name.Name -> Opt.Decider Opt.Choice -> [(Int, Opt.Expr)] -> [JS.Stmt] -generateCase mode parentModule label root decider jumps = - foldr (goto mode parentModule label) (generateDecider mode parentModule label root decider) jumps +generateCase :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Name.Name -> Name.Name -> Opt.Decider Opt.Choice -> [(Int, Opt.Expr)] -> [JS.Stmt] +generateCase mode argLookup parentModule label root decider jumps = + foldr (goto mode argLookup parentModule label) (generateDecider mode argLookup parentModule label root decider) jumps -goto :: Mode.Mode -> ModuleName.Canonical -> Name.Name -> (Int, Opt.Expr) -> [JS.Stmt] -> [JS.Stmt] -goto mode parentModule label (index, branch) stmts = +goto :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Name.Name -> (Int, Opt.Expr) -> [JS.Stmt] -> [JS.Stmt] +goto mode argLookup parentModule label (index, branch) stmts = let labeledDeciderStmt = JS.Labelled (JsName.makeLabel label index) (JS.While (JS.Bool True) (JS.Block stmts)) - in labeledDeciderStmt : codeToStmtList (generate mode parentModule branch) + in labeledDeciderStmt : codeToStmtList (generate mode argLookup parentModule branch) -generateDecider :: Mode.Mode -> ModuleName.Canonical -> Name.Name -> Name.Name -> Opt.Decider Opt.Choice -> [JS.Stmt] -generateDecider mode parentModule label root decisionTree = +generateDecider :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Name.Name -> Name.Name -> Opt.Decider Opt.Choice -> [JS.Stmt] +generateDecider mode argLookup parentModule label root decisionTree = case decisionTree of Opt.Leaf (Opt.Inline branch) -> - codeToStmtList (generate mode parentModule branch) + codeToStmtList (generate mode argLookup parentModule branch) Opt.Leaf (Opt.Jump index) -> [JS.Break (Just (JsName.makeLabel label index))] Opt.Chain testChain success failure -> [ JS.IfStmt (List.foldl1' (JS.Infix JS.OpAnd) (map (generateIfTest mode root) testChain)) - (JS.Block $ generateDecider mode parentModule label root success) - (JS.Block $ generateDecider mode parentModule label root failure) + (JS.Block $ generateDecider mode argLookup parentModule label root success) + (JS.Block $ generateDecider mode argLookup parentModule label root failure) ] Opt.FanOut path edges fallback -> [ JS.Switch (generateCaseTest mode root path (fst (head edges))) ( foldr - (\edge cases -> generateCaseBranch mode parentModule label root edge : cases) - [JS.Default (generateDecider mode parentModule label root fallback)] + (\edge cases -> generateCaseBranch mode argLookup parentModule label root edge : cases) + [JS.Default (generateDecider mode argLookup parentModule label root fallback)] edges ) ] @@ -742,11 +803,11 @@ generateIfTest mode root (path, test) = DT.IsRecord -> error "COMPILER BUG - there should never be tests on a record" -generateCaseBranch :: Mode.Mode -> ModuleName.Canonical -> Name.Name -> Name.Name -> (DT.Test, Opt.Decider Opt.Choice) -> JS.Case -generateCaseBranch mode parentModule label root (test, subTree) = +generateCaseBranch :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Name.Name -> Name.Name -> (DT.Test, Opt.Decider Opt.Choice) -> JS.Case +generateCaseBranch mode argLookup parentModule label root (test, subTree) = JS.Case (generateCaseValue mode test) - (generateDecider mode parentModule label root subTree) + (generateDecider mode argLookup parentModule label root subTree) generateCaseValue :: Mode.Mode -> DT.Test -> JS.Expr generateCaseValue mode test = @@ -825,8 +886,8 @@ pathToJsExpr mode root path = -- GENERATE MAIN -generateMain :: Mode.Mode -> ModuleName.Canonical -> Opt.Main -> JS.Expr -generateMain mode home main = +generateMain :: Mode.Mode -> FnArgLookup -> ModuleName.Canonical -> Opt.Main -> JS.Expr +generateMain mode argLookup home main = case main of Opt.StaticString -> JS.Ref (JsName.fromKernel Name.node "log") @@ -838,7 +899,7 @@ generateMain mode home main = # JS.Int 0 Opt.Dynamic msgType decoder -> JS.Ref (JsName.fromGlobal home "main") - # generateJsExpr mode home decoder + # generateJsExpr mode argLookup home decoder # toDebugMetadata mode msgType (#) :: JS.Expr -> JS.Expr -> JS.Expr diff --git a/compiler/src/Generate/JavaScript/Name.hs b/compiler/src/Generate/JavaScript/Name.hs index 95218105..9ae409cc 100644 --- a/compiler/src/Generate/JavaScript/Name.hs +++ b/compiler/src/Generate/JavaScript/Name.hs @@ -9,6 +9,7 @@ module Generate.JavaScript.Name fromLocal, fromLocalHumanReadable, fromGlobal, + fromGlobalDirectFn, fromGlobalHumanReadable, fromCycle, fromKernel, @@ -58,6 +59,10 @@ fromGlobal :: ModuleName.Canonical -> Name.Name -> Name fromGlobal home name = Name $ homeToBuilder home <> usd <> Name.toBuilder name +fromGlobalDirectFn :: ModuleName.Canonical -> Name.Name -> Name +fromGlobalDirectFn home name = + Name $ homeToBuilder home <> usd <> Name.toBuilder name <> usd + fromGlobalHumanReadable :: ModuleName.Canonical -> Name.Name -> Name fromGlobalHumanReadable (ModuleName.Canonical _ moduleName) name = Name $ diff --git a/compiler/src/Generate/Node.hs b/compiler/src/Generate/Node.hs index 8a7e13d7..6d535b0f 100644 --- a/compiler/src/Generate/Node.hs +++ b/compiler/src/Generate/Node.hs @@ -12,7 +12,7 @@ import Data.Name qualified as Name import Text.RawString.QQ (r) leadingLines :: Int -leadingLines = 3 +leadingLines = 7 sandwich :: Name.Name -> B.Builder -> B.Builder sandwich moduleName javascript = diff --git a/compiler/src/Nitpick/Debug.hs b/compiler/src/Nitpick/Debug.hs index 662d7408..0f5ab715 100644 --- a/compiler/src/Nitpick/Debug.hs +++ b/compiler/src/Nitpick/Debug.hs @@ -43,7 +43,7 @@ hasDebug expression = Opt.VarDebug _ _ _ _ -> True Opt.VarKernel _ _ _ -> False Opt.Array _ exprs -> any hasDebug exprs - Opt.Function _ expr -> hasDebug expr + Opt.Function _ _ expr -> hasDebug expr Opt.Call _ e es -> hasDebug e || any hasDebug es Opt.TailCall _ args -> any (hasDebug . snd) args Opt.If conds finally -> any (\(c, e) -> hasDebug c || hasDebug e) conds || hasDebug finally diff --git a/compiler/src/Optimize/DecisionTree.hs b/compiler/src/Optimize/DecisionTree.hs index 194556bd..8a1471ea 100644 --- a/compiler/src/Optimize/DecisionTree.hs +++ b/compiler/src/Optimize/DecisionTree.hs @@ -68,7 +68,7 @@ data Test | IsChr ES.String | IsStr ES.String | IsBool Bool - deriving (Eq, Ord) + deriving (Show, Eq, Ord) data Path = Index Index.ZeroBased Path @@ -76,7 +76,7 @@ data Path | RecordField Name.Name Path | Unbox Path | Empty - deriving (Eq) + deriving (Show, Eq) -- ACTUALLY BUILD DECISION TREES diff --git a/compiler/src/Optimize/Expression.hs b/compiler/src/Optimize/Expression.hs index b783b2bc..d6bc4ca0 100644 --- a/compiler/src/Optimize/Expression.hs +++ b/compiler/src/Optimize/Expression.hs @@ -70,7 +70,7 @@ optimize cycle (A.At region expression) = do (argNames, destructors) <- destructArgs args obody <- optimize cycle body - pure $ Opt.Function argNames (foldr Opt.Destruct obody destructors) + pure $ Opt.Function region argNames (foldr Opt.Destruct obody destructors) Can.Call func args -> Opt.Call region <$> optimize cycle func @@ -158,7 +158,7 @@ optimizeDefHelp cycle region name args expr body = _ -> do (argNames, destructors) <- destructArgs args - let ofunc = Opt.Function argNames (foldr Opt.Destruct oexpr destructors) + let ofunc = Opt.Function region argNames (foldr Opt.Destruct oexpr destructors) pure $ Opt.Let (Opt.Def region name ofunc) body -- DESTRUCTURING @@ -361,7 +361,7 @@ toTailDef :: A.Region -> Name.Name -> [A.Located Name.Name] -> [Opt.Destructor] toTailDef region name argNames destructors body = if hasTailCall body then Opt.TailDef region name argNames (foldr Opt.Destruct body destructors) - else Opt.Def region name (Opt.Function argNames (foldr Opt.Destruct body destructors)) + else Opt.Def region name (Opt.Function A.zero argNames (foldr Opt.Destruct body destructors)) hasTailCall :: Opt.Expr -> Bool hasTailCall expression = diff --git a/compiler/src/Optimize/Module.hs b/compiler/src/Optimize/Module.hs index 2dafc008..a00f8261 100644 --- a/compiler/src/Optimize/Module.hs +++ b/compiler/src/Optimize/Module.hs @@ -211,7 +211,7 @@ addDefNode home region name args body mainDeps graph = (argNames, destructors) <- Expr.destructArgs args obody <- Expr.optimize Set.empty body pure $ - Opt.Function argNames $ + Opt.Function A.zero argNames $ foldr Opt.Destruct obody destructors in addToGraph (Opt.Global home name) (Opt.Define region def (Set.union deps mainDeps)) fields graph diff --git a/compiler/src/Optimize/Port.hs b/compiler/src/Optimize/Port.hs index 21eff5d5..4c6e80c5 100644 --- a/compiler/src/Optimize/Port.hs +++ b/compiler/src/Optimize/Port.hs @@ -61,7 +61,7 @@ toEncoder tipe = object <- encode "object" keyValuePairs <- traverse encodeField (Map.toList fields) Names.registerFieldDict fields $ - Opt.Function [A.At A.zero Name.dollar] (Opt.Call A.zero object [Opt.Array A.zero keyValuePairs]) + Opt.Function A.zero [A.At A.zero Name.dollar] (Opt.Call A.zero object [Opt.Array A.zero keyValuePairs]) -- ENCODE HELPERS @@ -72,7 +72,7 @@ encodeMaybe tipe = encoder <- toEncoder tipe destruct <- Names.registerGlobal A.zero ModuleName.maybe "destruct" return $ - Opt.Function [A.At A.zero Name.dollar] $ + Opt.Function A.zero [A.At A.zero Name.dollar] $ Opt.Call A.zero destruct [null, encoder, Opt.VarLocal A.zero Name.dollar] encodeArray :: Can.Type -> Names.Tracker Opt.Expr @@ -183,7 +183,7 @@ fieldAndThen decoder (key, Can.FieldType _ tipe) = return $ (Opt.Call A.zero) andThen - [ Opt.Function [A.At A.zero key] decoder, + [ Opt.Function A.zero [A.At A.zero key] decoder, Opt.Call A.zero field [Opt.Str A.zero (Name.toGrenString key), typeDecoder] ] diff --git a/compiler/src/Reporting/Annotation.hs b/compiler/src/Reporting/Annotation.hs index b8452c96..580a84c1 100644 --- a/compiler/src/Reporting/Annotation.hs +++ b/compiler/src/Reporting/Annotation.hs @@ -12,6 +12,7 @@ module Reporting.Annotation toRegion, mergeRegions, zero, + zeroPosition, one, ) where @@ -74,7 +75,10 @@ mergeRegions (Region start _) (Region _ end) = zero :: Region zero = - Region (Position 0 0) (Position 0 0) + Region zeroPosition zeroPosition + +zeroPosition :: Position +zeroPosition = Position 0 0 one :: Region one = diff --git a/gren.json b/gren.json index 0d4c86ef..f25f832a 100644 --- a/gren.json +++ b/gren.json @@ -4,11 +4,11 @@ "source-directories": [ "src" ], - "gren-version": "0.4.3", + "gren-version": "0.4.4", "dependencies": { "direct": { - "gren-lang/core": "5.0.0", - "gren-lang/node": "4.1.0" + "gren-lang/core": "5.0.1", + "gren-lang/node": "4.1.1" }, "indirect": { "gren-lang/url": "4.0.0" diff --git a/index.js b/index.js index 5e3b7d3f..a0abab0e 100644 --- a/index.js +++ b/index.js @@ -268,12 +268,12 @@ var _Node_log = F2(function (text, args) { var _Node_init = _Scheduler_binding(function (callback) { callback( _Scheduler_succeed({ - ay: _FilePath_fromString(module.filename), - az: process.arch, + ax: _FilePath_fromString(module.filename), + ay: process.arch, i: process.argv, v: process.platform, h: process.stderr, - be: process.stdin, + bd: process.stdin, c: process.stdout, }) ); @@ -339,7 +339,7 @@ var _FilePath_parse = function (pathMod, str) { t: dirStr === "" ? [] : dirStr.split(pathMod.sep), j: result.ext.length > 0 ? result.ext.substring(1) : "", k: filename, - ba: result.root, + a9: result.root, }; }; @@ -348,8 +348,8 @@ var _FilePath_toPosix = function (filePath) { return "."; } - if (filePath.ba !== "" && filePath.ba !== "/") { - filePath = { ...filePath, ba: "/" }; + if (filePath.a9 !== "" && filePath.a9 !== "/") { + filePath = { ...filePath, a9: "/" }; } return _FilePath_format(path.posix, filePath); @@ -373,7 +373,7 @@ var _FilePath_toString = function (filePath) { var _FilePath_isEmpty = function (filePath) { return ( - filePath.ba === "" && + filePath.a9 === "" && filePath.t.length === 0 && filePath.k === "" && filePath.j === "" @@ -393,7 +393,7 @@ var _FilePath_format = function (pathMod, filePath) { pathArray = filePath.t.concat(filename); } - return filePath.ba + pathArray.join(pathMod.sep); + return filePath.a9 + pathArray.join(pathMod.sep); }; @@ -403,9 +403,9 @@ var _Platform_worker = F4(function (impl, flagDecoder, debugMetadata, args) { return _Platform_initialize( flagDecoder, args, - impl.aT, - impl.bg, + impl.aS, impl.bf, + impl.be, function () { return function () {}; } @@ -2289,8 +2289,8 @@ var $gren_lang$core$Json$Decode$errorToStringHelp = F2(function(error, context) return false; } else { var _v2 = _v1.a; - var _char = _v2.aO; - var rest = _v2.a9; + var _char = _v2.aN; + var rest = _v2.a8; return $gren_lang$core$Char$isAlpha(_char) && A2($gren_lang$core$String$all, $gren_lang$core$Char$isAlphaNum, rest); } }(); @@ -2532,7 +2532,7 @@ var $gren_lang$node$Node$platformFromString = function(platform) { } }; var $gren_lang$node$Node$initializeEnvironment = A2($gren_lang$core$Task$map, function(raw) { - return { ay: raw.ay, i: raw.i, aG: $gren_lang$node$Node$archFromString(raw.az), v: $gren_lang$node$Node$platformFromString(raw.v), h: A2($gren_lang$node$Internal$Stream$Stream, 1, raw.h), be: A2($gren_lang$node$Internal$Stream$Stream, 2, raw.be), c: A2($gren_lang$node$Internal$Stream$Stream, 0, raw.c) }; + return { ax: raw.ax, i: raw.i, aF: $gren_lang$node$Node$archFromString(raw.ay), v: $gren_lang$node$Node$platformFromString(raw.v), h: A2($gren_lang$node$Internal$Stream$Stream, 1, raw.h), bd: A2($gren_lang$node$Internal$Stream$Stream, 2, raw.bd), c: A2($gren_lang$node$Internal$Stream$Stream, 0, raw.c) }; }, _Node_init); var $gren_lang$core$Task$Perform = function (a) { return { $: 0, a: a }; @@ -2639,13 +2639,15 @@ var $gren_lang$node$Node$update = F3(function(appUpdate, msg, model) { }); var $gren_lang$core$Platform$worker = _Platform_worker; var $gren_lang$node$Node$defineProgram = function(config) { - return $gren_lang$core$Platform$worker({ aT: $gren_lang$node$Node$init(config.aT), bf: $gren_lang$node$Node$subscriptions(config.bf), bg: $gren_lang$node$Node$update(config.bg) }); + return $gren_lang$core$Platform$worker({ aS: $gren_lang$node$Node$init(config.aS), be: $gren_lang$node$Node$subscriptions(config.be), bf: $gren_lang$node$Node$update(config.bf) }); }; var $author$project$Main$ExistanceChecked = function (a) { return { $: 0, a: a }; }; -var $gren_lang$core$Basics$composeL = F3(function(g, f, x) { - return g(f(x)); +var $gren_lang$core$Basics$composeL = F2(function(g, f) { + return function(x) { + return g(f(x)); + }; }); var $gren_lang$core$Task$onError = _Scheduler_onError; var $gren_lang$core$Task$attempt = F2(function(resultToMessage, task) { @@ -2708,9 +2710,9 @@ var _FileSystem_close = function (fh) { var _FileSystem_readFromOffset = F2(function (fh, options) { var requestedLength = - options.a_ < 0 || options.a_ > bufferNs.constants.MAX_LENGTH + options.aZ < 0 || options.aZ > bufferNs.constants.MAX_LENGTH ? bufferNs.constants.MAX_LENGTH - : options.a_; + : options.aZ; var fileOffset = options.a < 0 ? 0 : options.a; @@ -2842,8 +2844,8 @@ var _FileSystem_writeHelper = function ( var _FileSystem_remove = F2(function (options, path) { var rmOpts = { - force: options.aS, - recursive: options.a7, + force: options.aR, + recursive: options.a6, }; return _Scheduler_binding(function (callback) { @@ -2861,7 +2863,7 @@ var _FileSystem_makeDirectory = F2(function (options, path) { return _Scheduler_binding(function (callback) { fs.mkdir( _FilePath_toString(path), - { recursive: options.a7 }, + { recursive: options.a6 }, function (err) { if (err != null) { callback(_Scheduler_fail(_FileSystem_constructError(err))); @@ -2886,7 +2888,7 @@ var _FileSystem_listDirectory = function (path) { callback( _Scheduler_succeed( content.map((f) => ({ - a0: f.name, + a2: _FilePath_fromString(f.name), ae: _FileSystem_toEntityType(f), })) ) @@ -3237,15 +3239,15 @@ var _FileSystem_lstat = function (path) { var _FileSystem_statToGrenRecord = function (stats) { return { ae: _FileSystem_toEntityType(stats), - aA: stats.blksize, - aB: stats.blocks, - aD: stats.size, - aH: $gren_lang$core$Time$millisToPosix(Math.floor(stats.birthtimeMs)), - aJ: stats.dev, + az: stats.blksize, + aA: stats.blocks, + aC: stats.size, + aG: $gren_lang$core$Time$millisToPosix(Math.floor(stats.birthtimeMs)), + aI: stats.dev, K: stats.gid, - aX: $gren_lang$core$Time$millisToPosix(Math.floor(stats.atimeMs)), - aY: $gren_lang$core$Time$millisToPosix(Math.floor(stats.ctimeMs)), - aZ: $gren_lang$core$Time$millisToPosix(Math.floor(stats.mtimeMs)), + aW: $gren_lang$core$Time$millisToPosix(Math.floor(stats.atimeMs)), + aX: $gren_lang$core$Time$millisToPosix(Math.floor(stats.ctimeMs)), + aY: $gren_lang$core$Time$millisToPosix(Math.floor(stats.mtimeMs)), P: stats.uid, }; }; @@ -3375,7 +3377,7 @@ var $gren_lang$core$Array$slice = _Array_slice; var $gren_lang$core$Array$dropFirst = F2(function(n, array) { return A3($gren_lang$core$Array$slice, n, $gren_lang$core$Array$length(array), array); }); -var $gren_lang$node$FileSystem$Path$empty = { t: [ ], j: '', k: '', ba: '' }; +var $gren_lang$node$FileSystem$Path$empty = { t: [ ], j: '', k: '', a9: '' }; var $gren_lang$core$Basics$eq = _Utils_equal; var $gren_lang$core$Task$execute = function(task) { return $gren_lang$core$Task$command($gren_lang$core$Task$Execute(A2($gren_lang$core$Task$map, function(_v0) { @@ -3431,12 +3433,12 @@ var process = require("node:process"); var _Terminal_init = _Scheduler_binding(function (callback) { callback( _Scheduler_succeed({ - aV: process.stdout.isTTY, - aF: process.stdout.getColorDepth + aU: process.stdout.isTTY, + aE: process.stdout.getColorDepth ? process.stdout.getColorDepth() : 0, ab: process.stdout.columns, - at: process.stdout.rows, + as: process.stdout.rows, }) ); }); @@ -3447,7 +3449,7 @@ var _Terminal_attachListener = function (sendToApp) { _Scheduler_rawSpawn( sendToApp({ ab: process.stdout.columns, - at: process.stdout.rows, + as: process.stdout.rows, }) ); }; @@ -3476,7 +3478,7 @@ var _Terminal_setProcessTitle = function (title) { }; var $gren_lang$node$Terminal$Permission = 0; var $gren_lang$node$Terminal$initialize = A2($gren_lang$core$Task$map, function(raw) { - return raw.aV ? $gren_lang$core$Maybe$Just({ aF: raw.aF, ab: raw.ab, a4: 0, at: raw.at }) : $gren_lang$core$Maybe$Nothing; + return raw.aU ? $gren_lang$core$Maybe$Just({ aE: raw.aE, ab: raw.ab, a3: 0, as: raw.as }) : $gren_lang$core$Maybe$Nothing; }, _Terminal_init); var $gren_lang$core$Array$append = F2(function(fst, second) { return A2($gren_lang$core$Array$prepend, second, fst); @@ -3847,47 +3849,47 @@ var $author$project$Main$init = function(env) { } }(); var maybePaths = function () { - var _v2 = { az: env.aG, a2: A2($gren_lang$core$Dict$get, 'GREN_BIN', envVars), v: env.v }; + var _v2 = { ay: env.aF, a0: A2($gren_lang$core$Dict$get, 'GREN_BIN', envVars), v: env.v }; _v2$1: while (true) { _v2$5: while (true) { switch (_v2.v.$) { case 0: - if (!_v2.a2.$) { - var overridePath = _v2.a2.a; + if (!_v2.a0.$) { + var overridePath = _v2.a0.a; var _v3 = _v2.v; return $gren_lang$core$Maybe$Just({ i: userArgs, d: $gren_lang$node$FileSystem$Path$fromWin32String(overridePath), l: $gren_lang$core$Maybe$Nothing, c: env.c }); } else { - if (_v2.az.$ === 9) { + if (_v2.ay.$ === 9) { var _v4 = _v2.v; - var _v5 = _v2.az; + var _v5 = _v2.ay; return $gren_lang$core$Maybe$Just({ i: userArgs, d: A3($author$project$Main$makeLocalPath, env.v, homeDir, envVars), l: $gren_lang$core$Maybe$Just($author$project$Main$makeRemotePath('gren.exe')), c: env.c }); } else { break _v2$5; } } case 1: - if (!_v2.a2.$) { + if (!_v2.a0.$) { break _v2$1; } else { var _v6 = _v2.v; return $gren_lang$core$Maybe$Just({ i: userArgs, d: A3($author$project$Main$makeLocalPath, env.v, homeDir, envVars), l: $gren_lang$core$Maybe$Just($author$project$Main$makeRemotePath('gren_mac')), c: env.c }); } case 2: - if (!_v2.a2.$) { + if (!_v2.a0.$) { break _v2$1; } else { - if (_v2.az.$ === 9) { + if (_v2.ay.$ === 9) { var _v7 = _v2.v; - var _v8 = _v2.az; + var _v8 = _v2.ay; return $gren_lang$core$Maybe$Just({ i: userArgs, d: A3($author$project$Main$makeLocalPath, env.v, homeDir, envVars), l: $gren_lang$core$Maybe$Just($author$project$Main$makeRemotePath('gren_linux')), c: env.c }); } else { break _v2$5; } } default: - if (!_v2.a2.$) { + if (!_v2.a0.$) { break _v2$1; } else { break _v2$5; @@ -3896,7 +3898,7 @@ var $author$project$Main$init = function(env) { } return $gren_lang$core$Maybe$Nothing; } - var overridePath = _v2.a2.a; + var overridePath = _v2.a0.a; return $gren_lang$core$Maybe$Just({ i: userArgs, d: $gren_lang$node$FileSystem$Path$fromPosixString(overridePath), l: $gren_lang$core$Maybe$Nothing, c: env.c }); }(); var model = function () { @@ -3946,12 +3948,12 @@ var $gren_lang$node$FileSystem$accessPermissionsToInt = function(values) { return (A2(numberFor, 4, 0) + A2(numberFor, 2, 1)) + A2(numberFor, 1, 2); }; var $gren_lang$node$FileSystem$changeAccess = F3(function(_v0, permissions, path) { - var mode = _Utils_ap($gren_lang$core$String$fromInt($gren_lang$node$FileSystem$accessPermissionsToInt(permissions.a3)), _Utils_ap($gren_lang$core$String$fromInt($gren_lang$node$FileSystem$accessPermissionsToInt(permissions.aQ)), $gren_lang$core$String$fromInt($gren_lang$node$FileSystem$accessPermissionsToInt(permissions.a1)))); + var mode = _Utils_ap($gren_lang$core$String$fromInt($gren_lang$node$FileSystem$accessPermissionsToInt(permissions.a1)), _Utils_ap($gren_lang$core$String$fromInt($gren_lang$node$FileSystem$accessPermissionsToInt(permissions.aP)), $gren_lang$core$String$fromInt($gren_lang$node$FileSystem$accessPermissionsToInt(permissions.a$)))); return A2(_FileSystem_chmod, mode, path); }); var $gren_lang$node$HttpClient$ExpectBytes = { $: 4 }; var $gren_lang$node$HttpClient$expectBytes = function(req) { - return { aa: req.aa, aM: $gren_lang$node$HttpClient$ExpectBytes, aR: req.aR, ak: req.ak, aw: req.aw, I: req.I }; + return { aa: req.aa, aL: $gren_lang$node$HttpClient$ExpectBytes, aQ: req.aQ, ak: req.ak, av: req.av, I: req.I }; }; var $gren_lang$node$HttpServer$GET = { $: 0 }; var $gren_lang$node$HttpClient$BodyEmpty = { $: 0 }; @@ -3959,7 +3961,7 @@ var $gren_lang$node$HttpClient$ExpectAnything = { $: 1 }; var $gren_lang$core$Basics$mul = _Basics_mul; var $gren_lang$node$HttpClient$defaultTimeout = 10 * 1000; var $gren_lang$node$HttpClient$request = F2(function(method, url) { - return { aa: $gren_lang$node$HttpClient$BodyEmpty, aM: $gren_lang$node$HttpClient$ExpectAnything, aR: $gren_lang$core$Dict$empty, ak: method, aw: $gren_lang$node$HttpClient$defaultTimeout, I: url }; + return { aa: $gren_lang$node$HttpClient$BodyEmpty, aL: $gren_lang$node$HttpClient$ExpectAnything, aQ: $gren_lang$core$Dict$empty, ak: method, av: $gren_lang$node$HttpClient$defaultTimeout, I: url }; }); var $gren_lang$node$HttpClient$get = function(url) { return A2($gren_lang$node$HttpClient$request, $gren_lang$node$HttpServer$GET, url); @@ -3989,9 +3991,9 @@ var _HttpClient_request = function (config) { $gren_lang$core$Dict$foldl, _HttpClient_dictToObject, {}, - config.aR + config.aQ ), - timeout: config.aw, + timeout: config.av, }); } catch (e) { if (e.code === "ERR_INVALID_HTTP_TOKEN") { @@ -4024,7 +4026,7 @@ var _HttpClient_request = function (config) { }); req.on("response", (res) => { - const expectType = config.aN; + const expectType = config.aM; let rawData = null; @@ -4094,7 +4096,7 @@ var _HttpClient_request = function (config) { case "JSON": const jsonResult = A2( $gren_lang$core$Json$Decode$decodeString, - config.aM.a, + config.aL.a, rawData ); if ($gren_lang$core$Result$isOk(jsonResult)) { @@ -4157,9 +4159,9 @@ var _HttpClient_stream = F4(function (cleanup, sendToApp, request, config) { $gren_lang$core$Dict$foldl, _HttpClient_dictToObject, {}, - config.aR + config.aQ ), - timeout: config.aw, + timeout: config.av, }); } catch (e) { callback(_Scheduler_succeed(request)); @@ -4307,7 +4309,7 @@ var _HttpClient_dictToObject = F3(function (key, value, obj) { }); var _HttpClient_extractRequestBody = function (config) { - switch (config.aC) { + switch (config.aB) { case "EMPTY": return null; case "STRING": @@ -4332,10 +4334,10 @@ var _HttpClient_formatResponse = function (res, data) { } return { - bc: res.statusCode, - bd: res.statusMessage, - aR: headerDict, - aI: data, + bb: res.statusCode, + bc: res.statusMessage, + aQ: headerDict, + aH: data, }; }; var $gren_lang$node$HttpClient$Aborted = { $: 3 }; @@ -4420,7 +4422,7 @@ var $gren_lang$node$HttpClient$kernelRequestConfig = F2(function(permission, con return _Utils_ap(prefix, config.I); } }(); - return { aa: config.aa, aC: $gren_lang$node$HttpClient$bodyTypeAsString(config.aa), aM: config.aM, aN: $gren_lang$node$HttpClient$expectTypeAsString(config.aM), aR: config.aR, ak: $gren_lang$node$HttpServer$methodToString(config.ak), aw: config.aw, I: actualUrl }; + return { aa: config.aa, aB: $gren_lang$node$HttpClient$bodyTypeAsString(config.aa), aL: config.aL, aM: $gren_lang$node$HttpClient$expectTypeAsString(config.aL), aQ: config.aQ, ak: $gren_lang$node$HttpServer$methodToString(config.ak), av: config.av, I: actualUrl }; }); var $gren_lang$node$HttpClient$send = F2(function(permission, config) { return _HttpClient_request(A2($gren_lang$node$HttpClient$kernelRequestConfig, permission, config)); @@ -4443,7 +4445,7 @@ var $gren_lang$node$HttpClient$errorToString = function(err) { return 'Bad headers: one or more of your headers contains invalid characters.'; case 2: var res = err.a; - return _Utils_ap('Bad status: ', _Utils_ap($gren_lang$core$String$fromInt(res.bc), _Utils_ap(' - ', res.bd))); + return _Utils_ap('Bad status: ', _Utils_ap($gren_lang$core$String$fromInt(res.bb), _Utils_ap(' - ', res.bc))); case 3: var message = err.a; return _Utils_ap('Unexpected response body: ', message); @@ -4470,7 +4472,7 @@ var $gren_lang$core$Array$popLast = function(array) { var _v0 = $gren_lang$core$Array$last(array); if (!_v0.$) { var value = _v0.a; - return $gren_lang$core$Maybe$Just({ aU: A2($gren_lang$core$Array$dropLast, 1, array), aW: value }); + return $gren_lang$core$Maybe$Just({ aT: A2($gren_lang$core$Array$dropLast, 1, array), aV: value }); } else { return $gren_lang$core$Maybe$Nothing; } @@ -4481,8 +4483,8 @@ var $gren_lang$node$FileSystem$Path$parentPath = function(path) { return _Utils_eq($gren_lang$node$FileSystem$Path$filenameWithExtension(path), '') ? $gren_lang$core$Maybe$Nothing : $gren_lang$core$Maybe$Just(_Utils_update(path, { j: '', k: '' })); } else { var _v1 = _v0.a; - var last = _v1.aW; - var initial = _v1.aU; + var last = _v1.aV; + var initial = _v1.aT; var _v2 = function () { var _v3 = A2($gren_lang$core$String$split, '.', last); if (_v3.length === 2) { @@ -4506,7 +4508,7 @@ var $gren_lang$node$ChildProcess$InheritEnvironmentVariables = { $: 0 }; var $gren_lang$node$ChildProcess$InheritWorkingDirectory = { $: 0 }; var $gren_lang$node$ChildProcess$Integrated = 0; var $gren_lang$node$ChildProcess$NoLimit = { $: 0 }; -var $gren_lang$node$ChildProcess$defaultSpawnOptions = { Q: 0, aK: $gren_lang$node$ChildProcess$InheritEnvironmentVariables, w: $gren_lang$node$ChildProcess$NoLimit, x: $gren_lang$node$ChildProcess$DefaultShell, y: $gren_lang$node$ChildProcess$InheritWorkingDirectory }; +var $gren_lang$node$ChildProcess$defaultSpawnOptions = { Q: 0, aJ: $gren_lang$node$ChildProcess$InheritEnvironmentVariables, w: $gren_lang$node$ChildProcess$NoLimit, x: $gren_lang$node$ChildProcess$DefaultShell, y: $gren_lang$node$ChildProcess$InheritWorkingDirectory }; var $gren_lang$core$Dict$singleton = F2(function(key, value) { return A5($gren_lang$core$Dict$RBNode_gren_builtin, 1, key, value, $gren_lang$core$Dict$RBEmpty_gren_builtin, $gren_lang$core$Dict$RBEmpty_gren_builtin); }); @@ -4519,11 +4521,11 @@ var childProcess = require("node:child_process"); var _ChildProcess_run = function (options) { return _Scheduler_binding(function (callback) { var workingDir = options.y; - var env = options.aK; + var env = options.aJ; var shell = options.x; childProcess.execFile( - options.as, + options.ar, options._, { encoding: "buffer", @@ -4553,7 +4555,7 @@ var _ChildProcess_run = function (options) { } else { callback( _Scheduler_fail({ - aL: + aK: typeof err.errno === "undefined" ? err.code : err.errno, c: new DataView( stdout.buffer, @@ -4576,10 +4578,10 @@ var _ChildProcess_run = function (options) { var _ChildProcess_spawn = function (options) { return _Scheduler_binding(function (callback) { var workingDir = options.y; - var env = options.aK; + var env = options.aJ; var shell = options.x; - var subproc = childProcess.spawn(options.as, options._, { + var subproc = childProcess.spawn(options.ar, options._, { cwd: _ChildProcess_handleCwd(workingDir), env: _ChildProcess_handleEnv(env), timeout: options.w, @@ -4599,7 +4601,7 @@ var _ChildProcess_spawn = function (options) { }; function _ChildProcess_handleCwd(cwd) { - return cwd.M ? process.cwd() : cwd.a2; + return cwd.M ? process.cwd() : cwd.a0; } function _ChildProcess_handleEnv(env) { @@ -4645,8 +4647,8 @@ var $gren_lang$node$ChildProcess$spawn = F4(function(_v0, program, _arguments, o default: return 2; } - }(), aK: function () { - var _v2 = opts.aK; + }(), aJ: function () { + var _v2 = opts.aJ; switch (_v2.$) { case 0: return { u: 0, b: $gren_lang$core$Dict$empty }; @@ -4657,7 +4659,7 @@ var $gren_lang$node$ChildProcess$spawn = F4(function(_v0, program, _arguments, o var value = _v2.a; return { u: 2, b: value }; } - }(), as: program, w: function () { + }(), ar: program, w: function () { var _v3 = opts.w; if (!_v3.$) { return 0; @@ -4679,16 +4681,16 @@ var $gren_lang$node$ChildProcess$spawn = F4(function(_v0, program, _arguments, o }(), y: function () { var _v5 = opts.y; if (!_v5.$) { - return { M: true, a2: '' }; + return { M: true, a0: '' }; } else { var value = _v5.a; - return { M: false, a2: value }; + return { M: false, a0: value }; } }() })); }); var $author$project$Main$runCompiler = function(model) { var colorEnvVar = model.Z ? A2($gren_lang$core$Dict$singleton, 'FORCE_COLOR', '1') : A2($gren_lang$core$Dict$singleton, 'NO_COLOR', '1'); - return A4($gren_lang$node$ChildProcess$spawn, model.R, model.E(model.d), model.i, _Utils_update($gren_lang$node$ChildProcess$defaultSpawnOptions, { aK: $gren_lang$node$ChildProcess$MergeWithEnvironmentVariables(colorEnvVar) })); + return A4($gren_lang$node$ChildProcess$spawn, model.R, model.E(model.d), model.i, _Utils_update($gren_lang$node$ChildProcess$defaultSpawnOptions, { aJ: $gren_lang$node$ChildProcess$MergeWithEnvironmentVariables(colorEnvVar) })); }; var $gren_lang$node$FileSystem$writeFile = F3(function(_v0, bytes, path) { return A2(_FileSystem_writeFile, bytes, path); @@ -4716,8 +4718,8 @@ var $author$project$Main$update = F2(function(msg, model) { if (msg.a.a.$ === 2) { var err = msg.a.a; var res = err.a; - if (_Utils_eq(res.bc, 302)) { - var _v3 = A2($gren_lang$core$Dict$get, 'location', res.aR); + if (_Utils_eq(res.bb, 302)) { + var _v3 = A2($gren_lang$core$Dict$get, 'location', res.aQ); if ((!_v3.$) && (_v3.a.length === 1)) { var location = _v3.a[0]; return { e: A2($gren_lang$core$Task$attempt, $author$project$Main$CompilerDownloaded, A2($author$project$Main$downloadBinary, model.L, location)), f: model }; @@ -4736,9 +4738,9 @@ var $author$project$Main$update = F2(function(msg, model) { var cacheFolder = A2($gren_lang$core$Maybe$withDefault, $gren_lang$node$FileSystem$Path$empty, $gren_lang$node$FileSystem$Path$parentPath(model.d)); return { e: A2($gren_lang$core$Task$attempt, $author$project$Main$CompilerInstalled, A2($gren_lang$core$Task$andThen, function(_v5) { return A2($gren_lang$node$Stream$sendLine, model.c, 'Downloaded'); - }, A2($gren_lang$core$Task$andThen, A2($gren_lang$node$FileSystem$changeAccess, model.z, { aQ: [ 0, 2 ], a1: [ 0, 2 ], a3: [ 0, 1, 2 ] }), A2($gren_lang$core$Task$andThen, function(_v4) { - return A3($gren_lang$node$FileSystem$writeFile, model.z, res.aI, model.d); - }, A3($gren_lang$node$FileSystem$makeDirectory, model.z, { a7: true }, cacheFolder))))), f: model }; + }, A2($gren_lang$core$Task$andThen, A2($gren_lang$node$FileSystem$changeAccess, model.z, { aP: [ 0, 2 ], a$: [ 0, 2 ], a1: [ 0, 1, 2 ] }), A2($gren_lang$core$Task$andThen, function(_v4) { + return A3($gren_lang$node$FileSystem$writeFile, model.z, res.aH, model.d); + }, A3($gren_lang$node$FileSystem$makeDirectory, model.z, { a6: true }, cacheFolder))))), f: model }; } default: if (msg.a.$ === 1) { @@ -4749,9 +4751,9 @@ var $author$project$Main$update = F2(function(msg, model) { } } }); -var $author$project$Main$main = $gren_lang$node$Node$defineProgram({ aT: $author$project$Main$init, bf: function(_v0) { +var $author$project$Main$main = $gren_lang$node$Node$defineProgram({ aS: $author$project$Main$init, be: function(_v0) { return $gren_lang$core$Platform$Sub$none; - }, bg: $author$project$Main$update }); + }, bf: $author$project$Main$update }); _Platform_export({'Main':{'init':$author$project$Main$main($gren_lang$core$Json$Decode$succeed({ }))(0)}});}(this.module ? this.module.exports : this)); this.Gren.Main.init({}); }