On Oct 31, 2005, at 7:49, John Lenz wrote:
On Fri, October 28, 2005 2:22 pm, Nick Glencross said:
Guys,
As mentioned on the list yesterday I started evaluating ffcall as a
way
of providing NCI functionality.
http://www.haible.de/bruno/packages-ffcall.html
I am a SWIG (www.swig.org) developer, and I recently started looking at
what it will take to add a parrot module to SWIG. I will post some of
the
issues I ran into, but I was wondering if there would be any interest
for
SWIG to become one of the official way to do NCI?
SWIG isn't a replacement for NCI. Parrot NCI is fully dynamic and
doesn't need any compiler, linker, interface definition file and what
not.
SWIG has a whole bunch of other benefits which I won't list here.
I think, it would need good reasons to include another ffi-alike. But
that doesn't preclude SWIG of course.
The main issue resolves around the problem that there isn't a standard
way
to just register a function as callable from parrot (that I can see).
Any PMC that provides the 'invoke' vtable is a callable.
SWIG can easily generate functions of the form
void* _wrap_foo(Interp* interpreter, PMC* pmc, void * next)
one for each function being wrapped. Can we inject that function
directly
into the vtable somehow? Or just create a class that passes on the
invoke
function?
I presume that would be a NCI_SWIG PMC. If this callable is inserted
into the vtable or dynamically looked up is an implementation detail.
One of the existing SWIG modules (CHICKEN) deals with a continuation
passing language, so SWIG can deal with continuation-aware languages.
Sounds interesting
SWIG does not require any code besides what it generates... think lex
or
yacc...
Well, it's fully static, while NCI is dynamic:
$ cat n.pir
.sub main :main
.local pmc l, f
.local string fn
.local float v
l = loadlib "libm"
loop:
(fn, v) = input_func_and_val()
f = dlfunc l, fn, "dd"
v = f(v)
print v
print "\n"
goto loop
.end
.sub input_func_and_val
.local pmc in, out
out = getstdout
print "> "
out."flush"()
.local string fn, v
in = getstdin
fn = readline in
chopn fn, 1
v = readline in
chopn v, 1
.return (fn, v)
.end
$ ./parrot n.pir
> sin
2
0.909297
> cos
2
-0.416147
John
leo