Cyclone Scheme
0.28.0
|
#include <math.h>
#include <complex.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include <stdint.h>
#include <dlfcn.h>
#include "cyclone/bignum.h"
Go to the source code of this file.
Data Structures | |
struct | atomic_type |
The atomic thread synchronization type. More... | |
struct | bignum_type |
Exact integer of unlimited precision. More... | |
struct | boolean_type |
The boolean type: True or False. More... | |
struct | bytevector_type |
Bytevector type. More... | |
struct | c_opaque_type |
C Opaque type - a wrapper around a pointer of any type. More... | |
struct | closure0_type |
A closed-over function with no variables. More... | |
struct | closure1_type |
A closed-over function with one variable. More... | |
struct | closureN_type |
A closed-over function with zero or more closed-over variables. More... | |
union | common_type |
A union of all the constant-size objects. More... | |
struct | complex_num_type |
Complex number. More... | |
struct | cond_var_type |
The condition variable thread synchronization type. More... | |
struct | cvar_type |
C-variable integration type - wrapper around a Cyclone object pointer. More... | |
struct | double_type |
Double-precision floating point type, also known as a flonum. More... | |
struct | gc_free_list_t |
struct | gc_header_type_t |
struct | gc_heap_root_t |
struct | gc_heap_t |
struct | gc_thread_data_t |
struct | integer_type |
Deprecated - boxed integers. More... | |
struct | list_2_type |
struct | list_3_type |
struct | list_4_type |
struct | macro_type |
Closure for a macro. More... | |
struct | mark_buffer_t |
struct | mutex_type |
The mutex thread synchronization type. More... | |
struct | pair_type |
The pair (cons) type. More... | |
struct | port_type |
The port object type. More... | |
struct | primitive_type |
A function built into the runtime. More... | |
struct | string_type |
The string type. More... | |
struct | symbol_type |
Symbols are similar to strings, but only one instance of each unique symbol is created, so comparisons are O(1). More... | |
struct | vector_2_type |
struct | vector_3_type |
struct | vector_4_type |
struct | vector_5_type |
struct | vector_type |
Vector type. More... | |
struct | vpbuffer_t |
Macros | |
#define | alloc_bignum(data, p) bignum_type *p = gc_alloc_bignum((gc_thread_data *)data); |
#define | alloc_bytevector(_data, _bv, _len) |
#define | alloc_string(_data, _s, _len, _num_cp) |
#define | alloca_cell(n, a) alloca_pair(n,a,NULL) |
#define | alloca_complex_num(n, r, i) |
#define | alloca_double(n, v) |
#define | alloca_empty_bytevector(v) |
#define | alloca_empty_vector(v) |
#define | alloca_pair(n, a, d) |
#define | assign_complex_num(pobj, v) |
#define | assign_double(pobj, v) |
#define | BIGNUM_CALL(x) |
#define | bignum_value(x) (((bignum_type *) x)->bn) |
#define | boolean_desc(x) (((boolean_type *) x)->desc) |
#define | caaaar(x) (car(car(car(car(x))))) |
#define | caaadr(x) (car(car(car(cdr(x))))) |
#define | caaar(x) (car(car(car(x)))) |
#define | caadar(x) (car(car(cdr(car(x))))) |
#define | caaddr(x) (car(car(cdr(cdr(x))))) |
#define | caadr(x) (car(car(cdr(x)))) |
#define | caar(x) (car(car(x))) |
#define | cadaar(x) (car(cdr(car(car(x))))) |
#define | cadadr(x) (car(cdr(car(cdr(x))))) |
#define | cadar(x) (car(cdr(car(x)))) |
#define | caddar(x) (car(cdr(cdr(car(x))))) |
#define | cadddr(x) (car(cdr(cdr(cdr(x))))) |
#define | caddr(x) (car(cdr(cdr(x)))) |
#define | cadr(x) (car(cdr(x))) |
#define | car(x) (((pair_type *) x)->pair_car) |
#define | cdaaar(x) (cdr(car(car(car(x))))) |
#define | cdaadr(x) (cdr(car(car(cdr(x))))) |
#define | cdaar(x) (cdr(car(car(x)))) |
#define | cdadar(x) (cdr(car(cdr(car(x))))) |
#define | cdaddr(x) (cdr(car(cdr(cdr(x))))) |
#define | cdadr(x) (cdr(car(cdr(x)))) |
#define | cdar(x) (cdr(car(x))) |
#define | cddaar(x) (cdr(cdr(car(car(x))))) |
#define | cddadr(x) (cdr(cdr(car(cdr(x))))) |
#define | cddar(x) (cdr(cdr(car(x)))) |
#define | cdddar(x) (cdr(cdr(cdr(car(x))))) |
#define | cddddr(x) (cdr(cdr(cdr(cdr(x))))) |
#define | cdddr(x) (cdr(cdr(cdr(x)))) |
#define | cddr(x) (cdr(cdr(x))) |
#define | cdr(x) (((pair_type *) x)->pair_cdr) |
#define | complex_num_value(x) (((complex_num_type *) x)->value) |
#define | CYC_BINARY_PORT_FLAG 0x10 |
#define | Cyc_caaaar(d, x) (Cyc_car(d, Cyc_car(d, Cyc_car(d, Cyc_car(d, x))))) |
#define | Cyc_caaadr(d, x) (Cyc_car(d, Cyc_car(d, Cyc_car(d, Cyc_cdr(d, x))))) |
#define | Cyc_caaar(d, x) (Cyc_car(d, Cyc_car(d, Cyc_car(d, x)))) |
#define | Cyc_caadar(d, x) (Cyc_car(d, Cyc_car(d, Cyc_cdr(d, Cyc_car(d, x))))) |
#define | Cyc_caaddr(d, x) (Cyc_car(d, Cyc_car(d, Cyc_cdr(d, Cyc_cdr(d, x))))) |
#define | Cyc_caadr(d, x) (Cyc_car(d, Cyc_car(d, Cyc_cdr(d, x)))) |
#define | Cyc_caar(d, x) (Cyc_car(d, Cyc_car(d, x))) |
#define | Cyc_cadaar(d, x) (Cyc_car(d, Cyc_cdr(d, Cyc_car(d, Cyc_car(d, x))))) |
#define | Cyc_cadadr(d, x) (Cyc_car(d, Cyc_cdr(d, Cyc_car(d, Cyc_cdr(d, x))))) |
#define | Cyc_cadar(d, x) (Cyc_car(d, Cyc_cdr(d, Cyc_car(d, x)))) |
#define | Cyc_caddar(d, x) (Cyc_car(d, Cyc_cdr(d, Cyc_cdr(d, Cyc_car(d, x))))) |
#define | Cyc_cadddr(d, x) (Cyc_car(d, Cyc_cdr(d, Cyc_cdr(d, Cyc_cdr(d, x))))) |
#define | Cyc_caddr(d, x) (Cyc_car(d, Cyc_cdr(d, Cyc_cdr(d, x)))) |
#define | Cyc_cadr(d, x) (Cyc_car(d, Cyc_cdr(d, x))) |
#define | Cyc_cdaaar(d, x) (Cyc_cdr(d, Cyc_car(d, Cyc_car(d, Cyc_car(d, x))))) |
#define | Cyc_cdaadr(d, x) (Cyc_cdr(d, Cyc_car(d, Cyc_car(d, Cyc_cdr(d, x))))) |
#define | Cyc_cdaar(d, x) (Cyc_cdr(d, Cyc_car(d, Cyc_car(d, x)))) |
#define | Cyc_cdadar(d, x) (Cyc_cdr(d, Cyc_car(d, Cyc_cdr(d, Cyc_car(d, x))))) |
#define | Cyc_cdaddr(d, x) (Cyc_cdr(d, Cyc_car(d, Cyc_cdr(d, Cyc_cdr(d, x))))) |
#define | Cyc_cdadr(d, x) (Cyc_cdr(d, Cyc_car(d, Cyc_cdr(d, x)))) |
#define | Cyc_cdar(d, x) (Cyc_cdr(d, Cyc_car(d, x))) |
#define | Cyc_cddaar(d, x) (Cyc_cdr(d, Cyc_cdr(d, Cyc_car(d, Cyc_car(d, x))))) |
#define | Cyc_cddadr(d, x) (Cyc_cdr(d, Cyc_cdr(d, Cyc_car(d, Cyc_cdr(d, x))))) |
#define | Cyc_cddar(d, x) (Cyc_cdr(d, Cyc_cdr(d, Cyc_car(d, x)))) |
#define | Cyc_cdddar(d, x) (Cyc_cdr(d, Cyc_cdr(d, Cyc_cdr(d, Cyc_car(d, x))))) |
#define | Cyc_cddddr(d, x) (Cyc_cdr(d, Cyc_cdr(d, Cyc_cdr(d, Cyc_cdr(d, x))))) |
#define | Cyc_cdddr(d, x) (Cyc_cdr(d, Cyc_cdr(d, Cyc_cdr(d, x)))) |
#define | Cyc_cddr(d, x) (Cyc_cdr(d, Cyc_cdr(d, x))) |
#define | CYC_FIXNUM_MAX 1073741823 |
#define | CYC_FIXNUM_MIN -1073741824 |
#define | CYC_IO_BUF_LEN 1024 |
#define | DEBUG_SHOW_DIAG 0 |
#define | defprimitive(name, desc, fnc) |
#define | defsymbol(name) static object quote_##name = NULL; |
#define | double_value(x) (((double_type *) x)->value) |
#define | forward(obj) (((pair_type *) obj)->pair_car) |
#define | GC_COLLECT_UNDER_UNSWEPT_HEAP_COUNT 3 |
#define | GC_COLLECTION_THRESHOLD 0.0125 |
#define | gc_color_blue 2 |
#define | gc_color_red 0 |
#define | GC_DEBUG_SHOW_SWEEP_DIAG 0 |
#define | GC_DEBUG_TRACE 0 |
#define | GC_DEBUG_VERBOSE 0 |
#define | GC_FREE_THRESHOLD 0.40 |
#define | gc_is_stack_obj(low_limit, thd, obj) |
Determine if object lives on the thread's stack. More... | |
#define | GC_SAFETY_CHECKS 0 |
#define | grayed(x) (((list) x)->hdr.grayed) |
#define | GROW_HEAP_BY_SIZE (2 * 1024 * 1024) |
#define | HEAP_SIZE (8 * 1024 * 1024) |
#define | immutable(x) (((list) x)->hdr.immutable) |
#define | INITIAL_HEAP_SIZE (3 * 1024 * 1024) |
#define | integer_value(x) (((integer_type *) x)->value) |
#define | is_object_type(x) ((x != NULL) && !is_value_type(x)) |
#define | is_value_type(x) ((unsigned long)(x) & (unsigned long)3) |
#define | LAST_FIXED_SIZE_HEAP_TYPE HEAP_96 |
#define | maclosure0(c, f, na) |
#define | make_boolean(x) (x ? boolean_t : boolean_f) |
#define | make_c_opaque(var, p) |
#define | make_cell(n, a) make_pair(n,a,NULL) |
#define | make_complex_num(n, r, i) |
#define | make_cvar(n, v) |
#define | make_double(n, v) |
#define | make_empty_bytevector(v) |
#define | make_empty_vector(v) |
#define | make_input_port(p, f, rl) |
#define | make_pair(n, a, d) |
#define | make_port(p, f, m) |
#define | make_string(cs, s) |
#define | make_string_noalloc(cs, s, length) |
#define | make_string_with_len(cs, s, length) |
#define | make_utf8_string(data, cs, s) |
#define | make_utf8_string_noalloc(cs, s, length) |
#define | make_utf8_string_with_len(cs, s, length, num_code_points) |
#define | mark(x) (((list) x)->hdr.mark) |
#define | MAX_STACK_OBJ (STACK_SIZE * 2) |
#define | MAX_STACK_TRACES 10 |
#define | mclosure0(c, f) static closure0_type c = { .hdr.mark = gc_color_red, .hdr.grayed = 0, .tag = closure0_tag, .fn = f, .num_args = -1 }; /* TODO: need a new macro that initializes num_args */ |
#define | mclosure1(c, f, a) |
#define | mmacro(c, f) |
#define | NANOSECONDS_PER_MILLISECOND 1000000 |
#define | NUM_GC_ARGS 128 |
#define | NUM_HEAP_TYPES (HEAP_HUGE + 1) |
#define | obj_char2obj(c) ((void *)((((uintptr_t)c)<<2) | 2)) |
#define | obj_int2obj(c) ((void *)((((long)c)*2) | 1)) |
#define | obj_is_char(x) (((unsigned long)(x) & (unsigned long)3) == 2) |
#define | obj_is_int(x) ((unsigned long)(x) & (unsigned long)1) |
#define | obj_is_not_closure(obj) ((obj == NULL) || is_value_type(obj) || (type_of(obj) > macro_tag)) |
#define | obj_obj2char(x) (char_type)((uintptr_t)(x)>>2) |
#define | obj_obj2int(x) ((long)((uintptr_t)x)>>1) |
#define | opaque_collect_ptr(x) (((c_opaque)x)->collect_ptr) |
#define | opaque_ptr(x) (((c_opaque)x)->ptr) |
#define | prim(x) (x && ((primitive)x)->tag == primitive_tag) |
#define | prim_name(x) (((primitive_type *) x)->desc) |
#define | return_copy(ptr, o) |
#define | return_thread_runnable(d, r) gc_mutator_thread_runnable(((gc_thread_data *)d), (r), NULL) |
Return from a blocked thread. More... | |
#define | return_thread_runnable_with_obj(d, r, maybe_copied) gc_mutator_thread_runnable(((gc_thread_data *)d), (r), maybe_copied) |
Return from a blocked thread with an object that may have been copied. If the object was copied we need to check and may need to copy it again. More... | |
#define | set_cell_as_expr(n, a) set_pair_as_expr(n,a,NULL) |
#define | set_pair(n, a, d) |
#define | set_pair_as_expr(n, a, d) |
#define | set_thread_blocked(d, c) gc_mutator_thread_blocked(((gc_thread_data *)d), (c)) |
#define | STACK_GROWTH_IS_DOWNWARD 1 |
#define | stack_overflow(x, y) ((x) < (y)) |
#define | STACK_SIZE 500000 |
#define | string_len(x) (((string_type *) x)->len) |
#define | string_num_cp(x) (((string_type *) x)->num_cp) |
#define | string_str(x) (((string_type *) x)->str) |
#define | symbol_desc(x) (((symbol_type *) x)->desc) |
#define | type_of(obj) (((pair_type *) obj)->tag) |
Typedefs | |
typedef atomic_type * | atomic |
typedef boolean_type * | boolean |
typedef bytevector_type * | bytevector |
typedef c_opaque_type * | c_opaque |
typedef uint32_t | char_type |
typedef closure0_type * | closure |
typedef closure0_type * | closure0 |
typedef closure1_type * | closure1 |
typedef closureN_type * | closureN |
typedef cond_var_type * | cond_var |
typedef cvar_type * | cvar |
typedef void(* | function_type) (void *data, object clo, int argc, object *args) |
typedef struct gc_free_list_t | gc_free_list |
typedef struct gc_header_type_t | gc_header_type |
typedef struct gc_heap_t | gc_heap |
Contains data for a single page of the heap. More... | |
typedef struct gc_heap_root_t | gc_heap_root |
typedef struct gc_thread_data_t | gc_thread_data |
Each thread is given an instance of this struct to maintain its state. More... | |
typedef object(* | inline_function_type) () |
typedef pair_type * | list |
typedef closure0_type * | macro |
typedef struct mark_buffer_t | mark_buffer |
typedef mutex_type * | mutex |
typedef void * | object |
typedef pair_type * | pair |
typedef primitive_type * | primitive |
typedef void(* | primitive_function_type) (void *data, object cont, object args) |
typedef symbol_type * | symbol |
typedef unsigned char | tag_type |
typedef vector_type * | vector |
typedef struct vpbuffer_t | vpbuffer |
Enumerations | |
enum | bn_cmp_type { CYC_BN_LTE = -2, CYC_BN_LT = MP_LT, CYC_BN_EQ = MP_EQ, CYC_BN_GT = MP_GT, CYC_BN_GTE = 2 } |
enum | cyc_thread_state_type { CYC_THREAD_STATE_NEW, CYC_THREAD_STATE_RUNNABLE, CYC_THREAD_STATE_BLOCKED, CYC_THREAD_STATE_BLOCKED_COOPERATING, CYC_THREAD_STATE_TERMINATED } |
enum | gc_heap_type { HEAP_SM = 0, HEAP_64, HEAP_96, HEAP_REST, HEAP_HUGE } |
enum | gc_stage_type { STAGE_CLEAR_OR_MARKING, STAGE_TRACING, STAGE_SWEEPING, STAGE_RESTING } |
enum | gc_status_type { STATUS_ASYNC, STATUS_SYNC1, STATUS_SYNC2 } |
enum | object_tag { closure0_tag = 0, closure1_tag = 1, closureN_tag = 2, macro_tag = 3, boolean_tag = 4, bytevector_tag = 5, c_opaque_tag = 6, cond_var_tag = 7, cvar_tag = 8, double_tag = 9, eof_tag = 10, forward_tag = 11, integer_tag = 12, bignum_tag = 13, mutex_tag = 14, pair_tag = 15, port_tag = 16, primitive_tag = 17, string_tag = 18, symbol_tag = 19, vector_tag = 20, complex_num_tag = 21, atomic_tag = 22, void_tag = 23, record_tag = 24 } |
Functions | |
void | add_mutation (void *data, object var, int index, object value) |
void | clear_mutations (void *data) |
int | Cyc_bignum_cmp (bn_cmp_type type, object x, int tx, object y, int ty) |
void | Cyc_import_shared_object (void *data, object cont, object filename, object entry_pt_fnc) |
void | Cyc_int2bignum (int n, mp_int *bn) |
void | Cyc_make_shared_object (void *data, object k, object obj) |
object | Cyc_scm_call (gc_thread_data *parent_thd, object fnc, int argc, object *args) |
object | Cyc_scm_call_no_gc (gc_thread_data *parent_thd, object fnc, object arg) |
void | gc_add_mutator (gc_thread_data *thd) |
Add data for a new mutator that is starting to run. More... | |
void | gc_add_new_unrunning_mutator (gc_thread_data *thd) |
Add data for a new mutator that is not yet scheduled to run. This is done so there is a record in the system even if the thread is not running, to prevent race conditions for any functions (EG: thread-join!) that need to access the thread. More... | |
void * | gc_alloc (gc_heap_root *h, size_t size, char *obj, gc_thread_data *thd, int *heap_grown) |
Allocate memory on the heap for an object. More... | |
void * | gc_alloc_bignum (gc_thread_data *data) |
A convenience function for allocating bignums. More... | |
void * | gc_alloc_from_bignum (gc_thread_data *data, bignum_type *src) |
A helper function to create a heap-allocated copy of a bignum. More... | |
void * | gc_alloc_rest (gc_heap_root *hrt, size_t size, char *obj, gc_thread_data *thd, int *heap_grown) |
size_t | gc_allocated_bytes (object obj, gc_free_list *q, gc_free_list *r) |
Get the number of bytes that will be allocated for obj . More... | |
void | gc_collector_trace () |
The collector's tracing algorithm. More... | |
char * | gc_copy_obj (object hp, char *obj, gc_thread_data *thd) |
Copy given object into given heap object. More... | |
void | gc_empty_collector_stack () |
Empty the collector's mark stack. More... | |
gc_heap * | gc_grow_heap (gc_heap *h, size_t size, gc_thread_data *thd) |
Grow a heap by allocating a new page. More... | |
void | gc_handshake (gc_status_type s) |
Called by the collector thread to perform a handshake with all of the mutators. More... | |
gc_heap * | gc_heap_create (int heap_type, size_t size, gc_thread_data *thd) |
Create a new heap page. The caller must hold the necessary locks. More... | |
void | gc_heap_create_rest (gc_heap *h, gc_thread_data *thd) |
gc_heap * | gc_heap_free (gc_heap *page, gc_heap *prev_page) |
Free a page of the heap. More... | |
gc_heap * | gc_heap_last (gc_heap *h) |
Get the heap's last page. More... | |
void | gc_heap_merge (gc_heap *hdest, gc_heap *hsrc) |
Merge one heap into another. More... | |
void | gc_init_fixed_size_free_list (gc_heap *h) |
Initialize free lists within a single heap page. Assumes that there is no data currently on the heap page! More... | |
void | gc_initialize (void) |
Perform one-time initialization before mutators can be executed. More... | |
int | gc_is_mutator_active (gc_thread_data *thd) |
Determine if the given mutator is in the list of active threads. More... | |
int | gc_is_mutator_new (gc_thread_data *thd) |
Determine if the given mutator is in the list of new threads. More... | |
void | gc_mark_globals (object globals, object global_table) |
Mark globals as part of the tracing collector. More... | |
void | gc_mark_gray (gc_thread_data *thd, object obj) |
Mark the given object gray if it is on the heap. More... | |
void | gc_mark_gray2 (gc_thread_data *thd, object obj) |
Add a pending write to the mark buffer. More... | |
void | gc_merge_all_heaps (gc_thread_data *dest, gc_thread_data *src) |
Merge all thread heaps into another. More... | |
int | gc_minor (void *data, object low_limit, object high_limit, closure cont, object *args, int num_args) |
void | gc_mut_cooperate (gc_thread_data *thd, int buf_len) |
Called by a mutator to cooperate with the collector thread. More... | |
void | gc_mut_update (gc_thread_data *thd, object old_obj, object value) |
Write barrier for updates to heap-allocated objects. More... | |
void | gc_mutator_thread_blocked (gc_thread_data *thd, object cont) |
Called explicitly from a mutator thread to let the collector know it (may) block for an unknown period of time. More... | |
void | gc_mutator_thread_runnable (gc_thread_data *thd, object result, object maybe_copied) |
Called explicitly from a mutator thread to let the collector know that it has finished blocking. More... | |
void | gc_post_handshake (gc_status_type s) |
Change GC status to the given type. More... | |
void | gc_print_stats (gc_heap *h) |
Print heap usage information. Before calling this function the current thread must have the heap lock. More... | |
void | gc_remove_mutator (gc_thread_data *thd) |
Remove selected mutator from the mutator list. This is done for terminated threads. Note data is queued to be freed, to prevent accidentally freeing it while the collector thread is potentially accessing it. More... | |
void | gc_request_mark_globals (void) |
A helper function for calling gc_mark_globals . More... | |
void | gc_sleep_ms (int ms) |
A high-resolution sleep function. More... | |
void | gc_start_collector () |
Spawn the collector thread. More... | |
gc_heap * | gc_sweep (gc_heap *h, gc_thread_data *thd) |
Sweep portion of the GC algorithm. More... | |
void | gc_thr_grow_move_buffer (gc_thread_data *d) |
Increase the size of the mutator's move buffer. More... | |
void | gc_thread_data_free (gc_thread_data *thd) |
Free all data for the given mutator. More... | |
void | gc_thread_data_init (gc_thread_data *thd, int mut_num, char *stack_base, long stack_size) |
Initialize runtime data structures for a thread. More... | |
void * | gc_try_alloc (gc_heap *h, size_t size, char *obj, gc_thread_data *thd) |
Attempt to allocate a new heap slot for the given object. More... | |
void * | gc_try_alloc_rest (gc_heap *h, size_t size, char *obj, gc_thread_data *thd) |
void * | gc_try_alloc_slow (gc_heap *h_passed, gc_heap *h, size_t size, char *obj, gc_thread_data *thd) |
void | gc_wait_handshake () |
Wait for all mutators to handshake. More... | |
object | transport_stack_value (gc_thread_data *data, object var, object value, int *run_gc) |
void | vp_add (vpbuffer *v, void *obj) |
vpbuffer * | vp_create (void) |
void ** | vpbuffer_add (void **buf, int *len, int i, void *obj) |
void | vpbuffer_free (void **buf) |
void ** | vpbuffer_realloc (void **buf, int *len) |