We planned to upgrade GitLab and Mattermost to the latest version this Friday morning (early). You may experience some downtime!

Verified Commit cb2754ab authored by Camil Staps's avatar Camil Staps 🚀

Unboxed record arrays now store the record descriptor + 2, as in native Clean

parent 2377b53a
Pipeline #17433 passed with stages
in 19 minutes and 24 seconds
......@@ -1337,7 +1337,7 @@ void code_create_array(char element_descriptor[],int a_size,int b_size) {
break;
}
add_instruction_w_w_label(Ccreate_array_r,a_size+b_size,b_size,element_descriptor);
add_instruction_w_w_label_offset(Ccreate_array_r,a_size+b_size,b_size,element_descriptor,2);
return;
} while(0);
......@@ -1382,11 +1382,11 @@ void code_create_array_(char element_descriptor[],int a_size,int b_size) {
}
if (b_size==0)
add_instruction_w_label(Ccreate_array_r_a,a_size,element_descriptor);
add_instruction_w_label_offset(Ccreate_array_r_a,a_size,element_descriptor,2);
else if (a_size==0)
add_instruction_w_label(Ccreate_array_r_b,b_size,element_descriptor);
add_instruction_w_label_offset(Ccreate_array_r_b,b_size,element_descriptor,2);
else
add_instruction_w_w_label(Ccreate_array_r_,a_size+b_size,a_size,element_descriptor);
add_instruction_w_w_label_offset(Ccreate_array_r_,a_size+b_size,a_size,element_descriptor,2);
}
void code_decI(void) {
......
......@@ -41,7 +41,6 @@ static inline int copied_node_size(struct program *program, BC_WORD *node) {
words_needed+=copied_node_size(program, (BC_WORD*)node[i+3]);
len=words_needed;
} else { /* unboxed array */
desc|=2;
int16_t elem_a_arity=*(int16_t*)desc;
int16_t elem_ab_arity=((int16_t*)desc)[-1]-256;
int words_needed=len*elem_ab_arity;
......@@ -349,8 +348,8 @@ static inline void restore_and_translate_descriptors(struct program *program, BC
int16_t elem_a_arity=((int16_t*)elem_desc)[0];
elem_ab_arity-=256;
struct host_symbol *elem_host_symbol=translate_descriptor(program,(BC_WORD*)(elem_desc & -3));
interpreter_node[2]=(BC_WORD)elem_host_symbol->interpreter_location|2;
struct host_symbol *elem_host_symbol=translate_descriptor(program,(BC_WORD*)(elem_desc-2));
interpreter_node[2]=(BC_WORD)elem_host_symbol->interpreter_location+2;
BC_WORD **array=(BC_WORD**)&node[3];
int len=node[1];
......@@ -415,7 +414,6 @@ static void add_shared_nodes(struct interpretation_environment *ie, BC_WORD *nod
for (int len=node[1]-1; len>=0; len--)
add_shared_nodes(ie, array[len]);
} else {
elem_desc|=2;
int16_t elem_ab_arity=((int16_t*)elem_desc)[-1];
if (elem_ab_arity>0) {
int16_t elem_a_arity=((int16_t*)elem_desc)[0];
......
......@@ -353,7 +353,6 @@ static inline int copied_node_size(BC_WORD *node) {
words_needed+=copied_node_size((BC_WORD*)node[i+3]);
len=words_needed;
} else { /* unboxed array */
desc|=2;
int16_t elem_a_arity=*(int16_t*)desc;
int16_t elem_ab_arity=((int16_t*)desc)[-1]-256;
int words_needed=len*elem_ab_arity;
......@@ -458,27 +457,23 @@ static inline BC_WORD *copy_to_host(struct InterpretationEnvironment *clean_ie,
return host_heap+len+2;
} else if (descriptor==(BC_WORD)&__ARRAY__+2) {
int len=node[1];
BC_WORD desc=node[2];
host_heap[0]=descriptor;
host_heap[1]=len;
BC_WORD desc=node[2];
host_heap[2]=desc;
if (desc==(BC_WORD)&BOOL+2) {
host_heap[2]=desc;
len=(len+IF_INT_64_OR_32(7,3))/IF_INT_64_OR_32(8,4);
} else if (desc==(BC_WORD)&INT+2 || desc==(BC_WORD)&REAL+2) {
host_heap[2]=desc;
/* len is correct */
} else if (desc==0) { /* boxed array */
host_heap[2]=desc;
BC_WORD **new_array=(BC_WORD**)&host_heap[5];
host_heap+=3+len;
for (int i=0; i<len; i++)
host_heap=copy_to_host(clean_ie, host_heap, &new_array[i], (BC_WORD*)node[i+3]);
return host_heap;
} else { /* unboxed array */
desc|=2;
int16_t elem_a_arity=*(int16_t*)desc;
int16_t elem_ab_arity=((int16_t*)desc)[-1]-256;
host_heap[2]=((BC_WORD*)(desc-2))[-2]+2; /* TODO check that the descriptor exists */
node+=3;
BC_WORD *new_array=&host_heap[3];
host_heap+=3+len*elem_ab_arity;
......@@ -749,8 +744,7 @@ static inline void restore_and_translate_descriptors(struct InterpretationEnviro
}
BC_WORD *host_descriptor=translate_descriptor((BC_WORD*)(descriptor-2)-host_descriptor_offset);
host_descriptor+=add_to_host_descriptor;
host_descriptor=(BC_WORD*)((BC_WORD)host_descriptor+2);
host_descriptor=(BC_WORD*)((BC_WORD)(host_descriptor+add_to_host_descriptor)+2);
host_node[0]=(BC_WORD)host_descriptor;
......@@ -764,7 +758,9 @@ static inline void restore_and_translate_descriptors(struct InterpretationEnviro
restore_and_translate_descriptors(clean_ie, array[len]);
} else {
int16_t elem_ab_arity=((int16_t*)elem_desc)[-1];
if (elem_ab_arity>0) {
if (elem_ab_arity>0) { /* unboxed records */
node[2]=(BC_WORD)translate_descriptor((BC_WORD*)(node[2]-2))+2;
int16_t elem_a_arity=((int16_t*)elem_desc)[0];
elem_ab_arity-=256;
......
......@@ -179,8 +179,8 @@ BC_WORD *collect_copy(BC_WORD *stack, BC_WORD *asp,
int16_t b_arity=0;
if (node[2]!=0) { /* unboxed */
BC_WORD *desc=(BC_WORD*)node[2];
arity=((int16_t*)desc)[0];
a_arity=((int16_t*)desc)[1];
arity=((int16_t*)desc)[-1];
a_arity=((int16_t*)desc)[0];
b_arity=arity-256-a_arity;
arity=a_arity+b_arity;
}
......
......@@ -201,8 +201,8 @@ void evaluate_grey_nodes(BC_WORD *heap, size_t heap_size, struct nodes_set *set)
int16_t b_arity=0;
if (node[2]!=0) { /* unboxed */
BC_WORD *desc=(BC_WORD*)node[2];
arity=((int16_t*)desc)[0];
a_arity=((int16_t*)desc)[1];
arity=((int16_t*)desc)[-1];
a_arity=((int16_t*)desc)[0];
b_arity=arity-256-a_arity;
arity=a_arity+b_arity;
}
......
......@@ -4007,14 +4007,14 @@ INSTRUCTION_BLOCK(printD):
char *cs;
s=(BC_WORD*)*bsp++;
if ((BC_WORD)s & 2) /* record descriptor in unboxed array */
s=(BC_WORD*)((BC_WORD)s-2);
l=s[0];
if (l>>16>>3) { /* function */
if (l>>16>>3) /* function */
s+=(l>>16>>3)*2+3;
l=s[0];
} else if (l>256) { /* record; skip arity and type string */
s+=2+s[1]/IF_INT_64_OR_32(8,4)+(s[1]%IF_INT_64_OR_32(8,4) ? 1 : 0);
l=s[0];
}
else if (l>256) /* record, skip arity and type string */
s+=2+(s[1]+IF_INT_64_OR_32(7,3))/IF_INT_64_OR_32(8,4);
l=s[0];
cs=(char*)&s[1];
for (i=0; i<l; ++i)
PUTCHAR(*cs++);
......@@ -9239,7 +9239,7 @@ INSTRUCTION_BLOCK(push_t_r_args):
}
INSTRUCTION_BLOCK(push_a_r_args):
/* Unboxed array of records in asp[0], index in bsp[0].
* Copy elements to the stacks and push record descriptor to B-stack. */
* Copy elements to the stacks and push type string to B-stack. */
{
BC_WORD *array,*desc,n,array_o,*a,*b;
int16_t a_arity,b_arity,ab_arity;
......@@ -9248,8 +9248,8 @@ INSTRUCTION_BLOCK(push_a_r_args):
n=*bsp++;
array=(BC_WORD*)asp[0];
desc=(BC_WORD*)array[2];
ab_arity=((int16_t*)desc)[0]-256;
a_arity=((int16_t*)desc)[1];
ab_arity=((int16_t*)desc)[-1]-256;
a_arity=((int16_t*)desc)[0];
b_arity=ab_arity-a_arity;
array_o=(ab_arity*n)+3;
a=&array[array_o];
......@@ -9260,7 +9260,7 @@ INSTRUCTION_BLOCK(push_a_r_args):
bsp-=b_arity;
for (int i=0;i<b_arity;i++)
bsp[i]=b[i];
*--bsp=(BC_WORD)(desc+2);
*--bsp=(BC_WORD)(desc+2)-2;
END_INSTRUCTION_BLOCK;
}
INSTRUCTION_BLOCK(push_r_arg_D):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment