Allow including C headers in a program

This commit is contained in:
Justin Ethier 2016-04-27 00:18:09 -04:00
parent c9fa2410cf
commit 1fddf8272a
2 changed files with 23 additions and 4 deletions

View file

@ -91,10 +91,24 @@
include))
input-program)))
includes))))
((tagged-list? 'import (car input-program))
(set! imports (cdar input-program))
(set! input-program (cdr input-program))
;(error (list 'imports (cdar input-program)))
(else
;; Handle import, if present
(cond
((tagged-list? 'import (car input-program))
(set! imports (cdar input-program))
(set! input-program (cdr input-program))
;(error (list 'imports (cdar input-program)))
))
;; Handle any C headers
(let ((headers (lib:include-c-headers `(dummy dummy ,@input-program))))
(cond
((not (null? headers))
(set! c-headers headers)
(set! input-program
(filter
(lambda (expr)
(not (tagged-list? 'include-c-header expr)))
input-program)))))
))
;; Process library imports

View file

@ -17,8 +17,13 @@
; (only (example life) life)
; (rename (prefix (example grid) grid-)
; (grid-make make-grid)))
;; Simple example of including headers in a program.
;; Just place them here in the top-level, after
;; the (import) expression, if any.
(include-c-header "stdlib.h")
(include-c-header "<stdio.h>")
;; END C headers
;; Initialize a grid with a glider.
;(define grid (make-grid 24 24))