[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] using the compiler at runtime
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] using the compiler at runtime |
Date: |
Wed, 12 Nov 2008 16:17:34 +0100 |
On Wed, Nov 12, 2008 at 3:15 PM, Felix Lange <address@hidden> wrote:
>
>
> i considered using (system ...), too, but it depends on having access to
> csc and a
> way of finding the executable. making an interface to the compiler
> available as a
> library-unit eliminates these needs, though a C compiler (and libchicken)
> would
> still be required. the csc code should contain a way to find both on
> all platforms.
>
> the whole thing boils down to implementing a library interface to csc.
> compiling closures won't work, of course, but i think (compile-file ...)
> would be enough for most tasks.
>
You mean something like this?
;;;; cf.scm
;
; to use it:
;
; csc -s cf.scm
; csi cf.so
(use utils data-structures)
#>
#ifndef C_INSTALL_BIN_HOME
# define C_INSTALL_BIN_HOME NULL
#endif
<#
(define compile-file
(let* ((binpath
(or (and-let* ((p (getenv "CHICKEN_PREFIX")))
(make-pathname p "bin") )
(foreign-value "C_INSTALL_BIN_HOME" c-string) ) ) ; ugly, we
need another way
(csc (make-pathname binpath "csc")))
(lambda (filename . opts)
(let ((tmp (create-temporary-file "so")))
(system*
"~a -s '~a' -o '~a' ~a"
csc filename tmp
(string-intersperse opts " "))
(on-exit
(lambda ()
(system (sprintf "rm -f '~a'" tmp))))
(load tmp) ) ) ) )
Various variations exist.
cheers,
felix