mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-19 05:39:17 +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 -Wall
|
||||||
#CFLAGS = -g -pg -Wall
|
#CFLAGS = -g -pg -Wall
|
||||||
CC ?= cc
|
CC ?= cc
|
||||||
LIBS = -pthread -lcyclone -lck -lm -ltommath
|
LIBS = -pthread -lcyclone -lck -lm -ltommath -ldl
|
||||||
|
|
||||||
# Commands "baked into" cyclone for invoking the C compiler
|
# Commands "baked into" cyclone for invoking the C compiler
|
||||||
CC_PROG ?= "$(CC) ~src-file~ $(COMP_CFLAGS) -c -o ~exec-file~.o"
|
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_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_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
|
AR ?= ar
|
||||||
#CD ?= cd
|
#CD ?= cd
|
||||||
|
|
18
cyclone.scm
18
cyclone.scm
|
@ -370,7 +370,7 @@
|
||||||
(read-all port))))
|
(read-all port))))
|
||||||
|
|
||||||
;; Compile and emit:
|
;; 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))
|
(let* ((in-file (car args))
|
||||||
(expander (base-expander))
|
(expander (base-expander))
|
||||||
(in-prog-raw (read-file in-file))
|
(in-prog-raw (read-file in-file))
|
||||||
|
@ -456,14 +456,23 @@
|
||||||
(string-replace-all
|
(string-replace-all
|
||||||
(get-comp-env 'cc-lib cc-lib)
|
(get-comp-env 'cc-lib cc-lib)
|
||||||
"~src-file~" src-file)
|
"~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
|
(cond
|
||||||
(cc?
|
(cc?
|
||||||
(system comp-lib-cmd)
|
(system comp-lib-cmd)
|
||||||
|
(system comp-so-cmd)
|
||||||
)
|
)
|
||||||
(else
|
(else
|
||||||
(display comp-lib-cmd)
|
(display comp-lib-cmd)
|
||||||
(newline)
|
(newline)
|
||||||
|
(display comp-so-cmd)
|
||||||
(newline))))))))
|
(newline))))))))
|
||||||
|
|
||||||
;; Collect values for the given command line arguments and option.
|
;; 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-prog (apply string-append (collect-opt-values args "-CP")))
|
||||||
(cc-exec (apply string-append (collect-opt-values args "-CE")))
|
(cc-exec (apply string-append (collect-opt-values args "-CE")))
|
||||||
(cc-lib (apply string-append (collect-opt-values args "-CL")))
|
(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"))
|
(append-dirs (collect-opt-values args "-A"))
|
||||||
(prepend-dirs (collect-opt-values args "-I")))
|
(prepend-dirs (collect-opt-values args "-I")))
|
||||||
;; Set optimization level(s)
|
;; Set optimization level(s)
|
||||||
|
@ -526,6 +536,8 @@
|
||||||
an executable.
|
an executable.
|
||||||
-CL cc-commands Specify a custom command line for the C compiler to compile
|
-CL cc-commands Specify a custom command line for the C compiler to compile
|
||||||
a library module.
|
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
|
-Ox Optimization level, higher means more optimizations will
|
||||||
be used. Set to 0 to disable optimizations.
|
be used. Set to 0 to disable optimizations.
|
||||||
-d Only generate intermediate C files, do not compile them
|
-d Only generate intermediate C files, do not compile them
|
||||||
|
@ -548,5 +560,5 @@
|
||||||
(display "cyclone: no input file")
|
(display "cyclone: no input file")
|
||||||
(newline))
|
(newline))
|
||||||
(else
|
(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 <time.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
#include "tommath.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,
|
int gc_minor(void *data, object low_limit, object high_limit, closure cont,
|
||||||
object * args, int num_args);
|
object * args, int num_args);
|
||||||
|
|
||||||
|
void Cyc_import_shared_object(void *data, object cont, object filename, object entry_pt_fnc);
|
||||||
#endif /* CYCLONE_TYPES_H */
|
#endif /* CYCLONE_TYPES_H */
|
||||||
|
|
18
runtime.c
18
runtime.c
|
@ -5592,3 +5592,21 @@ double MRG32k3a (double seed)
|
||||||
return ((p1 - p2) * norm);
|
return ((p1 - p2) * norm);
|
||||||
}
|
}
|
||||||
/* END RNG */
|
/* 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:lookup
|
||||||
lib:idb:entry->library-name
|
lib:idb:entry->library-name
|
||||||
lib:idb:entry->library-id
|
lib:idb:entry->library-id
|
||||||
|
;; Dynamic import
|
||||||
|
lib:dyn-load
|
||||||
)
|
)
|
||||||
(begin
|
(begin
|
||||||
|
|
||||||
|
@ -589,4 +591,17 @@
|
||||||
(deps (reverse (cdr (get-cell resolved))))) ;; cdr to get rid of master list
|
(deps (reverse (cdr (get-cell resolved))))) ;; cdr to get rid of master list
|
||||||
(map car deps)))
|
(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