comparison vext.ps1 @ 529:2cc8700975db

Update vext
author Chris Cannam
date Fri, 06 Oct 2017 13:28:52 +0100
parents 9fc762aafd01
children
comparison
equal deleted inserted replaced
528:b6906ff30276 529:2cc8700975db
3 .SYNOPSIS 3 .SYNOPSIS
4 A simple manager for third-party source code dependencies. 4 A simple manager for third-party source code dependencies.
5 Run "vext help" for more documentation. 5 Run "vext help" for more documentation.
6 6
7 #> 7 #>
8
9 Set-StrictMode -Version 2.0
10 $ErrorActionPreference = "Stop"
8 11
9 $sml = $env:VEXT_SML 12 $sml = $env:VEXT_SML
10 13
11 $mydir = Split-Path $MyInvocation.MyCommand.Path -Parent 14 $mydir = Split-Path $MyInvocation.MyCommand.Path -Parent
12 $program = "$mydir/vext.sml" 15 $program = "$mydir/vext.sml"
13 16
14 # We need either Poly/ML or SML/NJ. No great preference as to which. 17 # We need either Poly/ML or SML/NJ. No great preference as to which.
15 18
16 if (!$sml) { 19 if (!$sml) {
17 if (Get-Command "polyml" -ErrorAction SilentlyContinue) { 20 if (Get-Command "sml" -ErrorAction SilentlyContinue) {
21 $sml = "smlnj"
22 } elseif (Get-Command "polyml" -ErrorAction SilentlyContinue) {
18 $sml = "poly" 23 $sml = "poly"
19 } elseif (Get-Command "sml" -ErrorAction SilentlyContinue) {
20 $sml = "smlnj"
21 } else { 24 } else {
22 echo @" 25 echo @"
23 26
24 ERROR: No supported SML compiler or interpreter found 27 ERROR: No supported SML compiler or interpreter found
25 28
27 compiler or interpreter to run. 30 compiler or interpreter to run.
28 31
29 Please ensure you have one of the following SML implementations 32 Please ensure you have one of the following SML implementations
30 installed and present in your PATH, and try again. 33 installed and present in your PATH, and try again.
31 34
32 1. Poly/ML 35 1. Standard ML of New Jersey
36 - executable name: sml
37
38 2. Poly/ML
33 - executable name: polyml 39 - executable name: polyml
34
35 2. Standard ML of New Jersey
36 - executable name: sml
37 40
38 "@ 41 "@
39 exit 1 42 exit 1
40 } 43 }
41 } 44 }
42 45
43 if ($args -match "[^a-z]") { 46 if ($args -match "'""") {
44 $arglist = '["usage"]' 47 $arglist = '["usage"]'
45 } else { 48 } else {
46 $arglist = '["' + ($args -join '","') + '"]' 49 $arglist = '["' + ($args -join '","') + '"]'
47 } 50 }
48 51
49 if ($sml -eq "poly") { 52 if ($sml -eq "poly") {
50 53
51 $program = $program -replace "\\","\\\\" 54 $program = $program -replace "\\","\\\\"
52 echo "use ""$program""; vext $arglist" | polyml -q --error-exit | Out-Host 55 echo "use ""$program""; vext $arglist" | polyml -q --error-exit | Out-Host
56
57 if (-not $?) {
58 exit $LastExitCode
59 }
53 60
54 } elseif ($sml -eq "smlnj") { 61 } elseif ($sml -eq "smlnj") {
55 62
56 $lines = @(Get-Content $program) 63 $lines = @(Get-Content $program)
57 $lines = $lines -notmatch "val _ = main ()" 64 $lines = $lines -notmatch "val _ = main ()"
72 else (smlrun__prev := s; ())), 79 else (smlrun__prev := s; ())),
73 flush = fn s => () 80 flush = fn s => ()
74 }; 81 };
75 "@ -split "[\r\n]+" 82 "@ -split "[\r\n]+"
76 83
77 $outro = @" 84 $outro = @"
78 val _ = vext $arglist; 85 val _ = vext $arglist;
79 val _ = OS.Process.exit (OS.Process.success); 86 val _ = OS.Process.exit (OS.Process.success);
80 "@ -split "[\r\n]+" 87 "@ -split "[\r\n]+"
81 88
82 $script = @() 89 $script = @()
83 $script += $intro 90 $script += $intro
84 $script += $lines 91 $script += $lines
85 $script += $outro 92 $script += $outro
86 93
87 $tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml" 94 $tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml"
88 95
89 $script | Out-File -Encoding "ASCII" $tmpfile 96 $script | Out-File -Encoding "ASCII" $tmpfile
90 97
91 $env:CM_VERBOSE="false" 98 $env:CM_VERBOSE="false"
92 99
93 sml $tmpfile $args[1,$args.Length] 100 sml $tmpfile
94 101
95 del $tmpfile 102 if (-not $?) {
103 del $tmpfile
104 exit $LastExitCode
105 }
106
107 del $tmpfile
96 108
97 } else { 109 } else {
98 110
99 "Unknown SML implementation name: $sml" 111 "Unknown SML implementation name: $sml"
100 exit 2 112 exit 2
101 } 113 }