Merge branch 'master' into cargs2-dev

This commit is contained in:
Justin Ethier 2021-03-04 22:58:11 -05:00
commit ee11bc0ab0
8 changed files with 84 additions and 64 deletions

View file

@ -16,3 +16,4 @@ Adam Feuer
Sean Lynch Sean Lynch
@extrasharp @extrasharp
@nymacro @nymacro
Skye Soss

View file

@ -6,10 +6,13 @@ Features
- Arthur Maciel added `opaque?` and `opaque-null?` predicates to `(cyclone foreign)`. - Arthur Maciel added `opaque?` and `opaque-null?` predicates to `(cyclone foreign)`.
- Added `import-shared-object` to `(scheme eval)` to allow loading a third party C shared library. - Added `import-shared-object` to `(scheme eval)` to allow loading a third party C shared library.
- Allow C compiler/linker options from a library to be expanded via `cond-expand`.
Bug Fixes Bug Fixes
- Updated the runtime to avoid a race condition when creating new symbols. Thanks to Skye Soss for the bug report and patch.
- Prevent the compiler from inlining calls to primitives that open ports, avoiding a range of issues such as an open file operation being inlined across multiple places in the intermediate code. - Prevent the compiler from inlining calls to primitives that open ports, avoiding a range of issues such as an open file operation being inlined across multiple places in the intermediate code.
- Arthur Maciel updated `current-jiffy` to use `clock_gettime`.
## 0.26 - February 3, 2021 ## 0.26 - February 3, 2021

View file

@ -741,7 +741,7 @@
'())) '()))
;; Read all linker options from dependent libs ;; Read all linker options from dependent libs
(c-linker-options (c-linker-options
(let ((lib-options (lib:get-all-c-linker-options lib-deps append-dirs prepend-dirs))) (let ((lib-options (lib:get-all-c-linker-options lib-deps append-dirs prepend-dirs expander)))
(if program? (if program?
(string-append ;; Also read from current program (string-append ;; Also read from current program
(string-join (program-c-linker-opts! in-prog) " ") (string-join (program-c-linker-opts! in-prog) " ")
@ -791,7 +791,8 @@
(lib:get-all-c-linker-options (lib:get-all-c-linker-options
lib-deps lib-deps
append-dirs append-dirs
prepend-dirs)) prepend-dirs
expander))
;; Return new deps ;; Return new deps
lib-deps) lib-deps)
in-file in-file

View file

@ -459,9 +459,16 @@ static object find_symbol_by_name(const char *name)
object add_symbol(symbol_type * psym) object add_symbol(symbol_type * psym)
{ {
pthread_mutex_lock(&symbol_table_lock); // Only 1 "writer" allowed pthread_mutex_lock(&symbol_table_lock); // Only 1 "writer" allowed
set_insert(&symbol_table, psym); bool inserted = set_insert(&symbol_table, psym);
pthread_mutex_unlock(&symbol_table_lock); pthread_mutex_unlock(&symbol_table_lock);
if (!inserted) {
object sym = find_symbol_by_name(psym->desc);
free((char *)(psym->desc));
free(psym);
return sym;
} else {
return psym; return psym;
}
} }
static object add_symbol_by_name(const char *name) static object add_symbol_by_name(const char *name)

View file

@ -2251,12 +2251,6 @@
*globals*) *globals*)
(emit "") (emit "")
;; Initialize symbol table
(for-each
(lambda (sym)
(emit* " add_symbol(quote_" (mangle sym) ");"))
*symbols*)
;; Initialize globals ;; Initialize globals
(let* ((prefix " ") (let* ((prefix " ")
(emit-global (emit-global

View file

@ -168,6 +168,20 @@
(map scan exp)) (map scan exp))
(else exp) (else exp)
)) ))
;; Does given sexp contain any top-level define-c expressions?
(define (has-define-c? sexp)
(call/cc
(lambda (k)
(for-each
(lambda (exp)
(if (define-c? exp)
(k #t)))
sexp)
(k #f))))
(if (has-define-c? sexp)
sexp ;; Can't optimize with define-c (yet), so bail
(let ((new-exp (scan sexp))) (let ((new-exp (scan sexp)))
(cond (cond
((not (null? memo-tbl)) ((not (null? memo-tbl))
@ -201,9 +215,7 @@
memo-tbl) memo-tbl)
))) )))
new-exp))) new-exp)))
(else new-exp))) (else new-exp)))))
)
(cond-expand (cond-expand
(program (program

View file

@ -434,37 +434,43 @@
(close-input-port fp) (close-input-port fp)
includes)) includes))
(define (lib:read-c-linker-options import append-dirs prepend-dirs) (define (lib:read-c-linker-options import append-dirs prepend-dirs expander)
(let* ((lib-name (lib:import->library-name import)) (let* ((lib-name (lib:import->library-name import))
(dir (lib:import->filename lib-name ".sld" append-dirs prepend-dirs)) (dir (lib:import->filename lib-name ".sld" append-dirs prepend-dirs))
(fp (open-input-file dir)) (fp (open-input-file dir))
(lib (read-all fp)) (lib (read-all fp))
(options (lib:c-linker-options (car lib)))) (lib* (if expander
(list (lib:cond-expand (car lib) expander))
lib))
(options (lib:c-linker-options (car lib*))))
(close-input-port fp) (close-input-port fp)
(string-join options " "))) (string-join options " ")))
(define (lib:get-all-c-linker-options imports append-dirs prepend-dirs) (define (lib:get-all-c-linker-options imports append-dirs prepend-dirs expander)
(string-join (string-join
(map (map
(lambda (import) (lambda (import)
(lib:read-c-linker-options import append-dirs prepend-dirs)) (lib:read-c-linker-options import append-dirs prepend-dirs expander))
imports) imports)
" ")) " "))
(define (lib:read-c-compiler-options import append-dirs prepend-dirs) (define (lib:read-c-compiler-options import append-dirs prepend-dirs expander)
(let* ((lib-name (lib:import->library-name import)) (let* ((lib-name (lib:import->library-name import))
(dir (lib:import->filename lib-name ".sld" append-dirs prepend-dirs)) (dir (lib:import->filename lib-name ".sld" append-dirs prepend-dirs))
(fp (open-input-file dir)) (fp (open-input-file dir))
(lib (read-all fp)) (lib (read-all fp))
(options (lib:c-compiler-options (car lib)))) (lib* (if expander
(list (lib:cond-expand (car lib) expander))
lib))
(options (lib:c-compiler-options (car lib*))))
(close-input-port fp) (close-input-port fp)
(string-join options " "))) (string-join options " ")))
(define (lib:get-all-c-compiler-options imports append-dirs prepend-dirs) (define (lib:get-all-c-compiler-options imports append-dirs prepend-dirs expander)
(string-join (string-join
(map (map
(lambda (import) (lambda (import)
(lib:read-c-compiler-options import append-dirs prepend-dirs)) (lib:read-c-compiler-options import append-dirs prepend-dirs expander))
imports) imports)
" ")) " "))

View file

@ -10,12 +10,9 @@
(export (export
current-second current-second
current-jiffy current-jiffy
jiffies-per-second jiffies-per-second)
) (include-c-header "<time.h>")
(include-c-header "<sys/time.h>") (import (scheme base))
(import (scheme base)
)
;; TODO: get an FFI syntax for including C header files, even if it is not needed for this library
(begin (begin
(define-c current-second (define-c current-second
"(void *data, int argc, closure _, object k)" "(void *data, int argc, closure _, object k)"
@ -25,10 +22,10 @@
return_closcall1(data, k, &box); ") return_closcall1(data, k, &box); ")
(define-c current-jiffy (define-c current-jiffy
"(void *data, int argc, closure _, object k)" "(void *data, int argc, closure _, object k)"
" struct timeval tv; " struct timespec now;
make_double(box, 0.0); make_double(box, 0.0);
gettimeofday(&tv, NULL); /* TODO: longer-term consider using clock_gettime instead */ clock_gettime(CLOCK_MONOTONIC, &now);
long long jiffy = (tv.tv_sec)*1000000LL + tv.tv_usec; long long jiffy = (now.tv_sec)*1000000LL + now.tv_nsec/1000; // nano->microseconds
/* Future consideration: /* Future consideration:
mp_int bn_tmp, bn_tmp2, bn_tmp3; mp_int bn_tmp, bn_tmp2, bn_tmp3;
mp_init(&bn_tmp); mp_init(&bn_tmp);
@ -50,5 +47,4 @@
"(void *data, int argc, closure _, object k)" "(void *data, int argc, closure _, object k)"
" int n = 1000000; " int n = 1000000;
object obj = obj_int2obj(n); object obj = obj_int2obj(n);
return_closcall1(data, k, obj); ") return_closcall1(data, k, obj); ")))
))