comparison vext.ps1 @ 1733:d6d7c74c7eb7

Merge from branch "vext"
author Chris Cannam
date Mon, 10 Jul 2017 14:04:44 +0100
parents d60b30ea9b80
children 669bd699082d
comparison
equal deleted inserted replaced
1714:b693b9218f66 1733:d6d7c74c7eb7
1 <#
2
3 .SYNOPSIS
4 A simple manager for third-party source code dependencies.
5 Run "vext help" for more documentation.
6
7 #>
8
9 $sml = $env:VEXT_SML
10
11 $mydir = Split-Path $MyInvocation.MyCommand.Path -Parent
12 $program = "$mydir/vext.sml"
13
14 # We need either Poly/ML or SML/NJ. No great preference as to which.
15
16 if (!$sml) {
17 if (Get-Command "polyml" -ErrorAction SilentlyContinue) {
18 $sml = "poly"
19 } elseif (Get-Command "sml" -ErrorAction SilentlyContinue) {
20 $sml = "smlnj"
21 } else {
22 echo @"
23
24 ERROR: No supported SML compiler or interpreter found
25
26 The Vext external source code manager needs a Standard ML (SML)
27 compiler or interpreter to run.
28
29 Please ensure you have one of the following SML implementations
30 installed and present in your PATH, and try again.
31
32 1. Poly/ML
33 - executable name: polyml
34
35 2. Standard ML of New Jersey
36 - executable name: sml
37
38 "@
39 exit 1
40 }
41 }
42
43 if ($args -match "[^a-z]") {
44 $arglist = '["usage"]'
45 } else {
46 $arglist = '["' + ($args -join '","') + '"]'
47 }
48
49 if ($sml -eq "poly") {
50
51 $program = $program -replace "\\","\\\\"
52 echo "use ""$program""; vext $arglist" | polyml -q --error-exit | Out-Host
53
54 } elseif ($sml -eq "smlnj") {
55
56 $lines = @(Get-Content $program)
57 $lines = $lines -notmatch "val _ = main ()"
58
59 $intro = @"
60 val smlrun__cp =
61 let val x = !Control.Print.out in
62 Control.Print.out := { say = fn _ => (), flush = fn () => () };
63 x
64 end;
65 val smlrun__prev = ref "";
66 Control.Print.out := {
67 say = fn s =>
68 (if String.isSubstring "Error" s orelse String.isSubstring "Fail" s
69 then (Control.Print.out := smlrun__cp;
70 (#say smlrun__cp) (!smlrun__prev);
71 (#say smlrun__cp) s)
72 else (smlrun__prev := s; ())),
73 flush = fn s => ()
74 };
75 "@ -split "[\r\n]+"
76
77 $outro = @"
78 val _ = vext $arglist;
79 val _ = OS.Process.exit (OS.Process.success);
80 "@ -split "[\r\n]+"
81
82 $script = @()
83 $script += $intro
84 $script += $lines
85 $script += $outro
86
87 $tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml"
88
89 $script | Out-File -Encoding "ASCII" $tmpfile
90
91 $env:CM_VERBOSE="false"
92
93 sml $tmpfile $args[1,$args.Length]
94
95 del $tmpfile
96
97 } else {
98
99 "Unknown SML implementation name: $sml"
100 exit 2
101 }