forked from cannam/sml-buildscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polyrun.ps1
60 lines (40 loc) · 1.1 KB
/
polyrun.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<#
.SYNOPSIS
Use Poly/ML to run a Standard ML program defined in a .mlb file
.EXAMPLE
polyrun example.mlb datafile.txt
Run the Standard ML program defined in example.mlb using Poly/ML, passing datafile.txt as an argument to the program
#>
Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
if ($args.Count -lt 1) {
"Usage: polyrun file.mlb [args...]"
exit 1
}
$mlb = $args[0]
if ($mlb -notmatch "[.]mlb$") {
"Error: argument must be a .mlb file"
exit 1
}
$mydir = Split-Path -Parent $PSCommandPath
. $mydir/smlbuild-include.ps1
$lines = @(processMLB $mlb)
if ($lines -match "^Error: ") {
$lines -match "^Error: "
exit 1
}
$outro = @"
val _ = main ();
val _ = OS.Process.exit (OS.Process.success);
"@ -split "[\r\n]+"
$script = @()
$script += $lines
$script += $outro
$tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml"
$script | Out-File -Encoding "ASCII" $tmpfile
cat $tmpfile | polyml --error-exit $args[1..$args.Length] | Out-Host
if (-not $?) {
del $tmpfile
exit $LastExitCode
}
del $tmpfile