mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-20 14:19:17 +02:00
Example code builds, needs more debugging
This commit is contained in:
parent
55d2cd424a
commit
973279e2ff
4 changed files with 23 additions and 10 deletions
|
@ -1,14 +1,14 @@
|
||||||
all: calls
|
all: calls
|
||||||
|
|
||||||
sys.o: sys.c
|
sys.o: sys.c
|
||||||
cc -c sys.c
|
cc -g -c sys.c
|
||||||
|
|
||||||
calls.c: calls.scm
|
calls.c: calls.scm
|
||||||
cyclone -d calls.scm
|
cyclone -d calls.scm
|
||||||
|
|
||||||
calls: sys.o calls.c
|
calls: sys.o calls.c
|
||||||
cc calls.c -O2 -Wall -I/usr/local/include -c -o calls.o
|
cc calls.c -g -Wall -I/usr/local/include -c -o calls.o
|
||||||
cc calls.o /usr/local/share/cyclone/scheme/cyclone/common.o /usr/local/share/cyclone/scheme/base.o /usr/local/share/cyclone/srfi/18.o /usr/local/share/cyclone/scheme/write.o -pthread -lcyclone -lck -lm -lcyclonebn -ldl -O2 -fPIC -Wall -Wno-shift-negative-value -Wno-unused-command-line-argument -I/usr/local/include -L/usr/local/lib -Wl,--export-dynamic -o calls
|
cc calls.o sys.o /usr/local/share/cyclone/scheme/cyclone/common.o /usr/local/share/cyclone/scheme/base.o /usr/local/share/cyclone/srfi/18.o /usr/local/share/cyclone/scheme/write.o -pthread -lcyclone -lck -lm -lcyclonebn -ldl -g -fPIC -Wall -Wno-shift-negative-value -Wno-unused-command-line-argument -I/usr/local/include -L/usr/local/lib -Wl,--export-dynamic -o calls
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,16 @@
|
||||||
(scheme write)
|
(scheme write)
|
||||||
(srfi 18))
|
(srfi 18))
|
||||||
|
|
||||||
;;(include-c-header "sys.c")
|
(include-c-header "sys.h")
|
||||||
|
|
||||||
(define *done* #f)
|
(define *done* #f)
|
||||||
(define *dummy signal-done) ;; Hack to prevent optimizing-out signal-done
|
(define *dummy signal-done) ;; Hack to prevent optimizing-out signal-done
|
||||||
|
|
||||||
|
(define-c start-c-thread
|
||||||
|
"(void *data, int argc, closure _, object k)"
|
||||||
|
"start_c_thread();
|
||||||
|
return_closcall1(data, k, boolean_t); ")
|
||||||
|
|
||||||
(define (signal-done obj)
|
(define (signal-done obj)
|
||||||
(write `(Called from C set *done* to ,obj))
|
(write `(Called from C set *done* to ,obj))
|
||||||
(newline)
|
(newline)
|
||||||
|
@ -14,6 +19,7 @@
|
||||||
#t)
|
#t)
|
||||||
|
|
||||||
(define (wait)
|
(define (wait)
|
||||||
|
(start-c-thread)
|
||||||
(thread-sleep! 1)
|
(thread-sleep! 1)
|
||||||
(if *done*
|
(if *done*
|
||||||
#t
|
#t
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "cyclone/types.h"
|
#include "cyclone/types.h"
|
||||||
#include "cyclone/runtime.h"
|
#include "cyclone/runtime.h"
|
||||||
|
#include "sys.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern object __glo_signal_91done;
|
extern object __glo_signal_91done;
|
||||||
|
@ -12,10 +13,8 @@ void after_call_scm(gc_thread_data *thd, int argc, object k, object result)
|
||||||
|
|
||||||
void call_scm(gc_thread_data *thd, object obj)
|
void call_scm(gc_thread_data *thd, object obj)
|
||||||
{
|
{
|
||||||
// TODO
|
//static void __lambda_1(void *data, int argc, closure _,object k_7312, object obj_731_735) {
|
||||||
//static void __lambda_1(void *data, int argc, closure _,object k_7312, object obj_731_735) {
|
mclosure0(after, (function_type)after_call_scm);
|
||||||
|
|
||||||
mclosure1(after, (function_type)after_call_scm,
|
|
||||||
((closure)__glo_signal_91done)->fn(thd, 2, __glo_signal_91done, &after, obj);
|
((closure)__glo_signal_91done)->fn(thd, 2, __glo_signal_91done, &after, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,14 +31,21 @@ void *c_thread(void *arg)
|
||||||
{
|
{
|
||||||
int first = 1;
|
int first = 1;
|
||||||
long stack_size = 100000;
|
long stack_size = 100000;
|
||||||
char *stack_base = &stack_start;
|
char *stack_base = (char *)&stack_size;
|
||||||
|
char *stack_traces[MAX_STACK_TRACES];
|
||||||
gc_thread_data thd; // TODO: initialize
|
gc_thread_data thd; // TODO: initialize
|
||||||
|
jmp_buf jmp;
|
||||||
|
thd.jmp_start = &jmp;
|
||||||
thd.stack_start = stack_base;
|
thd.stack_start = stack_base;
|
||||||
#if STACK_GROWTH_IS_DOWNWARD
|
#if STACK_GROWTH_IS_DOWNWARD
|
||||||
thd.stack_limit = stack_base - stack_size;
|
thd.stack_limit = stack_base - stack_size;
|
||||||
#else
|
#else
|
||||||
thd.stack_limit = stack_base + stack_size;
|
thd.stack_limit = stack_base + stack_size;
|
||||||
#endif
|
#endif
|
||||||
|
thd.stack_traces = stack_traces; //calloc(MAX_STACK_TRACES, sizeof(char *));
|
||||||
|
thd.stack_trace_idx = 0;
|
||||||
|
thd.stack_prev_frame = NULL;
|
||||||
|
|
||||||
// TODO: many more initializations required, need to figure out
|
// TODO: many more initializations required, need to figure out
|
||||||
// minimum set to optimize for micro / short / long calls into Scheme.
|
// minimum set to optimize for micro / short / long calls into Scheme.
|
||||||
// We will make different assumptions in each case
|
// We will make different assumptions in each case
|
||||||
|
@ -54,7 +60,7 @@ void *c_thread(void *arg)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_c_thread()
|
void start_c_thread(void)
|
||||||
{
|
{
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
|
|
1
examples/callbacks/sys.h
Normal file
1
examples/callbacks/sys.h
Normal file
|
@ -0,0 +1 @@
|
||||||
|
void start_c_thread(void);
|
Loading…
Add table
Reference in a new issue