diff vext.ps1 @ 529:2cc8700975db

Update vext
author Chris Cannam
date Fri, 06 Oct 2017 13:28:52 +0100
parents 9fc762aafd01
children
line wrap: on
line diff
--- a/vext.ps1	Thu Aug 31 18:48:07 2017 +0100
+++ b/vext.ps1	Fri Oct 06 13:28:52 2017 +0100
@@ -6,6 +6,9 @@
 
 #>
 
+Set-StrictMode -Version 2.0
+$ErrorActionPreference = "Stop"
+
 $sml = $env:VEXT_SML
 
 $mydir = Split-Path $MyInvocation.MyCommand.Path -Parent
@@ -14,10 +17,10 @@
 # We need either Poly/ML or SML/NJ. No great preference as to which.
 
 if (!$sml) {
-    if (Get-Command "polyml" -ErrorAction SilentlyContinue) {
+    if (Get-Command "sml" -ErrorAction SilentlyContinue) {
+       $sml = "smlnj"
+    } elseif (Get-Command "polyml" -ErrorAction SilentlyContinue) {
        $sml = "poly"
-    } elseif (Get-Command "sml" -ErrorAction SilentlyContinue) {
-       $sml = "smlnj"
     } else {
        echo @"
 
@@ -29,18 +32,18 @@
   Please ensure you have one of the following SML implementations
   installed and present in your PATH, and try again.
 
-    1. Poly/ML
+    1. Standard ML of New Jersey
+       - executable name: sml
+
+    2. Poly/ML
        - executable name: polyml
 
-    2. Standard ML of New Jersey
-       - executable name: sml
-
 "@
        exit 1
     }
 }
 
-if ($args -match "[^a-z]") {
+if ($args -match "'""") {
     $arglist = '["usage"]'
 } else {
     $arglist = '["' + ($args -join '","') + '"]'
@@ -51,6 +54,10 @@
     $program = $program -replace "\\","\\\\"
     echo "use ""$program""; vext $arglist" | polyml -q --error-exit | Out-Host
 
+    if (-not $?) {
+        exit $LastExitCode
+    }
+
 } elseif ($sml -eq "smlnj") {
 
     $lines = @(Get-Content $program)
@@ -74,28 +81,33 @@
 };
 "@ -split "[\r\n]+"
 
-   $outro = @"
+    $outro = @"
 val _ = vext $arglist;
 val _ = OS.Process.exit (OS.Process.success);
 "@ -split "[\r\n]+"
 
-   $script = @()
-   $script += $intro
-   $script += $lines
-   $script += $outro
+    $script = @()
+    $script += $intro
+    $script += $lines
+    $script += $outro
 
-   $tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml"
+    $tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml"
 
-   $script | Out-File -Encoding "ASCII" $tmpfile
+    $script | Out-File -Encoding "ASCII" $tmpfile
 
-   $env:CM_VERBOSE="false"
+    $env:CM_VERBOSE="false"
 
-   sml $tmpfile $args[1,$args.Length]
+    sml $tmpfile
 
-   del $tmpfile
+    if (-not $?) {
+        del $tmpfile
+        exit $LastExitCode
+    }
+
+    del $tmpfile
 
 } else {
 
-   "Unknown SML implementation name: $sml"
-   exit 2
+    "Unknown SML implementation name: $sml"
+    exit 2
 }