From 19f21aaa71dc2ef103ded6f31ba68b8b24a95a73 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 27 Apr 2016 00:31:14 -0400 Subject: [PATCH] Added new docs --- docs/User-Manual.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/User-Manual.md b/docs/User-Manual.md index bc391a3e..449a7f90 100644 --- a/docs/User-Manual.md +++ b/docs/User-Manual.md @@ -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 "") + +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: `""`), 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).