r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3 Extensions] REBOL 3 Extensions discussions

jocko
5-Nov-2009
[291]
Are there Matlab users ? Going on in my investigation of the extensions, 
I have created an extension for executing Matlab instructions from 
R3, by calling the Matlab engine. Exe and source are here : http://colineau.societeg.com/rebol/R3_extensions.html
.
Pekr
5-Nov-2009
[292]
not anymore. I used it some 10 years ago for some astronomy purposes 
:-)
Maxim
5-Nov-2009
[293]
janko congratulations on your extensions... I knew extensions where 
the door to a whole new world of possibilities for REBOL.
Gregg
5-Nov-2009
[294]
Yes, this is all very cool to see things coming from people.
BrianH
6-Nov-2009
[295]
That's cool, Jocko :)
Robert
6-Nov-2009
[296]
Ass soon as I know how to call a Rebol function from Extension with 
some simple parameters I'm ready to start.
jocko
6-Nov-2009
[297]
Thanks
Robert: do you mean execute rebol code inside C programs?
BrianH
6-Nov-2009
[298]
The host code will allow that. Extensions are the opposite. The calling 
model will probably be similar though.
Pekr
6-Nov-2009
[299]
Host code will allow what? Callbacks? You want to tell me, that in 
order to call-back some rebol funciton, it has to be in host part?
BrianH
6-Nov-2009
[300]
Not that I'm aware of. Callbacks are a separate issue, which is supposed 
to be handled by devices, afaik.
Maxim
6-Nov-2009
[301]
so, Robert, not sure if you understood all of these replies as even 
I had a bit of a tough time to "get" them.


Right now, Extensions only allow REBOL to call functions from a dll. 
  What I would like is to simply improve the extension model so  
it can also call REBOL code, as a callback or something else, but 
there are a few issues which make this a non-trivial thing to do.


So far there seems to be a generalized idea that there should be 
a different kind of extension which allows this, but I see no reason 
why it should be another, different. api.  having one DLL   for  
REBOL -> DLL  and another for  DLL -> REBOL  makes absolutely no 
sense to me.   IMHO we need a single DLL able to do both.  Even if 
it means a little bit more work to design it.
Pekr
6-Nov-2009
[302]
agreed - just don't put another burden on user. By dismissing DLL 
interface, many users will not be able to make otherwise usefull 
things at all. So if it can be done in terms of current extension 
API, even if it would mean some additional work, let's add it. I 
don't want to hear, that in order to do a callback, feature available 
in R2, I hav to do some other tricks.
Rebolek
6-Nov-2009
[303]
I've updated http://box.lebeda.ws/~rebolek/rebol/srec.rip.

The fibonacci function can now be written as:

fibr: command [
    len [integer!]
][
    o: 0
    repeat i len [
        o: o + i
    ]
    return o
]


and compiled to DLL. If you prefer c-code, just use string! with 
c-code in command's body, instead of block! with RebC dialect.
Maxim
6-Nov-2009
[304]
will the rebol code be converted to C prior to compile?
Rebolek
6-Nov-2009
[305x2]
yes
Actually, it's not rebol code, it just looks like rebol code :)
Maxim
6-Nov-2009
[307x2]
I see the len function hehe.   Do you have the dialect documented 
somewhere?
actually len here is an input... doh.
Rebolek
6-Nov-2009
[309x3]
yes it is documented but the documentation needs to be converted 
to some format that everyone can read. Also the dialect  needs to 
be checked if it's without problems - it's three years old and probably 
needs more fixes to work with r3 without problems.
AFAIK, it supports most of the math, loops (loop, repeat, if...), 
conditions (if, either...).
Anyway, if you don't use the dialect (the command body is string! 
with c-code), the compilation should work without any problem.
Geomol
6-Nov-2009
[312]
Have you build it from the ground, or is it based on some of the 
opensource REBOLs (R#, ORCA)?
Rebolek
6-Nov-2009
[313]
It's build from the ground. It parses the dialect and translates 
it to c equivalent (a: 5 becomes a = 5 and so on).
Geomol
6-Nov-2009
[314x2]
How is loops and conditions perform compared to REBOL, plain C, Lua, 
Python, ...? Maybe you have rough estimate on this?
well, now I read your comments again, I bet it perform very well, 
as it is simple translation to C, right? What about blocks, have 
you implemented them?
Rebolek
6-Nov-2009
[316x2]
IIRC (the dialect is 3 years old and I haven't touched it for few 
years, I just made some fixes in last few days to run it under R3), 
most loops are translated to C's WHILE. You can try writing some 
RebC code and when you COMPILE it, in the %work/ directory you can 
find %your-filename.c file, where you can see the dialect translated 
to C. Do not expect it to be optimized in any way :)
Yes, exactly, it just translates to C.
Geomol
6-Nov-2009
[318]
Interesting anyway. :)
Rebolek
6-Nov-2009
[319x2]
IIRC, there was some support for blocks as long as they can be converted 
to arrray. Now that the COMPILE part works ok, I can focus more on 
the RebC dialect to enhance it.
The main reason I wrote the dialect was to convert mathematic functions 
in Sintezar to C to make it faster and not write it in C as C syntax 
makes my eyes hurt :)
Geomol
6-Nov-2009
[321]
Good idea. And you have strong typing rules, right? So if a var is 
defined as an integer, you can't change it to something else along 
the way?
Rebolek
6-Nov-2009
[322]
Hm, I'm not sure right now, I think it was possible to change it, 
but I may be wrong. But I think there were no error checks, it was 
just a basic version that can produce something working and I haven't 
much time to improve it since. That has changed recently.
Geomol
6-Nov-2009
[323]
Rebolek, about documentation, feel free to use NicomDoc: http://www.fys.ku.dk/~niclasen/nicomdoc/

