From a29bd9b752f416191d973aba731e88c0030d950f Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sat, 15 Apr 2023 17:17:01 +0100 Subject: [PATCH 01/15] Add files via upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes made in cm-boot.sml to recognise the new command line parameter passed from script. a) In function args, line added to recognise the new command-line parameter ‘--script’, and a new function ‘nextargscript’ is called to initiate the process of the file. b) In function init(), the new function (useScriptFile) is added as one of the parameter passed. c) In function procCmdLine (), new function processFileScript is added to process the script file, function will check for whether the file passed on is a script file starting with ‘#!’ thru another new function checkSharpbang, consumes the first line thru another new function eatuntilneline and pass the remaining content of the file to function useScriptFile. --- base/cm/main/cm-boot.sml | 49 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/base/cm/main/cm-boot.sml b/base/cm/main/cm-boot.sml index 46202add..78f227df 100644 --- a/base/cm/main/cm-boot.sml +++ b/base/cm/main/cm-boot.sml @@ -690,17 +690,53 @@ functor LinkCM (structure HostBackend : BACKEND) = struct end end in - fun init (bootdir, de, er, useStream, useFile, errorwrap, icm) = let + fun init (bootdir, de, er, useStream, useScriptFile, useFile, errorwrap, icm) = let fun procCmdLine () = let val autoload' = errorwrap (ignore o autoload mkStdSrcPath) val make' = errorwrap (ignore o makeStd) - fun processFile (file, mk, ext) = (case ext + fun processFile (file, mk, ext) = ( + case ext of ("sml" | "sig" | "fun") => useFile file | "cm" => mk file | _ => Say.say [ "!* unable to process '", file, "' (unknown extension '", ext, "')\n" ] (* end case *)) + + (* DAYA change starts here *) + fun eatuntilnewline (instream : TextIO.instream): bool = let + val c = TextIO.input1 instream + in + case TextIO.lookahead instream of + SOME #"\n" => true + | SOME c => eatuntilnewline instream + | NONE => false + end + + fun checkSharpbang (instream : TextIO.instream): bool = let + val c = TextIO.input1 instream + in + case c of + SOME #"#" => ( + case TextIO.lookahead instream of + SOME #"!" => eatuntilnewline instream + | SOME c => false + | NONE => false + ) + | SOME c => false + | NONE => false + end + + fun processFileScript (fname) = let + val stream = TextIO.openIn fname + val isscript = checkSharpbang stream + in + if (isscript) = false + then ( Say.say [ "!* Script file doesn't start with #!. \n" ] ) + else ( useScriptFile (fname, stream) ) + end + (* DAYA change ends here *) + fun inc n = n + 1 fun show_controls (getarg, getval, padval) level = let fun walk indent (ControlRegistry.RTree rt) = let @@ -778,6 +814,7 @@ functor LinkCM (structure HostBackend : BACKEND) = struct \ .cm (CM.make or CM.autoload)\n\ \ -m (switch to CM.make)\n\ \ -a (switch to CM.autoload; default)\n\ + \ --script (execute scripts)\n\ \ .sig (use)\n\ \ .sml (use)\n\ \ .fun (use)\n\ @@ -878,6 +915,7 @@ functor LinkCM (structure HostBackend : BACKEND) = struct | args ("-S" :: _ :: _, mk) = (showcur NONE; nextarg mk) | args (["-E"], _) = (show_envvars NONE; quit ()) | args ("-E" :: _ :: _, mk) = (show_envvars NONE; nextarg mk) + | args ("--script" :: _, _) = (nextargscript ()) (* line added by Daya HWU *) | args ("@CMbuild" :: rest, _) = mlbuild rest | args (["@CMredump", heapfile], _) = redump_heap heapfile | args (f :: rest, mk) = @@ -890,6 +928,13 @@ functor LinkCM (structure HostBackend : BACKEND) = struct let val l = SMLofNJ.getArgs () in SMLofNJ.shiftArgs (); args (l, mk) end + + (* nextargscript added by Daya HWU *) + and nextargscript () = + let val l = SMLofNJ.getArgs () + in SMLofNJ.shiftArgs (); processFileScript (hd l); quit () + end + in case SMLofNJ.getArgs () of ["@CMslave"] => (#set StdConfig.verbose false; slave ()) From a7c305548a8d0273a6cc239f35c8d1986960263e Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sat, 15 Apr 2023 17:23:27 +0100 Subject: [PATCH 02/15] Add files via upload In functor BootEnvF, cminit function declaration is amended to include the newly added function useScriptFile. --- base/system/smlnj/internal/boot-env-fn.sml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/base/system/smlnj/internal/boot-env-fn.sml b/base/system/smlnj/internal/boot-env-fn.sml index d9b2d1f6..bab070e1 100644 --- a/base/system/smlnj/internal/boot-env-fn.sml +++ b/base/system/smlnj/internal/boot-env-fn.sml @@ -15,6 +15,7 @@ functor BootEnvF (datatype envrequest = AUTOLOAD | BARE val architecture: string val cminit : string * DynamicEnv.env * envrequest * (TextIO.instream -> unit)(* useStream *) + * (string * TextIO.instream -> unit) (* useScriptFile *) * (string -> unit) (* useFile *) * ((string -> unit) -> (string -> unit)) (* errorwrap *) @@ -70,7 +71,8 @@ functor BootEnvF (datatype envrequest = AUTOLOAD | BARE U.pStruct := U.NILrde; cminit (bootdir, de, er, Backend.Interact.useStream, - errorwrap false useFile, + Backend.Interact.useScriptFile, + errorwrap false useFile, errorwrap true, Backend.Interact.installCompManagers) end From d2700f56e9bc316f0036ef9bb45ef2d37a623bfb Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sat, 15 Apr 2023 17:24:51 +0100 Subject: [PATCH 03/15] Add files via upload A new function (useScriptFile) is added to Backend.Interact structure, which takes the file name and its content as a stream and process the stream by passing it to EvalLoop.evalStream. The compiler messages are muted and unmuted before the processing of the file. a) New function declaration is added to interact.sig, b) New function definition is added to interact.sml, --- base/compiler/TopLevel/interact/interact.sig | 1 + base/compiler/TopLevel/interact/interact.sml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/base/compiler/TopLevel/interact/interact.sig b/base/compiler/TopLevel/interact/interact.sig index be83754c..e7af248b 100644 --- a/base/compiler/TopLevel/interact/interact.sig +++ b/base/compiler/TopLevel/interact/interact.sig @@ -27,6 +27,7 @@ signature INTERACT = val useFile : string -> bool val useStream : TextIO.instream -> unit + val useScriptFile : string * TextIO.instream -> unit (* Addded by DAYA *) val evalStream : TextIO.instream * Environment.environment -> Environment.environment val withErrorHandling : bool -> (* true: treat all exns like usercode exns *) diff --git a/base/compiler/TopLevel/interact/interact.sml b/base/compiler/TopLevel/interact/interact.sml index e726ebcf..903f85ab 100644 --- a/base/compiler/TopLevel/interact/interact.sml +++ b/base/compiler/TopLevel/interact/interact.sml @@ -91,6 +91,22 @@ functor Interact(EvalLoop : EVALLOOP) : INTERACT = fun useStream stream = EvalLoop.evalStream ("", stream) + (* Added by DAYA*) + + fun useScriptFile (fname, stream) = ( + + Mutecompiler.silenceCompiler () ; + EvalLoop.evalStream ("", (TextIO.openString "Backend.Mutecompiler.mcdummyfn ();") ) ; + Mutecompiler.unsilenceCompiler () ; + + (EvalLoop.evalStream (fname, stream)) + handle exn => ( + Mutecompiler.printStashedCompilerOutput (); + Mutecompiler.unsilenceCompiler (); + EvalLoop.uncaughtExnMessage exn + ) + ) + fun evalStream (stream, baseEnv) = let val r = ref Environment.emptyEnv val base = { set = fn _ => raise Fail "evalStream: #set base", From c6415b59f26422bbbf7a2f48f90fbcd7cb6588c2 Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sat, 15 Apr 2023 17:29:33 +0100 Subject: [PATCH 04/15] Add files via upload New signature MUTECOMPILER is defined with all the global variables and functions that are part of Structure Mutecompiler, New structure Mutecompiler has two core functions silencecompiler and unsilencecompier. a. silencecompiler function mutes the compiler messages by saving the current printing limits in a ref cell and then set them all to zero. b. unsilencecompiler function unmutes the compiler messages by restoring the printing limits. c. dummyfn function which does nothing is created and invoked to preload the Mutecompiler structure before the script is passed to evalloop, this is to supress the structure auto-loading logs in the script results. --- .../TopLevel/interact/mutecompiler.sig | 27 ++++ .../TopLevel/interact/mutecompiler.sml | 142 ++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 base/compiler/TopLevel/interact/mutecompiler.sig create mode 100644 base/compiler/TopLevel/interact/mutecompiler.sml diff --git a/base/compiler/TopLevel/interact/mutecompiler.sig b/base/compiler/TopLevel/interact/mutecompiler.sig new file mode 100644 index 00000000..d755ea1e --- /dev/null +++ b/base/compiler/TopLevel/interact/mutecompiler.sig @@ -0,0 +1,27 @@ +(* mutecompiler.sig + * + * COPYRIGHT (c) 2019 The Fellowship of SML/NJ (http://www.smlnj.org) + * All rights reserved. + *) + +signature MUTECOMPILER = + sig + + val printlineLimit : int ref + val compilerMuted : bool ref + val isNewline : char -> bool + val push : 'a list ref -> 'a -> unit + val installPrintingLimitSettings : int list -> unit + val saveControlPrintOut : unit -> unit + val stashCompilerOutput : string -> unit + val savePrintingLimits : unit -> unit + val lowerPrintingLimitsToMin : unit -> unit + val restoreControlPrintOut : unit -> unit + val restorePrintingLimits : unit -> unit + val outputFlush : TextIO.outstream -> TextIO.vector -> unit + val silenceCompiler : unit -> unit + val unsilenceCompiler : unit -> unit + val printStashedCompilerOutput : unit -> unit + val mcdummyfn : unit -> unit + + end (* signature MUTECOMPILER *) diff --git a/base/compiler/TopLevel/interact/mutecompiler.sml b/base/compiler/TopLevel/interact/mutecompiler.sml new file mode 100644 index 00000000..6349fa78 --- /dev/null +++ b/base/compiler/TopLevel/interact/mutecompiler.sml @@ -0,0 +1,142 @@ +(* mutecompiler.sml + * + * COPYRIGHT (c) 2017 The Fellowship of SML/NJ (http://www.smlnj.org) + * All rights reserved. + *) + +structure Mutecompiler : MUTECOMPILER = + struct + + (* compile and execute the contents of a file. *) + local + val printingLimitRefs = + let open Control.Print + in [ + printDepth, (* default: 5 , max 10 *) + printLength, (* default: 12 , max 16 *) + stringDepth, (* default: 70 *) + intinfDepth (* default: 70 *) + ] + end; + + val savedControlPrintOut = ref NONE; + + val savedPrintingLimitSettings = ref NONE; + + val compilerOutputPreviousFullLines = ref ([] : string list); + + val compilerOutputCurrentLine = ref ([] : string list); + + + + in + + val printlineLimit = ref 5; + + val compilerMuted = ref false; + + (* 121 *) + fun isNewline #"\n" = true + | isNewline _ = false; + + (* 122 *) + fun push stack item = stack := item :: ! stack; + + (* 221 *) + fun installPrintingLimitSettings settings = + ListPair.app (op :=) (printingLimitRefs, settings); + + (* 11 *) + fun saveControlPrintOut () = + if isSome (! savedControlPrintOut) + then () + else savedControlPrintOut := SOME (! Control.Print.out); + + (* 12 *) + fun stashCompilerOutput string + = case String.fields isNewline string + of nil => raise (Fail "impossible ") (* 121 *) + | [chunk] => push compilerOutputCurrentLine chunk (* 122 *) + | chunk :: lines + => (if chunk <> "" then push compilerOutputCurrentLine chunk else (); + push compilerOutputPreviousFullLines + (String.concat (rev (! compilerOutputCurrentLine))); + let val (last :: others) = rev lines + in app (push compilerOutputPreviousFullLines) + (rev others); + compilerOutputCurrentLine + := (if last <> "" then [last] else []) + end); + + (* 13 *) + fun savePrintingLimits () = + if isSome (! savedPrintingLimitSettings) + then () + else savedPrintingLimitSettings := SOME (map ! printingLimitRefs); + + (* 14 *) + fun lowerPrintingLimitsToMin () = + List.app (fn r => r := 0) printingLimitRefs; + + (* 21 *) + fun restoreControlPrintOut () = + case ! savedControlPrintOut of + NONE => () + | SOME value => (savedControlPrintOut := NONE; + Control.Print.out := value); + (* 22 *) + fun restorePrintingLimits () = + case ! savedPrintingLimitSettings of + NONE => () + | SOME settings => (savedPrintingLimitSettings := NONE; + installPrintingLimitSettings settings); (* 221*) + (* 311 *) + fun outputFlush f s = (TextIO.output (f, s); TextIO.flushOut f); + + (* 31 *) + val printStdErr = outputFlush TextIO.stdErr; + + (* 1 *) + fun silenceCompiler () = + (compilerMuted := true; + saveControlPrintOut (); (* 11 *) + Control.Print.out := { flush = fn () => (), say = stashCompilerOutput }; (* 12 *) + savePrintingLimits (); (* 13 *) + lowerPrintingLimitsToMin ()); (* 14 *) + + (* 2 *) + fun unsilenceCompiler () = (compilerMuted := false; + restoreControlPrintOut (); (* 21 *) + restorePrintingLimits ()); (* 22 *) + + (* dummy function to silence the autoloading messages *) + fun mcdummyfn () = ( ); + + (* 3 *) + fun printStashedCompilerOutput () + = let val completeLines = length (! compilerOutputPreviousFullLines) + val partialLine = 0 < length (! compilerOutputCurrentLine) + val partialLines = if partialLine then 1 else 0 + val stashedOutput = 0 < completeLines orelse partialLine + in if stashedOutput andalso (!compilerMuted) + then (printStdErr ("___________________________________________________________________\n"); + let val linesShown + = ((if partialLine then [String.concat (rev (! compilerOutputCurrentLine))] else []) + @ List.take (! compilerOutputPreviousFullLines, + Int.min (completeLines, + !printlineLimit - partialLines))) + val numLinesShown = length linesShown + val last = completeLines + partialLines + val first = last - numLinesShown + 1 + in printStdErr (String.concat ["The last " ^ Int.toString (!printlineLimit) ^ " lines " ^ Int.toString first ^ " through " ^ Int.toString last ^ " of suppressed compiler messages are:\n"]); + foldr (fn (line, ()) => printStdErr (line ^ "\n")) + () + linesShown + end; + printStdErr ("_____________End of suppressed compiler messages.__________________\n") + ) + else () + end; + end + + end (* structure Mutecompiler *) \ No newline at end of file From 5477a0bc803476b949e25a77cf8588e0facb9df0 Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sat, 15 Apr 2023 17:30:57 +0100 Subject: [PATCH 05/15] Add files via upload A new structure Mutecompiler is declared within signature BACKEND. New structure Mutecompiler is defined within functor BackendFn. --- base/compiler/TopLevel/backend/backend-fn.sml | 1 + base/compiler/TopLevel/backend/backend.sig | 1 + 2 files changed, 2 insertions(+) diff --git a/base/compiler/TopLevel/backend/backend-fn.sml b/base/compiler/TopLevel/backend/backend-fn.sml index ac6a2986..517d649c 100644 --- a/base/compiler/TopLevel/backend/backend-fn.sml +++ b/base/compiler/TopLevel/backend/backend-fn.sml @@ -92,4 +92,5 @@ functor BackendFn ( structure Machine = M.Machine val architecture = M.architecture val abi_variant = M.abi_variant + structure Mutecompiler = Mutecompiler end diff --git a/base/compiler/TopLevel/backend/backend.sig b/base/compiler/TopLevel/backend/backend.sig index b48d8eac..b60c0fdd 100644 --- a/base/compiler/TopLevel/backend/backend.sig +++ b/base/compiler/TopLevel/backend/backend.sig @@ -6,6 +6,7 @@ signature BACKEND = sig structure Profile : PROFILE structure Compile : COMPILE structure Interact : INTERACT + structure Mutecompiler : MUTECOMPILER structure Machine : MACHINE val architecture: string val abi_variant: string option From f30de50d6b666afc6c98baeaf6ad0f838cc83e3e Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sat, 15 Apr 2023 17:31:45 +0100 Subject: [PATCH 06/15] Add files via upload INDEX, MAP and core.cm are updated with definitions for signature MUTECOMPILER and structure Mutecompiler. --- base/compiler/INDEX | 4 ++++ base/compiler/MAP | 4 +++- base/compiler/core.cm | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/base/compiler/INDEX b/base/compiler/INDEX index 2b3cf30c..c1a96773 100644 --- a/base/compiler/INDEX +++ b/base/compiler/INDEX @@ -271,6 +271,10 @@ MODULEUTIL ElabData/modules/moduleutil.sig ModuleUtil ElabData/modules/moduleutil.sml +MUTECOMPILER + TopLevel/interact/mutecompiler.sig +Mutecompiler + TopLevel/interact/mutecompiler.sml PARSER_CONTROL Parse/main/parsercontrol.sml ParserControl diff --git a/base/compiler/MAP b/base/compiler/MAP index 052f9de5..ac19f456 100644 --- a/base/compiler/MAP +++ b/base/compiler/MAP @@ -518,7 +518,6 @@ Library/ (was MiscUtil) supporting unpickling defs: UNPICKLE_UTIL, UnpickleUtil :> UNPICKLE_UTIL - 3. Middle End ------------- @@ -623,6 +622,9 @@ TopLevel/ interact.sig,sml creating top-level loops defs: INTERACT, Interact: EVALLOOP => INTERACT + mutecompiler.sig,sml + allow compiler silencing + defs: MUTECOMPILER, Mutecompiler print/ Pretty printing for absyn declarations, values diff --git a/base/compiler/core.cm b/base/compiler/core.cm index fb37edc0..55f9f85c 100644 --- a/base/compiler/core.cm +++ b/base/compiler/core.cm @@ -163,6 +163,9 @@ TopLevel/interact/evalloop.sig TopLevel/interact/evalloop.sml TopLevel/interact/interact.sig TopLevel/interact/interact.sml +TopLevel/interact/mutecompiler.sig +TopLevel/interact/mutecompiler.sml + TopLevel/backend/backend.sig TopLevel/backend/backend-fn.sml @@ -367,3 +370,4 @@ $/pickle-lib.cm $smlnj/init/init.cmi : cm (* to gain access at CoreIntInf *) $smlnj/internal/smlnj-version.cm + From 1738ba139a0a7c5cded8d021d70b4c845819d0a0 Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sat, 15 Apr 2023 17:39:25 +0100 Subject: [PATCH 07/15] Add files via upload --- base/cm/main/cm-boot.sml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/base/cm/main/cm-boot.sml b/base/cm/main/cm-boot.sml index 78f227df..e9c19718 100644 --- a/base/cm/main/cm-boot.sml +++ b/base/cm/main/cm-boot.sml @@ -694,8 +694,7 @@ functor LinkCM (structure HostBackend : BACKEND) = struct fun procCmdLine () = let val autoload' = errorwrap (ignore o autoload mkStdSrcPath) val make' = errorwrap (ignore o makeStd) - fun processFile (file, mk, ext) = ( - case ext + fun processFile (file, mk, ext) = (case ext of ("sml" | "sig" | "fun") => useFile file | "cm" => mk file | _ => Say.say [ @@ -814,7 +813,7 @@ functor LinkCM (structure HostBackend : BACKEND) = struct \ .cm (CM.make or CM.autoload)\n\ \ -m (switch to CM.make)\n\ \ -a (switch to CM.autoload; default)\n\ - \ --script (execute scripts)\n\ + \ --script (execute scripts)\n\ \ .sig (use)\n\ \ .sml (use)\n\ \ .fun (use)\n\ @@ -915,7 +914,7 @@ functor LinkCM (structure HostBackend : BACKEND) = struct | args ("-S" :: _ :: _, mk) = (showcur NONE; nextarg mk) | args (["-E"], _) = (show_envvars NONE; quit ()) | args ("-E" :: _ :: _, mk) = (show_envvars NONE; nextarg mk) - | args ("--script" :: _, _) = (nextargscript ()) (* line added by Daya HWU *) + | args ("--script" :: _, _) = (nextargscript ()) (* line added by Daya HWU *) | args ("@CMbuild" :: rest, _) = mlbuild rest | args (["@CMredump", heapfile], _) = redump_heap heapfile | args (f :: rest, mk) = From 6d2aee274ce0cc6a69c045e328a0bfea283f5b04 Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sat, 15 Apr 2023 17:46:02 +0100 Subject: [PATCH 08/15] Add files via upload --- base/system/smlnj/internal/boot-env-fn.sml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/base/system/smlnj/internal/boot-env-fn.sml b/base/system/smlnj/internal/boot-env-fn.sml index bab070e1..b31ba97a 100644 --- a/base/system/smlnj/internal/boot-env-fn.sml +++ b/base/system/smlnj/internal/boot-env-fn.sml @@ -15,7 +15,7 @@ functor BootEnvF (datatype envrequest = AUTOLOAD | BARE val architecture: string val cminit : string * DynamicEnv.env * envrequest * (TextIO.instream -> unit)(* useStream *) - * (string * TextIO.instream -> unit) (* useScriptFile *) + * (string * TextIO.instream -> unit) (* useScriptFile *) * (string -> unit) (* useFile *) * ((string -> unit) -> (string -> unit)) (* errorwrap *) @@ -71,8 +71,8 @@ functor BootEnvF (datatype envrequest = AUTOLOAD | BARE U.pStruct := U.NILrde; cminit (bootdir, de, er, Backend.Interact.useStream, - Backend.Interact.useScriptFile, - errorwrap false useFile, + Backend.Interact.useScriptFile, + errorwrap false useFile, errorwrap true, Backend.Interact.installCompManagers) end From d37ae665519756608bd6de598a74984984d0c2e8 Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sat, 15 Apr 2023 17:46:36 +0100 Subject: [PATCH 09/15] Add files via upload --- base/compiler/core.cm | 2 -- 1 file changed, 2 deletions(-) diff --git a/base/compiler/core.cm b/base/compiler/core.cm index 55f9f85c..8d2231d3 100644 --- a/base/compiler/core.cm +++ b/base/compiler/core.cm @@ -166,7 +166,6 @@ TopLevel/interact/interact.sml TopLevel/interact/mutecompiler.sig TopLevel/interact/mutecompiler.sml - TopLevel/backend/backend.sig TopLevel/backend/backend-fn.sml @@ -370,4 +369,3 @@ $/pickle-lib.cm $smlnj/init/init.cmi : cm (* to gain access at CoreIntInf *) $smlnj/internal/smlnj-version.cm - From e34af801ae6c2260210e8668eb8b9398459a4d84 Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sat, 15 Apr 2023 17:49:28 +0100 Subject: [PATCH 10/15] Add files via upload --- base/compiler/MAP | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/compiler/MAP b/base/compiler/MAP index ac19f456..7ba0980f 100644 --- a/base/compiler/MAP +++ b/base/compiler/MAP @@ -518,6 +518,7 @@ Library/ (was MiscUtil) supporting unpickling defs: UNPICKLE_UTIL, UnpickleUtil :> UNPICKLE_UTIL + 3. Middle End ------------- @@ -772,4 +773,4 @@ SML stuff. 3. MiscUtil was renamed Library, and has been simplified. It now contains only three subdirectories, which can possibly be thought of as somewhat -general purpose libraries. \ No newline at end of file +general purpose libraries. From 9327b7eaab6389889474dcb6207663c9d6bf08c8 Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sat, 15 Apr 2023 17:50:02 +0100 Subject: [PATCH 11/15] Add files via upload --- base/compiler/TopLevel/backend/backend-fn.sml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/compiler/TopLevel/backend/backend-fn.sml b/base/compiler/TopLevel/backend/backend-fn.sml index 517d649c..a6c97ac1 100644 --- a/base/compiler/TopLevel/backend/backend-fn.sml +++ b/base/compiler/TopLevel/backend/backend-fn.sml @@ -92,5 +92,5 @@ functor BackendFn ( structure Machine = M.Machine val architecture = M.architecture val abi_variant = M.abi_variant - structure Mutecompiler = Mutecompiler + structure Mutecompiler = Mutecompiler end From 12ddb1cd9814a1789f291cf7e05ca54311bd6be7 Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sun, 16 Apr 2023 11:26:55 +0100 Subject: [PATCH 12/15] Add files via upload --- base/cm/main/cm-boot.sml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/base/cm/main/cm-boot.sml b/base/cm/main/cm-boot.sml index e9c19718..b8882143 100644 --- a/base/cm/main/cm-boot.sml +++ b/base/cm/main/cm-boot.sml @@ -690,7 +690,8 @@ functor LinkCM (structure HostBackend : BACKEND) = struct end end in - fun init (bootdir, de, er, useStream, useScriptFile, useFile, errorwrap, icm) = let + (* New function useScriptFile included in the argument list as part of 'Execute as a script' change *) + fun init (bootdir, de, er, useStream, useScriptFile, useFile, errorwrap, icm) = let fun procCmdLine () = let val autoload' = errorwrap (ignore o autoload mkStdSrcPath) val make' = errorwrap (ignore o makeStd) @@ -702,7 +703,7 @@ functor LinkCM (structure HostBackend : BACKEND) = struct ] (* end case *)) - (* DAYA change starts here *) + (* 'Execute as a script' change starts here - *) fun eatuntilnewline (instream : TextIO.instream): bool = let val c = TextIO.input1 instream in @@ -734,7 +735,7 @@ functor LinkCM (structure HostBackend : BACKEND) = struct then ( Say.say [ "!* Script file doesn't start with #!. \n" ] ) else ( useScriptFile (fname, stream) ) end - (* DAYA change ends here *) + (* 'Execute as a script' change ends here *) fun inc n = n + 1 fun show_controls (getarg, getval, padval) level = let @@ -813,7 +814,7 @@ functor LinkCM (structure HostBackend : BACKEND) = struct \ .cm (CM.make or CM.autoload)\n\ \ -m (switch to CM.make)\n\ \ -a (switch to CM.autoload; default)\n\ - \ --script (execute scripts)\n\ + \ --script (execute as a script)\n\ \ .sig (use)\n\ \ .sml (use)\n\ \ .fun (use)\n\ @@ -914,7 +915,7 @@ functor LinkCM (structure HostBackend : BACKEND) = struct | args ("-S" :: _ :: _, mk) = (showcur NONE; nextarg mk) | args (["-E"], _) = (show_envvars NONE; quit ()) | args ("-E" :: _ :: _, mk) = (show_envvars NONE; nextarg mk) - | args ("--script" :: _, _) = (nextargscript ()) (* line added by Daya HWU *) + | args ("--script" :: _, _) = (nextargscript ()) (* added as part of 'Execute as a script' change *) | args ("@CMbuild" :: rest, _) = mlbuild rest | args (["@CMredump", heapfile], _) = redump_heap heapfile | args (f :: rest, mk) = @@ -928,7 +929,7 @@ functor LinkCM (structure HostBackend : BACKEND) = struct in SMLofNJ.shiftArgs (); args (l, mk) end - (* nextargscript added by Daya HWU *) + (* nextargscript added as part of 'Execute as a script' change *) and nextargscript () = let val l = SMLofNJ.getArgs () in SMLofNJ.shiftArgs (); processFileScript (hd l); quit () From 0429e3338d9814ffe355e20c82ff075df3504f43 Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sun, 16 Apr 2023 11:27:20 +0100 Subject: [PATCH 13/15] Add files via upload --- base/system/smlnj/internal/boot-env-fn.sml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/system/smlnj/internal/boot-env-fn.sml b/base/system/smlnj/internal/boot-env-fn.sml index b31ba97a..99f07bdb 100644 --- a/base/system/smlnj/internal/boot-env-fn.sml +++ b/base/system/smlnj/internal/boot-env-fn.sml @@ -15,7 +15,7 @@ functor BootEnvF (datatype envrequest = AUTOLOAD | BARE val architecture: string val cminit : string * DynamicEnv.env * envrequest * (TextIO.instream -> unit)(* useStream *) - * (string * TextIO.instream -> unit) (* useScriptFile *) + * (string * TextIO.instream -> unit) (* useScriptFile - added as part of 'Execute as a script' change *) * (string -> unit) (* useFile *) * ((string -> unit) -> (string -> unit)) (* errorwrap *) @@ -71,7 +71,7 @@ functor BootEnvF (datatype envrequest = AUTOLOAD | BARE U.pStruct := U.NILrde; cminit (bootdir, de, er, Backend.Interact.useStream, - Backend.Interact.useScriptFile, + Backend.Interact.useScriptFile, (* added as part of Execute as a script change *) errorwrap false useFile, errorwrap true, Backend.Interact.installCompManagers) From fc5c7503fdf483dc996c7757f2ac1671d1ef29f3 Mon Sep 17 00:00:00 2001 From: dn2007hw <97540697+dn2007hw@users.noreply.github.com> Date: Sun, 16 Apr 2023 11:28:00 +0100 Subject: [PATCH 14/15] Add files via upload --- base/compiler/TopLevel/interact/interact.sig | 2 +- base/compiler/TopLevel/interact/interact.sml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/base/compiler/TopLevel/interact/interact.sig b/base/compiler/TopLevel/interact/interact.sig index e7af248b..7443a21e 100644 --- a/base/compiler/TopLevel/interact/interact.sig +++ b/base/compiler/TopLevel/interact/interact.sig @@ -27,7 +27,7 @@ signature INTERACT = val useFile : string -> bool val useStream : TextIO.instream -> unit - val useScriptFile : string * TextIO.instream -> unit (* Addded by DAYA *) + val useScriptFile : string * TextIO.instream -> unit (* Addded as part of Execute as a script change *) val evalStream : TextIO.instream * Environment.environment -> Environment.environment val withErrorHandling : bool -> (* true: treat all exns like usercode exns *) diff --git a/base/compiler/TopLevel/interact/interact.sml b/base/compiler/TopLevel/interact/interact.sml index 903f85ab..7e4bc57b 100644 --- a/base/compiler/TopLevel/interact/interact.sml +++ b/base/compiler/TopLevel/interact/interact.sml @@ -93,8 +93,8 @@ functor Interact(EvalLoop : EVALLOOP) : INTERACT = (* Added by DAYA*) + (* Added as part of Execute as a script change with Mutecompiler *) fun useScriptFile (fname, stream) = ( - Mutecompiler.silenceCompiler () ; EvalLoop.evalStream ("", (TextIO.openString "Backend.Mutecompiler.mcdummyfn ();") ) ; Mutecompiler.unsilenceCompiler () ; From 1d0715488120dfd439f7fc48bdce563805b126b2 Mon Sep 17 00:00:00 2001 From: Dayanandan Natarajan Date: Tue, 2 May 2023 15:04:01 +0100 Subject: [PATCH 15/15] Execute as a script change - Comments included to add author info. --- base/cm/main/cm-boot.sml | 5 +++- base/compiler/TopLevel/backend/backend-fn.sml | 2 +- base/compiler/TopLevel/backend/backend.sig | 2 +- base/compiler/TopLevel/interact/interact.sig | 3 +++ base/compiler/TopLevel/interact/interact.sml | 27 ++++++++++--------- .../TopLevel/interact/mutecompiler.sig | 4 +++ .../TopLevel/interact/mutecompiler.sml | 4 +++ base/compiler/core.cm | 2 ++ base/system/smlnj/internal/boot-env-fn.sml | 3 +++ 9 files changed, 36 insertions(+), 16 deletions(-) diff --git a/base/cm/main/cm-boot.sml b/base/cm/main/cm-boot.sml index b8882143..9327ea09 100644 --- a/base/cm/main/cm-boot.sml +++ b/base/cm/main/cm-boot.sml @@ -7,6 +7,9 @@ * structure CM people find in $smlnj/cm/full.cm. * * author: Matthias Blume (blume@cs.princeton.edu) + * + * This module amended to include 'Execute as a script' change done by Dayanandan Natarajan, Heriot Watt University + * *) functor LinkCM (structure HostBackend : BACKEND) = struct @@ -703,7 +706,7 @@ functor LinkCM (structure HostBackend : BACKEND) = struct ] (* end case *)) - (* 'Execute as a script' change starts here - *) + (* 'Execute as a script' change starts here. Change added by Dayanandan Natarajan *) fun eatuntilnewline (instream : TextIO.instream): bool = let val c = TextIO.input1 instream in diff --git a/base/compiler/TopLevel/backend/backend-fn.sml b/base/compiler/TopLevel/backend/backend-fn.sml index a6c97ac1..622d3344 100644 --- a/base/compiler/TopLevel/backend/backend-fn.sml +++ b/base/compiler/TopLevel/backend/backend-fn.sml @@ -92,5 +92,5 @@ functor BackendFn ( structure Machine = M.Machine val architecture = M.architecture val abi_variant = M.abi_variant - structure Mutecompiler = Mutecompiler + structure Mutecompiler = Mutecompiler (* Added as part of 'Execute as a script' change done by Dayanandan Natarajan Heriot Watt University *) end diff --git a/base/compiler/TopLevel/backend/backend.sig b/base/compiler/TopLevel/backend/backend.sig index b60c0fdd..3db24781 100644 --- a/base/compiler/TopLevel/backend/backend.sig +++ b/base/compiler/TopLevel/backend/backend.sig @@ -6,7 +6,7 @@ signature BACKEND = sig structure Profile : PROFILE structure Compile : COMPILE structure Interact : INTERACT - structure Mutecompiler : MUTECOMPILER + structure Mutecompiler : MUTECOMPILER (* Added as part of 'Execute as a script' change done by Dayanandan Natarajan Heriot Watt University *) structure Machine : MACHINE val architecture: string val abi_variant: string option diff --git a/base/compiler/TopLevel/interact/interact.sig b/base/compiler/TopLevel/interact/interact.sig index 7443a21e..3fc6d33a 100644 --- a/base/compiler/TopLevel/interact/interact.sig +++ b/base/compiler/TopLevel/interact/interact.sig @@ -2,6 +2,9 @@ * * COPYRIGHT (c) 2019 The Fellowship of SML/NJ (http://www.smlnj.org) * All rights reserved. + * + * This module amended to include 'Execute as a script' change done by Dayanandan Natarajan, Heriot Watt University + * *) signature INTERACT = diff --git a/base/compiler/TopLevel/interact/interact.sml b/base/compiler/TopLevel/interact/interact.sml index 7e4bc57b..fdcc502d 100644 --- a/base/compiler/TopLevel/interact/interact.sml +++ b/base/compiler/TopLevel/interact/interact.sml @@ -2,6 +2,9 @@ * * COPYRIGHT (c) 2017 The Fellowship of SML/NJ (http://www.smlnj.org) * All rights reserved. + * + * This module amended to include 'Execute as a script' change done by Dayanandan Natarajan, Heriot Watt University + * *) functor Interact(EvalLoop : EVALLOOP) : INTERACT = @@ -91,20 +94,18 @@ functor Interact(EvalLoop : EVALLOOP) : INTERACT = fun useStream stream = EvalLoop.evalStream ("", stream) - (* Added by DAYA*) - - (* Added as part of Execute as a script change with Mutecompiler *) + (* Function added as part of Execute as a script change*) fun useScriptFile (fname, stream) = ( - Mutecompiler.silenceCompiler () ; - EvalLoop.evalStream ("", (TextIO.openString "Backend.Mutecompiler.mcdummyfn ();") ) ; - Mutecompiler.unsilenceCompiler () ; - - (EvalLoop.evalStream (fname, stream)) - handle exn => ( - Mutecompiler.printStashedCompilerOutput (); - Mutecompiler.unsilenceCompiler (); - EvalLoop.uncaughtExnMessage exn - ) + Mutecompiler.silenceCompiler () ; + EvalLoop.evalStream ("", (TextIO.openString "Backend.Mutecompiler.mcdummyfn ();") ) ; (* Idea from Dr Joe Wells HWU, to preload structure *) + Mutecompiler.unsilenceCompiler () ; + + (EvalLoop.evalStream (fname, stream)) + handle exn => ( + Mutecompiler.printStashedCompilerOutput (); + Mutecompiler.unsilenceCompiler (); + EvalLoop.uncaughtExnMessage exn + ) ) fun evalStream (stream, baseEnv) = let diff --git a/base/compiler/TopLevel/interact/mutecompiler.sig b/base/compiler/TopLevel/interact/mutecompiler.sig index d755ea1e..6529a72d 100644 --- a/base/compiler/TopLevel/interact/mutecompiler.sig +++ b/base/compiler/TopLevel/interact/mutecompiler.sig @@ -2,6 +2,10 @@ * * COPYRIGHT (c) 2019 The Fellowship of SML/NJ (http://www.smlnj.org) * All rights reserved. + * + * This module introduced as part 'Execute as a script' change done by Dayanandan Natarajan, Heriot Watt University + * and functions derived from 'smlnj-script' developed by Dr Joe Wells, Heriot Watt University + * *) signature MUTECOMPILER = diff --git a/base/compiler/TopLevel/interact/mutecompiler.sml b/base/compiler/TopLevel/interact/mutecompiler.sml index 6349fa78..008d2b34 100644 --- a/base/compiler/TopLevel/interact/mutecompiler.sml +++ b/base/compiler/TopLevel/interact/mutecompiler.sml @@ -2,6 +2,10 @@ * * COPYRIGHT (c) 2017 The Fellowship of SML/NJ (http://www.smlnj.org) * All rights reserved. + * + * This module introduced as part 'Execute as a script' change done by Dayanandan Natarajan, Heriot Watt University + * and functions derived from 'smlnj-script' developed by Dr Joe Wells, Heriot Watt University + * *) structure Mutecompiler : MUTECOMPILER = diff --git a/base/compiler/core.cm b/base/compiler/core.cm index 8d2231d3..5ae2ae74 100644 --- a/base/compiler/core.cm +++ b/base/compiler/core.cm @@ -163,6 +163,8 @@ TopLevel/interact/evalloop.sig TopLevel/interact/evalloop.sml TopLevel/interact/interact.sig TopLevel/interact/interact.sml + +(* mutecompiler added as part of 'Excute as a script' change done by Dayanandan Natarajan Heriot Watt University *) TopLevel/interact/mutecompiler.sig TopLevel/interact/mutecompiler.sml diff --git a/base/system/smlnj/internal/boot-env-fn.sml b/base/system/smlnj/internal/boot-env-fn.sml index 99f07bdb..12d81b0d 100644 --- a/base/system/smlnj/internal/boot-env-fn.sml +++ b/base/system/smlnj/internal/boot-env-fn.sml @@ -5,6 +5,9 @@ * completely redone by M.Blume (5/1998) * ... and again in the course of switching over to the new CM * (M. Blume, 7/1999) + * + * This module amended to include 'Execute as a script' change done by Dayanandan Natarajan, Heriot Watt University + * *) signature BOOTENV = sig val init: