Replace symbol_t with struct
This commit is contained in:
parent
193ced5e73
commit
c9f5e4faeb
15
c/builtins.c
15
c/builtins.c
|
@ -148,14 +148,15 @@ static value_t fl_symbol(value_t *args, u_int32_t nargs)
|
||||||
static value_t fl_keywordp(value_t *args, u_int32_t nargs)
|
static value_t fl_keywordp(value_t *args, u_int32_t nargs)
|
||||||
{
|
{
|
||||||
argcount("keyword?", nargs, 1);
|
argcount("keyword?", nargs, 1);
|
||||||
return (issymbol(args[0]) && iskeyword((symbol_t *)ptr(args[0]))) ? FL_T
|
return (issymbol(args[0]) && iskeyword((struct symbol *)ptr(args[0])))
|
||||||
: FL_F;
|
? FL_T
|
||||||
|
: FL_F;
|
||||||
}
|
}
|
||||||
|
|
||||||
static value_t fl_top_level_value(value_t *args, u_int32_t nargs)
|
static value_t fl_top_level_value(value_t *args, u_int32_t nargs)
|
||||||
{
|
{
|
||||||
argcount("top-level-value", nargs, 1);
|
argcount("top-level-value", nargs, 1);
|
||||||
symbol_t *sym = tosymbol(args[0], "top-level-value");
|
struct symbol *sym = tosymbol(args[0], "top-level-value");
|
||||||
if (sym->binding == UNBOUND)
|
if (sym->binding == UNBOUND)
|
||||||
fl_raise(fl_list2(UnboundError, args[0]));
|
fl_raise(fl_list2(UnboundError, args[0]));
|
||||||
return sym->binding;
|
return sym->binding;
|
||||||
|
@ -164,13 +165,13 @@ static value_t fl_top_level_value(value_t *args, u_int32_t nargs)
|
||||||
static value_t fl_set_top_level_value(value_t *args, u_int32_t nargs)
|
static value_t fl_set_top_level_value(value_t *args, u_int32_t nargs)
|
||||||
{
|
{
|
||||||
argcount("set-top-level-value!", nargs, 2);
|
argcount("set-top-level-value!", nargs, 2);
|
||||||
symbol_t *sym = tosymbol(args[0], "set-top-level-value!");
|
struct symbol *sym = tosymbol(args[0], "set-top-level-value!");
|
||||||
if (!isconstant(sym))
|
if (!isconstant(sym))
|
||||||
sym->binding = args[1];
|
sym->binding = args[1];
|
||||||
return args[1];
|
return args[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void global_env_list(symbol_t *root, value_t *pv)
|
static void global_env_list(struct symbol *root, value_t *pv)
|
||||||
{
|
{
|
||||||
while (root != NULL) {
|
while (root != NULL) {
|
||||||
if (root->name[0] != ':' && (root->binding != UNBOUND)) {
|
if (root->name[0] != ':' && (root->binding != UNBOUND)) {
|
||||||
|
@ -181,7 +182,7 @@ static void global_env_list(symbol_t *root, value_t *pv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern symbol_t *symtab;
|
extern struct symbol *symtab;
|
||||||
|
|
||||||
value_t fl_global_env(value_t *args, u_int32_t nargs)
|
value_t fl_global_env(value_t *args, u_int32_t nargs)
|
||||||
{
|
{
|
||||||
|
@ -200,7 +201,7 @@ static value_t fl_constantp(value_t *args, u_int32_t nargs)
|
||||||
{
|
{
|
||||||
argcount("constant?", nargs, 1);
|
argcount("constant?", nargs, 1);
|
||||||
if (issymbol(args[0]))
|
if (issymbol(args[0]))
|
||||||
return (isconstant((symbol_t *)ptr(args[0])) ? FL_T : FL_F);
|
return (isconstant((struct symbol *)ptr(args[0])) ? FL_T : FL_F);
|
||||||
if (iscons(args[0])) {
|
if (iscons(args[0])) {
|
||||||
if (car_(args[0]) == QUOTE)
|
if (car_(args[0]) == QUOTE)
|
||||||
return FL_T;
|
return FL_T;
|
||||||
|
|
|
@ -867,7 +867,7 @@ static value_t cvalue_array_aset(value_t *args)
|
||||||
value_t fl_builtin(value_t *args, u_int32_t nargs)
|
value_t fl_builtin(value_t *args, u_int32_t nargs)
|
||||||
{
|
{
|
||||||
argcount("builtin", nargs, 1);
|
argcount("builtin", nargs, 1);
|
||||||
symbol_t *name = tosymbol(args[0], "builtin");
|
struct symbol *name = tosymbol(args[0], "builtin");
|
||||||
cvalue_t *cv;
|
cvalue_t *cv;
|
||||||
if (ismanaged(args[0]) || (cv = name->dlcache) == NULL) {
|
if (ismanaged(args[0]) || (cv = name->dlcache) == NULL) {
|
||||||
lerrorf(ArgError, "builtin: function %s not found", name->name);
|
lerrorf(ArgError, "builtin: function %s not found", name->name);
|
||||||
|
@ -884,7 +884,7 @@ value_t cbuiltin(char *name, builtin_t f)
|
||||||
*(void **)cv->data = f;
|
*(void **)cv->data = f;
|
||||||
|
|
||||||
value_t sym = symbol(name);
|
value_t sym = symbol(name);
|
||||||
((symbol_t *)ptr(sym))->dlcache = cv;
|
((struct symbol *)ptr(sym))->dlcache = cv;
|
||||||
ptrhash_put(&reverse_dlsym_lookup_table, cv, (void *)sym);
|
ptrhash_put(&reverse_dlsym_lookup_table, cv, (void *)sym);
|
||||||
|
|
||||||
return tagptr(cv, TAG_CVALUE);
|
return tagptr(cv, TAG_CVALUE);
|
||||||
|
|
|
@ -327,7 +327,7 @@ static uptrint_t bounded_hash(value_t a, int bound, int *oob)
|
||||||
oob);
|
oob);
|
||||||
return inthash(a);
|
return inthash(a);
|
||||||
case TAG_SYM:
|
case TAG_SYM:
|
||||||
return ((symbol_t *)ptr(a))->hash;
|
return ((struct symbol *)ptr(a))->hash;
|
||||||
case TAG_CPRIM:
|
case TAG_CPRIM:
|
||||||
cp = (struct cprim *)ptr(a);
|
cp = (struct cprim *)ptr(a);
|
||||||
data = cp_data(cp);
|
data = cp_data(cp);
|
||||||
|
|
33
c/flisp.c
33
c/flisp.c
|
@ -250,7 +250,7 @@ void bounds_error(char *fname, value_t arr, value_t ind)
|
||||||
type_error(fname, #type, v); \
|
type_error(fname, #type, v); \
|
||||||
}
|
}
|
||||||
SAFECAST_OP(cons, struct cons *, ptr)
|
SAFECAST_OP(cons, struct cons *, ptr)
|
||||||
SAFECAST_OP(symbol, symbol_t *, ptr)
|
SAFECAST_OP(symbol, struct symbol *, ptr)
|
||||||
SAFECAST_OP(fixnum, fixnum_t, numval)
|
SAFECAST_OP(fixnum, fixnum_t, numval)
|
||||||
SAFECAST_OP(cvalue, cvalue_t *, ptr)
|
SAFECAST_OP(cvalue, cvalue_t *, ptr)
|
||||||
SAFECAST_OP(string, char *, cvalue_data)
|
SAFECAST_OP(string, char *, cvalue_data)
|
||||||
|
@ -259,19 +259,20 @@ SAFECAST_OP(string, char *, cvalue_data)
|
||||||
// symbol table
|
// symbol table
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
|
|
||||||
symbol_t *symtab = NULL;
|
struct symbol *symtab = NULL;
|
||||||
|
|
||||||
int fl_is_keyword_name(char *str, size_t len)
|
int fl_is_keyword_name(char *str, size_t len)
|
||||||
{
|
{
|
||||||
return ((str[0] == ':' || str[len - 1] == ':') && str[1] != '\0');
|
return ((str[0] == ':' || str[len - 1] == ':') && str[1] != '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
static symbol_t *mk_symbol(char *str)
|
static struct symbol *mk_symbol(char *str)
|
||||||
{
|
{
|
||||||
symbol_t *sym;
|
struct symbol *sym;
|
||||||
size_t len = strlen(str);
|
size_t len = strlen(str);
|
||||||
|
|
||||||
sym = (symbol_t *)malloc(sizeof(symbol_t) - sizeof(void *) + len + 1);
|
sym =
|
||||||
|
(struct symbol *)malloc(sizeof(struct symbol) - sizeof(void *) + len + 1);
|
||||||
assert(((uptrint_t)sym & 0x7) == 0); // make sure malloc aligns 8
|
assert(((uptrint_t)sym & 0x7) == 0); // make sure malloc aligns 8
|
||||||
sym->left = sym->right = NULL;
|
sym->left = sym->right = NULL;
|
||||||
sym->flags = 0;
|
sym->flags = 0;
|
||||||
|
@ -288,7 +289,7 @@ static symbol_t *mk_symbol(char *str)
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
static symbol_t **symtab_lookup(symbol_t **ptree, char *str)
|
static struct symbol **symtab_lookup(struct symbol **ptree, char *str)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
|
@ -306,7 +307,7 @@ static symbol_t **symtab_lookup(symbol_t **ptree, char *str)
|
||||||
|
|
||||||
value_t symbol(char *str)
|
value_t symbol(char *str)
|
||||||
{
|
{
|
||||||
symbol_t **pnode;
|
struct symbol **pnode;
|
||||||
|
|
||||||
pnode = symtab_lookup(&symtab, str);
|
pnode = symtab_lookup(&symtab, str);
|
||||||
if (*pnode == NULL)
|
if (*pnode == NULL)
|
||||||
|
@ -350,7 +351,7 @@ char *symbol_name(value_t v)
|
||||||
*(--n) = 'g';
|
*(--n) = 'g';
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
return ((symbol_t *)ptr(v))->name;
|
return ((struct symbol *)ptr(v))->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// conses
|
// conses
|
||||||
|
@ -540,7 +541,7 @@ static value_t relocate(value_t v)
|
||||||
|
|
||||||
value_t relocate_lispvalue(value_t v) { return relocate(v); }
|
value_t relocate_lispvalue(value_t v) { return relocate(v); }
|
||||||
|
|
||||||
static void trace_globals(symbol_t *root)
|
static void trace_globals(struct symbol *root)
|
||||||
{
|
{
|
||||||
while (root != NULL) {
|
while (root != NULL) {
|
||||||
if (root->binding != UNBOUND)
|
if (root->binding != UNBOUND)
|
||||||
|
@ -874,7 +875,7 @@ static uint32_t process_keys(value_t kwtable, uint32_t nreq, uint32_t nkw,
|
||||||
args[i] = UNBOUND;
|
args[i] = UNBOUND;
|
||||||
for (i = nreq; i < nargs; i++) {
|
for (i = nreq; i < nargs; i++) {
|
||||||
v = Stack[bp + i];
|
v = Stack[bp + i];
|
||||||
if (issymbol(v) && iskeyword((symbol_t *)ptr(v)))
|
if (issymbol(v) && iskeyword((struct symbol *)ptr(v)))
|
||||||
break;
|
break;
|
||||||
if (a >= nopt)
|
if (a >= nopt)
|
||||||
goto no_kw;
|
goto no_kw;
|
||||||
|
@ -889,7 +890,7 @@ static uint32_t process_keys(value_t kwtable, uint32_t nreq, uint32_t nkw,
|
||||||
if (i >= nargs)
|
if (i >= nargs)
|
||||||
lerrorf(ArgError, "keyword %s requires an argument",
|
lerrorf(ArgError, "keyword %s requires an argument",
|
||||||
symbol_name(v));
|
symbol_name(v));
|
||||||
value_t hv = fixnum(((symbol_t *)ptr(v))->hash);
|
value_t hv = fixnum(((struct symbol *)ptr(v))->hash);
|
||||||
uptrint_t x = 2 * (labs(numval(hv)) % n);
|
uptrint_t x = 2 * (labs(numval(hv)) % n);
|
||||||
if (vector_elt(kwtable, x) == v) {
|
if (vector_elt(kwtable, x) == v) {
|
||||||
uptrint_t idx = numval(vector_elt(kwtable, x + 1));
|
uptrint_t idx = numval(vector_elt(kwtable, x + 1));
|
||||||
|
@ -906,7 +907,7 @@ static uint32_t process_keys(value_t kwtable, uint32_t nreq, uint32_t nkw,
|
||||||
if (i >= nargs)
|
if (i >= nargs)
|
||||||
break;
|
break;
|
||||||
v = Stack[bp + i];
|
v = Stack[bp + i];
|
||||||
} while (issymbol(v) && iskeyword((symbol_t *)ptr(v)));
|
} while (issymbol(v) && iskeyword((struct symbol *)ptr(v)));
|
||||||
no_kw:
|
no_kw:
|
||||||
nrestargs = nargs - i;
|
nrestargs = nargs - i;
|
||||||
if (!va && nrestargs > 0)
|
if (!va && nrestargs > 0)
|
||||||
|
@ -979,7 +980,7 @@ static value_t apply_cl(uint32_t nargs)
|
||||||
uint32_t op;
|
uint32_t op;
|
||||||
#endif
|
#endif
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
symbol_t *sym;
|
struct symbol *sym;
|
||||||
static struct cons *c;
|
static struct cons *c;
|
||||||
static value_t *pv;
|
static value_t *pv;
|
||||||
static int64_t accum;
|
static int64_t accum;
|
||||||
|
@ -1696,7 +1697,7 @@ apply_cl_top:
|
||||||
ip++;
|
ip++;
|
||||||
do_loadg:
|
do_loadg:
|
||||||
assert(issymbol(v));
|
assert(issymbol(v));
|
||||||
sym = (symbol_t *)ptr(v);
|
sym = (struct symbol *)ptr(v);
|
||||||
if (sym->binding == UNBOUND)
|
if (sym->binding == UNBOUND)
|
||||||
fl_raise(fl_list2(UnboundError, v));
|
fl_raise(fl_list2(UnboundError, v));
|
||||||
PUSH(sym->binding);
|
PUSH(sym->binding);
|
||||||
|
@ -1714,7 +1715,7 @@ apply_cl_top:
|
||||||
ip++;
|
ip++;
|
||||||
do_setg:
|
do_setg:
|
||||||
assert(issymbol(v));
|
assert(issymbol(v));
|
||||||
sym = (symbol_t *)ptr(v);
|
sym = (struct symbol *)ptr(v);
|
||||||
v = Stack[SP - 1];
|
v = Stack[SP - 1];
|
||||||
if (!isconstant(sym))
|
if (!isconstant(sym))
|
||||||
sym->binding = v;
|
sym->binding = v;
|
||||||
|
@ -2602,7 +2603,7 @@ int fl_load_system_image(value_t sys_image_iostream)
|
||||||
{
|
{
|
||||||
value_t e;
|
value_t e;
|
||||||
int saveSP;
|
int saveSP;
|
||||||
symbol_t *sym;
|
struct symbol *sym;
|
||||||
|
|
||||||
PUSH(sys_image_iostream);
|
PUSH(sys_image_iostream);
|
||||||
saveSP = SP;
|
saveSP = SP;
|
||||||
|
|
22
c/flisp.h
22
c/flisp.h
|
@ -15,20 +15,20 @@ struct cons {
|
||||||
value_t cdr;
|
value_t cdr;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _symbol_t {
|
struct symbol {
|
||||||
uptrint_t flags;
|
uptrint_t flags;
|
||||||
value_t binding; // global value binding
|
value_t binding; // global value binding
|
||||||
struct _fltype_t *type;
|
struct _fltype_t *type;
|
||||||
uint32_t hash;
|
uint32_t hash;
|
||||||
void *dlcache; // dlsym address
|
void *dlcache; // dlsym address
|
||||||
// below fields are private
|
// below fields are private
|
||||||
struct _symbol_t *left;
|
struct symbol *left;
|
||||||
struct _symbol_t *right;
|
struct symbol *right;
|
||||||
union {
|
union {
|
||||||
char name[1];
|
char name[1];
|
||||||
void *_pad; // ensure field aligned to pointer size
|
void *_pad; // ensure field aligned to pointer size
|
||||||
};
|
};
|
||||||
} symbol_t;
|
};
|
||||||
|
|
||||||
struct gensym {
|
struct gensym {
|
||||||
value_t isconst;
|
value_t isconst;
|
||||||
|
@ -97,15 +97,15 @@ struct gensym {
|
||||||
#define fn_env(f) (((value_t *)ptr(f))[2])
|
#define fn_env(f) (((value_t *)ptr(f))[2])
|
||||||
#define fn_name(f) (((value_t *)ptr(f))[3])
|
#define fn_name(f) (((value_t *)ptr(f))[3])
|
||||||
|
|
||||||
#define set(s, v) (((symbol_t *)ptr(s))->binding = (v))
|
#define set(s, v) (((struct symbol *)ptr(s))->binding = (v))
|
||||||
#define setc(s, v) \
|
#define setc(s, v) \
|
||||||
do { \
|
do { \
|
||||||
((symbol_t *)ptr(s))->flags |= 1; \
|
((struct symbol *)ptr(s))->flags |= 1; \
|
||||||
((symbol_t *)ptr(s))->binding = (v); \
|
((struct symbol *)ptr(s))->binding = (v); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define isconstant(s) ((s)->flags & 0x1)
|
#define isconstant(s) ((s)->flags & 0x1)
|
||||||
#define iskeyword(s) ((s)->flags & 0x2)
|
#define iskeyword(s) ((s)->flags & 0x2)
|
||||||
#define symbol_value(s) (((symbol_t *)ptr(s))->binding)
|
#define symbol_value(s) (((struct symbol *)ptr(s))->binding)
|
||||||
#define ismanaged(v) \
|
#define ismanaged(v) \
|
||||||
((((unsigned char *)ptr(v)) >= fromspace) && \
|
((((unsigned char *)ptr(v)) >= fromspace) && \
|
||||||
(((unsigned char *)ptr(v)) < fromspace + heapsize))
|
(((unsigned char *)ptr(v)) < fromspace + heapsize))
|
||||||
|
@ -157,7 +157,7 @@ int isnumtok_base(char *tok, value_t *pval, int base);
|
||||||
|
|
||||||
/* safe casts */
|
/* safe casts */
|
||||||
struct cons *tocons(value_t v, char *fname);
|
struct cons *tocons(value_t v, char *fname);
|
||||||
symbol_t *tosymbol(value_t v, char *fname);
|
struct symbol *tosymbol(value_t v, char *fname);
|
||||||
fixnum_t tofixnum(value_t v, char *fname);
|
fixnum_t tofixnum(value_t v, char *fname);
|
||||||
char *tostring(value_t v, char *fname);
|
char *tostring(value_t v, char *fname);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ fltype_t *get_type(value_t t)
|
||||||
{
|
{
|
||||||
fltype_t *ft;
|
fltype_t *ft;
|
||||||
if (issymbol(t)) {
|
if (issymbol(t)) {
|
||||||
ft = ((symbol_t *)ptr(t))->type;
|
ft = ((struct symbol *)ptr(t))->type;
|
||||||
if (ft != NULL)
|
if (ft != NULL)
|
||||||
return ft;
|
return ft;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ fltype_t *get_type(value_t t)
|
||||||
ft->type = t;
|
ft->type = t;
|
||||||
if (issymbol(t)) {
|
if (issymbol(t)) {
|
||||||
ft->numtype = sym_to_numtype(t);
|
ft->numtype = sym_to_numtype(t);
|
||||||
((symbol_t *)ptr(t))->type = ft;
|
((struct symbol *)ptr(t))->type = ft;
|
||||||
} else {
|
} else {
|
||||||
ft->numtype = N_NUMTYPES;
|
ft->numtype = N_NUMTYPES;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue