-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwstp.nimble
60 lines (48 loc) · 1.59 KB
/
wstp.nimble
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
# Package
version = "0.1.0"
author = "oskca"
description = "Nim bindings for WSTP"
license = "MIT"
srcDir = "src"
# Dependencies
requires "nim >= 0.18.0"
requires "c2nim"
let MMA_HOME="/usr/local/Wolfram/Mathematica/11.3"
import strutils
const
t1 = """typedef struct MLYieldData{
union {long l; double d; void * p;} private_data[8];
} * MLYieldDataPointer;
"""
r1 = """struct MLYieldData{
union {long l; double d; void * p;} private_data[8];
};
typedef struct MLYieldData * MLYieldDataPointer;
"""
t2 = """typedef WSYielderProcPtr MLYielderUPP, MLDeviceYielderUPP;"""
r2 = """typedef WSYielderProcPtr MLYielderUPP; typedef WSYielderProcPtr MLDeviceYielderUPP;"""
t3 = """typedef WSHandlerProcPtr MLHandlerUPP, MLDeviceHandlerUPP;"""
r3 = """typedef WSHandlerProcPtr MLHandlerUPP; typedef MLHandlerUPP MLDeviceHandlerUPP;"""
hdrPrefix = """
{.passC:"-I" & MMA_HOME & "/SystemFiles/Links/WSTP/DeveloperKit/Linux-x86-64/CompilerAdditions".}
{.passL: MMA_HOME & "/SystemFiles/Links/WSTP/DeveloperKit/Linux-x86-64/CompilerAdditions/libWSTP64i4.a".}
const
wstphdr = "wstp.h"
"""
proc replace(fn: string) =
var s = staticRead(fn)
s = s.replace(t1, r1)
s = s.replace(t2, r2)
s = s.replace(t3, r3)
writeFile(fn, s)
proc appendPrefix(fn: string) =
var s = staticRead(fn)
s = s.replace("__", "_")
s = hdrPrefix & s
writeFile(fn, s)
task gen, "Generate wstp.nim":
exec "gcc -E headers/wstp.h > wstpE.h"
replace "wstpE.h"
exec "c2nim --prefix:_ --suffix:_ --o:src/wstp.nim --header:wstphdr wstpE.h"
exec "rm -rf wstpE.h"
appendPrefix "src/wstp.nim"