mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 04:25:06 +02:00
WIP
This commit is contained in:
parent
2faa5fbb9a
commit
41548f4d64
1 changed files with 32 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
(import
|
(import
|
||||||
(scheme base)
|
(scheme base)
|
||||||
(scheme write)
|
(scheme write)
|
||||||
|
(cyclone test)
|
||||||
(scheme cyclone cgen)
|
(scheme cyclone cgen)
|
||||||
(scheme cyclone util)
|
(scheme cyclone util)
|
||||||
(scheme cyclone pretty-print))
|
(scheme cyclone pretty-print))
|
||||||
|
@ -61,9 +62,26 @@
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
(define-foreign-lambda scm-strlen int "strlen" string)
|
;; Unbox scheme object
|
||||||
(display (scm-strlen "testing 1, 2, 3"))
|
(define (scm->c code type)
|
||||||
(newline)
|
(cond
|
||||||
|
(else
|
||||||
|
(error "scm->c unable to convert" type))))
|
||||||
|
|
||||||
|
;; Box C object, basically the meat of (foreign-value)
|
||||||
|
(define (c->scm code type)
|
||||||
|
(case type
|
||||||
|
((int integer)
|
||||||
|
(string-append "obj_int2obj(" code ")"))
|
||||||
|
((bool)
|
||||||
|
(string-append "(" code " == 0 ? boolean_f : boolean_t)"))
|
||||||
|
((string)
|
||||||
|
TODO: how to handle the allocation here?
|
||||||
|
(string-append "
|
||||||
|
))
|
||||||
|
(else
|
||||||
|
(error "c->scm unable to convert" type))))
|
||||||
|
|
||||||
|
|
||||||
;(define-c foreign-value
|
;(define-c foreign-value
|
||||||
; "(void *data, int argc, closure _, object k, object code, object type)"
|
; "(void *data, int argc, closure _, object k, object code, object type)"
|
||||||
|
@ -75,7 +93,16 @@
|
||||||
|
|
||||||
;(write (Cyc-foreign-value "errno" "3"))
|
;(write (Cyc-foreign-value "errno" "3"))
|
||||||
;(newline)
|
;(newline)
|
||||||
|
(test-group "basic"
|
||||||
(write (foreign-code
|
(write (foreign-code
|
||||||
"printf(\"test %d %d \\n\", 1, 2);"
|
"printf(\"test %d %d \\n\", 1, 2);"
|
||||||
"printf(\"test %d %d %d\\n\", 1, 2, 3);"))
|
"printf(\"test %d %d %d\\n\", 1, 2, 3);")) (newline)
|
||||||
(newline)
|
)
|
||||||
|
|
||||||
|
;; Must be top-level
|
||||||
|
(define-foreign-lambda scm-strlen int "strlen" string)
|
||||||
|
|
||||||
|
(test-group "foreign lambda"
|
||||||
|
(test 15 (scm-strlen "testing 1, 2, 3"))
|
||||||
|
)
|
||||||
|
(test-exit)
|
||||||
|
|
Loading…
Add table
Reference in a new issue