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

World: r3wp

[!REBOL3 Extensions] REBOL 3 Extensions discussions

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)
BrianH
6-Nov-2009
[341x3]
Well, libtcc is LGPL (2, I think), as is libjit, but LLVM is BSD. 
The extension interface is LGPL compatible, so if you BSD the wrapper 
code (or more permissive, as long as it's LGPL compatible) then you 
should be fine.
I prefer more permissive licenses too :)
especially PD
Rebolek
6-Nov-2009
[344]
I'm fine with PD - code is just organized characters. Milion monkeys 
with typewriters can do same thing ;) so why licensing anything. 
But that's offtopic - the license will not be deffinitely more restrictive 
than BSD and it may be PD as well. Depends on my mood when I add 
it to header ;)
BrianH
6-Nov-2009
[345]
libtcc is LGPL 2.1
Robert
28-Nov-2009
[346x5]
Playing with the extension example: IMO it's done  to complicated.


- Why do I need make-ext.r? Do I always need it or just for this 
specific example?

- Why is the init block a const char array and not just a plain ASCII 
text?
How do I return a new string back to Rebol?
I seems I need to construct a RX string and set every single char?
This uniton gives a warning/error with mingw:

typedef union rxi_arg_val {

	i64 int64;

	double dec64;

	REBYTE bytes[8];

	struct {

		i32 int32a;

		i32 int32b;

	};
	struct {

		u32 index;

		void *series;

	};
	void *handle;

} RXIARG;
The structs give: warning: declaration does not declare anything
Ladislav
28-Nov-2009
[351x3]
yes, Robert, the other elements clearly declare something, but the 
structs don't declare anything, the compiler is right
generally, struct {...} my-struct; declares my-struct, while struct 
{...}; does not declare anything
(should have been my_struct)
Robert
28-Nov-2009
[354]
I commented the struct part and than it works. So either we need 
to give it a name, which will result in a ->struct_name.series sequence. 
Not sure if this makes any difference instead of just putting the 
members into the union.
Ladislav
28-Nov-2009
[355x3]
yes, it makes a difference
(since it is a union)
-only one of the variants is correct
Robert
28-Nov-2009
[358x4]
Ok, right. Using int32 and ser as struct names.
Works.
BTW: I'm currently making a R3 SQLite extension.
Looks like one need to be carful when designing the command interface 
(arguments) because if you insert an argument, the refinements shift 
to a new position. As the access to arguments on the c side is via 
positions you need to adjust your code. Need to think abou a good 
way to abstract this.
jocko
29-Nov-2009
[362]
is there a document showing how to define refinements in extensions 
?
Robert
29-Nov-2009
[363x2]
What do you mean with "define"? On the Rebol side or on the C side?
Anyhow, yes refinements are no problem.
jocko
29-Nov-2009
[365]
well in fact I have not found any mechanism to call a function with 
a changing number of arguments, like, for instance: 
my-func a b
my-func a b c
or, 
my-func a b
my-func/my-refinement a b c
Graham
29-Nov-2009
[366]
use a block of arguments ?
jocko
29-Nov-2009
[367x2]
Yes, of course it is a solution, but not a clean on in my case

in fact, you cannot know, from inside the C part of the code, the 
real number of arguments send to the function.
RXA_COUNT returns the number of arguments defined by the prototype 
of the function, not the actual one
Gabriele
29-Nov-2009
[369]
Jocko... you know... it has never been possible in REBOL to define 
functions with a variable number of arguments...
Rebolek
29-Nov-2009
[370]
it is possible, but usefull only in console
jocko
29-Nov-2009
[371]
that is why I was thinking of refinements
BrianH
29-Nov-2009
[372]
The method of calling with refinements is currently awkward. That 
is one of the problems that is intended to be addressed in the near 
future in further revisions of the extensions api.