summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/variable.c45
-rw-r--r--src/vm.c8
2 files changed, 47 insertions, 6 deletions
diff --git a/src/variable.c b/src/variable.c
index 36ad24d09..52ffb42e7 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -27,12 +27,21 @@ typedef struct segment {
struct segment *next;
} segment;
+/* Instance variable table structure */
typedef struct iv_tbl {
segment *rootseg;
size_t size;
size_t last_len;
} iv_tbl;
+/*
+ * Creates instance variable table.
+ *
+ * Parameters
+ * mrb
+ * Returns
+ * the instance variable table.
+ */
static iv_tbl*
iv_new(mrb_state *mrb)
{
@@ -47,6 +56,15 @@ iv_new(mrb_state *mrb)
return t;
}
+/*
+ * Set the value for the symbol in the instance variable table.
+ *
+ * Parameters
+ * mrb
+ * t the instance variable table to be set in.
+ * sym the symbol to be used as the key.
+ * val the value to be set.
+ */
static void
iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
{
@@ -59,7 +77,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
while (seg) {
for (i=0; i<MRB_SEGMENT_SIZE; i++) {
mrb_sym key = seg->key[i];
- /* found room in last segment after last_len */
+ /* Found room in last segment after last_len */
if (!seg->next && i >= t->last_len) {
seg->key[i] = sym;
seg->val[i] = val;
@@ -80,7 +98,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
seg = seg->next;
}
- /* not found */
+ /* Not found */
t->size++;
if (matched_seg) {
matched_seg->key[matched_idx] = sym;
@@ -103,6 +121,18 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
return;
}
+/*
+ * Get a value for a symbol from the instance the variable table.
+ *
+ * Parameters
+ * mrb
+ * t the variable table to be searched.
+ * sym the symbol to be used as the key.
+ * vp the value pointer. Recieves the value if if the specified symbol contains
+ * in the instance variable table.
+ * Returns
+ * true if the specfiyed symbol contains in the instance variable table.
+ */
static mrb_bool
iv_get(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
{
@@ -127,6 +157,17 @@ iv_get(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
return FALSE;
}
+/*
+ * Deletes the value for the symbol from the instance variable table.
+ *
+ * Parameters
+ * t the variable table to be searched.
+ * sym the symbol to be used as the key.
+ * vp the value pointer. Recieve the deleted value if the symbol contans
+ * in the instance varible table.
+ * Returns
+ * true if the specfied symbol contains in the instance variable table.
+ */
static mrb_bool
iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
{
diff --git a/src/vm.c b/src/vm.c
index d4e7fd483..c9e80e0ed 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -174,22 +174,22 @@ uvenv(mrb_state *mrb, int up)
struct REnv *e = mrb->c->ci->proc->env;
while (up--) {
- if (!e) return 0;
+ if (!e) return NULL;
e = (struct REnv*)e->c;
}
return e;
}
-static inline int
+static inline mrb_bool
is_strict(mrb_state *mrb, struct REnv *e)
{
int cioff = e->cioff;
if (cioff >= 0 && mrb->c->cibase[cioff].proc &&
MRB_PROC_STRICT_P(mrb->c->cibase[cioff].proc)) {
- return 1;
+ return TRUE;
}
- return 0;
+ return FALSE;
}
static inline struct REnv*