c@50: <# c@50: c@50: .SYNOPSIS c@50: A simple manager for third-party source code dependencies. c@50: Run "vext help" for more documentation. c@50: c@50: #> c@50: c@50: $sml = $env:VEXT_SML c@50: c@50: $mydir = Split-Path $MyInvocation.MyCommand.Path -Parent c@50: $program = "$mydir/vext.sml" c@50: c@50: # We need either Poly/ML or SML/NJ. No great preference as to which. c@50: c@50: if (!$sml) { c@50: if (Get-Command "polyml" -ErrorAction SilentlyContinue) { c@50: $sml = "poly" c@50: } elseif (Get-Command "sml" -ErrorAction SilentlyContinue) { c@50: $sml = "smlnj" c@50: } else { c@50: echo @" c@50: c@50: ERROR: No supported SML compiler or interpreter found c@50: c@50: The Vext external source code manager needs a Standard ML (SML) c@50: compiler or interpreter to run. c@50: c@50: Please ensure you have one of the following SML implementations c@50: installed and present in your PATH, and try again. c@50: c@50: 1. Poly/ML c@50: - executable name: polyml c@50: c@50: 2. Standard ML of New Jersey c@50: - executable name: sml c@50: c@50: "@ c@50: exit 1 c@50: } c@50: } c@50: c@50: if ($args -match "[^a-z]") { c@50: $arglist = '["usage"]' c@50: } else { c@50: $arglist = '["' + ($args -join '","') + '"]' c@50: } c@50: c@50: if ($sml -eq "poly") { c@50: c@50: $program = $program -replace "\\","\\\\" c@50: echo "use ""$program""; vext $arglist" | polyml -q --error-exit | Out-Host c@50: c@50: } elseif ($sml -eq "smlnj") { c@50: c@50: $lines = @(Get-Content $program) c@50: $lines = $lines -notmatch "val _ = main ()" c@50: c@50: $intro = @" c@50: val smlrun__cp = c@50: let val x = !Control.Print.out in c@50: Control.Print.out := { say = fn _ => (), flush = fn () => () }; c@50: x c@50: end; c@50: val smlrun__prev = ref ""; c@50: Control.Print.out := { c@50: say = fn s => c@50: (if String.isSubstring "Error" s orelse String.isSubstring "Fail" s c@50: then (Control.Print.out := smlrun__cp; c@50: (#say smlrun__cp) (!smlrun__prev); c@50: (#say smlrun__cp) s) c@50: else (smlrun__prev := s; ())), c@50: flush = fn s => () c@50: }; c@50: "@ -split "[\r\n]+" c@50: c@50: $outro = @" c@50: val _ = vext $arglist; c@50: val _ = OS.Process.exit (OS.Process.success); c@50: "@ -split "[\r\n]+" c@50: c@50: $script = @() c@50: $script += $intro c@50: $script += $lines c@50: $script += $outro c@50: c@50: $tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml" c@50: c@50: $script | Out-File -Encoding "ASCII" $tmpfile c@50: c@50: $env:CM_VERBOSE="false" c@50: c@50: sml $tmpfile $args[1,$args.Length] c@50: c@50: del $tmpfile c@50: c@50: } else { c@50: c@50: "Unknown SML implementation name: $sml" c@50: exit 2 c@50: }