Fixed compiler warnings

This commit is contained in:
Justin Ethier 2016-07-19 23:02:21 -04:00
parent f7a6c872cc
commit d6f5a81f2d
4 changed files with 88 additions and 63 deletions

27
gc.c
View file

@ -346,7 +346,6 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd)
return (char *)hp; return (char *)hp;
} }
case bytevector_tag:{ case bytevector_tag:{
int i;
bytevector_type *hp = dest; bytevector_type *hp = dest;
mark(hp) = thd->gc_alloc_color; mark(hp) = thd->gc_alloc_color;
type_of(hp) = bytevector_tag; type_of(hp) = bytevector_tag;
@ -433,7 +432,7 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd)
int gc_grow_heap(gc_heap * h, int heap_type, size_t size, size_t chunk_size) int gc_grow_heap(gc_heap * h, int heap_type, size_t size, size_t chunk_size)
{ {
size_t cur_size, new_size; size_t /*cur_size,*/ new_size;
gc_heap *h_last = h, *h_new; gc_heap *h_last = h, *h_new;
pthread_mutex_lock(&heap_lock); pthread_mutex_lock(&heap_lock);
// Compute size of new heap page // Compute size of new heap page
@ -524,7 +523,6 @@ void *gc_alloc(gc_heap_root * hrt, size_t size, char *obj, gc_thread_data * thd,
void *result = NULL; void *result = NULL;
gc_heap *h = NULL; gc_heap *h = NULL;
int heap_type; int heap_type;
size_t max_freed = 0, sum_freed = 0, total_size;
// TODO: check return value, if null (could not alloc) then // TODO: check return value, if null (could not alloc) then
// run a collection and check how much free space there is. if less // run a collection and check how much free space there is. if less
// the allowed ratio, try growing heap. // the allowed ratio, try growing heap.
@ -661,7 +659,10 @@ size_t gc_sweep(gc_heap * h, int heap_type, size_t * sum_freed_ptr)
size_t freed, max_freed = 0, heap_freed = 0, sum_freed = 0, size; size_t freed, max_freed = 0, heap_freed = 0, sum_freed = 0, size;
object p, end; object p, end;
gc_free_list *q, *r, *s; gc_free_list *q, *r, *s;
gc_heap *orig_heap_ptr = h, *prev_h = NULL; #if GC_DEBUG_SHOW_SWEEP_DIAG
gc_heap *orig_heap_ptr = h;
#endif
gc_heap *prev_h = NULL;
// //
// Lock the heap to prevent issues with allocations during sweep // Lock the heap to prevent issues with allocations during sweep
@ -910,7 +911,7 @@ static void mark_stack_or_heap_obj(gc_thread_data * thd, object obj)
*/ */
void gc_mut_update(gc_thread_data * thd, object old_obj, object value) void gc_mut_update(gc_thread_data * thd, object old_obj, object value)
{ {
int status = ck_pr_load_int(&gc_status_col), int //status = ck_pr_load_int(&gc_status_col),
stage = ck_pr_load_int(&gc_stage); stage = ck_pr_load_int(&gc_stage);
if (ck_pr_load_int(&(thd->gc_status)) != STATUS_ASYNC) { if (ck_pr_load_int(&(thd->gc_status)) != STATUS_ASYNC) {
pthread_mutex_lock(&(thd->lock)); pthread_mutex_lock(&(thd->lock));
@ -1288,8 +1289,10 @@ void debug_dump_globals();
void gc_collector() void gc_collector()
{ {
int old_clear, old_mark, heap_type; int old_clear, old_mark, heap_type;
size_t freed = 0, max_freed = 0, total_size, total_free; size_t freed = 0;
#if GC_DEBUG_TRACE #if GC_DEBUG_TRACE
size_t total_size;
size_t total_free;
time_t gc_collector_start = time(NULL); time_t gc_collector_start = time(NULL);
#endif #endif
//clear : //clear :
@ -1333,10 +1336,10 @@ void gc_collector()
ck_pr_cas_int(&gc_stage, STAGE_TRACING, STAGE_SWEEPING); ck_pr_cas_int(&gc_stage, STAGE_TRACING, STAGE_SWEEPING);
// //
//sweep : //sweep :
max_freed = gc_sweep(gc_get_heap()->heap, HEAP_REST, &freed); gc_sweep(gc_get_heap()->heap, HEAP_REST, &freed);
max_freed = gc_sweep(gc_get_heap()->small_obj_heap, HEAP_SM, &freed); gc_sweep(gc_get_heap()->small_obj_heap, HEAP_SM, &freed);
max_freed = gc_sweep(gc_get_heap()->medium_obj_heap, HEAP_MED, &freed); gc_sweep(gc_get_heap()->medium_obj_heap, HEAP_MED, &freed);
max_freed = gc_sweep(gc_get_heap()->huge_obj_heap, HEAP_HUGE, &freed); gc_sweep(gc_get_heap()->huge_obj_heap, HEAP_HUGE, &freed);
// TODO: this loop only includes smallest 2 heaps, is that sufficient?? // TODO: this loop only includes smallest 2 heaps, is that sufficient??
for (heap_type = 0; heap_type < 2; heap_type++) { for (heap_type = 0; heap_type < 2; heap_type++) {
@ -1361,8 +1364,8 @@ void gc_collector()
total_free = cached_heap_free_sizes[HEAP_SM] + total_free = cached_heap_free_sizes[HEAP_SM] +
cached_heap_free_sizes[HEAP_MED] + cached_heap_free_sizes[HEAP_REST]; cached_heap_free_sizes[HEAP_MED] + cached_heap_free_sizes[HEAP_REST];
fprintf(stderr, fprintf(stderr,
"sweep done, total_size = %zu, total_free = %zu, freed = %zu, max_freed = %zu, elapsed = %zu\n", "sweep done, total_size = %zu, total_free = %zu, freed = %zu, elapsed = %zu\n",
total_size, total_free, freed, max_freed, total_size, total_free, freed,
time(NULL) - gc_collector_start); time(NULL) - gc_collector_start);
#endif #endif
#if GC_DEBUG_TRACE #if GC_DEBUG_TRACE

View file

@ -130,19 +130,19 @@ void Cyc_apply(void *data, int argc, closure cont, object prim, ...);
void dispatch_apply_va(void *data, int argc, object clo, object cont, object func, ...); void dispatch_apply_va(void *data, int argc, object clo, object cont, object func, ...);
object apply_va(void *data, object cont, int argc, object func, ...); object apply_va(void *data, object cont, int argc, object func, ...);
object Cyc_string_cmp(void *data, object str1, object str2); object Cyc_string_cmp(void *data, object str1, object str2);
void dispatch_string_91append(void *data, int argc, object clo, object cont, object dispatch_string_91append(void *data, int argc, object clo, object cont,
object str1, ...); object str1, ...);
list malloc_make_pair(object, object); list malloc_make_pair(object, object);
cvar_type *mcvar(object * var); cvar_type *mcvar(object * var);
object Cyc_display(object, FILE * port); object Cyc_display(object, FILE * port);
object dispatch_display_va(void *data, int argc, object clo, object cont, void dispatch_display_va(void *data, int argc, object clo, object cont,
object x, ...); object x, ...);
object Cyc_display_va(int argc, object x, ...); object Cyc_display_va(int argc, object x, ...);
object Cyc_display_va_list(int argc, object x, va_list ap); object Cyc_display_va_list(int argc, object x, va_list ap);
object Cyc_write_char(void *data, object c, object port); object Cyc_write_char(void *data, object c, object port);
object Cyc_write(object, FILE * port); object Cyc_write(object, FILE * port);
object dispatch_write_va(void *data, int argc, object clo, object cont, void dispatch_write_va(void *data, int argc, object clo, object cont,
object x, ...); object x, ...);
object Cyc_write_va(int argc, object x, ...); object Cyc_write_va(int argc, object x, ...);
object Cyc_write_va_list(int argc, object x, va_list ap); object Cyc_write_va_list(int argc, object x, va_list ap);

View file

@ -640,10 +640,12 @@ void gc_mutator_thread_runnable(gc_thread_data * thd, object result);
gc_mutator_thread_blocked(((gc_thread_data *)d), (c)) gc_mutator_thread_blocked(((gc_thread_data *)d), (c))
#define return_thread_runnable(d, r) \ #define return_thread_runnable(d, r) \
gc_mutator_thread_runnable(((gc_thread_data *)d), (r)) gc_mutator_thread_runnable(((gc_thread_data *)d), (r))
/*
//#define do_with_blocked_thread(data, cont, result, body) \ //#define do_with_blocked_thread(data, cont, result, body) \
// set_thread_blocked((data), (cont)); \ // set_thread_blocked((data), (cont)); \
// body \ // body \
// return_thread_runnable((data), (result)); // return_thread_runnable((data), (result));
*/
gc_heap_root *gc_get_heap(); gc_heap_root *gc_get_heap();
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);

110
runtime.c
View file

@ -15,6 +15,7 @@
#include "cyclone/ck_ht_hash.h" #include "cyclone/ck_ht_hash.h"
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <ctype.h>
//#include <signal.h> // TODO: only used for debugging! //#include <signal.h> // TODO: only used for debugging!
//int JAE_DEBUG = 0; //int JAE_DEBUG = 0;
@ -97,6 +98,17 @@ if (type_is_pair_prim(clo)) { \
return;\ return;\
} \ } \
} }
#define _return_closcall1(td, clo, a1) { \
char top; \
if (stack_overflow(&top, (((gc_thread_data *)data)->stack_limit))) { \
object buf[1]; buf[0] = a1;\
GC(td, clo, buf, 1); \
return NULL; \
} else {\
closcall1(td, (closure) (clo), a1); \
return NULL;\
} \
}
#define closcall2(td, clo, a1, a2) \ #define closcall2(td, clo, a1, a2) \
if (type_is_pair_prim(clo)) { \ if (type_is_pair_prim(clo)) { \
Cyc_apply(td, 1, (closure)(a1), clo,a2); \ Cyc_apply(td, 1, (closure)(a1), clo,a2); \
@ -114,6 +126,17 @@ if (type_is_pair_prim(clo)) { \
return;\ return;\
} \ } \
} }
#define _return_closcall2(td, clo, a1, a2) { \
char top; \
if (stack_overflow(&top, (((gc_thread_data *)data)->stack_limit))) { \
object buf[2]; buf[0] = a1;buf[1] = a2;\
GC(td, clo, buf, 2); \
return NULL; \
} else {\
closcall2(td, (closure) (clo), a1, a2); \
return NULL;\
} \
}
/*END closcall section */ /*END closcall section */
/* Global variables. */ /* Global variables. */
@ -578,7 +601,7 @@ int double2buffer(char *buf, int buf_size, double num)
// to the value returned by (current-output-port). It is an // to the value returned by (current-output-port). It is an
// error to attempt an output operation on a closed port // error to attempt an output operation on a closed port
// //
object dispatch_display_va(void *data, int argc, object clo, object cont, void dispatch_display_va(void *data, int argc, object clo, object cont,
object x, ...) object x, ...)
{ {
object result; object result;
@ -734,7 +757,7 @@ object Cyc_display(object x, FILE * port)
return quote_void; return quote_void;
} }
object dispatch_write_va(void *data, int argc, object clo, object cont, void dispatch_write_va(void *data, int argc, object clo, object cont,
object x, ...) object x, ...)
{ {
object result; object result;
@ -1023,7 +1046,7 @@ object FUNC(void *data, object cont, int argc, object n, ...) { \
va_start(ap, n); \ va_start(ap, n); \
result = Cyc_num_cmp_va_list(data, argc, FUNC_OP, n, ap); \ result = Cyc_num_cmp_va_list(data, argc, FUNC_OP, n, ap); \
va_end(ap); \ va_end(ap); \
return_closcall1(data, cont, result); \ _return_closcall1(data, cont, result); \
} \ } \
void FUNC_APPLY(void *data, int argc, object clo, object cont, object n, ...) { \ void FUNC_APPLY(void *data, int argc, object clo, object cont, object n, ...) { \
object result; \ object result; \
@ -1274,6 +1297,7 @@ object Cyc_vector_length(void *data, object v)
} }
Cyc_rt_raise_msg(data, Cyc_rt_raise_msg(data,
"vector-length - invalid parameter, expected vector\n"); "vector-length - invalid parameter, expected vector\n");
return NULL;
} }
object Cyc_length(void *data, object l) object Cyc_length(void *data, object l)
@ -1345,7 +1369,7 @@ object Cyc_number2string2(void *data, object cont, int argc, object n, ...)
} }
} }
make_string(str, buffer); make_string(str, buffer);
return_closcall1(data, cont, &str); _return_closcall1(data, cont, &str);
} }
object Cyc_symbol2string(void *data, object cont, object sym) object Cyc_symbol2string(void *data, object cont, object sym)
@ -1354,7 +1378,7 @@ object Cyc_symbol2string(void *data, object cont, object sym)
{ {
const char *pname = symbol_pname(sym); const char *pname = symbol_pname(sym);
make_string(str, pname); make_string(str, pname);
return_closcall1(data, cont, &str); _return_closcall1(data, cont, &str);
}} }}
object Cyc_string2symbol(void *data, object str) object Cyc_string2symbol(void *data, object str)
@ -1387,7 +1411,7 @@ object Cyc_list2string(void *data, object cont, object lst)
//{ make_string_noalloc(str, buf, i); //{ make_string_noalloc(str, buf, i);
{ {
make_string(str, buf); make_string(str, buf);
return_closcall1(data, cont, &str); _return_closcall1(data, cont, &str);
} }
} }
@ -1407,16 +1431,17 @@ object Cyc_string2number2_(void *data, object cont, int argc, object str, ...)
Cyc_check_str(data, str); Cyc_check_str(data, str);
if (base_num == 2) { if (base_num == 2) {
result = binstr2int(string_str(str)); result = binstr2int(string_str(str));
return_closcall1(data, cont, obj_int2obj(result)); _return_closcall1(data, cont, obj_int2obj(result));
} else if (base_num == 8) { } else if (base_num == 8) {
result = octstr2int(string_str(str)); result = octstr2int(string_str(str));
return_closcall1(data, cont, obj_int2obj(result)); _return_closcall1(data, cont, obj_int2obj(result));
} else if (base_num == 16) { } else if (base_num == 16) {
result = hexstr2int(string_str(str)); result = hexstr2int(string_str(str));
return_closcall1(data, cont, obj_int2obj(result)); _return_closcall1(data, cont, obj_int2obj(result));
} }
} }
Cyc_string2number_(data, cont, str); Cyc_string2number_(data, cont, str);
return NULL;
} }
typedef enum { typedef enum {
@ -1474,9 +1499,8 @@ int str2double(double *out, char *s)
object Cyc_string2number_(void *data, object cont, object str) object Cyc_string2number_(void *data, object cont, object str)
{ {
int result, rv; int result, rv;
long l;
double n; double n;
char *s, *end; char *s;
Cyc_check_obj(data, string_tag, str); Cyc_check_obj(data, string_tag, str);
Cyc_check_str(data, str); Cyc_check_str(data, str);
if (type_of(str) == string_tag && ((string_type *) str)->str) { if (type_of(str) == string_tag && ((string_type *) str)->str) {
@ -1484,12 +1508,12 @@ object Cyc_string2number_(void *data, object cont, object str)
rv = str2int(&result, s, 10); rv = str2int(&result, s, 10);
if (rv == STR2INT_SUCCESS) { if (rv == STR2INT_SUCCESS) {
return_closcall1(data, cont, obj_int2obj(result)); _return_closcall1(data, cont, obj_int2obj(result));
} else { } else {
str2double(&n, s); str2double(&n, s);
{ {
make_double(result, n); make_double(result, n);
return_closcall1(data, cont, &result); _return_closcall1(data, cont, &result);
} }
} }
} else { } else {
@ -1498,6 +1522,7 @@ object Cyc_string2number_(void *data, object cont, object str)
} }
Cyc_rt_raise2(data, "Expected string but received", str); Cyc_rt_raise2(data, "Expected string but received", str);
return NULL;
} }
int binstr2int(const char *str) int binstr2int(const char *str)
@ -1572,10 +1597,10 @@ object Cyc_string_cmp(void *data, object str1, object str2)
*bufferp = '\0'; \ *bufferp = '\0'; \
make_string(result, buffer); \ make_string(result, buffer); \
va_end(ap); \ va_end(ap); \
return_closcall1(data, cont, &result); \ _return_closcall1(data, cont, &result); \
} }
void dispatch_string_91append(void *data, int _argc, object clo, object cont, object dispatch_string_91append(void *data, int _argc, object clo, object cont,
object str1, ...) object str1, ...)
{ {
va_list ap; va_list ap;
@ -1666,7 +1691,7 @@ object Cyc_substring(void *data, object cont, object str, object start,
{ {
make_string_with_len(sub, raw + s, e - s); make_string_with_len(sub, raw + s, e - s);
return_closcall1(data, cont, &sub); _return_closcall1(data, cont, &sub);
} }
} }
@ -1681,22 +1706,22 @@ object Cyc_installation_dir(void *data, object cont, object type)
char buf[1024]; char buf[1024];
snprintf(buf, sizeof(buf), "%s", CYC_INSTALL_SLD); snprintf(buf, sizeof(buf), "%s", CYC_INSTALL_SLD);
make_string(str, buf); make_string(str, buf);
return_closcall1(data, cont, &str); _return_closcall1(data, cont, &str);
} else if (Cyc_is_symbol(type) == boolean_t && } else if (Cyc_is_symbol(type) == boolean_t &&
strncmp(((symbol) type)->pname, "lib", 5) == 0) { strncmp(((symbol) type)->pname, "lib", 5) == 0) {
char buf[1024]; char buf[1024];
snprintf(buf, sizeof(buf), "%s", CYC_INSTALL_LIB); snprintf(buf, sizeof(buf), "%s", CYC_INSTALL_LIB);
make_string(str, buf); make_string(str, buf);
return_closcall1(data, cont, &str); _return_closcall1(data, cont, &str);
} else if (Cyc_is_symbol(type) == boolean_t && } else if (Cyc_is_symbol(type) == boolean_t &&
strncmp(((symbol) type)->pname, "inc", 5) == 0) { strncmp(((symbol) type)->pname, "inc", 5) == 0) {
char buf[1024]; char buf[1024];
snprintf(buf, sizeof(buf), "%s", CYC_INSTALL_INC); snprintf(buf, sizeof(buf), "%s", CYC_INSTALL_INC);
make_string(str, buf); make_string(str, buf);
return_closcall1(data, cont, &str); _return_closcall1(data, cont, &str);
} else { } else {
make_string(str, CYC_INSTALL_DIR); make_string(str, CYC_INSTALL_DIR);
return_closcall1(data, cont, &str); _return_closcall1(data, cont, &str);
} }
} }
@ -1725,7 +1750,7 @@ object Cyc_command_line_arguments(void *data, object cont)
((list) pl)->pair_cdr = lis; ((list) pl)->pair_cdr = lis;
lis = pl; lis = pl;
} }
return_closcall1(data, cont, lis); _return_closcall1(data, cont, lis);
} }
object Cyc_make_vector(void *data, object cont, int argc, object len, ...) object Cyc_make_vector(void *data, object cont, int argc, object len, ...)
@ -1777,14 +1802,14 @@ object Cyc_make_vector(void *data, object cont, int argc, object len, ...)
for (i = 0; i < ((vector) v)->num_elements; i++) { for (i = 0; i < ((vector) v)->num_elements; i++) {
((vector) v)->elements[i] = fill; ((vector) v)->elements[i] = fill;
} }
return_closcall1(data, cont, v); _return_closcall1(data, cont, v);
} }
object Cyc_make_bytevector(void *data, object cont, int argc, object len, ...) object Cyc_make_bytevector(void *data, object cont, int argc, object len, ...)
{ {
object bv = NULL; object bv = NULL;
object fill; object fill;
int i, length, fill_val; int length, fill_val;
va_list ap; va_list ap;
va_start(ap, len); va_start(ap, len);
if (argc > 1) { if (argc > 1) {
@ -1805,7 +1830,7 @@ object Cyc_make_bytevector(void *data, object cont, int argc, object len, ...)
fill_val = unbox_number(fill); fill_val = unbox_number(fill);
memset(((bytevector) bv)->data, (unsigned char)fill_val, length); memset(((bytevector) bv)->data, (unsigned char)fill_val, length);
} }
return_closcall1(data, cont, bv); _return_closcall1(data, cont, bv);
} }
#define Cyc_bytevector_va_list(argc) { \ #define Cyc_bytevector_va_list(argc) { \
@ -1830,10 +1855,10 @@ object Cyc_make_bytevector(void *data, object cont, int argc, object len, ...)
bv.len = argc; \ bv.len = argc; \
bv.data = buffer; \ bv.data = buffer; \
} \ } \
return_closcall1(data, cont, &bv); \ _return_closcall1(data, cont, &bv); \
} }
void dispatch_bytevector(void *data, int _argc, object clo, object cont, object dispatch_bytevector(void *data, int _argc, object clo, object cont,
object bval, ...) object bval, ...)
{ {
Cyc_bytevector_va_list((_argc - 1)); Cyc_bytevector_va_list((_argc - 1));
@ -1845,7 +1870,7 @@ object Cyc_bytevector(void *data, object cont, int _argc, object bval, ...)
} }
#define Cyc_bytevector_append_va_list(argc) { \ #define Cyc_bytevector_append_va_list(argc) { \
int i = 0, buf_idx = 0, val, total_length = 0; \ int i = 0, buf_idx = 0, total_length = 0; \
va_list ap; \ va_list ap; \
object tmp; \ object tmp; \
char *buffer; \ char *buffer; \
@ -1876,10 +1901,10 @@ object Cyc_bytevector(void *data, object cont, int _argc, object bval, ...)
result.len = total_length; \ result.len = total_length; \
result.data = buffer; \ result.data = buffer; \
} \ } \
return_closcall1(data, cont, &result); \ _return_closcall1(data, cont, &result); \
} }
void dispatch_bytevector_91append(void *data, int _argc, object clo, object dispatch_bytevector_91append(void *data, int _argc, object clo,
object cont, object bv, ...) object cont, object bv, ...)
{ {
Cyc_bytevector_append_va_list((_argc - 1)); Cyc_bytevector_append_va_list((_argc - 1));
@ -1893,7 +1918,6 @@ object Cyc_bytevector_append(void *data, object cont, int _argc, object bv, ...)
object Cyc_bytevector_copy(void *data, object cont, object bv, object start, object Cyc_bytevector_copy(void *data, object cont, object bv, object start,
object end) object end)
{ {
const char *buf;
int s, e; int s, e;
int len; int len;
make_empty_bytevector(result); make_empty_bytevector(result);
@ -1902,7 +1926,6 @@ object Cyc_bytevector_copy(void *data, object cont, object bv, object start,
Cyc_check_num(data, start); Cyc_check_num(data, start);
Cyc_check_num(data, end); Cyc_check_num(data, end);
buf = ((bytevector) bv)->data;
s = unbox_number(start); s = unbox_number(start);
e = unbox_number(end); e = unbox_number(end);
len = e - s; len = e - s;
@ -1918,7 +1941,7 @@ object Cyc_bytevector_copy(void *data, object cont, object bv, object start,
result.len = len; result.len = len;
result.data = alloca(sizeof(char) * len); result.data = alloca(sizeof(char) * len);
memcpy(&result.data[0], &(((bytevector) bv)->data)[s], len); memcpy(&result.data[0], &(((bytevector) bv)->data)[s], len);
return_closcall1(data, cont, &result); _return_closcall1(data, cont, &result);
} }
object Cyc_utf82string(void *data, object cont, object bv, object start, object Cyc_utf82string(void *data, object cont, object bv, object start,
@ -1950,14 +1973,13 @@ object Cyc_utf82string(void *data, object cont, object bv, object start,
st.str = alloca(sizeof(char) * (len + 1)); st.str = alloca(sizeof(char) * (len + 1));
memcpy(st.str, &buf[s], len); memcpy(st.str, &buf[s], len);
st.str[len] = '\0'; st.str[len] = '\0';
return_closcall1(data, cont, &st); _return_closcall1(data, cont, &st);
} }
} }
object Cyc_string2utf8(void *data, object cont, object str, object start, object Cyc_string2utf8(void *data, object cont, object str, object start,
object end) object end)
{ {
const char *buf;
int s, e; int s, e;
int len; int len;
make_empty_bytevector(result); make_empty_bytevector(result);
@ -1966,7 +1988,6 @@ object Cyc_string2utf8(void *data, object cont, object str, object start,
Cyc_check_num(data, start); Cyc_check_num(data, start);
Cyc_check_num(data, end); Cyc_check_num(data, end);
buf = string_str(str);
s = unbox_number(start); s = unbox_number(start);
e = unbox_number(end); e = unbox_number(end);
len = e - s; len = e - s;
@ -1982,7 +2003,7 @@ object Cyc_string2utf8(void *data, object cont, object str, object start,
result.len = len; result.len = len;
result.data = alloca(sizeof(char) * len); result.data = alloca(sizeof(char) * len);
memcpy(&result.data[0], &(string_str(str))[s], len); memcpy(&result.data[0], &(string_str(str))[s], len);
return_closcall1(data, cont, &result); _return_closcall1(data, cont, &result);
} }
object Cyc_bytevector_u8_ref(void *data, object bv, object k) object Cyc_bytevector_u8_ref(void *data, object bv, object k)
@ -2031,6 +2052,7 @@ object Cyc_bytevector_length(void *data, object bv)
} }
Cyc_rt_raise_msg(data, Cyc_rt_raise_msg(data,
"bytevector-length - invalid parameter, expected bytevector\n"); "bytevector-length - invalid parameter, expected bytevector\n");
return NULL;
} }
object Cyc_list2vector(void *data, object cont, object l) object Cyc_list2vector(void *data, object cont, object l)
@ -2054,7 +2076,7 @@ object Cyc_list2vector(void *data, object cont, object l)
((vector) v)->elements[i++] = car(lst); ((vector) v)->elements[i++] = car(lst);
lst = cdr(lst); lst = cdr(lst);
} }
return_closcall1(data, cont, v); _return_closcall1(data, cont, v);
} }
object Cyc_system(object cmd) object Cyc_system(object cmd)
@ -2132,7 +2154,7 @@ object FUNC(void *data, object cont, int argc, object n, ...) { \
va_start(ap, n); \ va_start(ap, n); \
result = Cyc_num_op_va_list(data, argc, FUNC_OP, NO_ARG, ONE_ARG, n, ap, &buffer); \ result = Cyc_num_op_va_list(data, argc, FUNC_OP, NO_ARG, ONE_ARG, n, ap, &buffer); \
va_end(ap); \ va_end(ap); \
return_closcall1(data, cont, result); \ _return_closcall1(data, cont, result); \
} \ } \
void FUNC_APPLY(void *data, int argc, object clo, object cont, object n, ...) { \ void FUNC_APPLY(void *data, int argc, object clo, object cont, object n, ...) { \
common_type buffer; \ common_type buffer; \
@ -2188,7 +2210,7 @@ object Cyc_div(void *data, object cont, int argc, object n, ...)
va_start(ap, n); va_start(ap, n);
result = Cyc_num_op_va_list(data, argc, Cyc_div_op, -1, 1, n, ap, &buffer); result = Cyc_num_op_va_list(data, argc, Cyc_div_op, -1, 1, n, ap, &buffer);
va_end(ap); va_end(ap);
return_closcall1(data, cont, result); _return_closcall1(data, cont, result);
} }
void dispatch_div(void *data, int argc, object clo, object cont, object n, ...) void dispatch_div(void *data, int argc, object clo, object cont, object n, ...)
@ -2350,7 +2372,8 @@ object Cyc_io_flush_output_port(void *data, object port)
{ {
FILE *stream = ((port_type *) port)->fp; FILE *stream = ((port_type *) port)->fp;
if (stream) { if (stream) {
int rv = fflush(stream); //int rv =
fflush(stream);
// TODO: handle error if non-zero value returned // TODO: handle error if non-zero value returned
} }
} }
@ -2374,7 +2397,7 @@ object Cyc_io_file_exists(void *data, object filename)
fname = ((string_type *) filename)->str; fname = ((string_type *) filename)->str;
FILE *file; FILE *file;
// Possibly overkill, but portable // Possibly overkill, but portable
if (file = fopen(fname, "r")) { if ((file = fopen(fname, "r"))) {
fclose(file); fclose(file);
return boolean_t; return boolean_t;
} }
@ -2748,21 +2771,18 @@ void _bytevector_91append(void *data, object cont, object args)
void _Cyc_91bytevector_91copy(void *data, object cont, object args) void _Cyc_91bytevector_91copy(void *data, object cont, object args)
{ {
object argc = Cyc_length(data, args);
Cyc_check_num_args(data, "Cyc-bytevector-copy", 3, args); Cyc_check_num_args(data, "Cyc-bytevector-copy", 3, args);
Cyc_bytevector_copy(data, cont, car(args), cadr(args), caddr(args)); Cyc_bytevector_copy(data, cont, car(args), cadr(args), caddr(args));
} }
void _Cyc_91string_91_125utf8(void *data, object cont, object args) void _Cyc_91string_91_125utf8(void *data, object cont, object args)
{ {
object argc = Cyc_length(data, args);
Cyc_check_num_args(data, "Cyc-string->utf8", 3, args); Cyc_check_num_args(data, "Cyc-string->utf8", 3, args);
Cyc_string2utf8(data, cont, car(args), cadr(args), caddr(args)); Cyc_string2utf8(data, cont, car(args), cadr(args), caddr(args));
} }
void _Cyc_91utf8_91_125string(void *data, object cont, object args) void _Cyc_91utf8_91_125string(void *data, object cont, object args)
{ {
object argc = Cyc_length(data, args);
Cyc_check_num_args(data, "Cyc-utf8->string", 3, args); Cyc_check_num_args(data, "Cyc-utf8->string", 3, args);
Cyc_utf82string(data, cont, car(args), cadr(args), caddr(args)); Cyc_utf82string(data, cont, car(args), cadr(args), caddr(args));
} }
@ -3462,7 +3482,7 @@ object apply(void *data, object cont, object func, object args)
case closure1_tag: case closure1_tag:
case closureN_tag: case closureN_tag:
if (func == Cyc_glo_call_cc) { if (func == Cyc_glo_call_cc) {
make_pair(c, cont, args); // make_pair(c, cont, args);
//Cyc_display(args, stderr); //Cyc_display(args, stderr);
// args = &c; // args = &c;
//Cyc_display(&c, stderr); //Cyc_display(&c, stderr);