mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
You don't need to keep index in local variables info in irep.
This commit is contained in:
@@ -31,6 +31,13 @@
|
||||
/* exclude floating point numbers */
|
||||
//#define MRB_WITHOUT_FLOAT
|
||||
|
||||
/* stop inlining floating point numbers in mrb_value (effective only with MRB_WORD_BOXING)*/
|
||||
/* floating numbers are rounded to fit in 30 bits (float) and 62 bits respectively, */
|
||||
/* by inlining. If you need full precision of floating numbers on the platform, */
|
||||
/* you have to define this option. when mrb_int is 32bit and mrb_float is double, */
|
||||
/* this option is set automatically. */
|
||||
// #define MRB_NO_FLOAT_INLINE
|
||||
|
||||
/* add -DMRB_NO_METHOD_CACHE to disable method cache to save memory */
|
||||
//#define MRB_NO_METHOD_CACHE
|
||||
/* size of the method cache (need to be the power of 2) */
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#error MRB_INT64 cannot be used with MRB_WORD_BOXING in 32-bit mode.
|
||||
#endif
|
||||
|
||||
#ifndef MRB_WITHOUT_FLOAT
|
||||
#if !defined(MRB_WITHOUT_FLOAT) || defined(MRB_NO_FLOAT_INLINE)
|
||||
struct RFloat {
|
||||
MRB_OBJECT_HEADER;
|
||||
mrb_float f;
|
||||
@@ -64,6 +64,7 @@ enum mrb_special_consts {
|
||||
* undef : ...0001 0100
|
||||
* fixnum: ...IIII III1
|
||||
* symbol: ...SSSS SS10 (use only upper 32-bit as symbol value on 64-bit CPU)
|
||||
* symbol: ...SSSS SS10 (use only upper 32-bit as symbol value on 64-bit CPU)
|
||||
* object: ...PPPP P000 (any bits are 1)
|
||||
*/
|
||||
typedef union mrb_value {
|
||||
|
||||
@@ -39,11 +39,6 @@ typedef struct mrb_pool_value {
|
||||
} u;
|
||||
} mrb_pool_value;
|
||||
|
||||
struct mrb_lvinfo { /* local variable info (name, idx) */
|
||||
mrb_sym name;
|
||||
uint16_t r;
|
||||
};
|
||||
|
||||
/* Program data array struct */
|
||||
typedef struct mrb_irep {
|
||||
uint16_t nlocals; /* Number of local variables */
|
||||
@@ -55,7 +50,7 @@ typedef struct mrb_irep {
|
||||
const mrb_sym *syms;
|
||||
const struct mrb_irep * const *reps;
|
||||
|
||||
const struct mrb_lvinfo *lv;
|
||||
const mrb_sym *lv;
|
||||
/* debug info */
|
||||
struct mrb_irep_debug_info* debug_info;
|
||||
|
||||
|
||||
@@ -677,10 +677,12 @@ search_upvar(codegen_scope *s, mrb_sym id, int *idx)
|
||||
while (u && !MRB_PROC_CFUNC_P(u)) {
|
||||
const struct mrb_irep *ir = u->body.irep;
|
||||
uint_fast16_t n = ir->nlocals;
|
||||
const struct mrb_lvinfo *v = ir->lv;
|
||||
for (; n > 1; n --, v ++) {
|
||||
if (v->name == id) {
|
||||
*idx = v->r;
|
||||
int i;
|
||||
|
||||
const mrb_sym *v = ir->lv;
|
||||
for (i=1; n > 1; n--, v++, i++) {
|
||||
if (*v == id) {
|
||||
*idx = i;
|
||||
return lv - 1;
|
||||
}
|
||||
}
|
||||
@@ -3035,19 +3037,13 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *nlv)
|
||||
s->sp += node_len(nlv)+1; /* add self */
|
||||
s->nlocals = s->sp;
|
||||
if (nlv) {
|
||||
struct mrb_lvinfo *lv;
|
||||
mrb_sym *lv;
|
||||
node *n = nlv;
|
||||
size_t i = 0;
|
||||
|
||||
s->irep->lv = lv = (struct mrb_lvinfo*)mrb_malloc(mrb, sizeof(struct mrb_lvinfo)*(s->nlocals-1));
|
||||
s->irep->lv = lv = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym)*(s->nlocals-1));
|
||||
for (i=0, n=nlv; n; i++,n=n->cdr) {
|
||||
lv[i].name = lv_name(n);
|
||||
if (lv_name(n)) {
|
||||
lv[i].r = lv_idx(s, lv_name(n));
|
||||
}
|
||||
else {
|
||||
lv[i].r = 0;
|
||||
}
|
||||
lv[i] = lv_name(n);
|
||||
}
|
||||
mrb_assert(i + 1 == s->nlocals);
|
||||
}
|
||||
|
||||
@@ -280,10 +280,12 @@ local_var_p(parser_state *p, mrb_sym sym)
|
||||
u = p->upper;
|
||||
while (u && !MRB_PROC_CFUNC_P(u)) {
|
||||
const struct mrb_irep *ir = u->body.irep;
|
||||
uint_fast16_t n = ir->nlocals;
|
||||
const struct mrb_lvinfo *v = ir->lv;
|
||||
for (; v && n > 1; n--, v++) {
|
||||
if (v->name == sym) return TRUE;
|
||||
const mrb_sym *v = ir->lv;
|
||||
int i;
|
||||
|
||||
if (!v) break;
|
||||
for (i=0; i < ir->nlocals; i++) {
|
||||
if (v[i] == sym) return TRUE;
|
||||
}
|
||||
if (MRB_PROC_SCOPE_P(u)) break;
|
||||
u = u->upper;
|
||||
|
||||
+4837
-4655
File diff suppressed because it is too large
Load Diff
@@ -148,8 +148,8 @@ mrb_local_variables(mrb_state *mrb, mrb_value self)
|
||||
irep = proc->body.irep;
|
||||
if (irep->lv) {
|
||||
for (i = 0; i + 1 < irep->nlocals; ++i) {
|
||||
if (irep->lv[i].name) {
|
||||
mrb_sym sym = irep->lv[i].name;
|
||||
if (irep->lv[i]) {
|
||||
mrb_sym sym = irep->lv[i];
|
||||
const char *name = mrb_sym_name(mrb, sym);
|
||||
switch (name[0]) {
|
||||
case '*': case '&':
|
||||
|
||||
@@ -148,8 +148,8 @@ mrb_proc_parameters(mrb_state *mrb, mrb_value self)
|
||||
|
||||
a = mrb_ary_new(mrb);
|
||||
mrb_ary_push(mrb, a, sname);
|
||||
if (i < max && irep->lv[i].name) {
|
||||
mrb_sym sym = irep->lv[i].name;
|
||||
if (i < max && irep->lv[i]) {
|
||||
mrb_sym sym = irep->lv[i];
|
||||
const char *name = mrb_sym_name(mrb, sym);
|
||||
switch (name[0]) {
|
||||
case '*': case '&':
|
||||
|
||||
+4
-13
@@ -9,17 +9,9 @@
|
||||
static void
|
||||
print_r(mrb_state *mrb, const mrb_irep *irep, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (n == 0) return;
|
||||
|
||||
for (i=0; i+1<irep->nlocals; i++) {
|
||||
if (irep->lv[i].r == n) {
|
||||
mrb_sym sym = irep->lv[i].name;
|
||||
printf(" R%d:%s", (int)n, mrb_sym_dump(mrb, sym));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (n > irep->nlocals) return;
|
||||
printf(" R%d:%s", (int)n, mrb_sym_dump(mrb, irep->lv[n-1]));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -82,9 +74,8 @@ codedump(mrb_state *mrb, const mrb_irep *irep)
|
||||
|
||||
printf("local variable names:\n");
|
||||
for (i = 1; i < irep->nlocals; ++i) {
|
||||
char const *s = mrb_sym_dump(mrb, irep->lv[i - 1].name);
|
||||
int n = irep->lv[i - 1].r ? irep->lv[i - 1].r : i;
|
||||
printf(" R%d:%s\n", n, s ? s : "");
|
||||
char const *s = mrb_sym_dump(mrb, irep->lv[i - 1]);
|
||||
printf(" R%d:%s\n", i, s ? s : "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-8
@@ -585,7 +585,7 @@ create_lv_sym_table(mrb_state *mrb, const mrb_irep *irep, mrb_sym **syms, uint32
|
||||
}
|
||||
|
||||
for (i = 0; i + 1 < irep->nlocals; ++i) {
|
||||
mrb_sym const name = irep->lv[i].name;
|
||||
mrb_sym const name = irep->lv[i];
|
||||
if (name == 0) continue;
|
||||
if (find_filename_index(*syms, *syms_len, name) != -1) continue;
|
||||
|
||||
@@ -628,16 +628,14 @@ write_lv_record(mrb_state *mrb, const mrb_irep *irep, uint8_t **start, mrb_sym c
|
||||
int i;
|
||||
|
||||
for (i = 0; i + 1 < irep->nlocals; ++i) {
|
||||
if (irep->lv[i].name == 0) {
|
||||
if (irep->lv[i] == 0) {
|
||||
cur += uint16_to_bin(RITE_LV_NULL_MARK, cur);
|
||||
cur += uint16_to_bin(0, cur);
|
||||
}
|
||||
else {
|
||||
int const sym_idx = find_filename_index(syms, syms_len, irep->lv[i].name);
|
||||
int const sym_idx = find_filename_index(syms, syms_len, irep->lv[i]);
|
||||
mrb_assert(sym_idx != -1); /* local variable name must be in syms */
|
||||
|
||||
cur += uint16_to_bin(sym_idx, cur);
|
||||
cur += uint16_to_bin(irep->lv[i].r, cur);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,7 +654,7 @@ get_lv_record_size(mrb_state *mrb, const mrb_irep *irep)
|
||||
size_t ret = 0;
|
||||
int i;
|
||||
|
||||
ret += (sizeof(uint16_t) + sizeof(uint16_t)) * (irep->nlocals - 1);
|
||||
ret += sizeof(uint16_t) * (irep->nlocals - 1);
|
||||
|
||||
for (i = 0; i < irep->rlen; ++i) {
|
||||
ret += get_lv_record_size(mrb, irep->reps[i]);
|
||||
@@ -1033,9 +1031,9 @@ dump_irep_struct(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, FILE *fp,
|
||||
/* dump lv */
|
||||
if (irep->lv) {
|
||||
len=irep->nlocals;
|
||||
fprintf(fp, "static const struct mrb_lvinfo %s_lv_%d[%d] = {", name, n, len);
|
||||
fprintf(fp, "static const mrb_sym %s_lv_%d[%d] = {", name, n, len);
|
||||
for (i=0; i+1<len; i++) {
|
||||
fprintf(fp, "{%u,%d},\n", irep->lv[i].name, irep->lv[i].r);
|
||||
fprintf(fp, "%u, ", irep->lv[i]);
|
||||
}
|
||||
fputs("};\n", fp);
|
||||
}
|
||||
|
||||
+4
-8
@@ -426,28 +426,24 @@ static int
|
||||
read_lv_record(mrb_state *mrb, const uint8_t *start, mrb_irep *irep, size_t *record_len, mrb_sym const *syms, uint32_t syms_len)
|
||||
{
|
||||
const uint8_t *bin = start;
|
||||
struct mrb_lvinfo *lv;
|
||||
mrb_sym *lv;
|
||||
ptrdiff_t diff;
|
||||
int i;
|
||||
|
||||
irep->lv = lv = (struct mrb_lvinfo*)mrb_malloc(mrb, sizeof(struct mrb_lvinfo) * (irep->nlocals - 1));
|
||||
irep->lv = lv = (mrb_sym*)mrb_malloc(mrb, sizeof(mrb_sym) * (irep->nlocals - 1));
|
||||
|
||||
for (i = 0; i + 1< irep->nlocals; ++i) {
|
||||
uint16_t const sym_idx = bin_to_uint16(bin);
|
||||
bin += sizeof(uint16_t);
|
||||
if (sym_idx == RITE_LV_NULL_MARK) {
|
||||
lv[i].name = 0;
|
||||
lv[i].r = 0;
|
||||
lv[i] = 0;
|
||||
}
|
||||
else {
|
||||
if (sym_idx >= syms_len) {
|
||||
return MRB_DUMP_GENERAL_FAILURE;
|
||||
}
|
||||
lv[i].name = syms[sym_idx];
|
||||
|
||||
lv[i].r = bin_to_uint16(bin);
|
||||
lv[i] = syms[sym_idx];
|
||||
}
|
||||
bin += sizeof(uint16_t);
|
||||
}
|
||||
|
||||
for (i = 0; i < irep->rlen; ++i) {
|
||||
|
||||
Reference in New Issue
Block a user