add pic_intern_(str|cstr|lit)
This commit is contained in:
parent
b3d5b1eea5
commit
c7f8293368
|
@ -11,7 +11,7 @@ file_error(pic_state *pic, const char *msg)
|
|||
{
|
||||
struct pic_error *e;
|
||||
|
||||
e = pic_make_error(pic, pic_intern(pic, "file"), msg, pic_nil_value());
|
||||
e = pic_make_error(pic, pic_intern_lit(pic, "file"), msg, pic_nil_value());
|
||||
|
||||
pic_raise(pic, pic_obj_value(e));
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ pic_print_backtrace(pic_state *pic, xFILE *file)
|
|||
pic_value elem, it;
|
||||
|
||||
e = pic_error_ptr(pic->err);
|
||||
if (e->type != pic_intern(pic, "")) {
|
||||
if (e->type != pic_intern_lit(pic, "")) {
|
||||
pic_fwrite(pic, pic_obj_value(e->type), file);
|
||||
xfprintf(pic, file, " ");
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ pic_error(pic_state *pic, const char *msg, pic_value irrs)
|
|||
{
|
||||
struct pic_error *e;
|
||||
|
||||
e = pic_make_error(pic, pic_intern(pic, ""), msg, irrs);
|
||||
e = pic_make_error(pic, pic_intern_lit(pic, ""), msg, irrs);
|
||||
|
||||
pic_raise(pic, pic_obj_value(e));
|
||||
}
|
||||
|
|
|
@ -160,10 +160,10 @@ define_var(pic_state *pic, analyze_scope *scope, pic_sym *sym)
|
|||
static pic_value analyze(pic_state *, analyze_scope *, pic_value);
|
||||
static pic_value analyze_lambda(pic_state *, analyze_scope *, pic_value);
|
||||
|
||||
#define GREF pic_intern(pic, "gref")
|
||||
#define LREF pic_intern(pic, "lref")
|
||||
#define CREF pic_intern(pic, "cref")
|
||||
#define CALL pic_intern(pic, "call")
|
||||
#define GREF pic_intern_lit(pic, "gref")
|
||||
#define LREF pic_intern_lit(pic, "lref")
|
||||
#define CREF pic_intern_lit(pic, "cref")
|
||||
#define CALL pic_intern_lit(pic, "call")
|
||||
|
||||
static pic_value
|
||||
analyze_var(pic_state *pic, analyze_scope *scope, pic_sym *sym)
|
||||
|
|
|
@ -29,8 +29,10 @@ struct pic_id {
|
|||
#define pic_id_p(v) (pic_type(v) == PIC_TT_ID || pic_type(v) == PIC_TT_SYMBOL)
|
||||
#define pic_id_ptr(v) ((pic_id *)pic_ptr(v))
|
||||
|
||||
pic_sym *pic_intern(pic_state *, const char *);
|
||||
pic_sym *pic_intern_str(pic_state *, pic_str *);
|
||||
pic_sym *pic_intern(pic_state *, pic_str *);
|
||||
#define pic_intern_str(pic,s,i) pic_intern(pic, pic_make_str(pic, (s), (i)))
|
||||
#define pic_intern_cstr(pic,s) pic_intern(pic, pic_make_cstr(pic, (s)))
|
||||
#define pic_intern_lit(pic,lit) pic_intern(pic, pic_make_lit(pic, lit))
|
||||
|
||||
pic_id *pic_make_identifier(pic_state *, pic_id *, struct pic_env *);
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ pic_add_identifier(pic_state *pic, pic_id *id, struct pic_env *env)
|
|||
} else {
|
||||
str = pic_format(pic, ".%s.%d", name, pic->ucnt++);
|
||||
}
|
||||
uid = pic_intern_str(pic, str);
|
||||
uid = pic_intern(pic, str);
|
||||
|
||||
return pic_put_identifier(pic, id, uid, env);
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ file_error(pic_state *pic, const char *msg)
|
|||
{
|
||||
struct pic_error *e;
|
||||
|
||||
e = pic_make_error(pic, pic_intern(pic, "file"), msg, pic_nil_value());
|
||||
e = pic_make_error(pic, pic_intern_lit(pic, "file"), msg, pic_nil_value());
|
||||
|
||||
pic_raise(pic, pic_obj_value(e));
|
||||
}
|
||||
|
|
|
@ -904,7 +904,7 @@ pic_define_(pic_state *pic, const char *name, pic_value val)
|
|||
{
|
||||
pic_sym *sym, *uid;
|
||||
|
||||
sym = pic_intern(pic, name);
|
||||
sym = pic_intern_cstr(pic, name);
|
||||
|
||||
if ((uid = pic_find_identifier(pic, (pic_id *)sym, pic->lib->env)) == NULL) {
|
||||
uid = pic_add_identifier(pic, (pic_id *)sym, pic->lib->env);
|
||||
|
@ -921,7 +921,7 @@ void
|
|||
pic_define(pic_state *pic, const char *name, pic_value val)
|
||||
{
|
||||
pic_define_(pic, name, val);
|
||||
pic_export(pic, pic_intern(pic, name));
|
||||
pic_export(pic, pic_intern_cstr(pic, name));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -934,7 +934,7 @@ void
|
|||
pic_defun(pic_state *pic, const char *name, pic_func_t cfunc)
|
||||
{
|
||||
pic_defun_(pic, name, cfunc);
|
||||
pic_export(pic, pic_intern(pic, name));
|
||||
pic_export(pic, pic_intern_cstr(pic, name));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -947,7 +947,7 @@ void
|
|||
pic_defvar(pic_state *pic, const char *name, pic_value init, struct pic_proc *conv)
|
||||
{
|
||||
pic_defvar_(pic, name, init, conv);
|
||||
pic_export(pic, pic_intern(pic, name));
|
||||
pic_export(pic, pic_intern_cstr(pic, name));
|
||||
}
|
||||
|
||||
pic_value
|
||||
|
@ -955,7 +955,7 @@ pic_ref(pic_state *pic, struct pic_lib *lib, const char *name)
|
|||
{
|
||||
pic_sym *sym, *uid;
|
||||
|
||||
sym = pic_intern(pic, name);
|
||||
sym = pic_intern_cstr(pic, name);
|
||||
|
||||
if ((uid = pic_find_identifier(pic, (pic_id *)sym, lib->env)) == NULL) {
|
||||
pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name);
|
||||
|
@ -969,7 +969,7 @@ pic_set(pic_state *pic, struct pic_lib *lib, const char *name, pic_value val)
|
|||
{
|
||||
pic_sym *sym, *uid;
|
||||
|
||||
sym = pic_intern(pic, name);
|
||||
sym = pic_intern_cstr(pic, name);
|
||||
|
||||
if ((uid = pic_find_identifier(pic, (pic_id *)sym, lib->env)) == NULL) {
|
||||
pic_errorf(pic, "symbol \"%s\" not defined in library ~s", name, lib->name);
|
||||
|
@ -1088,19 +1088,19 @@ pic_proc_env(pic_state *pic, struct pic_proc *proc)
|
|||
bool
|
||||
pic_proc_env_has(pic_state *pic, struct pic_proc *proc, const char *key)
|
||||
{
|
||||
return pic_dict_has(pic, pic_proc_env(pic, proc), pic_intern(pic, key));
|
||||
return pic_dict_has(pic, pic_proc_env(pic, proc), pic_intern_cstr(pic, key));
|
||||
}
|
||||
|
||||
pic_value
|
||||
pic_proc_env_ref(pic_state *pic, struct pic_proc *proc, const char *key)
|
||||
{
|
||||
return pic_dict_ref(pic, pic_proc_env(pic, proc), pic_intern(pic, key));
|
||||
return pic_dict_ref(pic, pic_proc_env(pic, proc), pic_intern_cstr(pic, key));
|
||||
}
|
||||
|
||||
void
|
||||
pic_proc_env_set(pic_state *pic, struct pic_proc *proc, const char *key, pic_value val)
|
||||
{
|
||||
pic_dict_set(pic, pic_proc_env(pic, proc), pic_intern(pic, key), val);
|
||||
pic_dict_set(pic, pic_proc_env(pic, proc), pic_intern_cstr(pic, key), val);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
|
|
@ -14,7 +14,7 @@ read_error(pic_state *pic, const char *msg, pic_value irritant)
|
|||
{
|
||||
struct pic_error *e;
|
||||
|
||||
e = pic_make_error(pic, pic_intern(pic, "read"), msg, irritant);
|
||||
e = pic_make_error(pic, pic_intern_lit(pic, "read"), msg, irritant);
|
||||
|
||||
pic_raise(pic, pic_obj_value(e));
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ read_symbol(pic_state *pic, struct pic_port *port, int c)
|
|||
buf[len] = 0;
|
||||
}
|
||||
|
||||
sym = pic_intern(pic, buf);
|
||||
sym = pic_intern_cstr(pic, buf);
|
||||
pic_free(pic, buf);
|
||||
|
||||
return pic_obj_value(sym);
|
||||
|
@ -487,7 +487,7 @@ read_pipe(pic_state *pic, struct pic_port *port, int c)
|
|||
}
|
||||
buf[cnt] = '\0';
|
||||
|
||||
sym = pic_intern(pic, buf);
|
||||
sym = pic_intern_cstr(pic, buf);
|
||||
pic_free(pic, buf);
|
||||
|
||||
return pic_obj_value(sym);
|
||||
|
|
|
@ -15,7 +15,7 @@ pic_set_argv(pic_state *pic, int argc, char *argv[], char **envp)
|
|||
void
|
||||
pic_add_feature(pic_state *pic, const char *feature)
|
||||
{
|
||||
pic_push(pic, pic_obj_value(pic_intern(pic, feature)), pic->features);
|
||||
pic_push(pic, pic_obj_value(pic_intern_cstr(pic, feature)), pic->features);
|
||||
}
|
||||
|
||||
void pic_init_bool(pic_state *);
|
||||
|
@ -109,14 +109,14 @@ pic_features(pic_state *pic)
|
|||
|
||||
#define import_builtin_syntax(name) do { \
|
||||
pic_sym *nick, *real; \
|
||||
nick = pic_intern(pic, "builtin:" name); \
|
||||
real = pic_intern(pic, name); \
|
||||
nick = pic_intern_lit(pic, "builtin:" name); \
|
||||
real = pic_intern_lit(pic, name); \
|
||||
pic_put_identifier(pic, (pic_id *)nick, real, pic->lib->env); \
|
||||
} while (0)
|
||||
|
||||
#define declare_vm_procedure(name) do { \
|
||||
pic_sym *sym; \
|
||||
sym = pic_intern(pic, name); \
|
||||
sym = pic_intern_lit(pic, name); \
|
||||
pic_put_identifier(pic, (pic_id *)sym, sym, pic->lib->env); \
|
||||
} while (0)
|
||||
|
||||
|
@ -301,7 +301,7 @@ pic_open(pic_allocf allocf, void *userdata)
|
|||
|
||||
ai = pic_gc_arena_preserve(pic);
|
||||
|
||||
#define S(slot,name) pic->slot = pic_intern(pic, name)
|
||||
#define S(slot,name) pic->slot = pic_intern_lit(pic, name)
|
||||
|
||||
S(sDEFINE, "define");
|
||||
S(sDEFINE_MACRO, "define-macro");
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
KHASH_DEFINE(s, pic_str *, pic_sym *, kh_pic_str_hash, kh_pic_str_cmp)
|
||||
|
||||
pic_sym *
|
||||
pic_intern_str(pic_state *pic, pic_str *str)
|
||||
pic_intern(pic_state *pic, pic_str *str)
|
||||
{
|
||||
khash_t(s) *h = &pic->syms;
|
||||
pic_sym *sym;
|
||||
|
@ -31,12 +31,6 @@ pic_intern_str(pic_state *pic, pic_str *str)
|
|||
return sym;
|
||||
}
|
||||
|
||||
pic_sym *
|
||||
pic_intern(pic_state *pic, const char *cstr)
|
||||
{
|
||||
return pic_intern_str(pic, pic_make_cstr(pic, cstr));
|
||||
}
|
||||
|
||||
pic_id *
|
||||
pic_make_identifier(pic_state *pic, pic_id *id, struct pic_env *env)
|
||||
{
|
||||
|
@ -110,7 +104,7 @@ pic_symbol_string_to_symbol(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "s", &str);
|
||||
|
||||
return pic_obj_value(pic_intern_str(pic, str));
|
||||
return pic_obj_value(pic_intern(pic, str));
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
|
Loading…
Reference in New Issue