| #include <assert.h> |
#include <assert.h> |
| #include <stdlib.h> |
#include <stdlib.h> |
| #include "forth.h" |
#include "forth.h" |
| |
#include "io.h" |
| |
|
| #ifndef DEFAULTBIN |
#ifndef DEFAULTBIN |
| # define DEFAULTBIN "" |
# define DEFAULTBIN "" |
| /* image file format: |
/* image file format: |
| * size of image with stacks without tags (in bytes) |
* size of image with stacks without tags (in bytes) |
| * size of image without stacks and tags (in bytes) |
* size of image without stacks and tags (in bytes) |
| * size of return, FP and locals stack (in bytes, just one entry) |
* size of data and FP stack (in bytes) |
| * !! have a different number for each one! |
|
| * pointer to start of code |
* pointer to start of code |
| * data (size in image[1]) |
* data (size in image[1]) |
| * tags (1 bit/data cell) |
* tags (1 bit/data cell) |
| |
|
| void relocate(int *image, char *bitstring, int size, Label symbols[]) |
void relocate(int *image, char *bitstring, int size, Label symbols[]) |
| { |
{ |
| int i; |
int i=0, j, k, steps=(size/sizeof(Cell))/8; |
| static char bits[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; |
char bits; |
| |
/* static char bits[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};*/ |
| #ifdef DEBUG |
|
| printf("Dodoes-Adresse: %08x\n",(int)symbols[DODOES]); |
for(k=0; k<=steps; k++) |
| #endif |
for(j=0, bits=bitstring[k]; j<8; j++, i++, bits<<=1) |
| |
if(bits & 0x80) |
| for(i=0;i<size/sizeof(Cell);i++) |
|
| if(bitstring[i >> 3] & bits[i & 7]) |
|
| if(image[i]<0) |
if(image[i]<0) |
| switch(image[i]) |
switch(image[i]) |
| { |
{ |
| case CF_NIL : |
case CF_NIL : image[i]=0; break; |
| image[i]=0; break; |
|
| case CF(DOCOL) : |
case CF(DOCOL) : |
| case CF(DOVAR) : |
case CF(DOVAR) : |
| case CF(DOCON) : |
case CF(DOCON) : |
| case CF(DOUSER) : |
case CF(DOUSER) : MAKE_CF(image+i,symbols[CF(image[i])]); break; |
| MAKE_CF(image+i,symbols[CF(image[i])]); break; |
case CF(DODOES) : MAKE_DOES_CF(image+i,image[i+1]+((int)image)); |
| case CF(DODOES) : |
|
| MAKE_DOES_CF(image+i,image[i+1]+((int)image)); |
|
| i++; break; /* is this necessary? */ |
|
| case CF(DOESJUMP): |
|
| MAKE_DOES_HANDLER(image+i); |
|
| break; |
break; |
| default: |
case CF(DOESJUMP): MAKE_DOES_HANDLER(image+i); break; |
| image[i]=(Cell)CA(CF(image[i])); |
default : image[i]=(Cell)CA(CF(image[i])); |
| } |
} |
| else |
else |
| image[i]+=(Cell)image; |
image[i]+=(Cell)image; |