Merge branch 'master' into record-vector-optimization

This commit is contained in:
Doug Currie 2016-02-08 11:59:32 -05:00
commit f213119dd6
3 changed files with 22 additions and 28 deletions

View File

@ -364,7 +364,7 @@ typedef struct codegen_context {
pic_code *code; pic_code *code;
size_t clen, ccapa; size_t clen, ccapa;
/* child ireps */ /* child ireps */
union irep_node *irep; struct pic_irep **irep;
size_t ilen, icapa; size_t ilen, icapa;
/* constant object pool */ /* constant object pool */
int *ints; int *ints;
@ -393,7 +393,7 @@ codegen_context_init(pic_state *pic, codegen_context *cxt, codegen_context *up,
cxt->clen = 0; cxt->clen = 0;
cxt->ccapa = PIC_ISEQ_SIZE; cxt->ccapa = PIC_ISEQ_SIZE;
cxt->irep = pic_calloc(pic, PIC_IREP_SIZE, sizeof(union irep_node)); cxt->irep = pic_calloc(pic, PIC_IREP_SIZE, sizeof(struct pic_irep *));
cxt->ilen = 0; cxt->ilen = 0;
cxt->icapa = PIC_IREP_SIZE; cxt->icapa = PIC_IREP_SIZE;
@ -424,10 +424,10 @@ codegen_context_destroy(pic_state *pic, codegen_context *cxt)
irep->argc = (int)cxt->args->len + 1; irep->argc = (int)cxt->args->len + 1;
irep->localc = (int)cxt->locals->len; irep->localc = (int)cxt->locals->len;
irep->capturec = (int)cxt->captures->len; irep->capturec = (int)cxt->captures->len;
irep->u.s.code = pic_realloc(pic, cxt->code, sizeof(pic_code) * cxt->clen); irep->code = pic_realloc(pic, cxt->code, sizeof(pic_code) * cxt->clen);
irep->u.s.irep = pic_realloc(pic, cxt->irep, sizeof(union irep_node) * cxt->ilen); irep->irep = pic_realloc(pic, cxt->irep, sizeof(struct pic_irep *) * cxt->ilen);
irep->u.s.ints = pic_realloc(pic, cxt->ints, sizeof(int) * cxt->klen); irep->ints = pic_realloc(pic, cxt->ints, sizeof(int) * cxt->klen);
irep->u.s.nums = pic_realloc(pic, cxt->nums, sizeof(double) * cxt->flen); irep->nums = pic_realloc(pic, cxt->nums, sizeof(double) * cxt->flen);
irep->pool = pic_realloc(pic, cxt->pool, sizeof(struct pic_object *) * cxt->plen); irep->pool = pic_realloc(pic, cxt->pool, sizeof(struct pic_object *) * cxt->plen);
irep->ncode = cxt->clen; irep->ncode = cxt->clen;
irep->nirep = cxt->ilen; irep->nirep = cxt->ilen;
@ -647,7 +647,7 @@ codegen_lambda(pic_state *pic, codegen_context *cxt, pic_value obj, bool tailpos
/* emit irep */ /* emit irep */
codegen_context_init(pic, inner_cxt, cxt, rest, args, locals, captures); codegen_context_init(pic, inner_cxt, cxt, rest, args, locals, captures);
codegen(pic, inner_cxt, body, true); codegen(pic, inner_cxt, body, true);
cxt->irep[cxt->ilen].i = codegen_context_destroy(pic, inner_cxt); cxt->irep[cxt->ilen] = codegen_context_destroy(pic, inner_cxt);
/* emit OP_LAMBDA */ /* emit OP_LAMBDA */
emit_i(pic, cxt, OP_LAMBDA, cxt->ilen++); emit_i(pic, cxt, OP_LAMBDA, cxt->ilen++);

View File

@ -24,17 +24,11 @@ struct pic_irep {
unsigned refc; unsigned refc;
int argc, localc, capturec; int argc, localc, capturec;
bool varg; bool varg;
union { pic_code *code;
struct { struct pic_irep **irep;
pic_code *code; int *ints;
int *ints; double *nums;
double *nums; struct pic_object **pool;
union irep_node {
struct pic_irep *i;
} *irep;
} s;
} u;
struct pic_object **pool; /* pool of heap objects */
size_t ncode, nirep, nints, nnums, npool; size_t ncode, nirep, nints, nnums, npool;
}; };

View File

@ -392,15 +392,15 @@ pic_apply(pic_state *pic, struct pic_proc *proc, int argc, pic_value *argv)
NEXT; NEXT;
} }
CASE(OP_PUSHINT) { CASE(OP_PUSHINT) {
PUSH(pic_int_value(pic->ci->irep->u.s.ints[c.a])); PUSH(pic_int_value(pic->ci->irep->ints[c.a]));
NEXT; NEXT;
} }
CASE(OP_PUSHFLOAT) { CASE(OP_PUSHFLOAT) {
PUSH(pic_float_value(pic->ci->irep->u.s.nums[c.a])); PUSH(pic_float_value(pic->ci->irep->nums[c.a]));
NEXT; NEXT;
} }
CASE(OP_PUSHCHAR) { CASE(OP_PUSHCHAR) {
PUSH(pic_char_value(pic->ci->irep->u.s.ints[c.a])); PUSH(pic_char_value(pic->ci->irep->ints[c.a]));
NEXT; NEXT;
} }
CASE(OP_PUSHEOF) { CASE(OP_PUSHEOF) {
@ -560,7 +560,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, int argc, pic_value *argv)
ci->regc = irep->capturec; ci->regc = irep->capturec;
ci->regs = ci->fp + irep->argc + irep->localc; ci->regs = ci->fp + irep->argc + irep->localc;
pic->ip = irep->u.s.code; pic->ip = irep->code;
pic_gc_arena_restore(pic, ai); pic_gc_arena_restore(pic, ai);
JUMP; JUMP;
} }
@ -622,7 +622,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, int argc, pic_value *argv)
vm_push_cxt(pic); vm_push_cxt(pic);
} }
proc = pic_make_proc_irep(pic, pic->ci->irep->u.s.irep[c.a].i, pic->ci->cxt); proc = pic_make_proc_irep(pic, pic->ci->irep->irep[c.a], pic->ci->cxt);
PUSH(pic_obj_value(proc)); PUSH(pic_obj_value(proc));
pic_gc_arena_restore(pic, ai); pic_gc_arena_restore(pic, ai);
NEXT; NEXT;
@ -1032,9 +1032,9 @@ pic_irep_decref(pic_state *pic, struct pic_irep *irep)
size_t i; size_t i;
if (--irep->refc == 0) { if (--irep->refc == 0) {
pic_free(pic, irep->u.s.code); pic_free(pic, irep->code);
pic_free(pic, irep->u.s.ints); pic_free(pic, irep->ints);
pic_free(pic, irep->u.s.nums); pic_free(pic, irep->nums);
pic_free(pic, irep->pool); pic_free(pic, irep->pool);
/* unchain before decref children ireps */ /* unchain before decref children ireps */
@ -1042,9 +1042,9 @@ pic_irep_decref(pic_state *pic, struct pic_irep *irep)
irep->list.next->prev = irep->list.prev; irep->list.next->prev = irep->list.prev;
for (i = 0; i < irep->nirep; ++i) { for (i = 0; i < irep->nirep; ++i) {
pic_irep_decref(pic, irep->u.s.irep[i].i); pic_irep_decref(pic, irep->irep[i]);
} }
pic_free(pic, irep->u.s.irep); pic_free(pic, irep->irep);
pic_free(pic, irep); pic_free(pic, irep);
} }
} }