This commit is contained in:
Justin Ethier 2020-05-04 16:24:07 -04:00
parent 5e7d896a95
commit 41e6aedb25
2 changed files with 40 additions and 1 deletions

View file

@ -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)

View file

@ -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)))))))