Skip to content

Commit fe2724e

Browse files
author
Chongkai Zhu
committed
racket on chez
wstp
1 parent e826fc5 commit fe2724e

File tree

3 files changed

+75
-82
lines changed

3 files changed

+75
-82
lines changed

light.ss

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@
9393
(define (MLGet lp)
9494
(with-handlers ((exn:break?
9595
(lambda _ (MLPutMessage lp 3))))
96-
(MLFlush lp)
97-
(MLWait lp (break-enabled)))
96+
(MLWait lp))
9897
(unless (zero? (MLError lp))
9998
(mathlink-error (MLErrorMessage lp)))
10099
(case (MLNextPacket lp)
@@ -117,7 +116,7 @@
117116
((5)
118117
(MLNewPacket lp)
119118
(MLNextPacket lp)
120-
(warning (MLGetString lp))
119+
(displayln (MLGetString lp) (current-error-port))
121120
(MLNewPacket lp)
122121
(MLGet lp))
123122
((21)
@@ -133,7 +132,7 @@
133132
(define (MLGetExp lp)
134133
(case (MLGetNext lp)
135134
((35)
136-
(let ((sym (MLGetSymbol lp)))
135+
(let ((sym (string->symbol (MLGetString lp))))
137136
(case sym
138137
((True) #t)
139138
((False) #f)
@@ -144,7 +143,7 @@
144143
((34)
145144
(MLGetString lp))
146145
((43)
147-
(MLGetInteger lp))
146+
(string->number (MLGetString lp)))
148147
((42)
149148
(MLGetReal lp))
150149
((70)

mathlink.ss

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,29 @@
77

88
(define-struct MathLink (ep lp (ref #:mutable) sema phantom))
99

10-
(define warning
11-
(get-ffi-obj 'scheme_warning #f
12-
(_fun (_bytes = #"%T") _scheme -> _void)))
13-
1410
(define-struct (exn:fail:mathlink exn:fail) () #:transparent)
1511
(define-syntax-rule (mathlink-error str)
1612
(raise (make-exn:fail:mathlink str (current-continuation-marks))))
1713

1814
(define mathlink
1915
(ffi-lib (case (system-type 'os)
2016
((unix)
21-
(string-append "libML"
17+
(string-append "libWSTP"
2218
(number->string (* (compiler-sizeof '*) 8))
23-
"i3"))
19+
"i4"))
2420
((windows)
25-
(string-append "ml"
21+
(string-append "wstp"
2622
(number->string (* (compiler-sizeof '*) 8))
27-
"i3"))
23+
"i4"))
2824
((macosx)
29-
"mathlink.framework/mathlink"))))
25+
"wstp.framework/wstp"))))
3026

3127
(define MLOpen
3228
(let ((MLInitialize
33-
(get-ffi-obj 'MLInitialize mathlink
29+
(get-ffi-obj 'WSInitialize mathlink
3430
(_fun (_pointer = #f) -> (p : _pointer)
3531
-> (or p (mathlink-error "MathKernel: MathLink Initialize Error"))))))
36-
(get-ffi-obj 'MLOpenArgcArgv mathlink
32+
(get-ffi-obj 'WSOpenArgcArgv mathlink
3733
(_fun args ::
3834
(ep : _pointer = (MLInitialize))
3935
(_int = (add1 (length args)))
@@ -47,109 +43,106 @@
4743
(mathlink-error "MathKernel: MathLink Open Error"))))))
4844

4945
(define MLClose
50-
(let ((MLClose (get-ffi-obj 'MLClose mathlink
46+
(let ((MLClose (get-ffi-obj 'WSClose mathlink
5147
(_fun _pointer -> _void)))
5248
(MLDeinitialize
53-
(get-ffi-obj 'MLDeinitialize mathlink
49+
(get-ffi-obj 'WSDeinitialize mathlink
5450
(_fun _pointer -> _void))))
5551
(lambda (link)
5652
(MLPutMessage (MathLink-lp link) 1)
5753
(MLClose (MathLink-lp link))
5854
(MLDeinitialize (MathLink-ep link)))))
5955

6056
(define MLPutFunction
61-
(get-ffi-obj 'MLPutFunction mathlink
57+
(get-ffi-obj 'WSPutFunction mathlink
6258
(_fun _pointer _bytes _int -> _bool)))
6359

6460
(define MLPutArgCount
65-
(get-ffi-obj 'MLPutArgCount mathlink
61+
(get-ffi-obj 'WSPutArgCount mathlink
6662
(_fun _pointer _int -> _bool)))
6763

6864
(define MLPutString
69-
(get-ffi-obj 'MLPutUTF32String mathlink
70-
(_fun _pointer (s : _string/ucs-4) (_int = (string-length s)) -> _bool)))
65+
(get-ffi-obj 'WSPutUTF32String mathlink
66+
(_fun (l s) ::
67+
(l : _pointer)
68+
(_string/ucs-4 = (string-append "\uFEFF" s))
69+
(_int = (add1 (string-length s)))
70+
-> _bool)))
7171

7272
(define MLPutReal
73-
(get-ffi-obj 'MLPutReal mathlink
73+
(get-ffi-obj 'WSPutReal mathlink
7474
(_fun _pointer _double -> _bool)))
7575

7676
(define MLPutNext
77-
(get-ffi-obj 'MLPutNext mathlink
77+
(get-ffi-obj 'WSPutNext mathlink
7878
(_fun _pointer _int -> _bool)))
7979

8080
(define MLNextPacket
81-
(get-ffi-obj 'MLNextPacket mathlink
81+
(get-ffi-obj 'WSNextPacket mathlink
8282
(_fun _pointer -> _int)))
8383

8484
(define MLEndPacket
85-
(get-ffi-obj 'MLEndPacket mathlink
85+
(get-ffi-obj 'WSEndPacket mathlink
8686
(_fun _pointer -> _bool)))
8787

8888
(define MLNewPacket
89-
(get-ffi-obj 'MLNewPacket mathlink
89+
(get-ffi-obj 'WSNewPacket mathlink
9090
(_fun _pointer -> _bool)))
9191

9292
(define MLGetString
93-
(let ((release (get-ffi-obj 'MLReleaseUTF32String mathlink
94-
(_fun _pointer _pointer _int -> _void)))
95-
(make (get-ffi-obj 'scheme_make_sized_char_string #f
96-
(_fun _pointer _intptr _bool -> _scheme))))
97-
(get-ffi-obj 'MLGetUTF32String mathlink
98-
(_fun (l : _pointer) (s : (_ptr o _pointer)) (len : (_ptr o _int)) -> _bool
99-
-> (begin0 (make s len #t)
100-
(release l s len))))))
101-
102-
(define MLGetSymbol
103-
(let ((release (get-ffi-obj 'MLReleaseUTF8Symbol mathlink
104-
(_fun _pointer _pointer _int -> _void)))
105-
(make (get-ffi-obj 'scheme_intern_exact_symbol #f
106-
(_fun _pointer _int -> _scheme))))
107-
(get-ffi-obj 'MLGetUTF8Symbol mathlink
108-
(_fun (l : _pointer) (s : (_ptr o _pointer)) (b : (_ptr o _int)) (_ptr o _int) -> _bool
109-
-> (begin0 (make s b)
110-
(release l s b))))))
111-
112-
(define MLGetInteger
113-
(let ((release (get-ffi-obj 'MLReleaseString mathlink
114-
(_fun _pointer _pointer -> _void)))
115-
(make (get-ffi-obj 'scheme_read_bignum_bytes #f
116-
(_fun _pointer (_int = 0) (_int = 10) -> _scheme))))
117-
(get-ffi-obj 'MLGetString mathlink
118-
(_fun (l : _pointer) (s : (_ptr o _pointer)) -> _bool
119-
-> (begin0 (make s)
120-
(release l s))))))
93+
(case (system-type 'vm)
94+
((racket)
95+
(let ((release (get-ffi-obj 'WSReleaseUTF32String mathlink
96+
(_fun _pointer _pointer _int -> _void)))
97+
(make (get-ffi-obj 'scheme_make_sized_char_string #f
98+
(_fun _pointer _intptr _bool -> _scheme))))
99+
(get-ffi-obj 'WSGetUTF32String mathlink
100+
(_fun (l : _pointer) (s : (_ptr o _pointer)) (len : (_ptr o _int)) -> _bool
101+
-> (begin0 (make (ptr-add s 4) (sub1 len) #t)
102+
(release l s len))))))
103+
((chez-scheme)
104+
(let ((release (get-ffi-obj 'WSReleaseUTF8String mathlink
105+
(_fun _pointer _pointer _int -> _void)))
106+
(make (get-ffi-obj 'Sstring_utf8 #f
107+
(_fun _pointer _intptr -> _scheme))))
108+
(get-ffi-obj 'WSGetUTF8String mathlink
109+
(_fun (l : _pointer) (s : (_ptr o _pointer)) (len : (_ptr o _int)) (_ptr o _int) -> _bool
110+
-> (begin0 (make s len)
111+
(release l s len))))))))
121112

122113
(define MLGetNext
123-
(get-ffi-obj 'MLGetNext mathlink
114+
(get-ffi-obj 'WSGetNext mathlink
124115
(_fun _pointer -> _int)))
125116

126117
(define MLGetArgCount
127-
(get-ffi-obj 'MLGetArgCount mathlink
118+
(get-ffi-obj 'WSGetArgCount mathlink
128119
(_fun _pointer (n : (_ptr o _int)) -> _bool
129120
-> n)))
130121

131-
(define MLFlush
132-
(get-ffi-obj 'MLFlush mathlink
133-
(_fun _pointer -> _bool)))
134-
135122
(define MLWait
136-
(let ((MLReady (ffi-obj-ref 'MLReady mathlink)))
137-
(get-ffi-obj 'scheme_block_until_enable_break #f
138-
(_fun (_fpointer = MLReady) (_fpointer = #f) _pointer (_float = 0.0) _bool
139-
-> _bool))))
123+
(let ((MLFlush (get-ffi-obj 'WSFlush mathlink
124+
(_fun _pointer -> _bool)))
125+
(MLReady (get-ffi-obj 'WSReady mathlink
126+
(_fun _pointer -> _bool))))
127+
(lambda (lp)
128+
(MLFlush lp)
129+
(let loop ()
130+
(unless (MLReady lp)
131+
(sleep 0.01)
132+
(loop))))))
140133

141134
(define MLPutMessage
142-
(get-ffi-obj 'MLPutMessage mathlink
135+
(get-ffi-obj 'WSPutMessage mathlink
143136
(_fun _pointer _int -> _bool)))
144137

145138
(define MLError
146-
(get-ffi-obj 'MLError mathlink
139+
(get-ffi-obj 'WSError mathlink
147140
(_fun _pointer -> _int)))
148141

149142
(define MLErrorMessage
150-
(get-ffi-obj 'MLErrorMessage mathlink
143+
(get-ffi-obj 'WSErrorMessage mathlink
151144
(_fun _pointer -> _string/latin-1)))
152145

153146
(define MLClearError
154-
(get-ffi-obj 'MLClearError mathlink
147+
(get-ffi-obj 'WSClearError mathlink
155148
(_fun _pointer -> _bool)))

mrmma.scrbl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,28 @@ MrMathematica allows you to call
2020

2121
Before installing MrMathematica, you need to do the following two things:
2222

23-
@itemize[@item{Install the MathLink dynamic library by copying it into the PLT
23+
@itemize[@item{Install the WSTP dynamic library by copying it into the PLT
2424
libraries (see @scheme[get-lib-search-dirs]), or into a systemwide
25-
location such as @filepath{C:\Windows\SysWOW64} or @filepath{/lib}.
26-
@link["https://reference.wolfram.com/legacy/v6/tutorial/MathLinkDeveloperGuide-Windows.html#25820"]{On Windows}
27-
it is @filepath{ml32i3.dll} or @filepath{ml64i3.dll}, depending
25+
location such as @filepath{C:\Windows\SysWOW64}, @filepath{/lib},
26+
@filepath{/Library/Frameworks} or @filepath{~/Library/Frameworks}.
27+
@link["https://reference.wolfram.com/language/tutorial/WSTPDeveloperGuide-Windows.html#19602"]{On Windows}
28+
it is @filepath{wstp32i4.dll} or @filepath{wstp64i4.dll}, depending
2829
on whether you are on a 32-bit or 64-bit platform.
29-
@link["https://reference.wolfram.com/legacy/v6/tutorial/MathLinkDeveloperGuide-Unix.html#26966"]{On Unix/Linux},
30-
it is @filepath{libML32i3.so} or @filepath{libML64i3.so}.
31-
@link["https://reference.wolfram.com/legacy/v6/tutorial/MathLinkDeveloperGuide-Macintosh.html#30231"]{On Mac OS X},
32-
it is @filepath{mathlink.framework}.}
30+
@link["https://reference.wolfram.com/language/tutorial/WSTPDeveloperGuide-Unix.html#1726529900"]{On Unix/Linux},
31+
it is @filepath{libWSTP32i4.so} or @filepath{libWSTP64i4.so}.
32+
@link["https://reference.wolfram.com/language/tutorial/WSTPDeveloperGuide-Macintosh.html#669747147"]{On Mac OS X},
33+
it is @filepath{wstp.framework}.}
3334

34-
@item{Make sure that @link["http://reference.wolfram.com/legacy/v6/ref/program/MathKernel.html"]{@exec{MathKernel}}
35-
or @link["http://reference.wolfram.com/legacy/v6/ref/program/math.html"]{@exec{math}}
35+
@item{Make sure that @link["http://reference.wolfram.com/legacy/v8/ref/program/MathKernel.html"]{@exec{MathKernel}}
36+
or @link["http://reference.wolfram.com/legacy/v8/ref/program/math.html"]{@exec{math}}
3637
will launch Mathematica kernel. On Unix/Linux the Mathematica
37-
installer has done that. On Windows setting @envvar{PATH} to
38+
installer should have done that. On Windows setting @envvar{PATH} to
3839
include the directory where Mathematica executable files locate
39-
should be enough. On Mac OS X, MrMathematica looks for
40+
should be enough. On Mac OS, MrMathematica looks for
4041
@filepath{/Applications/Mathematica.app/Contents/MacOS/MathKernel},
4142
which should be the correct place.}]
4243

43-
Install @link["http://www.cs.utah.edu/~czhu/mrmathematica.plt"]{mrmathematica.plt}
44+
Install @link["https://github.com/mrmathematica/MrMathematica/releases"]{mrmathematica.plt}
4445
from File menu in DrScheme.
4546

4647
@section{Use MrMathematica}

0 commit comments

Comments
 (0)