diff --git a/docs/api/cyclone/foreign.md b/docs/api/cyclone/foreign.md index 50673ac7..51fd29b7 100644 --- a/docs/api/cyclone/foreign.md +++ b/docs/api/cyclone/foreign.md @@ -3,6 +3,19 @@ The `(cyclone foreign)` provides a convenient interface for integrating with C code. It is based in concept on the `(chicken foreign)` module from CHICKEN Scheme. Similarly to that module, this library manipulates the C code directly before it is compiled to a native binary. It is not possible to call these forms at runtime. TODO: list of type specifiers +built-in types +Scheme | C +int | int +integer | int +bool | int +char | int +string | char * +symbol | const char * +bytevector | char * +float | double +double | double +bignum | mp_int +opaque | void * - [`c-code`](#c-code) - [`c-value`](#c-value) diff --git a/libs/cyclone/foreign.sld b/libs/cyclone/foreign.sld index 7011e07e..57e97df6 100644 --- a/libs/cyclone/foreign.sld +++ b/libs/cyclone/foreign.sld @@ -64,10 +64,22 @@ `(case ,type ((int integer) (string-append "obj_obj2int(" ,code ")")) + ((double float) + (string-append "double_value(" ,code ")")) + ((bignum bigint) + (string-append "bignum_value(" ,code ")")) ((bool) (string-append "(" ,code " == boolean_f)")) + ((char) + (string-append "obj_obj2char(" ,code ")")) ((string) (string-append "string_str(" ,code ")")) + ((symbol) + (string-append "symbol_desc(" ,code ")")) + ((bytevector) + (string-append "(((bytevector_type *)" ,code ")->data)")) + ((opaque + (string-append "opaque_ptr(" ,code ")")) (else (error "scm->c unable to convert scheme object of type " ,type))))))) @@ -102,11 +114,25 @@ (cons "" (string-append "(" ,code " == 0 ? boolean_f : boolean_t)"))) - ; ((string) + ((char) + (cons + "" + (string-append "obj_char2obj(" ,code ")"))) + ((string) + (let ((var (mangle (gensym 'var)))) + (cons + (string-append + "make_double(" var ", " ,code ");") + (string-append "&" var) + ))) ; TODO: how to handle the allocation here? ; may need to return a c-code pair??? ; (string-append " ; )) +; /*bytevector_tag */ , "bytevector" +; /*c_opaque_tag */ , "opaque" +; /*bignum_tag */ , "bignum" +; /*symbol_tag */ , "symbol" (else (error "c->scm unable to convert C object of type " ,type)))))))