change pic_find_rename API
This commit is contained in:
parent
8b17e70a43
commit
c10f40acd4
|
@ -42,7 +42,7 @@ struct pic_senv *pic_minimal_syntactic_env(pic_state *);
|
||||||
struct pic_senv *pic_core_syntactic_env(pic_state *);
|
struct pic_senv *pic_core_syntactic_env(pic_state *);
|
||||||
|
|
||||||
pic_sym pic_add_rename(pic_state *, struct pic_senv *, pic_sym);
|
pic_sym pic_add_rename(pic_state *, struct pic_senv *, pic_sym);
|
||||||
pic_sym pic_find_rename(pic_state *, struct pic_senv *, pic_sym); /* may return 0! */
|
bool pic_find_rename(pic_state *, struct pic_senv *, pic_sym, pic_sym * /* = NULL */);
|
||||||
void pic_put_rename(pic_state *, struct pic_senv *, pic_sym, pic_sym);
|
void pic_put_rename(pic_state *, struct pic_senv *, pic_sym, pic_sym);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
|
|
@ -51,7 +51,7 @@ static void pop_scope(analyze_state *);
|
||||||
#define register_renamed_symbol(pic, state, slot, lib, id) do { \
|
#define register_renamed_symbol(pic, state, slot, lib, id) do { \
|
||||||
pic_sym sym, gsym; \
|
pic_sym sym, gsym; \
|
||||||
sym = pic_intern_cstr(pic, id); \
|
sym = pic_intern_cstr(pic, id); \
|
||||||
if ((gsym = pic_find_rename(pic, lib->senv, sym)) == 0) { \
|
if (! pic_find_rename(pic, lib->senv, sym, &gsym)) { \
|
||||||
pic_error(pic, "internal error! native VM procedure not found"); \
|
pic_error(pic, "internal error! native VM procedure not found"); \
|
||||||
} \
|
} \
|
||||||
state->slot = gsym; \
|
state->slot = gsym; \
|
||||||
|
|
24
src/macro.c
24
src/macro.c
|
@ -28,17 +28,20 @@ pic_put_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym renam
|
||||||
xh_put(&senv->renames, sym, &rename);
|
xh_put(&senv->renames, sym, &rename);
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_sym
|
bool
|
||||||
pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym)
|
pic_find_rename(pic_state *pic, struct pic_senv *senv, pic_sym sym, pic_sym *rename)
|
||||||
{
|
{
|
||||||
xh_entry *e;
|
xh_entry *e;
|
||||||
|
|
||||||
UNUSED(pic);
|
UNUSED(pic);
|
||||||
|
|
||||||
if ((e = xh_get(&senv->renames, sym)) == NULL) {
|
if ((e = xh_get(&senv->renames, sym)) == NULL) {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
return xh_val(e, pic_sym);
|
if (rename != NULL) {
|
||||||
|
*rename = xh_val(e, pic_sym);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value macroexpand(pic_state *, pic_value, struct pic_senv *);
|
static pic_value macroexpand(pic_state *, pic_value, struct pic_senv *);
|
||||||
|
@ -160,8 +163,7 @@ pic_export(pic_state *pic, pic_sym sym)
|
||||||
{
|
{
|
||||||
pic_sym rename;
|
pic_sym rename;
|
||||||
|
|
||||||
rename = pic_find_rename(pic, pic->lib->senv, sym);
|
if (! pic_find_rename(pic, pic->lib->senv, sym, &rename)) {
|
||||||
if (rename == 0) {
|
|
||||||
pic_errorf(pic, "export: symbol not defined %s", pic_symbol_name(pic, sym));
|
pic_errorf(pic, "export: symbol not defined %s", pic_symbol_name(pic, sym));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +201,7 @@ symbol_rename(pic_state *pic, pic_sym sym, struct pic_senv *senv)
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
if ((rename = pic_find_rename(pic, senv, sym)) != 0) {
|
if (pic_find_rename(pic, senv, sym, &rename)) {
|
||||||
return rename;
|
return rename;
|
||||||
}
|
}
|
||||||
if (! senv->up)
|
if (! senv->up)
|
||||||
|
@ -318,7 +320,7 @@ macroexpand_node(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
||||||
pic_error(pic, "binding to non-symbol object");
|
pic_error(pic, "binding to non-symbol object");
|
||||||
}
|
}
|
||||||
sym = pic_sym(var);
|
sym = pic_sym(var);
|
||||||
if ((rename = pic_find_rename(pic, senv, sym)) == 0) {
|
if (! pic_find_rename(pic, senv, sym, &rename)) {
|
||||||
rename = pic_add_rename(pic, senv, sym);
|
rename = pic_add_rename(pic, senv, sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +369,7 @@ macroexpand_node(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
||||||
pic_error(pic, "syntax error");
|
pic_error(pic, "syntax error");
|
||||||
}
|
}
|
||||||
sym = pic_sym(var);
|
sym = pic_sym(var);
|
||||||
if ((rename = pic_find_rename(pic, senv, sym)) == 0) {
|
if (! pic_find_rename(pic, senv, sym, &rename)) {
|
||||||
rename = pic_add_rename(pic, senv, sym);
|
rename = pic_add_rename(pic, senv, sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,7 +420,7 @@ macroexpand_node(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
||||||
pic_error(pic, "binding to non-symbol object");
|
pic_error(pic, "binding to non-symbol object");
|
||||||
}
|
}
|
||||||
sym = pic_sym(a);
|
sym = pic_sym(a);
|
||||||
if (pic_find_rename(pic, senv, sym) == 0) {
|
if (! pic_find_rename(pic, senv, sym, NULL)) {
|
||||||
pic_add_rename(pic, senv, sym);
|
pic_add_rename(pic, senv, sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +438,7 @@ macroexpand_node(pic_state *pic, pic_value expr, struct pic_senv *senv)
|
||||||
pic_error(pic, "binding to non-symbol object");
|
pic_error(pic, "binding to non-symbol object");
|
||||||
}
|
}
|
||||||
sym = pic_sym(formals);
|
sym = pic_sym(formals);
|
||||||
if (pic_find_rename(pic, senv, sym) == 0) {
|
if (! pic_find_rename(pic, senv, sym, NULL)) {
|
||||||
pic_add_rename(pic, senv, sym);
|
pic_add_rename(pic, senv, sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
src/vm.c
2
src/vm.c
|
@ -336,7 +336,7 @@ global_ref(pic_state *pic, const char *name)
|
||||||
pic_sym sym, rename;
|
pic_sym sym, rename;
|
||||||
|
|
||||||
sym = pic_intern_cstr(pic, name);
|
sym = pic_intern_cstr(pic, name);
|
||||||
if ((rename = pic_find_rename(pic, pic->lib->senv, sym)) == 0) {
|
if (! pic_find_rename(pic, pic->lib->senv, sym, &rename)) {
|
||||||
return SIZE_MAX;
|
return SIZE_MAX;
|
||||||
}
|
}
|
||||||
if (! (e = xh_get(&pic->global_tbl, rename))) {
|
if (! (e = xh_get(&pic->global_tbl, rename))) {
|
||||||
|
|
Loading…
Reference in New Issue