It can easily produce HTML output as (MakeDoc), but also PDF output 
by first producing LaTeX.
Rebolek
6-Nov-2009
[324]
Geomol thanks. Currently the documentation is written in special 
version of MakeDoc that supports literate programming so it's mixed 
with the source code.
Maxim
6-Nov-2009
[325]
rebolek, I will definitely check this out.  if you have any docs 
converted to html, I will read them, so know it will not have been 
done in vain ;-)
BrianH
6-Nov-2009
[326x2]
I was looking at making a libtcc extension, which would allow something 
like RebC to be used as a JIT compiler.
You wouldn't need to package your generated code as an extension, 
just generate to memory and run it from there.
Rebolek
6-Nov-2009
[328]
Hm, that would be interesting.
BrianH
6-Nov-2009
[329x4]
The command! type makes this possible, since commands can dispatch 
to dynamically generated code if  need be.
Eventually I was going to make a libjit or LLVM backend, but it looks 
like I can get libtcc working sooner.
Not the first thing on my list though (which is HTTP) so if you want 
to take a crack at it first, I can help with the extension/module 
model.
It looks like libtcc can be statically linked into an extension, 
only providiing an extension interface to its functions.
Rebolek
6-Nov-2009
[333x2]
Hm, I haven't looked at libtcc yet, but it it looks very interesting.
But first, I need to go thru the RebC code and improve it. It shows 
it's age :)
BrianH
6-Nov-2009
[335x4]
A command! is an indexed dispatch function, and the index has no 
inherent meaning. You could dynamically generate functions with libtcc, 
which would all have the same function signiature because they would 
just take command! call frames. These generated functions could be 
referenced from an array of function pointers. After you generate 
a new function and assign it to a new array slot, return the index 
of that slot to the calling REBOL code (embedded in the libtcc extension) 
and it can then make a command! with the libtcc extension's handle 
and that index. Then that command! can be called like any other REBOL 
function.


A trick though is that the generated C code would need to use the 
extension macros to manipulate the function arguments, rather than 
direct variable access. In other words, your generated functions 
would be extension-style code, not regular C code.
Pekr, the reason callbacks are so tricky in R3 is that you need a 
way to dispatch to the correct task within REBOL. R3 is not going 
to be single-tasking anymore, so direct callbacks will be impossible: 
You have to coordinate between the task/thread of the external code 
and the tasks/threads of R3. Devices manage that coordination and 
synchronization.
Bolek, if you have the commands that are exported from the libtcc 
extension themselves implemented as functions with the same signiature 
as the generated functions, you can call them through the dispatch 
array as well. This would reduce your RX_Call function to just a 
few lines.
Be sure to BSD the extension wraapper code though, so it can be reused 
by an LLVM wrapper :)
Rebolek
6-Nov-2009
[339x2]
If you mean BSD-license, that's understood. I prefer PD/MIT/BSD licenses, 
GPL is stupid.
(I prefer no licenses at all, but I'm an anarchist)