[MLton-devel] RE: calling SML from C in MLton

Mike Thomas miketh@brisbane.paradigmgeo.com
Wed, 30 Apr 2003 17:36:10 +1000


Hi again.

I tried building the new experimental MLTON from source under Cygwin with
the last standard release:

MLton 20030312 (built Wed Mar 12 12:55:40 2003 on CYGWIN)

but got a crash in mllex:

=========================================================================
make compiler dirs
make[1]: Entering directory `/c/lang/source/cygwin/mlton-20030419'
make -C /c/lang/source/cygwin/mlton-20030419/mlton
make[2]: Entering directory `/c/lang/source/cygwin/mlton-20030419/mlton'
rm -f front-end/ml.grm.*
mlyacc front-end/ml.grm
1 shift/reduce conflict
chmod -w front-end/ml.grm.*
rm -f front-end/ml.lex.sml
mllex front-end/ml.lex
make[2]: *** [front-end/ml.lex.sml] Segmentation fault (core dumped)
make[2]: Leaving directory `/c/lang/source/cygwin/mlton-20030419/mlton'
make[1]: *** [compiler] Error 2
make[1]: Leaving directory `/c/lang/source/cygwin/mlton-20030419'
make: *** [all] Error 2
=========================================================================

and in fact:

=========================================================================
$ mllex
Segmentation fault (core dumped)
=========================================================================

from which came this stackdump:

=========================================================================
$ cat mllex.stackdump
Exception: STATUS_ACCESS_VIOLATION at eip=00425644
eax=00000001 ebx=FFEB395C ecx=FFBE395C edx=FFEB395C esi=006B395C
edi=FFBE395C
ebp=006B0000 esp=0022FCF4 program=C:\cygwin\bin\mllex
cs=001B ds=0023 es=0023 fs=0038 gs=0000 ss=0023
Stack trace:
Frame     Function  Args
006B0000  00425644  (00000003, 6B636162, 20646E65, 756F6874)
End of stack trace
=========================================================================

On the topic of the FFI, is it possible to set use reference variables to
pass results back from SML callbacks to the C side?

Cheers

Mike Thomas.





| -----Original Message-----
| From: Stephen Weeks [mailto:sweeks@sweeks.com]
| Sent: Wednesday, April 30, 2003 11:00 AM
| To: Mike Thomas
| Cc: MLton@mlton.org
| Subject: calling SML from C in MLton
|
|
|
| Hi Mike.  I wanted to let you know that we have added an experimental
| feature to MLton that allows one to call back to SML from C.  To try
| it out, download experimental version 20030419 from
|
| 	http://www.mlton.org/experimental/
|
| Hopefully this will inspire you to get back to your OpenGL port! :-)
|
| The facility is very simple, but you can build complexity on top of
| it.  The relevant structure is
|
| MLton.FFI:
|    sig
|       val handleCallFromC: (unit -> unit) -> unit
|    end
|
| handleCallFromC allows you to register the (single) SML function that
| is called from C.  On the C side, we export a single function that
| allows you to call back to SML:
|
|   	void MLton_callFromC ();
|
| So, after calling "MLton.FFI.handleCallFromC f", then a call from C to
| MLton_callFromC will cause "f ()" to be run.
|
| To call multiple SML functions, you can build C wrappers around
| MLton_callFromC that set some global integer, which you then dispatch
| on from the SML side to call the appropriate function.  You can also
| pass arguments using a simple hand implemented calling convention in
| which you set globals in the C wrapper and fetch them with _ffi from
| the SML code.
|
| Let us know of any questions or problems.  Thanks.
|
|




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel