struct pic_record * -> pic_value
This commit is contained in:
parent
da30be167b
commit
73f2578648
|
@ -137,16 +137,21 @@ find_var(pic_state *pic, analyze_scope *scope, pic_value sym)
|
|||
static void
|
||||
define_var(pic_state *pic, analyze_scope *scope, pic_value sym)
|
||||
{
|
||||
if (search_scope(pic, scope, sym)) {
|
||||
if (scope->depth > 0 || pic_weak_has(pic, pic->globals, sym)) {
|
||||
if (scope->depth > 0) {
|
||||
/* local */
|
||||
if (search_scope(pic, scope, sym)) {
|
||||
pic_warnf(pic, "redefining variable: ~s", sym);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
pic_dict_set(pic, scope->locals, sym, pic_true_value(pic));
|
||||
} else {
|
||||
/* global */
|
||||
if (pic_weak_has(pic, pic->globals, sym)) {
|
||||
pic_warnf(pic, "redefining variable: ~s", sym);
|
||||
return;
|
||||
}
|
||||
pic_weak_set(pic, pic->globals, sym, pic_invalid_value());
|
||||
}
|
||||
|
||||
pic_weak_set(pic, pic->globals, sym, pic_invalid_value());
|
||||
|
||||
pic_dict_set(pic, scope->locals, sym, pic_true_value(pic));
|
||||
}
|
||||
|
||||
static pic_value analyze(pic_state *, analyze_scope *, pic_value);
|
||||
|
|
|
@ -146,8 +146,7 @@ struct pic_checkpoint {
|
|||
#define pic_env_ptr(pic, o) ((struct pic_env *)pic_obj_ptr(o))
|
||||
#define pic_port_ptr(pic, o) ((struct pic_port *)pic_obj_ptr(o))
|
||||
#define pic_error_ptr(pic, o) ((struct pic_error *)pic_obj_ptr(o))
|
||||
#define pic_context_ptr(o) ((struct pic_context *)pic_obj_ptr(o))
|
||||
#define pic_rec_ptr(v) ((struct pic_record *)pic_obj_ptr(v))
|
||||
#define pic_rec_ptr(pic, o) ((struct pic_record *)pic_obj_ptr(o))
|
||||
|
||||
#define pic_obj_p(pic,v) (pic_vtype(pic,v) == PIC_IVAL_END)
|
||||
#define pic_env_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ENV)
|
||||
|
@ -175,7 +174,7 @@ pic_value pic_make_proc(pic_state *, pic_func_t, int, pic_value *);
|
|||
pic_value pic_make_proc_irep(pic_state *, struct pic_irep *, struct pic_context *);
|
||||
pic_value pic_make_env(pic_state *, pic_value env);
|
||||
pic_value pic_make_error(pic_state *, const char *type, const char *msg, pic_value irrs);
|
||||
struct pic_record *pic_make_rec(pic_state *, pic_value, pic_value);
|
||||
pic_value pic_make_rec(pic_state *, pic_value type, pic_value datum);
|
||||
|
||||
pic_value pic_add_identifier(pic_state *, pic_value id, pic_value env);
|
||||
pic_value pic_put_identifier(pic_state *, pic_value id, pic_value uid, pic_value env);
|
||||
|
|
|
@ -27,10 +27,11 @@
|
|||
* l pic_value * lambda object
|
||||
* p pic_value * port object
|
||||
* d pic_value * dictionary object
|
||||
* r struct pic_record ** record object
|
||||
* r pic_value * record object
|
||||
*
|
||||
* | optional operator
|
||||
* * int *, pic_value ** variable length operator
|
||||
* * int *, pic_value ** variable length operator
|
||||
* ---- ---- ----
|
||||
*/
|
||||
|
||||
int
|
||||
|
@ -143,11 +144,6 @@ pic_get_args(pic_state *pic, const char *format, ...)
|
|||
VAL_CASE('c', char, char, pic_char(pic, v))
|
||||
VAL_CASE('z', str, const char *, pic_str(pic, v))
|
||||
|
||||
#define PTR_CASE(c, type, ctype) \
|
||||
VAL_CASE(c, type, ctype, pic_## type ##_ptr(v))
|
||||
|
||||
PTR_CASE('r', rec, struct pic_record *)
|
||||
|
||||
#define OBJ_CASE(c, type) VAL_CASE(c, type, pic_value, v)
|
||||
|
||||
OBJ_CASE('m', sym)
|
||||
|
@ -157,6 +153,7 @@ pic_get_args(pic_state *pic, const char *format, ...)
|
|||
OBJ_CASE('v', vec)
|
||||
OBJ_CASE('d', dict)
|
||||
OBJ_CASE('p', port)
|
||||
OBJ_CASE('r', rec)
|
||||
|
||||
default:
|
||||
pic_errorf(pic, "pic_get_args: invalid argument specifier '%c' given", c);
|
||||
|
@ -182,6 +179,9 @@ vm_gref(pic_state *pic, pic_value uid)
|
|||
{
|
||||
pic_value val;
|
||||
|
||||
if (! pic_weak_has(pic, pic->globals, uid)) {
|
||||
pic_errorf(pic, "undefined variable ~s", uid);
|
||||
}
|
||||
val = pic_weak_ref(pic, pic->globals, uid);;
|
||||
if (pic_invalid_p(pic, val)) {
|
||||
pic_errorf(pic, "uninitialized global variable: ~s", uid);
|
||||
|
@ -192,6 +192,9 @@ vm_gref(pic_state *pic, pic_value uid)
|
|||
static void
|
||||
vm_gset(pic_state *pic, pic_value uid, pic_value value)
|
||||
{
|
||||
if (! pic_weak_has(pic, pic->globals, uid)) {
|
||||
pic_errorf(pic, "undefined variable ~s", uid);
|
||||
}
|
||||
pic_weak_set(pic, pic->globals, uid, value);
|
||||
}
|
||||
|
||||
|
@ -904,35 +907,25 @@ pic_define(pic_state *pic, const char *lib, const char *name, pic_value val)
|
|||
pic_value
|
||||
pic_ref(pic_state *pic, const char *lib, const char *name)
|
||||
{
|
||||
pic_value sym, uid, env;
|
||||
pic_value sym, env;
|
||||
|
||||
sym = pic_intern_cstr(pic, name);
|
||||
|
||||
env = pic_library_environment(pic, lib);
|
||||
|
||||
uid = pic_find_identifier(pic, sym, env);
|
||||
if (! pic_weak_has(pic, pic->globals, uid)) {
|
||||
pic_errorf(pic, "symbol \"%s\" not defined in library %s", name, lib);
|
||||
}
|
||||
|
||||
return vm_gref(pic, uid);
|
||||
return vm_gref(pic, pic_find_identifier(pic, sym, env));
|
||||
}
|
||||
|
||||
void
|
||||
pic_set(pic_state *pic, const char *lib, const char *name, pic_value val)
|
||||
{
|
||||
pic_value sym, uid, env;
|
||||
pic_value sym, env;
|
||||
|
||||
sym = pic_intern_cstr(pic, name);
|
||||
|
||||
env = pic_library_environment(pic, lib);
|
||||
|
||||
uid = pic_find_identifier(pic, sym, env);
|
||||
if (! pic_weak_has(pic, pic->globals, uid)) {
|
||||
pic_errorf(pic, "symbol \"%s\" not defined in library %s", name, lib);
|
||||
}
|
||||
|
||||
vm_gset(pic, uid, val);
|
||||
vm_gset(pic, pic_find_identifier(pic, sym, env), val);
|
||||
}
|
||||
|
||||
pic_value
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "picrin.h"
|
||||
#include "picrin/object.h"
|
||||
|
||||
struct pic_record *
|
||||
pic_value
|
||||
pic_make_rec(pic_state *pic, pic_value type, pic_value datum)
|
||||
{
|
||||
struct pic_record *rec;
|
||||
|
@ -14,7 +14,7 @@ pic_make_rec(pic_state *pic, pic_value type, pic_value datum)
|
|||
rec->type = type;
|
||||
rec->datum = datum;
|
||||
|
||||
return rec;
|
||||
return pic_obj_value(rec);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
@ -24,7 +24,7 @@ pic_rec_make_record(pic_state *pic)
|
|||
|
||||
pic_get_args(pic, "oo", &type, &datum);
|
||||
|
||||
return pic_obj_value(pic_make_rec(pic, type, datum));
|
||||
return pic_make_rec(pic, type, datum);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
@ -40,21 +40,21 @@ pic_rec_record_p(pic_state *pic)
|
|||
static pic_value
|
||||
pic_rec_record_type(pic_state *pic)
|
||||
{
|
||||
struct pic_record *rec;
|
||||
pic_value rec;
|
||||
|
||||
pic_get_args(pic, "r", &rec);
|
||||
|
||||
return rec->type;
|
||||
return pic_rec_ptr(pic, rec)->type;
|
||||
}
|
||||
|
||||
static pic_value
|
||||
pic_rec_record_datum(pic_state *pic)
|
||||
{
|
||||
struct pic_record *rec;
|
||||
pic_value rec;
|
||||
|
||||
pic_get_args(pic, "r", &rec);
|
||||
|
||||
return rec->datum;
|
||||
return pic_rec_ptr(pic, rec)->datum;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue