save all ireps into pic_state
in order to decrease the stress GC will get, restore irep structures under pic_state instead of under each procs and making it collectable object
This commit is contained in:
		
							parent
							
								
									c593a46a62
								
							
						
					
					
						commit
						f6eddbc6d3
					
				| 
						 | 
				
			
			@ -4,6 +4,7 @@
 | 
			
		|||
#define PIC_ARENA_SIZE 100
 | 
			
		||||
#define PIC_HEAP_SIZE 8192
 | 
			
		||||
#define PIC_STACK_SIZE 1024
 | 
			
		||||
#define PIC_IREP_SIZE 256
 | 
			
		||||
 | 
			
		||||
#define DEBUG 1
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,6 +23,9 @@ typedef struct {
 | 
			
		|||
  pic_value sADD, sSUB, sMUL, sDIV;
 | 
			
		||||
  struct pic_env *global_env;
 | 
			
		||||
 | 
			
		||||
  struct pic_irep **irep;
 | 
			
		||||
  size_t ilen, icapa;
 | 
			
		||||
 | 
			
		||||
  struct heap_page *heap;
 | 
			
		||||
  struct pic_object *arena[PIC_ARENA_SIZE];
 | 
			
		||||
  int arena_idx;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,9 +30,6 @@ struct pic_code {
 | 
			
		|||
struct pic_irep {
 | 
			
		||||
  struct pic_code *code;
 | 
			
		||||
  size_t clen, ccapa;
 | 
			
		||||
 | 
			
		||||
  struct pic_irep **proto;
 | 
			
		||||
  size_t plen, pcapa;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -37,6 +37,11 @@ pic_open()
 | 
			
		|||
  pic->heap = (struct heap_page *)malloc(sizeof(struct heap_page));
 | 
			
		||||
  init_heap_page(pic->heap);
 | 
			
		||||
 | 
			
		||||
  /* irep */
 | 
			
		||||
  pic->irep = (struct pic_irep **)malloc(sizeof(struct pic_irep *) * PIC_IREP_SIZE);
 | 
			
		||||
  pic->ilen = 0;
 | 
			
		||||
  pic->icapa = PIC_IREP_SIZE;
 | 
			
		||||
 | 
			
		||||
  /* GC arena */
 | 
			
		||||
  pic->arena_idx = 0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										23
									
								
								src/vm.c
								
								
								
								
							
							
						
						
									
										23
									
								
								src/vm.c
								
								
								
								
							| 
						 | 
				
			
			@ -165,9 +165,6 @@ new_irep(pic_state *pic)
 | 
			
		|||
  irep->code = (struct pic_code *)pic_alloc(pic, sizeof(struct pic_code) * 1024);
 | 
			
		||||
  irep->clen = 0;
 | 
			
		||||
  irep->ccapa = 1024;
 | 
			
		||||
  irep->proto = NULL;
 | 
			
		||||
  irep->plen = irep->pcapa = 0;
 | 
			
		||||
 | 
			
		||||
  return irep;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -218,19 +215,11 @@ pic_gen(pic_state *pic, struct pic_irep *irep, pic_value obj, struct pic_env *en
 | 
			
		|||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    else if (pic_eq_p(pic, proc, sLAMBDA)) {
 | 
			
		||||
      if (irep->proto == NULL) {
 | 
			
		||||
	irep->proto = (struct pic_irep **)pic_alloc(pic, sizeof(struct pic_irep **) * 5);
 | 
			
		||||
	irep->pcapa = 5;
 | 
			
		||||
      }
 | 
			
		||||
      if (irep->plen >= irep->pcapa) {
 | 
			
		||||
	irep->proto = (struct pic_irep **)pic_realloc(pic, irep->proto, irep->pcapa * 2);
 | 
			
		||||
	irep->pcapa *= 2;
 | 
			
		||||
      }
 | 
			
		||||
      irep->code[irep->clen].insn = OP_LAMBDA;
 | 
			
		||||
      irep->code[irep->clen].u.i = irep->plen;
 | 
			
		||||
      irep->code[irep->clen].u.i = pic->ilen;
 | 
			
		||||
      irep->clen++;
 | 
			
		||||
 | 
			
		||||
      irep->proto[irep->plen++] = pic_gen_lambda(pic, obj, env);
 | 
			
		||||
      pic->irep[pic->ilen++] = pic_gen_lambda(pic, obj, env);
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    else if (pic_eq_p(pic, proc, sCONS)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -334,6 +323,12 @@ pic_gen_lambda(pic_state *pic, pic_value obj, struct pic_env *env)
 | 
			
		|||
  irep->code[irep->clen].insn = OP_RET;
 | 
			
		||||
  irep->clen++;
 | 
			
		||||
 | 
			
		||||
#if VM_DEBUG
 | 
			
		||||
  printf("LAMBDA_%d:\n", pic->ilen);
 | 
			
		||||
  print_irep(pic, irep);
 | 
			
		||||
  puts("");
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  return irep;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -430,7 +425,7 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
 | 
			
		|||
 | 
			
		||||
      proc = (struct pic_proc *)pic_obj_alloc(pic, sizeof(struct pic_proc *), PIC_TT_PROC);
 | 
			
		||||
      proc->cfunc_p = false;
 | 
			
		||||
      proc->u.irep = ci->proc->u.irep->proto[pc->u.i];
 | 
			
		||||
      proc->u.irep = pic->irep[pc->u.i];
 | 
			
		||||
      PUSH(pic_obj_value(proc));
 | 
			
		||||
      pic_gc_arena_restore(pic, ai);
 | 
			
		||||
      NEXT;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue