| */ |
*/ |
| |
|
| #include "config.h" |
#include "config.h" |
| |
#include "forth.h" |
| #include <errno.h> |
#include <errno.h> |
| #include <ctype.h> |
#include <ctype.h> |
| #include <stdio.h> |
#include <stdio.h> |
| #include <sys/mman.h> |
#include <sys/mman.h> |
| #endif |
#endif |
| #endif |
#endif |
| #include "forth.h" |
|
| #include "io.h" |
#include "io.h" |
| #include "getopt.h" |
#include "getopt.h" |
| #ifdef STANDALONE |
#ifdef STANDALONE |
| is it's number, otherwise this contains 0 */ |
is it's number, otherwise this contains 0 */ |
| |
|
| static int no_super=0; /* true if compile_prim should not fuse prims */ |
static int no_super=0; /* true if compile_prim should not fuse prims */ |
| /* --no-dynamic by default on gcc versions >=3.1 (it works with 3.0.4, |
static int no_dynamic=NO_DYNAMIC_DEFAULT; /* if true, no code is generated |
| but not with 3.2) */ |
dynamically */ |
| #if (__GNUC__>2 && __GNUC_MINOR__>=1) |
|
| static int no_dynamic=1; /* true if compile_prim should not generate code */ |
|
| #else |
|
| static int no_dynamic=0; /* true if compile_prim should not generate code */ |
|
| #endif |
|
| |
|
| #ifdef HAS_DEBUG |
#ifdef HAS_DEBUG |
| int debug=0; |
int debug=0; |
| /* image file format: |
/* image file format: |
| * "#! binary-path -i\n" (e.g., "#! /usr/local/bin/gforth-0.4.0 -i\n") |
* "#! binary-path -i\n" (e.g., "#! /usr/local/bin/gforth-0.4.0 -i\n") |
| * padding to a multiple of 8 |
* padding to a multiple of 8 |
| * magic: "Gforth2x" means format 0.4, |
* magic: "Gforth3x" means format 0.6, |
| * where x is a byte with |
* where x is a byte with |
| * bit 7: reserved = 0 |
* bit 7: reserved = 0 |
| * bit 6:5: address unit size 2^n octets |
* bit 6:5: address unit size 2^n octets |
| compile_prim1(&image[i]); |
compile_prim1(&image[i]); |
| #endif |
#endif |
| } else |
} else |
| fprintf(stderr,"Primitive %d used in this image at $%lx is not implemented by this\n engine (%s); executing this code will crash.\n",CF(token),(long)&image[i],VERSION); |
fprintf(stderr,"Primitive %d used in this image at $%lx is not implemented by this\n engine (%s); executing this code will crash.\n",CF(token),(long)&image[i],PACKAGE_VERSION); |
| } |
} |
| else { |
else { |
| // if base is > 0: 0 is a null reference so don't adjust |
// if base is > 0: 0 is a null reference so don't adjust |
| Label compile_prim(Label prim) |
Label compile_prim(Label prim) |
| { |
{ |
| Cell x=(Cell)prim; |
Cell x=(Cell)prim; |
| |
assert(0); |
| compile_prim1(&x); |
compile_prim1(&x); |
| return (Label)x; |
return (Label)x; |
| } |
} |
| |
|
| do { |
do { |
| if(fread(magic,sizeof(Char),8,imagefile) < 8) { |
if(fread(magic,sizeof(Char),8,imagefile) < 8) { |
| fprintf(stderr,"%s: image %s doesn't seem to be a Gforth (>=0.4) image.\n", |
fprintf(stderr,"%s: image %s doesn't seem to be a Gforth (>=0.6) image.\n", |
| progname, filename); |
progname, filename); |
| exit(1); |
exit(1); |
| } |
} |
| preamblesize+=8; |
preamblesize+=8; |
| } while(memcmp(magic,"Gforth2",7)); |
} while(memcmp(magic,"Gforth3",7)); |
| magic7 = magic[7]; |
magic7 = magic[7]; |
| if (debug) { |
if (debug) { |
| magic[7]='\0'; |
magic[7]='\0'; |
| case 'c': clear_dictionary = 1; break; |
case 'c': clear_dictionary = 1; break; |
| case 's': die_on_signal = 1; break; |
case 's': die_on_signal = 1; break; |
| case 'x': debug = 1; break; |
case 'x': debug = 1; break; |
| case 'v': fprintf(stderr, "gforth %s\n", VERSION); exit(0); |
case 'v': fputs(PACKAGE_STRING"\n", stderr); exit(0); |
| case 'h': |
case 'h': |
| fprintf(stderr, "Usage: %s [engine options] ['--'] [image arguments]\n\ |
fprintf(stderr, "Usage: %s [engine options] ['--'] [image arguments]\n\ |
| Engine Options:\n\ |
Engine Options:\n\ |