New update to BEAM engine.

BEAM now uses YAP Indexing (JITI)


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1575 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
rslopes 2006-03-24 16:19:31 +00:00
parent 3241452d64
commit 8947654162
7 changed files with 1273 additions and 1235 deletions

View File

@ -21,7 +21,6 @@
128 -> show EAM abstrac machine code
*/
#define Variavel 1
#define Lista 2
#define Estrutura 4
@ -192,3 +191,105 @@ struct AND_BOX {
#define CUT 32 /* Greater than 32 always cut */
/**********************************************************************************/
struct EAM_TEMP {
struct EAM_TEMP *previous;
struct EAM_TEMP *next;
};
struct EAM_Global {
Cell *pc;
Cell *_H;
Cell *_S;
short _Mode; /* read or write mode */
short ES; /* goal shoud do Eager Split yes or no ? */
short MemGoing; /* Direction the that stacks use to grow */
Cell *varlocals; /* local vars to the working AND-BOX */
struct AND_BOX *ABX; /* working AND-BOX */
struct OR_BOX *OBX; /* working OR-BOX */
struct SUSPENSIONS *su; /* list with suspended work */
struct AND_BOX *top;
struct status_and *USE_SAME_ANDBOX; /* when only 1 alternative */
struct status_or *nr_alternative; /* working alternative */
struct status_and *nr_call; /* working goal */
Cell *VAR_TRAIL;
int VAR_TRAIL_NR;
int Mem_FULL; /* if mem_full, then perform GC */
int nr_call_forking; /* number of splits already performed */
unsigned long START_ADDR_HEAP, START_ADDR_BOXES, END_BOX, END_H;
unsigned int nr_gc_heap;
unsigned int nr_gc_boxed;
Cell **IndexFree;
Cell *NextFree;
Cell *sp;
struct PERM_VAR *NextVar;
#if Memory_Stat
unsigned long TOTAL_MEM, MEM_REUSED, TOTAL_TEMPS,TEMPS_REUSED, TOTAL_PERMS, PERMS_REUSED;
unsigned long Memory_STAT[5000][5];
#endif
};
#define beam_X XREGS /* use the same X-Regs as YAP */
#define beam_pc (eamGlobal->pc)
#define beam_H (eamGlobal->_H)
#define beam_S (eamGlobal->_S)
#define beam_Mode (eamGlobal->_Mode)
#define beam_ES (eamGlobal->ES)
#define beam_MemGoing (eamGlobal->MemGoing)
#define beam_varlocals (eamGlobal->varlocals)
#define beam_ABX (eamGlobal->ABX)
#define beam_OBX (eamGlobal->OBX)
#define beam_su (eamGlobal->su)
#define beam_top (eamGlobal->top)
#define beam_USE_SAME_ANDBOX (eamGlobal->USE_SAME_ANDBOX)
#define beam_nr_alternative (eamGlobal->nr_alternative)
#define beam_nr_call (eamGlobal->nr_call)
#define beam_VAR_TRAIL (eamGlobal->VAR_TRAIL)
#define beam_VAR_TRAIL_NR (eamGlobal->VAR_TRAIL_NR)
#define beam_Mem_FULL (eamGlobal->Mem_FULL)
#define beam_nr_call_forking (eamGlobal->nr_call_forking)
#define beam_START_ADDR_HEAP (eamGlobal->START_ADDR_HEAP)
#define beam_START_ADDR_BOXES (eamGlobal->START_ADDR_BOXES)
#define beam_END_BOX (eamGlobal->END_BOX)
#define beam_END_H (eamGlobal->END_H)
#define beam_nr_gc_heap (eamGlobal->nr_gc_heap)
#define beam_nr_gc_boxed (eamGlobal->nr_gc_boxed)
#define beam_IndexFree (eamGlobal->IndexFree)
#define beam_NextFree (eamGlobal->NextFree)
#define beam_sp (eamGlobal->sp)
#define beam_NextVar (eamGlobal->NextVar)
#if Memory_Stat
#define beam_TOTAL_MEM (eamGlobal->TOTAL_MEM)
#define beam_MEM_REUSED (eamGlobal->MEM_REUSED)
#define beam_TOTAL_TEMPS (eamGlobal->TOTAL_TEMPS)
#define beam_TEMPS_REUSED (eamGlobal->TEMPS_REUSED)
#define beam_TOTAL_PERMS (eamGlobal->TOTAL_PERMS)
#define beam_PERMS_REUSED (eamGlobal->PERMS_REUSED)
#define beam_Memory_STAT (eamGlobal->Memory_STAT)
#endif
#define arg1 *(beam_pc+1)
#define arg2 *(beam_pc+2)
#define arg3 *(beam_pc+3)
#define arg4 *(beam_pc+4)
#define CELL_SIZE (sizeof(Cell))
#define POINTER_SIZE (sizeof(Cell *))
#define ANDBOX_SIZE (sizeof(struct AND_BOX))
#define ORBOX_SIZE (sizeof(struct OR_BOX))
#define PERM_VAR_SIZE (sizeof(struct PERM_VAR))
#define EXTERNAL_VAR_SIZE (sizeof(struct EXTERNAL_VAR))
#define SUSPENSIONS_SIZE (sizeof(struct SUSPENSIONS))
#define SUSPENSIONS_VAR_SIZE (sizeof(struct SUSPENSIONS_VAR))
#define STATUS_AND_SIZE (sizeof(struct status_and))
#define STATUS_OR_SIZE (sizeof(struct status_or))

File diff suppressed because it is too large Load Diff

View File

@ -57,8 +57,8 @@ Cell OldC,OldH;
OldC=deref((Cell) c);
/*
if (MEM_Going==1 && ((unsigned long) OldC) <START_ADDR_HEAP+MEM_H/2) return(OldC);
if (MEM_Going==-1 && ((unsigned long) OldC)>=START_ADDR_HEAP+MEM_H/2 && ((unsigned long) OldC) <START_ADDR_BOXES) return(OldC);
if (beam_MemGoing==1 && ((unsigned long) OldC) <beam_START_ADDR_HEAP+beam_MEM_H/2) return(OldC);
if (beam_MemGoing==-1 && ((unsigned long) OldC)>=beam_START_ADDR_HEAP+beam_MEM_H/2 && ((unsigned long) OldC) <beam_START_ADDR_BOXES) return(OldC);
*/
if (isvar(OldC)) {
return(OldC);
@ -67,15 +67,15 @@ Cell OldC,OldH;
return(OldC);
}
OldH=(Cell) _H;
NewH=_H;
OldH=(Cell) beam_H;
NewH=beam_H;
if (isappl(OldC)) {
int i,arity;
NewC=(Cell *) repappl(OldC);
arity = ((int) ArityOfFunctor((Functor) *NewC));
*NewH++=*NewC++;
_H+=arity+1;
beam_H+=arity+1;
for(i=0;i<arity ;i++) {
*NewH=move_structures((Cell) NewC);
NewH++;
@ -85,7 +85,7 @@ Cell OldC,OldH;
}
/* else if (ispair(c)) { */
NewC=(Cell *) reppair(OldC);
_H+=2;
beam_H+=2;
*NewH=move_structures((Cell) NewC);
NewC++;
NewH++;
@ -101,85 +101,91 @@ void garbage_collector()
struct AND_BOX *new_top;
#endif
if (Mem_FULL & 2) nr_call_gc_heap++; else nr_call_gc_boxed++;
if (beam_Mem_FULL & 2) beam_nr_gc_heap++; else beam_nr_gc_boxed++;
#if Debug || Debug_GC
printf("Entering Garbage Collector for the %dth time (Reason=%d)\n",nr_call_gc_heap+nr_call_gc_boxed,Mem_FULL);
printf("Entering Garbage Collector for the %dth time (Reason=%d)\n",beam_nr_gc_heap+beam_nr_gc_boxed,beam_Mem_FULL);
#endif
#if Debug_Dump_State & 2
dump_eam_state();
printf("--------------------------------------------------------------------\n");
#endif
Mem_FULL=0;
beam_Mem_FULL=0;
#if Memory_Stat
if (MEM_Going==1) {
Memory_STAT[nr_call_gc_heap+nr_call_gc_boxed][1]=(unsigned long) _H-START_ADDR_HEAP;
Memory_STAT[nr_call_gc_heap+nr_call_gc_boxed][2]=(unsigned long) Next_Free-START_ADDR_BOXES;
if (beam_MemGoing==1) {
beam_Memory_STAT[beam_nr_gc_heap+beam_nr_gc_boxed][1]=(unsigned long) beam_H-beam_START_ADDR_HEAP;
beam_Memory_STAT[beam_nr_gc_heap+beam_nr_gc_boxed][2]=(unsigned long) beam_NextFree-beam_START_ADDR_BOXES;
} else {
Memory_STAT[nr_call_gc_heap+nr_call_gc_boxed][1]=(unsigned long) _H-START_ADDR_HEAP-MEM_H/2;
Memory_STAT[nr_call_gc_heap+nr_call_gc_boxed][2]=END_BOX- ((unsigned long) Next_Free);
beam_Memory_STAT[beam_nr_gc_heap+beam_nr_gc_boxed][1]=(unsigned long) beam_H-beam_START_ADDR_HEAP-MEM_H/2;
beam_Memory_STAT[beam_nr_gc_heap+beam_nr_gc_boxed][2]=beam_END_BOX- ((unsigned long) beam_NextFree);
}
if (GARBAGE_COLLECTOR==1)
Memory_STAT[nr_call_gc_heap+nr_call_gc_boxed][2]=END_BOX- ((unsigned long) Next_Free);
beam_Memory_STAT[beam_nr_gc_heap+beam_nr_gc_boxed][2]=beam_END_BOX- ((unsigned long) beam_NextFree);
#endif
#if GARBAGE_COLLECTOR==1
if (MEM_Going==1) {
if (_H < (Cell *) (START_ADDR_HEAP+MEM_H/2)) _H=(Cell *) (START_ADDR_HEAP+MEM_H/2); else _H++;
MEM_Going=-1;
if (beam_MemGoing==1) {
if (beam_H < (Cell *) (beam_START_ADDR_HEAP+MEM_H/2)) beam_H=(Cell *) (beam_START_ADDR_HEAP+MEM_H/2); else beam_H++;
beam_MemGoing=-1;
beam_sp=(Cell *) beam_START_ADDR_HEAP+MEM_H/2;
beam_sp--;
} else {
_H=(Cell *) START_ADDR_HEAP;
MEM_Going=1;
beam_H=(Cell *) beam_START_ADDR_HEAP;
beam_MemGoing=1;
beam_sp=(Cell *) beam_END_H;
beam_sp--;
}
refresh_andbox(top);
refresh_andbox(beam_top);
#if Clear_MEMORY
if (MEM_Going==-1) {
memset(START_ADDR_HEAP,0,MEM_H/2);
if (beam_MemGoing==-1) {
memset(beam_START_ADDR_HEAP,0,MEM_H/2);
} else {
memset(START_ADDR_HEAP+MEM_H/2,0,MEM_H/2);
memset(beam_START_ADDR_HEAP+MEM_H/2,0,MEM_H/2);
}
#endif
#else
memset(Index_Free,0,INDEX_SIZE*POINTER_SIZE);
if (MEM_Going==1) {
if (_H < (Cell *) (START_ADDR_HEAP+MEM_H/2)) _H=(Cell *) (START_ADDR_HEAP+MEM_H/2); else _H++;
Next_Free=(Cell *)END_BOX;
MEM_Going=-1;
memset(beam_IndexFree,0,INDEX_SIZE*POINTER_SIZE);
if (beam_MemGoing==1) {
if (beam_H < (Cell *) (beam_START_ADDR_HEAP+MEM_H/2)) beam_H=(Cell *) (beam_START_ADDR_HEAP+MEM_H/2); else beam_H++;
beam_NextFree=(Cell *) beam_END_BOX;
beam_MemGoing=-1;
beam_sp=(Cell *) beam_START_ADDR_HEAP+MEM_H/2; beam_sp-=2;
} else {
if (_H>=(Cell *) START_ADDR_BOXES) Next_Free=_H+1; else Next_Free=(Cell *) START_ADDR_BOXES;
_H=(Cell *) START_ADDR_HEAP;
MEM_Going=1;
if (beam_H>=(Cell *) beam_START_ADDR_BOXES) beam_NextFree=beam_H+1; else beam_NextFree=(Cell *) beam_START_ADDR_BOXES;
beam_H=(Cell *) beam_START_ADDR_HEAP;
beam_MemGoing=1;
beam_sp=(Cell *) beam_END_H; beam_sp-=2;
}
Mem_FULL=0;
beam_Mem_FULL=0;
SU=NULL;
new_top=move_andbox(top,NULL,NULL);
top=new_top;
beam_su=NULL;
new_top=move_andbox(beam_top,NULL,NULL);
beam_top=new_top;
#if Clear_MEMORY
if (MEM_Going==-1) {
memset((void *) START_ADDR_HEAP,0,MEM_H/2);
memset((void *) START_ADDR_BOXES,0,MEM_BOXES/2);
if (beam_MemGoing==-1) {
memset((void *) beam_START_ADDR_HEAP,0,MEM_H/2);
memset((void *) beam_START_ADDR_BOXES,0,MEM_BOXES/2);
} else {
memset((void *) START_ADDR_HEAP+MEM_H/2,0,MEM_H/2);
memset((void *) START_ADDR_BOXES+MEM_BOXES/2,0,MEM_BOXES/2);
memset((void *) beam_START_ADDR_HEAP+MEM_H/2,0,MEM_H/2);
memset((void *) beam_START_ADDR_BOXES+MEM_BOXES/2,0,MEM_BOXES/2);
}
#endif
#endif
#if Memory_Stat
if (MEM_Going==1) {
Memory_STAT[nr_call_gc_heap+nr_call_gc_boxed][3]=(unsigned long) _H-START_ADDR_HEAP;
Memory_STAT[nr_call_gc_heap+nr_call_gc_boxed][4]=(unsigned long) Next_Free-START_ADDR_BOXES;
if (beam_MemGoing==1) {
beam_Memory_STAT[beam_nr_gc_heap+beam_nr_gc_boxed][3]=(unsigned long) beam_H- beam_START_ADDR_HEAP;
beam_Memory_STAT[beam_nr_gc_heap+beam_nr_gc_boxed][4]=(unsigned long) beam_NextFree- beam_START_ADDR_BOXES;
} else {
Memory_STAT[nr_call_gc_heap+nr_call_gc_boxed][3]=(unsigned long) _H-START_ADDR_HEAP-MEM_H/2;
Memory_STAT[nr_call_gc_heap+nr_call_gc_boxed][4]=END_BOX- ((unsigned long) Next_Free);
beam_Memory_STAT[beam_nr_gc_heap+beam_nr_gc_boxed][3]=(unsigned long) beam_H- beam_START_ADDR_HEAP-MEM_H/2;
beam_Memory_STAT[beam_nr_gc_heap+beam_nr_gc_boxed][4]= beam_END_BOX- ((unsigned long) beam_NextFree);
}
if (GARBAGE_COLLECTOR==1)
Memory_STAT[nr_call_gc_heap+nr_call_gc_boxed][4]=END_BOX- ((unsigned long) Next_Free);
beam_Memory_STAT[beam_nr_gc_heap+beam_nr_gc_boxed][4]= beam_END_BOX- ((unsigned long) beam_NextFree);
#endif
#if Debug_Dump_State & 2
@ -202,11 +208,11 @@ Cell *args,*newargs;
if (o==NULL) return(NULL);
#if !Fast_go
if ((Cell *) o<(Cell *) START_ADDR_BOXES || (Cell *) o>(Cell *) END_BOX) return (NULL);
if ((Cell *) o<(Cell *) beam_START_ADDR_BOXES || (Cell *) o>(Cell *) beam_END_BOX) return (NULL);
#endif
new_orbox=(struct OR_BOX *) request_memory(ORBOX_SIZE);
if (Mem_FULL) abort_eam("Sem Memoria para GC\n");
if (OBX==o) OBX=new_orbox;
if (beam_Mem_FULL) abort_eam("Sem Memoria para GC\n");
if (beam_OBX==o) beam_OBX=new_orbox;
new_orbox->parent=parent;
new_orbox->nr_call=nr_call;
new_orbox->nr_all_alternatives=o->nr_all_alternatives;
@ -214,9 +220,9 @@ Cell *args,*newargs;
old=o->alternatives;
while(old!=NULL) {
new=(struct status_or *) request_memory(STATUS_OR_SIZE);
if (Mem_FULL) abort_eam("Sem Memoria para GC\n");
if (beam_Mem_FULL) abort_eam("Sem Memoria para GC\n");
if (nr_alternative==old) nr_alternative=new;
if (beam_nr_alternative==old) beam_nr_alternative=new;
new->args=old->args;
new->code=old->code;
new->state=old->state;
@ -244,7 +250,7 @@ Cell *args,*newargs;
printf("Request args=%d \n",(int) args[0]);
#endif
newargs=(Cell *)request_memory((args[0])*sizeof(Cell));
if (Mem_FULL) abort_eam("Sem Memoria para GC\n");
if (beam_Mem_FULL) abort_eam("Sem Memoria para GC\n");
newargs[0]=args[0];
for(y=1;y<args[0];y++) newargs[y]=move_structures(args[y]);
}
@ -263,11 +269,11 @@ struct PERM_VAR *l;
struct EXTERNAL_VAR *old_externals,*externals;
if (a==NULL) return(NULL);
OLD_VAR_TRAIL_NR=VAR_TRAIL_NR;
OLD_VAR_TRAIL_NR=beam_VAR_TRAIL_NR;
new_andbox=(struct AND_BOX *) request_memory(ANDBOX_SIZE);
if (Mem_FULL) abort_eam("Sem Memoria para GC\n");
if (ABX==a) ABX=new_andbox;
if (beam_Mem_FULL) abort_eam("Sem Memoria para GC\n");
if (beam_ABX==a) beam_ABX=new_andbox;
new_andbox->parent=parent;
new_andbox->nr_alternative=alt;
new_andbox->level=a->level;
@ -309,7 +315,7 @@ struct EXTERNAL_VAR *old_externals,*externals;
old_externals=old_externals->next;
}
new_andbox->externals=externals;
if (Mem_FULL) abort_eam("Sem Memoria para GC\n");
if (beam_Mem_FULL) abort_eam("Sem Memoria para GC\n");
/* CUIDADO: Preciso agora de duplicar os vectores das variaveis locais */
@ -338,7 +344,7 @@ struct EXTERNAL_VAR *old_externals,*externals;
nr=oldvars[-1];
newvars=request_memory_locals(nr);
if (var_locals==oldvars) var_locals=newvars;
if (beam_varlocals==oldvars) beam_varlocals=newvars;
calls->locals=newvars;
/* primeiro actualizo as variaveis */
@ -383,11 +389,11 @@ struct EXTERNAL_VAR *old_externals,*externals;
calls=a->calls;
while(calls!=NULL){
calls_new=(struct status_and *) request_memory(STATUS_AND_SIZE);
if (Mem_FULL) abort_eam("Sem Memoria para GC\n");
if (beam_Mem_FULL) abort_eam("Sem Memoria para GC\n");
calls_new->code=calls->code;
calls_new->state=calls->state;
calls_new->locals=calls->locals;
if (nr_call==calls) nr_call=calls_new;
if (beam_nr_call==calls) beam_nr_call=calls_new;
calls_new->call=move_orbox(calls->call,new_andbox,calls_new);

View File

@ -23,10 +23,10 @@ extern int am_to_inst(Cell inst);
void eam_showcode(Cell *code)
{
int n;
#define arg1 *(code+1)
#define arg2 *(code+2)
#define arg3 *(code+3)
#define arg4 *(code+4)
#define carg1 *(code+1)
#define carg2 *(code+2)
#define carg3 *(code+3)
#define carg4 *(code+4)
printf("--------------------------------------------------\n");
while (1) {
@ -47,39 +47,39 @@ int n;
code++;
break;
case(_prepare_tries):
printf("_prepare_tries for %d clauses with arity=%d \n",(int) arg1,(int) arg2);
printf("_prepare_tries for %d clauses with arity=%d \n",(int) carg1,(int) carg2);
code+=3;
break;
case(_prepare_calls ):
printf("_prepare_calls %d \n",(int) arg1);
printf("_prepare_calls %d \n",(int) carg1);
code+=2;
break;
case(_get_var_X_op ):
printf("_get_var_X_op X%d, X%d\n",(int) arg1,(int) arg2);
printf("_get_var_X_op X%d, X%d\n",(int) carg1,(int) carg2);
code+=3;
break;
case(_get_var_Y_op ):
printf("_get_var_Y_op X%d, Y%d\n",(int) arg1,(int) arg2);
printf("_get_var_Y_op X%d, Y%d\n",(int) carg1,(int) carg2);
code+=3;
break;
case(_get_val_X_op ):
printf("_get_val_X_op X%d, X%d\n",(int) arg1,(int) arg2);
printf("_get_val_X_op X%d, X%d\n",(int) carg1,(int) carg2);
code+=3;
break;
case(_get_val_Y_op ):
printf("_get_val_Y_op X%d, Y%d\n",(int) arg1,(int) arg2);
printf("_get_val_Y_op X%d, Y%d\n",(int) carg1,(int) carg2);
code+=3;
break;
case(_get_atom_op ):
printf("_get_atom_op X%d, %d \n",(int) arg1,(int) arg2);
printf("_get_atom_op X%d, %d \n",(int) carg1,(int) carg2);
code+=3;
break;
case(_get_list_op ):
printf("_get_list_op X%d\n",(int) arg1);
printf("_get_list_op X%d\n",(int) carg1);
code+=2;
break;
case(_get_struct_op ):
printf("_get_struct_op X%d, %lX/%d\n",(int) arg1,(unsigned long) arg2,(int) arg3);
printf("_get_struct_op X%d, %lX/%d\n",(int) carg1,(unsigned long) carg2,(int) carg3);
code+=4;
break;
case(_unify_void_op ):
@ -87,23 +87,23 @@ int n;
code++;
break;
case(_unify_val_X_op ):
printf("_unify_val_X_op X%d\n",(int) arg1);
printf("_unify_val_X_op X%d\n",(int) carg1);
code+=2;
break;
case(_unify_val_Y_op ):
printf("_unify_val_Y_op Y%d\n",(int) arg1);
printf("_unify_val_Y_op Y%d\n",(int) carg1);
code+=2;
break;
case(_unify_var_X_op ):
printf("_unify_var_X_op X%d\n",(int) arg1);
printf("_unify_var_X_op X%d\n",(int) carg1);
code+=2;
break;
case(_unify_var_Y_op ):
printf("_unify_var_Y_op Y%d\n",(int) arg1);
printf("_unify_var_Y_op Y%d\n",(int) carg1);
code+=2;
break;
case(_unify_atom_op ):
printf("_unify_atom_op 0x%lX\n",(unsigned long) arg1);
printf("_unify_atom_op 0x%lX\n",(unsigned long) carg1);
code+=2;
break;
case(_unify_list_op ):
@ -115,59 +115,59 @@ int n;
code++;
break;
case(_unify_struct_op ):
printf("_unify_struct_op 0x%lX,%d\n",(unsigned long) arg1,(int) arg2);
printf("_unify_struct_op 0x%lX,%d\n",(unsigned long) carg1,(int) carg2);
code+=3;
break;
case(_unify_last_struct_op ):
printf("_unify_last_struct_op 0x%lX,%d\n",(unsigned long) arg1,(int) arg2);
printf("_unify_last_struct_op 0x%lX,%d\n",(unsigned long) carg1,(int) carg2);
code+=3;
break;
case(_unify_last_atom_op ):
printf("_unify_last_atom_op 0x%lX\n",(unsigned long) arg1);
printf("_unify_last_atom_op 0x%lX\n",(unsigned long) carg1);
code+=2;
break;
case(_unify_local_X_op ):
printf("_unify_local_X_op X%d\n",(int) arg1);
printf("_unify_local_X_op X%d\n",(int) carg1);
code+=2;
break;
case(_unify_local_Y_op ):
printf("_unify_local_Y_op X%d\n",(int) arg1);
printf("_unify_local_Y_op X%d\n",(int) carg1);
code+=2;
break;
case(_put_var_X_op ):
printf("_put_var_X_op X%d,X%d \n",(int) arg1,(int) arg2);
printf("_put_var_X_op X%d,X%d \n",(int) carg1,(int) carg2);
code+=3;
break;
case(_put_var_Y_op ):
printf("_put_var_Y_op X%d,Y%d \n",(int) arg1,(int) arg2);
printf("_put_var_Y_op X%d,Y%d \n",(int) carg1,(int) carg2);
code+=3;
break;
case(_put_var_P_op ):
printf("_put_var_P_op X%d,Y%d \n",(int) arg1,(int) arg2);
printf("_put_var_P_op X%d,Y%d \n",(int) carg1,(int) carg2);
code+=3;
break;
case(_put_val_X_op ):
printf("_put_val_X_op X%d,X%d \n",(int) arg1,(int) arg2);
printf("_put_val_X_op X%d,X%d \n",(int) carg1,(int) carg2);
code+=3;
break;
case(_put_val_Y_op ):
printf("_put_val_Y_op X%d,Y%d \n",(int) arg1,(int) arg2);
printf("_put_val_Y_op X%d,Y%d \n",(int) carg1,(int) carg2);
code+=3;
break;
case(_put_atom_op ):
printf("_put_atom_op X%d, %d \n",(int) arg1,(int) arg2);
printf("_put_atom_op X%d, %d \n",(int) carg1,(int) carg2);
code+=3;
break;
case(_put_list_op ):
printf("_put_list_op X%d \n",(int) arg1);
printf("_put_list_op X%d \n",(int) carg1);
code+=2;
break;
case(_put_struct_op ):
printf("_put_struct_op X%d,%d,%d \n",(int) arg1,(int) arg2,(int) arg3);
printf("_put_struct_op X%d,%d,%d \n",(int) carg1,(int) carg2,(int) carg3);
code+=4;
break;
case(_put_unsafe_op ):
printf("_put_unsafe_op X%d, Y%d \n",(int) arg1,(int) arg2);
printf("_put_unsafe_op X%d, Y%d \n",(int) carg1,(int) carg2);
code+=3;
break;
case(_write_void ):
@ -175,27 +175,27 @@ int n;
code++;
break;
case(_write_var_X_op ):
printf("_write_var_X_op X%d \n",(int) arg1);
printf("_write_var_X_op X%d \n",(int) carg1);
code+=2;
break;
case(_write_var_Y_op ):
printf("_write_var_Y_op Y%d \n",(int) arg1);
printf("_write_var_Y_op Y%d \n",(int) carg1);
code+=2;
break;
case(_write_var_P_op ):
printf("_write_var_P_op Y%d \n",(int) arg1);
printf("_write_var_P_op Y%d \n",(int) carg1);
code+=2;
break;
case(_write_val_X_op ):
printf("_write_val_X_op X%d \n",(int) arg1);
printf("_write_val_X_op X%d \n",(int) carg1);
code+=2;
break;
case(_write_val_Y_op ):
printf("_write_val_Y_op Y%d \n",(int) arg1);
printf("_write_val_Y_op Y%d \n",(int) carg1);
code+=2;
break;
case(_write_atom_op ):
printf("_write_atom_op %d \n",(int) arg1);
printf("_write_atom_op %d \n",(int) carg1);
code+=2;
break;
case(_write_list_op ):
@ -203,7 +203,7 @@ int n;
code++;
break;
case(_write_struct_op ):
printf("_write_struct_op %d,%d \n",(int) arg1,(int) arg2);
printf("_write_struct_op %d,%d \n",(int) carg1,(int) carg2);
code+=3;
break;
case(_write_last_list_op ):
@ -211,15 +211,15 @@ int n;
code++;
break;
case(_write_last_struct_op ):
printf("_write_last_struct_op %d,%d \n",(int) arg1,(int) arg2);
printf("_write_last_struct_op %d,%d \n",(int) carg1,(int) carg2);
code+=3;
break;
case(_write_local_X_op ):
printf("_write_local_X_op X%d \n",(int) arg1);
printf("_write_local_X_op X%d \n",(int) carg1);
code+=2;
break;
case(_write_local_Y_op ):
printf("_write_local_Y_op Y%d \n",(int) arg1);
printf("_write_local_Y_op Y%d \n",(int) carg1);
code+=2;
break;
case(_pop_op ):
@ -227,7 +227,7 @@ int n;
code++;
break;
case(_jump_op ):
printf("_jump_op %ld\n",(long int) arg1);
printf("_jump_op %ld\n",(long int) carg1);
code+=4;
break;
case(_proceed_op ):
@ -235,36 +235,36 @@ int n;
code++;
break;
case(_call_op ):
printf("_call_op %s/%d \n", ((PredEntry *) arg1)->beamTable->name,((PredEntry *) arg1)->beamTable->arity);
printf("_call_op %s/%d \n", ((PredEntry *) carg1)->beamTable->name,((PredEntry *) carg1)->beamTable->arity);
code+=2;
break;
case(_safe_call_op ):
printf("_safe_call_op %ld \n",(long) arg1);
printf("_safe_call_op %ld \n",(long) carg1);
code+=2;
break;
case(_safe_call_unary_op ):
printf("_safe_call_unary_op %ld \n",(long) arg1);
printf("_safe_call_unary_op %ld \n",(long) carg1);
code+=2;
break;
case(_safe_call_binary_op ):
printf("_safe_call_binary_op %ld \n",(long) arg1);
printf("_safe_call_binary_op %ld \n",(long) carg1);
code+=2;
break;
case(_only_1_clause_op ):
printf("_only_1_clause_op -> Use the same AND_BOX for the %dth clause of predicate %s/%d (Yvars=%d) \n",(int) arg4,((struct Clauses *)arg1)->predi->name,(int) arg2,(int) arg3);
printf("_only_1_clause_op -> Use the same AND_BOX for the %dth clause of predicate %s/%d (Yvars=%d) \n",(int) carg4,((struct Clauses *)carg1)->predi->name,(int) carg2,(int) carg3);
code+=4;
break;
case(_try_me_op ):
printf("_try_me_op -> Create AND_BOX for the %dth clause of predicate %s/%d (Yvars=%d) \n",(int) arg4,((struct Clauses *)arg1)->predi->name,(int) arg2,(int) arg3);
printf("_try_me_op -> Create AND_BOX for the %dth clause of predicate %s/%d (Yvars=%d) \n",(int) carg4,((struct Clauses *)carg1)->predi->name,(int) carg2,(int) carg3);
code+=5;
break;
case(_retry_me_op ):
printf("_retry_me_op -> Create AND_BOX for the %dth clause of predicate %s/%d (Yvars=%d) \n",(int) arg4,((struct Clauses *)arg1)->predi->name,(int) arg2,(int) arg3);
printf("_retry_me_op -> Create AND_BOX for the %dth clause of predicate %s/%d (Yvars=%d) \n",(int) carg4,((struct Clauses *)carg1)->predi->name,(int) carg2,(int) carg3);
code+=5;
break;
case(_trust_me_op ):
printf("_trust_me_op -> Create AND_BOX for the %dth clause of predicate %s/%d (Yvars=%d) \n",(int) arg4,((struct Clauses *)arg1)->predi->name,(int) arg2,(int) arg3);
printf("_trust_me_op -> Create AND_BOX for the %dth clause of predicate %s/%d (Yvars=%d) \n",(int) carg4,((struct Clauses *)carg1)->predi->name,(int) carg2,(int) carg3);
code+=5;
break;
case(_do_nothing_op ):
@ -272,15 +272,15 @@ int n;
code++;
break;
case(_direct_safe_call_op ):
printf("_direct_safe_call_op %ld \n",(long) arg1);
printf("_direct_safe_call_op %ld \n",(long) carg1);
code+=2;
break;
case(_direct_safe_call_unary_op ):
printf("_direct_safe_call_unary_op %ld \n",(long) arg1);
printf("_direct_safe_call_unary_op %ld \n",(long) carg1);
code+=2;
break;
case(_direct_safe_call_binary_op ):
printf("_direct_safe_call_binary_op %ld \n",(long) arg1);
printf("_direct_safe_call_binary_op %ld \n",(long) carg1);
code+=2;
break;

View File

@ -24,7 +24,7 @@ int nr_all_alternatives, nr_all_calls;
struct status_and *nr_call,*new_call;
struct status_or *nr_alternative, *alternatives, *new_alternatives;
nr_call_forking++;
beam_nr_call_forking++;
op=a->parent; /* or box parent */
ap=op->parent; /* and box parent */
opp=ap->parent; /* or box parent parent */
@ -153,10 +153,10 @@ struct status_or *nr_alternative, *alternatives, *new_alternatives;
/* Now we have to create new local vars and refresh the external vars to point to those */
if (MEM_Going==1) {
VAR_TRAIL=((Cell *) START_ADDR_BOXES)-1;
} else VAR_TRAIL=(Cell *) START_ADDR_HEAP;
VAR_TRAIL_NR=0;
if (beam_MemGoing==1) {
beam_VAR_TRAIL=((Cell *) beam_START_ADDR_BOXES)-1;
} else beam_VAR_TRAIL=(Cell *) beam_START_ADDR_HEAP;
beam_VAR_TRAIL_NR=0;
replicate_local_variables(new_andbox);
}
@ -243,7 +243,7 @@ struct EXTERNAL_VAR *old_externals,*externals;
if (a==NULL) return;
OLD_VAR_TRAIL_NR=VAR_TRAIL_NR;
OLD_VAR_TRAIL_NR=beam_VAR_TRAIL_NR;
l=a->perms;
new_list=NULL;
while(l) {
@ -256,10 +256,10 @@ if (a==NULL) return;
new_list=new;
c=&l->value;
VAR_TRAIL[VAR_TRAIL_NR]=(Cell) c;
VAR_TRAIL_NR-=MEM_Going;
VAR_TRAIL[VAR_TRAIL_NR]=(Cell) *c;
VAR_TRAIL_NR-=MEM_Going;
beam_VAR_TRAIL[beam_VAR_TRAIL_NR]=(Cell) c;
beam_VAR_TRAIL_NR-=beam_MemGoing;
beam_VAR_TRAIL[beam_VAR_TRAIL_NR]=(Cell) *c;
beam_VAR_TRAIL_NR-=beam_MemGoing;
if ((Cell *)*c==c) {
new->value=(Cell) &new->value;
@ -279,10 +279,10 @@ if (a==NULL) return;
/* At this point all old local vars are pointing to the new local vars */
if (a==ABX) { /* Nao preciso de criar um novo vector das externals */
if (a==beam_ABX) { /* Nao preciso de criar um novo vector das externals */
old_externals=a->externals;
while(old_externals) {
if (old_externals->var->home->level>=ABX->parent->parent->level) {
if (old_externals->var->home->level>=beam_ABX->parent->parent->level) {
old_externals->value=copy_structures((Cell ) old_externals->value);
old_externals->var=(struct PERM_VAR *) old_externals->var->value;
if (isvar(old_externals->var)) {
@ -309,7 +309,7 @@ if (a==NULL) return;
e->next=externals;
externals=e;
if (old_externals->var->home->level>=ABX->parent->parent->level) {
if (old_externals->var->home->level>=beam_ABX->parent->parent->level) {
e->value=copy_structures((Cell ) old_externals->value);
e->var=(struct PERM_VAR *) old_externals->var->value;
} else {
@ -359,10 +359,10 @@ if (a==NULL) return;
/* primeiro actualizo as variaveis */
for(i=0;i<nr;i++) {
c=&oldvars[i];
VAR_TRAIL[VAR_TRAIL_NR]=(Cell) c;
VAR_TRAIL_NR-=MEM_Going;
VAR_TRAIL[VAR_TRAIL_NR]=(Cell) *c;
VAR_TRAIL_NR-=MEM_Going;
beam_VAR_TRAIL[beam_VAR_TRAIL_NR]=(Cell) c;
beam_VAR_TRAIL_NR-=beam_MemGoing;
beam_VAR_TRAIL[beam_VAR_TRAIL_NR]=(Cell) *c;
beam_VAR_TRAIL_NR-=beam_MemGoing;
if ((Cell *)*c==c) {
newvars[i]=(Cell) &newvars[i];
@ -418,21 +418,21 @@ if (a==NULL) return;
}
}
if (MEM_Going==1) {
for(i=OLD_VAR_TRAIL_NR;i>VAR_TRAIL_NR;i-=2) {
if (beam_MemGoing==1) {
for(i=OLD_VAR_TRAIL_NR;i>beam_VAR_TRAIL_NR;i-=2) {
Cell *c;
c=(Cell *) VAR_TRAIL[i];
*c=(Cell) VAR_TRAIL[i-1];
c=(Cell *) beam_VAR_TRAIL[i];
*c=(Cell) beam_VAR_TRAIL[i-1];
}
} else {
for(i=OLD_VAR_TRAIL_NR;i<VAR_TRAIL_NR;i+=2) {
for(i=OLD_VAR_TRAIL_NR;i<beam_VAR_TRAIL_NR;i+=2) {
Cell *c;
c=(Cell *) VAR_TRAIL[i];
*c=(Cell) VAR_TRAIL[i+1];
c=(Cell *) beam_VAR_TRAIL[i];
*c=(Cell) beam_VAR_TRAIL[i+1];
}
}
VAR_TRAIL_NR=OLD_VAR_TRAIL_NR;
beam_VAR_TRAIL_NR=OLD_VAR_TRAIL_NR;
}
@ -451,15 +451,15 @@ Cell OldC,OldH;
return(OldC);
}
OldH=(Cell) _H;
NewH=_H;
OldH=(Cell) beam_H;
NewH=beam_H;
if (isappl(OldC)) {
int i,arity;
NewC=(Cell *) repappl(OldC);
arity = ((int) ArityOfFunctor((Functor) *NewC));
*NewH++=*NewC++;
_H+=arity+1;
beam_H+=arity+1;
for(i=0;i<arity ;i++) {
*NewH=copy_structures((Cell) NewC);
NewH++;
@ -469,7 +469,7 @@ Cell OldC,OldH;
}
/* else if (ispair(c)) { */
NewC=(Cell *) reppair(OldC);
_H+=2;
beam_H+=2;
*NewH=copy_structures((Cell) NewC);
NewC++;
NewH++;

View File

@ -27,7 +27,7 @@ Cell *Code_Start;
Cell Area_Code[200000];
Cell area_code=0;
extern Int inst_am(int n);
extern Cell inst_am(int n);
void emit_inst(long int i);
void emit_par(long int i);
void emit_upar(Cell i);
@ -477,6 +477,14 @@ void eam_pass(CInstr *ppc)
if (pass==0) labels[ppc->new4] = get_addr();
break;
case run_op:
/* se ficar vazio, retirar no eam_am.c o +5 das linhas pc=clause->code+5 no only_1_clause e no call */
emit_inst(_try_me_op);
emit_par(0);
emit_par(0);
emit_par(0);
emit_par(0);
break;
case only_1_clause_op:
emit_inst(_only_1_clause_op);

View File

@ -306,7 +306,7 @@ return(0);
void eam_instructions(struct Clauses *clause)
{
int calls=0,nr_call=0;
int calls=0,nrcall=0;
CInstr *b_code=NULL;
inter_code=StartCode;
@ -345,12 +345,12 @@ if (calls) {
inter_code=inter_code->nextInst;
}
if (needs_box(inter_code->op)) {
insert_inst(inter_code,remove_box_op,nr_call,0);
insert_inst(inter_code,remove_box_op,nrcall,0);
inter_code=inter_code->nextInst;
b_code=inter_code;
insert_inst(inter_code,label_op,nr_call,labelno);
insert_inst(inter_code,label_op,nrcall,labelno);
inter_code=inter_code->nextInst;
insert_inst(inter_code,create_box_op,++nr_call,++labelno);
insert_inst(inter_code,create_box_op,++nrcall,++labelno);
}
inter_code=inter_code->nextInst;
}
@ -475,6 +475,7 @@ int calls=0;
emit_new(nop_op, 0,0);
emit_new(nop_op, 0,0);
/*
CodeStart->nextInst=NULL;
ppc=CodeStart;
@ -483,7 +484,7 @@ int calls=0;
Yap_emit(cut_op,Zero,Zero,&CGLOBS->cint);
Yap_emit(run_op,Zero,(unsigned long) (CGLOBS->cint).CurrentPred,&CGLOBS->cint);
Yap_emit(procceed_op, Zero, Zero, &CGLOBS->cint);
*/
return;
}