mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-11 23:07:36 +02:00
Added new docs
This commit is contained in:
parent
8ca5d516bf
commit
19f21aaa71
1 changed files with 23 additions and 0 deletions
|
@ -17,6 +17,8 @@ title: User Manual
|
|||
- [Language Details](#language-details)
|
||||
- [Multithreaded Programming](#multithreaded-programming)
|
||||
- [Foreign Function Interface](#foreign-function-interface)
|
||||
- [Writing a Scheme Function in C](#writing-a-scheme-function-in-c)
|
||||
- [Including a C Header File](#including-a-c-header-file)
|
||||
- [Licensing](#licensing)
|
||||
- [References and Further Reading](#references-and-further-reading)
|
||||
|
||||
|
@ -149,6 +151,8 @@ Finally, note there are some objects that are not relocated so the above does no
|
|||
|
||||
# Foreign Function Interface
|
||||
|
||||
## Writing a Scheme Function in C
|
||||
|
||||
The `define-c` special form can be used to define a function containing user-defined C code. This code will be carried through from the Scheme file all the way to the compiled C file. For example:
|
||||
|
||||
(define-c Cyc-add-exception-handler
|
||||
|
@ -183,6 +187,25 @@ Functions that may block must call the `set_thread_blocked` macro to let the sys
|
|||
|
||||
The Cyclone runtime can be used as a reference for how to write your own C functions. A good starting point would be [`runtime.c`](../runtime.c) and [`types.h`](../include/cyclone/types.h).
|
||||
|
||||
## Including a C Header File
|
||||
|
||||
A C header may be included using the `include-c-header` special form. This special form may be used either as part of a library definition:
|
||||
|
||||
(define-library (example life)
|
||||
(include-c-header "../write-png.h")
|
||||
(export life)
|
||||
... )
|
||||
|
||||
Or as part of a program (add any includes immediately after the `import` expression, if one is present):
|
||||
|
||||
(import (scheme base)
|
||||
(example life)
|
||||
(example grid))
|
||||
(include-c-header "stdlib.h")
|
||||
(include-c-header "<stdio.h>")
|
||||
|
||||
By default this will generate an `#include` preprocessor directive with the name of the header file in double quotes. However, if `include-c-header` is passed a text string with angle brackets (EG: `"<stdio.h>"`), the generated C code will use angle brackets instead.
|
||||
|
||||
# Licensing
|
||||
Cyclone is available under the [MIT license](http://www.opensource.org/licenses/mit-license.php).
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue