Skip to content

Commit 4480e64

Browse files
committed
Chez Scheme: add libffi support for pb
By using libffi, we can fill in the one piece of Chez Scheme that was previously unimplemented for pb (portable bytecode) mode: calling foreign functions and converting a closure to a foreign function. In principle, this change allows Racket CS to run on any platform where Racket BC runs (in interpreted mode); the performance of interpreted Racket code is about the same in those two. But since Racket BC's compiler is in C and its expander can be compiled to C (via cify), BC is still much faster to expand and compile programs. A next step might be to set up a similar compiltion via C for the static part of Chez Scheme and Racket.
1 parent d41b86c commit 4480e64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1756
-221
lines changed

.makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ RACKET_FOR_BOOTFILES = $(RACKET)
344344
RACKET_FOR_BUILD = $(RACKET)
345345

346346
# This branch name changes each time the pb boot files are updated:
347-
PB_BRANCH == circa-8.4.0.2-1
347+
PB_BRANCH == circa-8.4.0.4-1
348348
PB_REPO = https://github.com/racket/pb
349349

350350
# Set to empty for Git before v1.7.10:

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ RACKETCS_SUFFIX =
4747
RACKET =
4848
RACKET_FOR_BOOTFILES = $(RACKET)
4949
RACKET_FOR_BUILD = $(RACKET)
50-
PB_BRANCH = circa-8.4.0.2-1
50+
PB_BRANCH = circa-8.4.0.4-1
5151
PB_REPO = https://github.com/racket/pb
5252
SINGLE_BRANCH_FLAG = --single-branch
5353
EXTRA_REPOS_BASE =
@@ -310,19 +310,19 @@ maybe-fetch-pb-as-is:
310310
echo done
311311
fetch-pb-from:
312312
mkdir -p racket/src/ChezScheme/boot
313-
if [ ! -d racket/src/ChezScheme/boot/pb ] ; then git clone -q $(SINGLE_BRANCH_FLAG) -b circa-8.4.0.2-1 $(PB_REPO) racket/src/ChezScheme/boot/pb ; else cd racket/src/ChezScheme/boot/pb && git fetch -q origin circa-8.4.0.2-1:remotes/origin/circa-8.4.0.2-1 ; fi
314-
cd racket/src/ChezScheme/boot/pb && git remote set-branches origin circa-8.4.0.2-1
315-
cd racket/src/ChezScheme/boot/pb && git checkout -q circa-8.4.0.2-1
313+
if [ ! -d racket/src/ChezScheme/boot/pb ] ; then git clone -q $(SINGLE_BRANCH_FLAG) -b circa-8.4.0.4-1 $(PB_REPO) racket/src/ChezScheme/boot/pb ; else cd racket/src/ChezScheme/boot/pb && git fetch -q origin circa-8.4.0.4-1:remotes/origin/circa-8.4.0.4-1 ; fi
314+
cd racket/src/ChezScheme/boot/pb && git remote set-branches origin circa-8.4.0.4-1
315+
cd racket/src/ChezScheme/boot/pb && git checkout -q circa-8.4.0.4-1
316316
pb-fetch:
317317
$(MAKE) fetch-pb EXTRA_REPOS_BASE="$(EXTRA_REPOS_BASE)" PB_REPO="$(PB_REPO)" SINGLE_BRANCH_FLAG="$(SINGLE_BRANCH_FLAG)"
318318
pb-build:
319319
cd racket/src/ChezScheme && racket rktboot/main.rkt --machine pb
320320
pb-stage:
321-
cd racket/src/ChezScheme/boot/pb && git branch circa-8.4.0.2-1
322-
cd racket/src/ChezScheme/boot/pb && git checkout circa-8.4.0.2-1
321+
cd racket/src/ChezScheme/boot/pb && git branch circa-8.4.0.4-1
322+
cd racket/src/ChezScheme/boot/pb && git checkout circa-8.4.0.4-1
323323
cd racket/src/ChezScheme/boot/pb && git add . && git commit --amend -m "new build"
324324
pb-push:
325-
cd racket/src/ChezScheme/boot/pb && git push -u origin circa-8.4.0.2-1
325+
cd racket/src/ChezScheme/boot/pb && git push -u origin circa-8.4.0.4-1
326326
win-cs-base:
327327
IF "$(RACKET_FOR_BUILD)" == "" $(MAKE) win-bc-then-cs-base SETUP_BOOT_MODE=--boot WIN32_BUILD_LEVEL=bc PLAIN_RACKET=racket\racketbc DISABLE_STATIC_LIBS="$(DISABLE_STATIC_LIBS)" EXTRA_REPOS_BASE="$(EXTRA_REPOS_BASE)" JOB_OPTIONS="$(JOB_OPTIONS)" PLT_SETUP_OPTIONS="$(PLT_SETUP_OPTIONS)" RACKETBC_SUFFIX="$(RACKETBC_SUFFIX)" RACKETCS_SUFFIX="$(RACKETCS_SUFFIX)"
328328
IF not "$(RACKET_FOR_BUILD)" == "" $(MAKE) win-just-cs-base SETUP_BOOT_MODE=--chain DISABLE_STATIC_LIBS="$(DISABLE_STATIC_LIBS)" EXTRA_REPOS_BASE="$(EXTRA_REPOS_BASE)" JOB_OPTIONS="$(JOB_OPTIONS)" PLT_SETUP_OPTIONS="$(PLT_SETUP_OPTIONS)" RACKETCS_SUFFIX="$(RACKETCS_SUFFIX)" RACKET_FOR_BUILD="$(RACKET_FOR_BUILD)"

pkgs/base/info.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
;; In the Racket source repo, this version should change only when
1616
;; "racket_version.h" changes:
17-
(define version "8.4.0.3")
17+
(define version "8.4.0.4")
1818

1919
(define deps `("racket-lib"
2020
["racket" #:version ,version]))

racket/src/ChezScheme/c/Mf-base

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ KernelLibLinkLibs=${zlibLib} ${LZ4Lib}
4040

4141
kernelsrc=statics.c segment.c alloc.c symbol.c intern.c gcwrapper.c gc-011.c gc-par.c gc-ocd.c gc-oce.c\
4242
number.c schsig.c io.c new-io.c print.c fasl.c vfasl.c stats.c foreign.c prim.c prim5.c flushcache.c\
43-
schlib.c thread.c expeditor.c scheme.c compress-io.c random.c
43+
schlib.c thread.c expeditor.c scheme.c compress-io.c random.c ffi.c
4444

4545
kernelobj=${kernelsrc:%.c=%.$o} ${mdobj}
4646

racket/src/ChezScheme/c/alloc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ void S_alloc_init() {
8787

8888
S_protect(&S_G.zero_length_bignum);
8989
S_G.zero_length_bignum = S_bignum(tc, 0, 0);
90+
91+
#ifdef PORTABLE_BYTECODE
92+
S_protect(&S_G.foreign_callables);
93+
S_G.foreign_callables = Snil;
94+
#endif
9095
}
9196
}
9297

racket/src/ChezScheme/c/atomic.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@
3838
#elif defined(__arm64__) || defined(__aarch64__)
3939
FORCEINLINE int CAS_LOAD_ACQUIRE(volatile void *addr, void *old_val, void *new_val) {
4040
long ret;
41-
__asm__ __volatile__ ("mov %0, #0\n\t"
41+
__asm__ __volatile__ ("mov %0, #0\n\t"
4242
"0:\n\t"
4343
"ldaxr x12, [%1, #0]\n\t"
4444
"cmp x12, %2\n\t"
4545
"bne 1f\n\t"
46-
"stxr x7, %3, [%1, #0]\n\t"
46+
"stxr w7, %3, [%1, #0]\n\t"
4747
"cmp x7, #0\n\t"
4848
"bne 1f\n\t"
49-
"moveq %0, #1\n\t"
49+
"mov %0, #1\n\t"
5050
"1:\n\t"
5151
: "=&r" (ret)
5252
: "r" (addr), "r" (old_val), "r" (new_val)
@@ -61,10 +61,10 @@ FORCEINLINE int CAS_STORE_RELEASE(volatile void *addr, void *old_val, void *new_
6161
"ldxr x12, [%1, #0]\n\t"
6262
"cmp x12, %2\n\t"
6363
"bne 1f\n\t"
64-
"stlxr x7, %3, [%1, #0]\n\t"
64+
"stlxr w7, %3, [%1, #0]\n\t"
6565
"cmp x7, #0\n\t"
6666
"bne 1f\n\t"
67-
"moveq %0, #1\n\t"
67+
"mov %0, #1\n\t"
6868
"1:\n\t"
6969
: "=&r" (ret)
7070
: "r" (addr), "r" (old_val), "r" (new_val)
@@ -126,4 +126,6 @@ FORCEINLINE int S_cas_any_fence(volatile void *addr, void *old_val, void *new_va
126126
#ifdef CAS_ANY_FENCE
127127
# define CAS_LOAD_ACQUIRE(a, old, new) CAS_ANY_FENCE(a, old, new)
128128
# define CAS_STORE_RELEASE(a, old, new) CAS_ANY_FENCE(a, old, new)
129+
#else
130+
# define CAS_ANY_FENCE(a, old, new) CAS_LOAD_ACQUIRE(a, old, new)
129131
#endif

racket/src/ChezScheme/c/externs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ void S_longjmp(void *b, int v);
438438
#ifdef PORTABLE_BYTECODE
439439
/* pb.c */
440440
extern void S_pb_interp(ptr tc, void *bytecode);
441+
extern ptr *S_get_call_arena(ptr tc);
441442
#endif
442443

443444
#ifdef WIN32
@@ -471,6 +472,11 @@ double S_random_state_next_double PROTO((ptr s));
471472
void S_random_state_init PROTO((ptr s, UINT x));
472473
IBOOL S_random_state_check PROTO((double x10, double x11, double x12,
473474
double x20, double x21, double x22));
475+
/* ffi.c */
476+
#ifdef PORTABLE_BYTECODE
477+
extern void S_ffi_call(ptr types, ptr proc, ptr *stack);
478+
extern ptr S_ffi_closure(ptr types, ptr proc);
479+
#endif
474480

475481
/* statics.c */
476482
extern void scheme_statics();

0 commit comments

Comments
 (0)