rev: tip rubberband-qt-example/repoint.ps1 -rw-r--r-- 2.7 KiB View raw Log this file
6737d6595c4b — Chris Cannam Smaller image a month ago
                                                                                
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<#

.SYNOPSIS
A simple manager for third-party source code dependencies.
Run "repoint help" for more documentation.

#>

Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
$env:HGPLAIN = "true"

$sml = $env:REPOINT_SML

$mydir = Split-Path $MyInvocation.MyCommand.Path -Parent
$program = "$mydir/repoint.sml"

# We need either Poly/ML or SML/NJ. No great preference as to which.

# Typical locations
$env:PATH = "$env:PATH;C:\Program Files (x86)\SMLNJ\bin;C:\Program Files\Poly ML;C:\Program Files (x86)\Poly ML"

if (!$sml) {
    if (Get-Command "sml" -ErrorAction SilentlyContinue) {
       $sml = "smlnj"
    } elseif (Get-Command "polyml" -ErrorAction SilentlyContinue) {
       $sml = "poly"
    } else {
       echo @"

ERROR: No supported SML compiler or interpreter found       

  The Repoint external source code manager needs a Standard ML (SML)
  compiler or interpreter to run.

  Please ensure you have one of the following SML implementations
  installed and present in your PATH, and try again.

    1. Standard ML of New Jersey
       - executable name: sml

    2. Poly/ML
       - executable name: polyml

"@
       exit 1
    }
}

if ($args -match "'""") {
    $arglist = '["usage"]'
} else {
    $arglist = '["' + ($args -join '","') + '"]'
}

if ($sml -eq "poly") {

    $program = $program -replace "\\","\\\\"
    echo "use ""$program""; repoint $arglist" | polyml -q --error-exit | Out-Host

    if (-not $?) {
        exit $LastExitCode
    }

} elseif ($sml -eq "smlnj") {

    $lines = @(Get-Content $program)
    $lines = $lines -notmatch "val _ = main ()"

    $intro = @"
val smlrun__cp = 
    let val x = !Control.Print.out in
        Control.Print.out := { say = fn _ => (), flush = fn () => () };
        x
    end;
val smlrun__prev = ref "";
Control.Print.out := { 
    say = fn s => 
        (if String.isSubstring "Error" s orelse String.isSubstring "Fail" s
         then (Control.Print.out := smlrun__cp;
               (#say smlrun__cp) (!smlrun__prev);
               (#say smlrun__cp) s)
         else (smlrun__prev := s; ())),
    flush = fn s => ()
};
"@ -split "[\r\n]+"

    $outro = @"
val _ = repoint $arglist;
val _ = OS.Process.exit (OS.Process.success);
"@ -split "[\r\n]+"

    $script = @()
    $script += $intro
    $script += $lines
    $script += $outro

    $tmpfile = ([System.IO.Path]::GetTempFileName()) -replace "[.]tmp",".sml"

    $script | Out-File -Encoding "ASCII" $tmpfile

    $env:CM_VERBOSE="false"

    sml $tmpfile

    if (-not $?) {
        del $tmpfile
        exit $LastExitCode
    }

    del $tmpfile

} else {

    "Unknown SML implementation name: $sml"
    exit 2
}