|
@ -1,32 +1,49 @@ |
|
|
typedef |
|
|
typedef |
|
|
struct { |
|
|
struct { |
|
|
size_t size; |
|
|
size_t size; |
|
|
char* string; |
|
|
char *string; |
|
|
} sc_string_t; |
|
|
} sc_string_t; |
|
|
|
|
|
|
|
|
|
|
|
/* This is not the most space efficient representation
|
|
|
|
|
|
* However it is an easy to understand and debug one |
|
|
|
|
|
*/ |
|
|
typedef |
|
|
typedef |
|
|
union { |
|
|
union { |
|
|
sc_string_t string; |
|
|
|
|
|
double doublev; |
|
|
|
|
|
int integer; |
|
|
int integer; |
|
|
float floating; |
|
|
float floating; |
|
|
|
|
|
double doublev; |
|
|
|
|
|
sc_string_t string; |
|
|
struct closure_t *closure; |
|
|
struct closure_t *closure; |
|
|
} svalue_variants_t; |
|
|
} svalue_variants_t; |
|
|
|
|
|
|
|
|
|
|
|
/* The tag values for each different type */ |
|
|
typedef |
|
|
typedef |
|
|
enum { |
|
|
enum { |
|
|
INT = 0, |
|
|
INT = 0, |
|
|
FLOAT = 1, |
|
|
FLOAT = 1, |
|
|
DOUBLE = 2, |
|
|
DOUBLE = 2, |
|
|
STRING = 3 |
|
|
STRING = 3, |
|
|
|
|
|
CLOSURE = 4 |
|
|
} stype_t; |
|
|
} stype_t; |
|
|
|
|
|
|
|
|
|
|
|
/* An actual boxed scheme value */ |
|
|
typedef |
|
|
typedef |
|
|
struct { |
|
|
struct { |
|
|
stype_t type_tag; |
|
|
stype_t type_tag; |
|
|
svalue_variants_t value; |
|
|
svalue_variants_t value; |
|
|
} svalue_t; |
|
|
} svalue_t; |
|
|
|
|
|
|
|
|
|
|
|
/* A closure is a function pointer taking a
|
|
|
|
|
|
* single argument and an environment |
|
|
|
|
|
* What will happen is that applications of |
|
|
|
|
|
* procedures will be 'curried' but they will |
|
|
|
|
|
* always be required to be fully applied earlier |
|
|
|
|
|
* on in the compiler by checking applications |
|
|
|
|
|
* against the arity of a procedure (obtained by looking |
|
|
|
|
|
* at its definition). This simplifies compilation, but |
|
|
|
|
|
* does not change the semantics of procedures in any |
|
|
|
|
|
* way |
|
|
|
|
|
*/ |
|
|
typedef |
|
|
typedef |
|
|
struct { |
|
|
struct { |
|
|
svalue_t *(*func)(svalue_t, svalue_t*); |
|
|
svalue_t *(*func)(svalue_t, svalue_t*); |
|
@ -44,12 +61,29 @@ svalue_t * |
|
|
box_value(svalue_variants_t, stype_t); |
|
|
box_value(svalue_variants_t, stype_t); |
|
|
|
|
|
|
|
|
closure_t |
|
|
closure_t |
|
|
make_closure(svalue_t* (*func)(svalue_t, svalue_t*), |
|
|
make_closure(svalue_t *(*func)(svalue_t, svalue_t*), |
|
|
svalue_t*); |
|
|
svalue_t*); |
|
|
|
|
|
|
|
|
svalue_t* |
|
|
svalue_t * |
|
|
invoke(closure_t, svalue_t); |
|
|
invoke(closure_t, svalue_t); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline svalue_t * |
|
|
|
|
|
box_int(int x); |
|
|
|
|
|
|
|
|
|
|
|
inline svalue_t * |
|
|
|
|
|
box_float(float x); |
|
|
|
|
|
|
|
|
|
|
|
inline svalue_t * |
|
|
|
|
|
box_double(double x); |
|
|
|
|
|
|
|
|
|
|
|
inline svalue_t * |
|
|
|
|
|
box_string(char *, |
|
|
|
|
|
size_t); |
|
|
|
|
|
|
|
|
|
|
|
inline svalue_t * |
|
|
|
|
|
box_closure(closure_t); |
|
|
|
|
|
|
|
|
#ifndef LIB |
|
|
#ifndef LIB |
|
|
static svalue_t* |
|
|
static svalue_t* |
|
|
make_adder_inner(svalue_t, svalue_t *); |
|
|
make_adder_inner(svalue_t, svalue_t *); |
|
|