Cleanup of runtime library

This commit is contained in:
Justin Ethier 2015-04-21 17:16:29 -04:00
parent 5118a4e456
commit cfdac7963d
3 changed files with 21 additions and 90 deletions

View file

@ -280,4 +280,8 @@ typedef union {
string_type string_t; string_type string_t;
} common_type; } common_type;
/* Function prototypes */
void Cyc_rt_raise(object err);
void Cyc_rt_raise_msg(const char *err);
#endif /* CYCLONE_H */ #endif /* CYCLONE_H */

105
runtime.c
View file

@ -1,88 +1,5 @@
#include "cyclone.h" #include "cyclone.h"
// //#ifdef __x86_64__
// //# define C_AMD64_ABI_WEIRDNESS , ...
// //#else
// //# define C_AMD64_ABI_WEIRDNESS
// //#endif
// typedef void (*Cyc_proc0) ( int, object);
// typedef void (*Cyc_proc1) ( int, object, object);
// //typedef void (*Cyc_proc2) ( object, object, object);
//
// /* C_WORD_p<P>_<B>: List of ((2 ** P) * B) 'C_word' parameters */
// #define C_WORD_p0_0
// #define C_WORD_p1_0
// #define C_WORD_p2_0
// #define C_WORD_p3_0
// #define C_WORD_p4_0
// #define C_WORD_p5_0
// #define C_WORD_p6_0
// #define C_WORD_p7_0
// #define C_WORD_p0_1 object, //C_word,
// #define C_WORD_p1_1 object, object, //C_word, C_word,
// #define C_WORD_p2_1 C_WORD_p1_1 C_WORD_p1_1
// #define C_WORD_p3_1 C_WORD_p2_1 C_WORD_p2_1
// #define C_WORD_p4_1 C_WORD_p3_1 C_WORD_p3_1
// #define C_WORD_p5_1 C_WORD_p4_1 C_WORD_p4_1
// #define C_WORD_p6_1 C_WORD_p5_1 C_WORD_p5_1
// #define C_WORD_p7_1 C_WORD_p6_1 C_WORD_p6_1
//
// /* Declaration macro from CHICKEN scheme */
// /* DECL_C_PROC_p0 (n0, p7,p6,p5,p4,p3,p2,p1,p0):
// * declare function C_proc<n0>, which have <n0> 'C_word' parameters
// * (not counting last 'C_word C_AMD64_ABI_WEIRDNESS' one).
// * We must have: n0 = SUM (i = 7 to 0, p<i> * (1 << i)).
// * DECL_C_PROC_p<N+1> (...):
// * declare 2 as much functions as DECL_C_PROC_p<N>...
// */
// #define DECL_C_PROC_p0( n0, p7,p6,p5,p4,p3,p2,p1,p0) \
// typedef void (*Cyc_proc##n0) (int, C_WORD_p7_##p7 C_WORD_p6_##p6 \
// C_WORD_p5_##p5 C_WORD_p4_##p4 \
// C_WORD_p3_##p3 C_WORD_p2_##p2 \
// C_WORD_p1_##p1 C_WORD_p0_##p0 \
// object);
// //C_word C_AMD64_ABI_WEIRDNESS) ; //C_noret;
// #define DECL_C_PROC_p1( n0,n1, p7,p6,p5,p4,p3,p2,p1) \
// DECL_C_PROC_p0 (n0, p7,p6,p5,p4,p3,p2,p1,0) \
// DECL_C_PROC_p0 (n1, p7,p6,p5,p4,p3,p2,p1,1)
// #define DECL_C_PROC_p2( n0,n1,n2,n3, p7,p6,p5,p4,p3,p2) \
// DECL_C_PROC_p1 (n0,n1, p7,p6,p5,p4,p3,p2,0) \
// DECL_C_PROC_p1 (n2,n3, p7,p6,p5,p4,p3,p2,1)
// #define DECL_C_PROC_p3( n0,n1,n2,n3,n4,n5,n6,n7, p7,p6,p5,p4,p3) \
// DECL_C_PROC_p2 (n0,n1,n2,n3, p7,p6,p5,p4,p3,0) \
// DECL_C_PROC_p2 (n4,n5,n6,n7, p7,p6,p5,p4,p3,1)
//
// DECL_C_PROC_p1 (2,3, 0,0,0,0,0,0,1)
// DECL_C_PROC_p2 (4,5,6,7, 0,0,0,0,0,1)
// DECL_C_PROC_p3 (8,9,10,11,12,13,14,15, 0,0,0,0,1)
// DECL_C_PROC_p3 (16,17,18,19,20,21,22,23, 0,0,0,1,0)
// DECL_C_PROC_p3 (24,25,26,27,28,29,30,31, 0,0,0,1,1)
// DECL_C_PROC_p3 (32,33,34,35,36,37,38,39, 0,0,1,0,0)
// DECL_C_PROC_p3 (40,41,42,43,44,45,46,47, 0,0,1,0,1)
// DECL_C_PROC_p3 (48,49,50,51,52,53,54,55, 0,0,1,1,0)
// DECL_C_PROC_p3 (56,57,58,59,60,61,62,63, 0,0,1,1,1)
// DECL_C_PROC_p1 (64,65, 0,1,0,0,0,0,0)
// DECL_C_PROC_p0 (66, 0,1,0,0,0,0,1,0)
// DECL_C_PROC_p0 (67, 0,1,0,0,0,0,1,1)
// DECL_C_PROC_p2 (68,69,70,71, 0,1,0,0,0,1)
// DECL_C_PROC_p3 (72,73,74,75,76,77,78,79, 0,1,0,0,1)
// DECL_C_PROC_p3 (80,81,82,83,84,85,86,87, 0,1,0,1,0)
// DECL_C_PROC_p3 (88,89,90,91,92,93,94,95, 0,1,0,1,1)
// DECL_C_PROC_p3 (96,97,98,99,100,101,102,103, 0,1,1,0,0)
// DECL_C_PROC_p3 (104,105,106,107,108,109,110,111, 0,1,1,0,1)
// DECL_C_PROC_p3 (112,113,114,115,116,117,118,119, 0,1,1,1,0)
// DECL_C_PROC_p3 (120,121,122,123,124,125,126,127, 0,1,1,1,1)
// DECL_C_PROC_p0 (128, 1,0,0,0,0,0,0,0)
/**
* Take list of args and call a function with them as params.
*
* Note memory scheme below is not compatible with GC,
* so macro calls funcs directly.
*/
// TODO: get VA args function below to work
/** /**
* Receive a list of arguments and apply them to the given function * Receive a list of arguments and apply them to the given function
*/ */
@ -117,8 +34,18 @@ void dispatch_va(int argc, function_type_va func, object clo, object cont, objec
do_dispatch(argc, (function_type)func, clo, b); do_dispatch(argc, (function_type)func, clo, b);
} }
/**
* Take list of args and call a function with them as params.
*
* All of the clever C macro expansions were taken from the
* macro expansion code from CHICKEN's do_apply. TBD if this will
* remain. On the one hand it reduces the size of the C code, but
* on the other I think it ties this code to CHICKEN's license terms.
*
* Note memory scheme we are using is not compatible with GC,
* so macro calls funcs directly.
*/
void do_dispatch(int argc, function_type func, object clo, object *b) { void do_dispatch(int argc, function_type func, object clo, object *b) {
/* The following is based on the macro expansion code from CHICKEN's do_apply */
/* PTR_O_p<P>_<B>(o): list of COUNT = ((2 ** P) * B) '*(b+I)' arguments, /* PTR_O_p<P>_<B>(o): list of COUNT = ((2 ** P) * B) '*(b+I)' arguments,
* with offset I in range [o, o+COUNT-1]. * with offset I in range [o, o+COUNT-1].
@ -190,10 +117,12 @@ PTR_O_p0_##p0(((n0-2)&0xFE)+0));
CASE_C_PROC_p2 (122,123,124,125, 1,1,1,1,0) CASE_C_PROC_p2 (122,123,124,125, 1,1,1,1,0)
CASE_C_PROC_p1 (126,127, 1,1,1,1,1,0) CASE_C_PROC_p1 (126,127, 1,1,1,1,1,0)
CASE_C_PROC_p0 (128, 1,1,1,1,1,1,0) CASE_C_PROC_p0 (128, 1,1,1,1,1,1,0)
default: //barf(C_TOO_MANY_PARAMETERS_ERROR, "apply"); default:
// TODO: not good enough, throw an exception instead, using (error) {
printf("Unhandled number of function arguments: %d\n", argc); char buf[1024];
exit(1); snprintf(buf, 1023, "Unhandled number of function arguments: %d\n", argc);
Cyc_rt_raise_msg(buf);
}
} }
} }

View file

@ -77,8 +77,6 @@ static string_type Cyc_string_append_va_list(int, object, va_list);
//object Cyc_raise(object); //object Cyc_raise(object);
static object Cyc_default_exception_handler(int argc, closure _, object err); static object Cyc_default_exception_handler(int argc, closure _, object err);
object Cyc_current_exception_handler(); object Cyc_current_exception_handler();
void Cyc_rt_raise(object err);
void Cyc_rt_raise_msg(const char *err);
static list mcons(object,object); static list mcons(object,object);
static object terpri(void); static object terpri(void);
static object Cyc_display(object); static object Cyc_display(object);