Commit 63329256 authored by John van Groningen's avatar John van Groningen

port to 64 bit windows

parent 9f93bd7e
all: copy_graph_to_string.obj copy_graph_to_string_interface.obj copy_string_to_graph.obj copy_string_to_graph_interface.obj
copy_graph_to_string.obj: copy_graph_to_string.c
cl /nologo /c /O2 /Gy copy_graph_to_string.c
copy copy_graph_to_string.obj "Clean System Files"\copy_graph_to_string.obj
copy_graph_to_string_interface.obj: copy_graph_to_string_interface.s
ml64 /nologo /c copy_graph_to_string_interface.asm
copy copy_graph_to_string_interface.obj "Clean System Files"\copy_graph_to_string_interface.obj
copy_string_to_graph.obj: copy_string_to_graph.c
cl /nologo /c /O2 /Gy copy_string_to_graph.c
copy copy_string_to_graph.obj "Clean System Files"\copy_string_to_graph.obj
copy_string_to_graph_interface.obj: copy_string_to_graph_interface.s
ml64 /nologo /c copy_string_to_graph_interface.asm
copy copy_string_to_graph_interface.obj "Clean System Files"\copy_string_to_graph_interface.obj
#include <stdlib.h> #include <stdlib.h>
extern void *INT,*CHAR,*BOOL,*REAL,*_STRING__,*_ARRAY__; #ifdef _WIN64
# define Int __int64
# define INT_descriptor dINT
#else
# define Int int
# define INT_descriptor INT
# define __STRING__ _STRING__
# define __ARRAY__ _ARRAY__
#endif
extern void *INT_descriptor,*CHAR,*BOOL,*REAL,*__STRING__,*__ARRAY__;
/*inline*/ /*inline*/
static void copy (int *dest_p,int *source_p,int n_words) static void copy (Int *dest_p,Int *source_p,Int n_words)
{ {
int i; Int i;
for (i=0; i<n_words; ++i) for (i=0; i<n_words; ++i)
dest_p[i]=source_p[i]; dest_p[i]=source_p[i];
} }
int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap) Int *copy_graph_to_string (Int *node_p,void *begin_free_heap,void *end_free_heap)
{ {
int **stack_p,**stack_begin,**stack_end,*heap_p; Int **stack_p,**stack_begin,**stack_end,*heap_p;
stack_end=end_free_heap; stack_end=end_free_heap;
stack_begin=end_free_heap; stack_begin=end_free_heap;
...@@ -22,53 +32,62 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap ...@@ -22,53 +32,62 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap
heap_p=begin_free_heap; heap_p=begin_free_heap;
if (heap_p+2>(int*)stack_begin) if (heap_p+2>(Int*)stack_begin)
return NULL; return NULL;
heap_p[0]=(int)&_STRING__+2; heap_p[0]=(Int)&__STRING__+2;
heap_p[1]=0; heap_p[1]=0;
heap_p+=2; heap_p+=2;
for (;;){ for (;;){
for (;;){ for (;;){
int desc; Int desc;
desc=*node_p; desc=*node_p;
if (heap_p>=(int*)stack_begin) if (heap_p>=(Int*)stack_begin)
return NULL; return NULL;
if (!(desc & 1)){ if (!(desc & 1)){
*node_p=1+(int)heap_p; *node_p=1+(Int)heap_p;
*heap_p++=desc; *heap_p++=desc;
if (desc & 2){ if (desc & 2){
unsigned int arity; unsigned Int arity;
arity=((unsigned short *)desc)[-1]; arity=((unsigned short *)desc)[-1];
if (arity==0){ if (arity==0){
if (desc==(int)&INT+2 || desc==(int)&CHAR+2 || desc==(int)&BOOL+2){ if (desc==(Int)&INT_descriptor+2 || desc==(Int)&CHAR+2 || desc==(Int)&BOOL+2
if (heap_p>=(int*)stack_begin) #ifdef _WIN64
|| desc==(Int)&REAL+2
#endif
){
if (heap_p>=(Int*)stack_begin)
return NULL; return NULL;
*heap_p++=node_p[1]; *heap_p++=node_p[1];
break; break;
} else if (desc==(int)&REAL+2){ #ifndef _WIN64
if (heap_p+2>(int*)stack_begin) } else if (desc==(Int)&REAL+2){
if (heap_p+2>(Int*)stack_begin)
return NULL; return NULL;
heap_p[0]=node_p[1]; heap_p[0]=node_p[1];
heap_p[1]=node_p[2]; heap_p[1]=node_p[2];
heap_p+=2; heap_p+=2;
break; break;
} else if (desc==(int)&_STRING__+2){ #endif
unsigned int length,n_words; } else if (desc==(Int)&__STRING__+2){
unsigned Int length,n_words;
length=node_p[1]; length=node_p[1];
node_p+=2; node_p+=2;
#ifdef _WIN64
n_words=(length+7)>>3;
#else
n_words=(length+3)>>2; n_words=(length+3)>>2;
#endif
if (heap_p+n_words>=(int*)stack_begin) if (heap_p+n_words>=(Int*)stack_begin)
return NULL; return NULL;
*heap_p++=length; *heap_p++=length;
...@@ -76,10 +95,10 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap ...@@ -76,10 +95,10 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap
copy (heap_p,node_p,n_words); copy (heap_p,node_p,n_words);
heap_p+=n_words; heap_p+=n_words;
break; break;
} else if (desc==(int)&_ARRAY__+2){ } else if (desc==(Int)&__ARRAY__+2){
int array_size,elem_desc; Int array_size,elem_desc;
if (heap_p+2>(int*)stack_begin) if (heap_p+2>(Int*)stack_begin)
return NULL; return NULL;
array_size=node_p[1]; array_size=node_p[1];
...@@ -93,49 +112,58 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap ...@@ -93,49 +112,58 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap
if (elem_desc==0){ if (elem_desc==0){
stack_p-=array_size; stack_p-=array_size;
if (stack_p<stack_begin){ if (stack_p<stack_begin){
if ((int*)stack_p<heap_p) if ((Int*)stack_p<heap_p)
return NULL; return NULL;
stack_begin=stack_p; stack_begin=stack_p;
} }
while (--array_size>=0) while (--array_size>=0)
stack_p[array_size]=(int*)node_p[array_size]; stack_p[array_size]=(Int*)node_p[array_size];
break; break;
} else if (elem_desc==(int)&INT+2){ } else if (elem_desc==(Int)&INT_descriptor+2
if (heap_p+array_size>(int*)stack_begin) #ifdef _WIN64
|| elem_desc==(Int)&REAL+2
#endif
){
if (heap_p+array_size>(Int*)stack_begin)
return NULL; return NULL;
copy (heap_p,node_p,array_size); copy (heap_p,node_p,array_size);
heap_p+=array_size; heap_p+=array_size;
break; break;
} else if (elem_desc==(int)&REAL+2){ #ifndef _WIN64
} else if (elem_desc==(Int)&REAL+2){
array_size<<=1; array_size<<=1;
if (heap_p+array_size>(int*)stack_begin) if (heap_p+array_size>(Int*)stack_begin)
return NULL; return NULL;
copy (heap_p,node_p,array_size); copy (heap_p,node_p,array_size);
heap_p+=array_size; heap_p+=array_size;
break; break;
} else if (elem_desc==(int)&BOOL+2){ #endif
} else if (elem_desc==(Int)&BOOL+2){
#ifdef _WIN64
array_size=(array_size+7)>>3;
#else
array_size=(array_size+3)>>2; array_size=(array_size+3)>>2;
#endif
if (heap_p+array_size>(int*)stack_begin) if (heap_p+array_size>(Int*)stack_begin)
return NULL; return NULL;
copy (heap_p,node_p,array_size); copy (heap_p,node_p,array_size);
heap_p+=array_size; heap_p+=array_size;
break; break;
} else { } else {
int n_field_pointers,field_size; Int n_field_pointers,field_size;
n_field_pointers=*(unsigned short *)elem_desc; n_field_pointers=*(unsigned short *)elem_desc;
field_size=((unsigned short *)elem_desc)[-1]-256; field_size=((unsigned short *)elem_desc)[-1]-(Int)256;
if (n_field_pointers==0){ if (n_field_pointers==0){
array_size*=field_size; array_size*=field_size;
if (heap_p+array_size>(int*)stack_begin) if (heap_p+array_size>(Int*)stack_begin)
return NULL; return NULL;
copy (heap_p,node_p,array_size); copy (heap_p,node_p,array_size);
...@@ -146,32 +174,32 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap ...@@ -146,32 +174,32 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap
stack_p-=array_size; stack_p-=array_size;
if (stack_p<stack_begin){ if (stack_p<stack_begin){
if ((int*)stack_p<heap_p) if ((Int*)stack_p<heap_p)
return NULL; return NULL;
stack_begin=stack_p; stack_begin=stack_p;
} }
while (--array_size>=0) while (--array_size>=0)
stack_p[array_size]=(int*)node_p[array_size]; stack_p[array_size]=(Int*)node_p[array_size];
break; break;
} else { } else {
int n_non_field_pointers,n_array_pointers,n_array_non_pointers,i,*pointer_p; Int n_non_field_pointers,n_array_pointers,n_array_non_pointers,i,*pointer_p;
n_non_field_pointers=field_size-n_field_pointers; n_non_field_pointers=field_size-n_field_pointers;
n_array_pointers=n_field_pointers*array_size; n_array_pointers=n_field_pointers*array_size;
n_array_non_pointers=n_non_field_pointers*array_size; n_array_non_pointers=n_non_field_pointers*array_size;
if (heap_p+n_array_non_pointers>(int*)stack_begin) if (heap_p+n_array_non_pointers>(Int*)stack_begin)
return NULL; return NULL;
stack_p-=n_array_pointers; stack_p-=n_array_pointers;
if (stack_p<stack_begin){ if (stack_p<stack_begin){
if ((int*)stack_p<heap_p+n_array_non_pointers) if ((Int*)stack_p<heap_p+n_array_non_pointers)
return NULL; return NULL;
stack_begin=stack_p; stack_begin=stack_p;
} }
pointer_p=(int*)stack_p; pointer_p=(Int*)stack_p;
for (i=0; i<array_size; ++i){ for (i=0; i<array_size; ++i){
copy (pointer_p,node_p,n_field_pointers); copy (pointer_p,node_p,n_field_pointers);
...@@ -189,27 +217,27 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap ...@@ -189,27 +217,27 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap
break; break;
} }
} else if (arity==1){ } else if (arity==1){
node_p=(int*)node_p[1]; node_p=(Int*)node_p[1];
continue; continue;
} else if (arity==2){ } else if (arity==2){
if (stack_p<=stack_begin){ if (stack_p<=stack_begin){
if ((int*)stack_p<=heap_p) if ((Int*)stack_p<=heap_p)
return NULL; return NULL;
--stack_begin; --stack_begin;
} }
*--stack_p=(int*)node_p[2]; *--stack_p=(Int*)node_p[2];
node_p=(int*)node_p[1]; node_p=(Int*)node_p[1];
continue; continue;
} else if (arity<256){ } else if (arity<256){
int **args,n_words; Int **args,n_words;
args=(int**)node_p[2]; args=(Int**)node_p[2];
n_words=arity-1; n_words=arity-1;
stack_p-=n_words; stack_p-=n_words;
if (stack_p<stack_begin){ if (stack_p<stack_begin){
if ((int*)stack_p<heap_p) if ((Int*)stack_p<heap_p)
return NULL; return NULL;
stack_begin=stack_p; stack_begin=stack_p;
} }
...@@ -221,28 +249,28 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap ...@@ -221,28 +249,28 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap
while (--n_words>=0) while (--n_words>=0)
stack_p[n_words]=args[n_words]; stack_p[n_words]=args[n_words];
node_p=(int*)node_p[1]; node_p=(Int*)node_p[1];
continue; continue;
} else { } else {
int n_pointers; Int n_pointers;
n_pointers=*(unsigned short*)desc; n_pointers=*(unsigned short*)desc;
arity-=256; arity-=256;
if (arity==1){ if (arity==1){
if (n_pointers==0){ if (n_pointers==0){
if (heap_p>=(int*)stack_begin) if (heap_p>=(Int*)stack_begin)
return NULL; return NULL;
*heap_p++=node_p[1]; *heap_p++=node_p[1];
break; break;
} else { } else {
node_p=(int*)node_p[1]; node_p=(Int*)node_p[1];
continue; continue;
} }
} else if (arity==2){ } else if (arity==2){
if (n_pointers==0){ if (n_pointers==0){
if (heap_p+2>(int*)stack_begin) if (heap_p+2>(Int*)stack_begin)
return NULL; return NULL;
heap_p[0]=node_p[1]; heap_p[0]=node_p[1];
...@@ -251,29 +279,29 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap ...@@ -251,29 +279,29 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap
break; break;
} else { } else {
if (n_pointers==1){ if (n_pointers==1){
if (heap_p>=(int*)stack_begin) if (heap_p>=(Int*)stack_begin)
return NULL; return NULL;
*heap_p++=node_p[2]; *heap_p++=node_p[2];
} else { } else {
if (stack_p<=stack_begin){ if (stack_p<=stack_begin){
if ((int*)stack_p<=heap_p) if ((Int*)stack_p<=heap_p)
return NULL; return NULL;
--stack_begin; --stack_begin;
} }
*--stack_p=(int*)node_p[2]; *--stack_p=(Int*)node_p[2];
} }
node_p=(int*)node_p[1]; node_p=(Int*)node_p[1];
continue; continue;
} }
} else { } else {
int *args; Int *args;
args=(int*)node_p[2]; args=(Int*)node_p[2];
if (n_pointers==0){ if (n_pointers==0){
if (heap_p+arity>=(int*)stack_begin) if (heap_p+arity>=(Int*)stack_begin)
return NULL; return NULL;
heap_p[0]=node_p[1]; heap_p[0]=node_p[1];
...@@ -284,14 +312,14 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap ...@@ -284,14 +312,14 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap
heap_p+=arity; heap_p+=arity;
break; break;
} else { } else {
int n_non_pointers; Int n_non_pointers;
n_non_pointers=arity-n_pointers; n_non_pointers=arity-n_pointers;
if (n_non_pointers>0){ if (n_non_pointers>0){
int *non_pointers_p; Int *non_pointers_p;
if (heap_p+n_non_pointers>(int*)stack_begin) if (heap_p+n_non_pointers>(Int*)stack_begin)
return NULL; return NULL;
non_pointers_p=&args[n_pointers-1]; non_pointers_p=&args[n_pointers-1];
...@@ -304,33 +332,33 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap ...@@ -304,33 +332,33 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap
if (n_pointers>0){ if (n_pointers>0){
stack_p-=n_pointers; stack_p-=n_pointers;
if (stack_p<stack_begin){ if (stack_p<stack_begin){
if ((int*)stack_p<heap_p) if ((Int*)stack_p<heap_p)
return NULL; return NULL;
stack_begin=stack_p; stack_begin=stack_p;
} }
copy ((int*)stack_p,args,n_pointers); copy ((Int*)stack_p,args,n_pointers);
} }
node_p=(int*)node_p[1]; node_p=(Int*)node_p[1];
continue; continue;
} }
} }
} }
} else { } else {
int arity; Int arity;
arity=((int*)desc)[-1]; arity=((int*)desc)[-1];
if (arity>1){ if (arity>1){
if (arity<256){ if (arity<256){
int **args,n_words; Int **args,n_words;
args=(int**)&node_p[2]; args=(Int**)&node_p[2];
n_words=arity-1; n_words=arity-1;
stack_p-=n_words; stack_p-=n_words;
if (stack_p<stack_begin){ if (stack_p<stack_begin){
if ((int*)stack_p<heap_p) if ((Int*)stack_p<heap_p)
return NULL; return NULL;
stack_begin=stack_p; stack_begin=stack_p;
} }
...@@ -340,15 +368,15 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap ...@@ -340,15 +368,15 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap
while (--n_words>=0) while (--n_words>=0)
stack_p[n_words]=args[n_words]; stack_p[n_words]=args[n_words];
node_p=(int*)node_p[1]; node_p=(Int*)node_p[1];
continue; continue;
} else { } else {
int n_pointers,n_non_pointers,*non_pointers_p; Int n_pointers,n_non_pointers,*non_pointers_p;
n_non_pointers=arity>>8; n_non_pointers=arity>>8;
n_pointers=(arity & 255) - n_non_pointers; n_pointers=(arity & 255) - n_non_pointers;
if (heap_p+n_non_pointers>(int*)stack_begin) if (heap_p+n_non_pointers>(Int*)stack_begin)
return NULL; return NULL;
non_pointers_p=&node_p[1+n_pointers]; non_pointers_p=&node_p[1+n_pointers];
...@@ -360,14 +388,14 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap ...@@ -360,14 +388,14 @@ int *copy_graph_to_string (int *node_p,void *begin_free_heap,void *end_free_heap
break;