mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-13 07:47:39 +02:00
WIP
This commit is contained in:
parent
5e7d896a95
commit
41e6aedb25
2 changed files with 40 additions and 1 deletions
|
@ -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.
|
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
|
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-code`](#c-code)
|
||||||
- [`c-value`](#c-value)
|
- [`c-value`](#c-value)
|
||||||
|
|
|
@ -64,10 +64,22 @@
|
||||||
`(case ,type
|
`(case ,type
|
||||||
((int integer)
|
((int integer)
|
||||||
(string-append "obj_obj2int(" ,code ")"))
|
(string-append "obj_obj2int(" ,code ")"))
|
||||||
|
((double float)
|
||||||
|
(string-append "double_value(" ,code ")"))
|
||||||
|
((bignum bigint)
|
||||||
|
(string-append "bignum_value(" ,code ")"))
|
||||||
((bool)
|
((bool)
|
||||||
(string-append "(" ,code " == boolean_f)"))
|
(string-append "(" ,code " == boolean_f)"))
|
||||||
|
((char)
|
||||||
|
(string-append "obj_obj2char(" ,code ")"))
|
||||||
((string)
|
((string)
|
||||||
(string-append "string_str(" ,code ")"))
|
(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
|
(else
|
||||||
(error "scm->c unable to convert scheme object of type " ,type)))))))
|
(error "scm->c unable to convert scheme object of type " ,type)))))))
|
||||||
|
|
||||||
|
@ -102,11 +114,25 @@
|
||||||
(cons
|
(cons
|
||||||
""
|
""
|
||||||
(string-append "(" ,code " == 0 ? boolean_f : boolean_t)")))
|
(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?
|
; TODO: how to handle the allocation here?
|
||||||
; may need to return a c-code pair???
|
; may need to return a c-code pair???
|
||||||
; (string-append "
|
; (string-append "
|
||||||
; ))
|
; ))
|
||||||
|
; /*bytevector_tag */ , "bytevector"
|
||||||
|
; /*c_opaque_tag */ , "opaque"
|
||||||
|
; /*bignum_tag */ , "bignum"
|
||||||
|
; /*symbol_tag */ , "symbol"
|
||||||
(else
|
(else
|
||||||
(error "c->scm unable to convert C object of type " ,type)))))))
|
(error "c->scm unable to convert C object of type " ,type)))))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue