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