module SaplLinker import StdEnv, StdMaybe, ArgEnv import StringAppender, Map, File, FastString import linkargs, set_return_code import UtilStrictLists import SaplTokenizer, SaplLinkerShared import Platform, UtilIO Start world # commandline = getCommandLine # s_commandline = size commandline # (default_dir, world) = accFiles FStartUpDir world // the path of the linker # linkoptspath = if (s_commandline >= 3 && commandline.[1] == "-I") commandline.[2] (default_dir +++ "\\linkopts") # errors_path = if (s_commandline >= 5 && commandline.[3] == "-O") commandline.[4] (default_dir +++ "\\linkerrs") # ((linkopts,ok,message),world) = accFiles (ReadLinkOpts linkoptspath) world | not ok # (_,world) = accFiles (WriteLinkErrors errors_path [message]) world # world = set_return_code (-1) world = world # output_file = (fst (extractPathFileAndExtension linkopts.exe_path)) +++ "." +++ sapl_program_name_extension # (ok, built_ins_dir, world) = case sapl_stdenv_dir default_dir world of (Just dir, world) = (True, dir, world) (_ , world) = (False, "", world) | not ok # (_,world) = accFiles (WriteLinkErrors errors_path ["Error: Sapl built-in modules path not found"]) world # world = set_return_code (-1) world = world # (ok, builtin_module_paths, world) = built_in_modules built_ins_dir world # messages = case ok of False = ["Warning: built-in Sapl functions in "+++ built_ins_dir +++ " not found."] _ = [] # module_paths = map replace_extension (StrictListToList linkopts.object_paths) // Add first the conventional modules and the built-ins after that to ensure that // the built-in functions are used if they are avalaible # (lmap, messages, startfn, world) = read_modules module_paths newMap messages world # (lmap, messages, _, world) = read_modules builtin_module_paths lmap messages world // To debug // # messages = map (\(a,b) = a+++" - "+++toString b) (toList lmap) # (messages, world) = case startfn of Just fn # a = newAppender <++ "main = " <++ fn <++ "\n" # (lmap, loader, world, a) = generate_source lmap (dummy_loader,0) fn world a = (messages, writeFile output_file (toString a) world) = (["Error: Start function not found.":messages], world) # (err,world) = accFiles (WriteLinkErrors errors_path [ toString m \\ m <- reverse messages]) world | isNothing err = world # world = set_return_code (-1) world = world where replace_extension f = (fst (extractPathFileAndExtension f)) +++ "." +++ sapl_module_name_extension dummy_loader ls fn lmap world = (get fn lmap, lmap, ls, world)