1+ $prefixDir = Split-Path - Parent (Split-Path - Parent (Split-Path - Parent $PSScriptRoot ))
2+ $exePath = Join-Path $prefixDir ' prefix.exe'
3+
4+ if (-not (Test-Path $exePath )) {
5+ throw " Interpreter executable not found at: $exePath "
6+ }
7+
8+ $tempDir = Join-Path ([IO.Path ]::GetTempPath()) ([IO.Path ]::GetRandomFileName())
9+ New-Item - ItemType Directory - Path $tempDir | Out-Null
10+
11+ try {
12+ $modulePath = Join-Path $tempDir ' main_func_wrapper.pre'
13+ $programPath = Join-Path $tempDir ' program.pre'
14+
15+ Set-Content - Path $modulePath - Encoding Ascii - Value @'
16+ FUNC BOOL: imported_main(){
17+ RETURN(MAIN())
18+ }
19+
20+ FUNC BOOL: call_callback(FUNC: callback){
21+ RETURN(callback())
22+ }
23+
24+ FUNC BOOL: call_imported_main(){
25+ RETURN(imported_main())
26+ }
27+ '@
28+
29+ $moduleLiteral = $modulePath.Replace (' \' , ' \\' )
30+
31+ Set-Content - Path $programPath - Encoding Ascii - Value @"
32+ IMPORT_PATH("$moduleLiteral ", helper)
33+
34+ FUNC BOOL: local_main(){
35+ RETURN(MAIN())
36+ }
37+
38+ ASSERT(helper.call_callback(local_main))
39+ ASSERT(NOT(helper.call_imported_main()))
40+ "@
41+
42+ $output = & $exePath $programPath 2>&1
43+ if ($LASTEXITCODE -ne 0 ) {
44+ $outputText = ($output | ForEach-Object { $_.ToString () }) -join [Environment ]::NewLine
45+ throw " Prefix exited with code $LASTEXITCODE `n $outputText "
46+ }
47+ }
48+ finally {
49+ Remove-Item - Path $tempDir - Recurse - Force - ErrorAction SilentlyContinue
50+ }
0 commit comments