mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-18 21:29:18 +02:00
Added so generation and dl lib
This commit is contained in:
parent
afcc5eaecd
commit
a93c1e8cde
5 changed files with 52 additions and 5 deletions
|
@ -12,13 +12,13 @@ COMP_CFLAGS ?= -O2 -fPIC -Wall -I$(PREFIX)/include -L$(PREFIX)/lib
|
|||
#CFLAGS = -g -Wall
|
||||
#CFLAGS = -g -pg -Wall
|
||||
CC ?= cc
|
||||
LIBS = -pthread -lcyclone -lck -lm -ltommath
|
||||
LIBS = -pthread -lcyclone -lck -lm -ltommath -ldl
|
||||
|
||||
# Commands "baked into" cyclone for invoking the C compiler
|
||||
CC_PROG ?= "$(CC) ~src-file~ $(COMP_CFLAGS) -c -o ~exec-file~.o"
|
||||
CC_EXEC ?= "$(CC) ~exec-file~.o ~obj-files~ $(LIBS) $(COMP_CFLAGS) -o ~exec-file~"
|
||||
CC_LIB ?= "$(CC) ~src-file~ $(COMP_CFLAGS) -c -o ~exec-file~.o"
|
||||
CC_SO ?= "$(CC) -shared -o ~exec-file~.so -o ~exec-file~.o"
|
||||
CC_SO ?= "$(CC) -shared -o ~exec-file~.so ~exec-file~.o"
|
||||
|
||||
AR ?= ar
|
||||
#CD ?= cd
|
||||
|
|
18
cyclone.scm
18
cyclone.scm
|
@ -370,7 +370,7 @@
|
|||
(read-all port))))
|
||||
|
||||
;; Compile and emit:
|
||||
(define (run-compiler args cc? cc-prog cc-exec cc-lib append-dirs prepend-dirs)
|
||||
(define (run-compiler args cc? cc-prog cc-exec cc-lib cc-so append-dirs prepend-dirs)
|
||||
(let* ((in-file (car args))
|
||||
(expander (base-expander))
|
||||
(in-prog-raw (read-file in-file))
|
||||
|
@ -456,14 +456,23 @@
|
|||
(string-replace-all
|
||||
(get-comp-env 'cc-lib cc-lib)
|
||||
"~src-file~" src-file)
|
||||
"~exec-file~" exec-file)))
|
||||
"~exec-file~" exec-file))
|
||||
(comp-so-cmd
|
||||
(string-replace-all
|
||||
(string-replace-all
|
||||
(get-comp-env 'cc-so cc-so)
|
||||
"~src-file~" src-file)
|
||||
"~exec-file~" exec-file))
|
||||
)
|
||||
(cond
|
||||
(cc?
|
||||
(system comp-lib-cmd)
|
||||
(system comp-so-cmd)
|
||||
)
|
||||
(else
|
||||
(display comp-lib-cmd)
|
||||
(newline)
|
||||
(display comp-so-cmd)
|
||||
(newline))))))))
|
||||
|
||||
;; Collect values for the given command line arguments and option.
|
||||
|
@ -500,6 +509,7 @@
|
|||
(cc-prog (apply string-append (collect-opt-values args "-CP")))
|
||||
(cc-exec (apply string-append (collect-opt-values args "-CE")))
|
||||
(cc-lib (apply string-append (collect-opt-values args "-CL")))
|
||||
(cc-so (apply string-append (collect-opt-values args "-CS")))
|
||||
(append-dirs (collect-opt-values args "-A"))
|
||||
(prepend-dirs (collect-opt-values args "-I")))
|
||||
;; Set optimization level(s)
|
||||
|
@ -526,6 +536,8 @@
|
|||
an executable.
|
||||
-CL cc-commands Specify a custom command line for the C compiler to compile
|
||||
a library module.
|
||||
-CS cc-commands Specify a custom command line for the C compiler to compile
|
||||
a shared object module.
|
||||
-Ox Optimization level, higher means more optimizations will
|
||||
be used. Set to 0 to disable optimizations.
|
||||
-d Only generate intermediate C files, do not compile them
|
||||
|
@ -548,5 +560,5 @@
|
|||
(display "cyclone: no input file")
|
||||
(newline))
|
||||
(else
|
||||
(run-compiler non-opts compile? cc-prog cc-exec cc-lib append-dirs prepend-dirs))))
|
||||
(run-compiler non-opts compile? cc-prog cc-exec cc-lib cc-so append-dirs prepend-dirs))))
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <time.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <dlfcn.h>
|
||||
#include "tommath.h"
|
||||
|
||||
/**
|
||||
|
@ -1059,4 +1060,5 @@ void *gc_alloc_from_bignum(gc_thread_data *data, bignum_type *src);
|
|||
int gc_minor(void *data, object low_limit, object high_limit, closure cont,
|
||||
object * args, int num_args);
|
||||
|
||||
void Cyc_import_shared_object(void *data, object cont, object filename, object entry_pt_fnc);
|
||||
#endif /* CYCLONE_TYPES_H */
|
||||
|
|
18
runtime.c
18
runtime.c
|
@ -5592,3 +5592,21 @@ double MRG32k3a (double seed)
|
|||
return ((p1 - p2) * norm);
|
||||
}
|
||||
/* END RNG */
|
||||
|
||||
|
||||
/** Dynamic loading */
|
||||
void Cyc_import_shared_object(void *data, object cont, object filename, object entry_pt_fnc)
|
||||
{
|
||||
void *handle;
|
||||
function_type entry_pt;
|
||||
Cyc_check_str(data, filename);
|
||||
Cyc_check_str(data, entry_pt_fnc);
|
||||
handle = dlopen(string_str(filename), RTLD_LAZY);
|
||||
if (handle == NULL) {
|
||||
Cyc_rt_raise2(data, "Unable to import library from", filename);
|
||||
}
|
||||
entry_pt = (function_type) dlsym(handle, string_str(entry_pt_fnc));
|
||||
mclosure1(clo, entry_pt, cont);
|
||||
entry_pt(data, 0, &clo, &clo);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,8 @@
|
|||
lib:idb:lookup
|
||||
lib:idb:entry->library-name
|
||||
lib:idb:entry->library-id
|
||||
;; Dynamic import
|
||||
lib:dyn-load
|
||||
)
|
||||
(begin
|
||||
|
||||
|
@ -589,4 +591,17 @@
|
|||
(deps (reverse (cdr (get-cell resolved))))) ;; cdr to get rid of master list
|
||||
(map car deps)))
|
||||
|
||||
|
||||
(define (lib:dyn-load import)
|
||||
(let ((lib-name (lib:list->import-set import)))
|
||||
(c:dyn-load
|
||||
(lib:import->filename lib-name ".so")
|
||||
(string-append
|
||||
" c_" (lib:name->string lib-name) "_entry_pt_first_lambda"))))
|
||||
|
||||
(define-c c:dyn-load
|
||||
"(void *data, int argc, closure _, object k, object fn, object entry_fnc)"
|
||||
" Cyc_import_shared_object(data, k, fn, entry_fnc); ")
|
||||
|
||||
|
||||
))
|
||||
|
|
Loading…
Add table
Reference in a new issue