Re: [Chicken-users] chicken-setup failure with gmp

2005-07-25 Thread felix winkelmann
The egg should be fixed now. 


cheers,
felix


On 7/23/05, Raffael Cavallaro <[EMAIL PROTECTED]> wrote:
> 
> 
> On Jul 22, 2005, at Fri, Jul 22, 7:22 42 PM, Dale Jordan wrote:
> 
> 
> Change to: 
> 
> (map (lambda (s o) (list o (list s) (lambda () (run (csc -s -O2 -d0 -R
> syntax-case s -L -lgmp) 
> 
> 
>  
> 
> (Ignore line breaks above).  You will need the syntax-case egg. 
> Did the trick - thanks for your help.
> 
> regards,
> 
> Ralph
>  
> Raffael Cavallaro, Ph.D. 
> [EMAIL PROTECTED] 
>  
> ___
> Chicken-users mailing list
> Chicken-users@nongnu.org
> http://lists.nongnu.org/mailman/listinfo/chicken-users
> 
> 
>


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Constructing parameter lists in C: can I use FFI?

2005-07-25 Thread felix winkelmann
On 7/25/05, Daniel B. Faken <[EMAIL PROTECTED]> wrote:
> 
> Also, this helps me understand why the FFI is so focussed on callbacks
> (instead of having equivalent facilities for entry points): entry points
> are just "default continuations" followed by ##sys#call-host, which
> temporarily interrupts (so to speak) the Scheme continuation to let C
> take over for a while.
>   (did I get that right?)

Yes, that's exactly how it works.

>   What do you think about getting rid of the entry-point API, storing
> the continuation somewhere it can explicitly retrieved (if you want to
> exec some more top-level code), and letting callbacks always "just work"
> (after the initial setup).
>   This seems to me much simpler, etc.  The current entry-point API calls
> could easily be translated to callbacks, if anyone needs them.
> 

This is in fact a good solution. The entry-point API is pretty clunky, and this
method is both more lightweight and more convenient. Have to test it
more, though.


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Constructing parameter lists in C: can I use FFI?

2005-07-25 Thread felix winkelmann
On 7/25/05, felix winkelmann <[EMAIL PROTECTED]> wrote:
> 
>  x.scm:
> 
> (define-external (foo (int x) (c-string y)) double
>   (print (list x y))
>   (sqrt x) )
> 
> (##sys#call-host)
> 
> /* y.c */
> 
> #include "chicken.h"
> 
> extern double foo(int, char*);
> 
> int main()
> {
>   CHICKEN_run(NULL, NULL, NULL, C_toplevel);
>   C_restore; /* <- pop continuation, unless we call an entry-point
> this should be ok, */
>   printf("-> %g\n", foo(42, "abc"));
>   printf("-> %g\n", foo(32, "abc"));
>   return 0;
> }
> 

Here the same example with callbacks (from C to Scheme to C and into Scheme
again):


 x.scm

#>!
___safe double cb1(int x, char *y) { foo(x, y); }
<#

(define-external (foo (int x) (c-string y)) double
 (print (list x y))
 (sqrt x) )

(define-external (bar (int x) (c-string y)) double
 (print "bar: " (list x y))
 (cb1 x y) )

(##sys#call-host)

/* y.c */

#include "chicken.h"

extern double foo(int, char*);

int main()
{
 CHICKEN_run(NULL, NULL, NULL, C_toplevel);
 C_restore; /* <- pop continuation, unless we call an entry-point this
should be ok, */
 printf("-> %g\n", foo(42, "abc"));
 printf("-> %g\n", bar(32, "def"));
 printf("-> %g\n", foo(2, "xyz"));
 return 0;
}


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Constructing parameter lists in C: can I use FFI?

2005-07-25 Thread Daniel B. Faken
On Mon, 25 Jul 2005, felix winkelmann wrote:
> Since this is performance critical, I'd suggest that you implement the
> translation of C to Scheme types yourself (in C). If you are using OpenGL,
> the number of argument types you have to support is (relatively) small.

Yeah.. I actually "bit the bullet" & did this a few days ago.. I was just 
hoping there was someway to use Chicken's nice type-conversion facilities 
:).

> [..] Another method would be to store the arguments in
> a Scheme list allocated in static memory (this requires that you store
> only immediate or static data in that list), or in a once-allocated list
> that is GC-protected (via CHICKEN_new_gc_root()).

Interesting.. I had not considered that.

> Note that mixing callbacks and entry-points can be tricky: an entry-point
> leaves a continuation object on the temporary stack.
> Doing a callback after an entry-point returned will not work.
> A better idea might be to
> run CHICKEN_run once, with a Scheme toplevel that performs a
> ##sys#call-host and from then on only invoke Scheme via callbacks:
> 
[code elided]
> 
> This is somewhat, well, unorthodox, but might actually work... ;-)

AHA!  This is exactly what I was looking for, but didn't know existed -- 
some way to "enter the Scheme toplevel" without calling-back into C (which 
for me is verboten since my code "is just a C library")  Merci!

Also, this helps me understand why the FFI is so focussed on callbacks 
(instead of having equivalent facilities for entry points): entry points 
are just "default continuations" followed by ##sys#call-host, which 
temporarily interrupts (so to speak) the Scheme continuation to let C
take over for a while.
  (did I get that right?)
(now I also see what "if(!return_to_host)" in runtime.c:1079 is for..)

So..
  What do you think about getting rid of the entry-point API, storing
the continuation somewhere it can explicitly retrieved (if you want to 
exec some more top-level code), and letting callbacks always "just work" 
(after the initial setup).
  This seems to me much simpler, etc.  The current entry-point API calls 
could easily be translated to callbacks, if anyone needs them.

This is all from my primitive understanding of whats going on, though, so 
maybe there are some things that wouldn't work.


cheers,
Daniel Faken




___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] signed-char* not handled correctly

2005-07-25 Thread Daniel B. Faken
On Mon, 25 Jul 2005, felix winkelmann wrote:
> On 7/22/05, Daniel B. Faken <[EMAIL PROTECTED]> wrote:
> > Hello,
> > 
> >   I've been encountering problems using the FFI with functions that take a
> > (signed char *).  For example, with this short program:
> > ---
> > (define-foreign-type GLbyte signed-char)
> > #>!
> > typedef signed char GLbyte;
> > int call_fn(GLbyte x, GLbyte *y);
> > <#
> > 
> 
> Does the C compiler fail with an error, or is this just a warning?

Just a warning (I should have been more clear).

And that is probably ignoreable, if annoying.  I'm not sure what 
would/could happen with (char)<->(unsigned char) conversions that are 
silently allowed, though.

cheers,
Daniel




___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Constructing parameter lists in C: can I use FFI?

2005-07-25 Thread felix winkelmann
On 7/21/05, Daniel B. Faken <[EMAIL PROTECTED]> wrote:
> 
> Now a preferable solution would be to construct the parameter list,
> as a C_word (scheme-object) via C_list(...), and either
> * use C_callback(scmfn, arglist) for callbacks or
> * use a single entry-point 'scm_applyfn' that takes two
>   scheme-object args and just calls (apply scmfn arglist).

This looks definitely more appropriate. You really want to reduce
the number of switches between Scheme and C (and back).

> The "Problem": its not easy to construct these arglists; or, at least, its
> much harder than using the Chicken-FFI's ability to define & translate
> types (e.g. using define-foreign-type). [an aside: I'm using a
> code-generator, since there are so many functions, but there are about
> 200 different C-function signatures in all]
> 

Since this is performance critical, I'd suggest that you implement the
translation of C to Scheme types yourself (in C). If you are using OpenGL,
the number of argument types you have to support is (relatively) small.
You can (as you correctly suggest), allocate space for the argument lists
on the C-stack. Another method would be to store the arguments in
a Scheme list allocated in static memory (this requires that you store
only immediate or static data in that list), or in a once-allocated list
that is GC-protected (via CHICKEN_new_gc_root()).

Note that mixing callbacks and entry-points can be tricky: an entry-point
leaves a continuation object on the temporary stack. Doing a callback
after an entry-point returned will not work. A better idea might be to
run CHICKEN_run once, with a Scheme toplevel that performs a
##sys#call-host and from then on only invoke Scheme via callbacks:

 x.scm:

(define-external (foo (int x) (c-string y)) double
  (print (list x y)) 
  (sqrt x) )

(##sys#call-host)

/* y.c */

#include "chicken.h"

extern double foo(int, char*);

int main()
{
  CHICKEN_run(NULL, NULL, NULL, C_toplevel);
  C_restore; /* <- pop continuation, unless we call an entry-point
this should be ok, */
  printf("-> %g\n", foo(42, "abc"));
  printf("-> %g\n", foo(32, "abc"));
  return 0;
}

% csc -e x.scm y.c -kv && x
/usr/local/bin/chicken x.scm -output-file x.c -quiet
gcc y.c -o y.o -g -DHAVE_CHICKEN_CONFIG_H -DC_EMBEDDED -c -DC_NO_PIC_NO_DLL
gcc x.c -o x.o -g -DHAVE_CHICKEN_CONFIG_H -DC_EMBEDDED -c -DC_NO_PIC_NO_DLL
gcc -o x y.o x.o -lchicken -L/usr/local/lib -Wl,-R/usr/local/lib -ldl
-lpcre -lffi -lm  -ldl -lpcre -lffi
(42 abc)
-> 6.48074
(32 abc)
-> 5.65685

This is somewhat, well, unorthodox, but might actually work... ;-)


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] static compile with eggs

2005-07-25 Thread felix winkelmann
On 7/22/05, Daishi Kato <[EMAIL PROTECTED]> wrote:
> This may be a faq, but I could not find
> related subjects in the mailing list archive.
> 
> Is it possible to build a static excecutable that uses eggs?
> I'm trying with a simple example, which turned to be not working.
> Here is the log what I've done.
>
>[...]

You should do the following:

% csc gdbm.scm -unit gdbm -c -O2 -d0
% csc foo.scm -uses gdbm -prelude '(provide (quote gdbm))' gdbm.o
% ./foo


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] signed-char* not handled correctly

2005-07-25 Thread felix winkelmann
On 7/22/05, Daniel B. Faken <[EMAIL PROTECTED]> wrote:
> Hello,
> 
>   I've been encountering problems using the FFI with functions that take a
> (signed char *).  For example, with this short program:
> ---
> (define-foreign-type GLbyte signed-char)
> #>!
> typedef signed char GLbyte;
> int call_fn(GLbyte x, GLbyte *y);
> <#
> 

Does the C compiler fail with an error, or is this just a warning?


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users