Annotation of gforth/engine/forth.h, revision 1.133

1.1       anton       1: /* common header file
                      2: 
1.133   ! anton       3:   Copyright (C) 1995,1996,1997,1998,2000,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012 Free Software Foundation, Inc.
1.1       anton       4: 
                      5:   This file is part of Gforth.
                      6: 
                      7:   Gforth is free software; you can redistribute it and/or
                      8:   modify it under the terms of the GNU General Public License
1.89      anton       9:   as published by the Free Software Foundation, either version 3
1.1       anton      10:   of the License, or (at your option) any later version.
                     11: 
                     12:   This program is distributed in the hope that it will be useful,
                     13:   but WITHOUT ANY WARRANTY; without even the implied warranty of
                     14:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     15:   GNU General Public License for more details.
                     16: 
                     17:   You should have received a copy of the GNU General Public License
1.89      anton      18:   along with this program; if not, see http://www.gnu.org/licenses/.
1.1       anton      19: */
                     20: 
                     21: #include "config.h"
1.90      anton      22: #include "128bit.h"
1.18      anton      23: #include <stdio.h>
1.35      anton      24: #include <sys/time.h>
                     25: #include <unistd.h>
1.95      pazsan     26: #ifndef STANDALONE
1.103     anton      27: #if defined(HAVE_LIBLTDL)
1.87      anton      28: #include <ltdl.h>
1.95      pazsan     29: #endif
1.103     anton      30: #endif
1.1       anton      31: 
1.93      anton      32: #if !defined(FORCE_LL) && !defined(BUGGY_LONG_LONG)
                     33: #define BUGGY_LONG_LONG
                     34: #endif
                     35: 
1.32      anton      36: #if defined(DOUBLY_INDIRECT)||defined(INDIRECT_THREADED)||defined(VM_PROFILING)
                     37: #define NO_DYNAMIC
                     38: #endif
                     39: 
1.1       anton      40: #if defined(DOUBLY_INDIRECT)
                     41: #  undef DIRECT_THREADED
                     42: #  undef INDIRECT_THREADED
                     43: #  define INDIRECT_THREADED
                     44: #endif
                     45: 
1.57      anton      46: #if defined(GFORTH_DEBUGGING) || defined(INDIRECT_THREADED) || defined(DOUBLY_INDIRECT) || defined(VM_PROFILING)
1.23      anton      47: #  undef USE_TOS
                     48: #  undef USE_FTOS
1.56      anton      49: #  undef USE_NO_TOS
                     50: #  undef USE_NO_FTOS
1.23      anton      51: #  define USE_NO_TOS
                     52: #  define USE_NO_FTOS
1.57      anton      53: 
                     54: #define PRIM_I "prim.i"
                     55: #define PRIM_LAB_I "prim_lab.i"
                     56: #define PRIM_NAMES_I "prim_names.i"
                     57: #define PRIM_SUPEREND_I "prim_superend.i"
                     58: #define PRIM_NUM_I "prim_num.i"
                     59: #define PRIM_GRP_I "prim_grp.i"
                     60: #define COSTS_I "costs.i"
                     61: #define SUPER2_I "super2.i"
1.58      anton      62: /* #define PROFILE_I "profile.i" */
1.57      anton      63: 
                     64: #else
                     65: /* gforth-fast or gforth-native */
1.59      anton      66: #  undef USE_TOS
                     67: #  undef USE_FTOS
                     68: #  undef USE_NO_TOS
                     69: #  undef USE_NO_FTOS
                     70: #  define USE_TOS
1.57      anton      71: 
                     72: #define PRIM_I "prim-fast.i"
                     73: #define PRIM_LAB_I "prim_lab-fast.i"
                     74: #define PRIM_NAMES_I "prim_names-fast.i"
                     75: #define PRIM_SUPEREND_I "prim_superend-fast.i"
                     76: #define PRIM_NUM_I "prim_num-fast.i"
                     77: #define PRIM_GRP_I "prim_grp-fast.i"
                     78: #define COSTS_I "costs-fast.i"
                     79: #define SUPER2_I "super2-fast.i"
1.58      anton      80: /* profile.c uses profile.i but does not define VM_PROFILING */
                     81: /* #define PROFILE_I "profile-fast.i" */
1.57      anton      82: 
1.23      anton      83: #endif
1.57      anton      84: 
                     85: 
1.23      anton      86: 
1.1       anton      87: #include <limits.h>
                     88: 
                     89: #if defined(NeXT)
                     90: #  include <libc.h>
                     91: #endif /* NeXT */
                     92: 
                     93: /* symbol indexed constants */
                     94: 
                     95: #define DOCOL  0
                     96: #define DOCON  1
                     97: #define DOVAR  2
                     98: #define DOUSER 3
                     99: #define DODEFER        4
                    100: #define DOFIELD        5
1.86      pazsan    101: #define DOVAL  6
                    102: #define DODOES 7
1.110     anton     103: #define DOABICODE      8
                    104: #define DOSEMIABICODE   9
1.108     dvdkhlng  105: #define DOER_MAX        9
1.1       anton     106: 
1.6       jwilke    107: #include "machine.h"
1.1       anton     108: 
1.68      pazsan    109: /* C interface data types */
                    110: 
                    111: typedef WYDE_TYPE Wyde;
                    112: typedef TETRABYTE_TYPE Tetrabyte;
1.112     pazsan    113: typedef OCTABYTE_TYPE Octabyte;
1.68      pazsan    114: typedef unsigned WYDE_TYPE UWyde;
                    115: typedef unsigned TETRABYTE_TYPE UTetrabyte;
1.112     pazsan    116: typedef unsigned OCTABYTE_TYPE UOctabyte;
1.68      pazsan    117: 
1.1       anton     118: /* Forth data types */
                    119: /* Cell and UCell must be the same size as a pointer */
                    120: #define CELL_BITS      (sizeof(Cell) * CHAR_BIT)
1.77      anton     121: #define CELL_MIN (((Cell)1)<<(sizeof(Cell)*CHAR_BIT-1))
1.78      anton     122: 
                    123: #define HALFCELL_BITS  (CELL_BITS/2)
                    124: #define HALFCELL_MASK   ((~(UCell)0)>>HALFCELL_BITS)
                    125: #define UH(x)          (((UCell)(x))>>HALFCELL_BITS)
                    126: #define LH(x)          ((x)&HALFCELL_MASK)
                    127: #define L2U(x)         (((UCell)(x))<<HALFCELL_BITS)
                    128: #define HIGHBIT(x)     (((UCell)(x))>>(CELL_BITS-1))
                    129: 
1.1       anton     130: #define FLAG(b) (-(b))
                    131: #define FILEIO(error)  (FLAG(error) & -37)
                    132: #define FILEEXIST(error)       (FLAG(error) & -38)
                    133: 
                    134: #define F_TRUE (FLAG(0==0))
                    135: #define F_FALSE (FLAG(0!=0))
                    136: 
1.65      pazsan    137: /* define this false if you want native division */
1.66      pazsan    138: #ifdef FORCE_CDIV
                    139: #define FLOORED_DIV 0
                    140: #else
1.65      pazsan    141: #define FLOORED_DIV ((1%-3)>0)
1.66      pazsan    142: #endif
1.65      pazsan    143: 
1.93      anton     144: #if defined(BUGGY_LONG_LONG)
1.64      pazsan    145: 
                    146: #define BUGGY_LL_CMP    /* compares not possible */
                    147: #define BUGGY_LL_MUL    /* multiplication not possible */
                    148: #define BUGGY_LL_DIV    /* division not possible */
                    149: #define BUGGY_LL_ADD    /* addition not possible */
                    150: #define BUGGY_LL_SHIFT  /* shift not possible */
                    151: #define BUGGY_LL_D2F    /* to float not possible */
                    152: #define BUGGY_LL_F2D    /* from float not possible */
                    153: #define BUGGY_LL_SIZE   /* long long "too short", so we use something else */
                    154: 
1.1       anton     155: typedef struct {
                    156:   Cell hi;
                    157:   UCell lo;
                    158: } DCell;
                    159: 
                    160: typedef struct {
                    161:   UCell hi;
                    162:   UCell lo;
                    163: } UDCell;
                    164: 
1.64      pazsan    165: #define DHI(x) (x).hi
                    166: #define DLO(x) (x).lo
                    167: #define DHI_IS(x,y) (x).hi=(y)
                    168: #define DLO_IS(x,y) (x).lo=(y)
                    169: 
1.78      anton     170: #define UD2D(ud)       ({UDCell _ud=(ud); (DCell){_ud.hi,_ud.lo};})
1.80      anton     171: #define D2UD(d)                ({DCell _d1=(d); (UDCell){_d1.hi,_d1.lo};})
                    172: 
                    173: /* shifts by less than CELL_BITS */
1.104     anton     174: #define DLSHIFT(d,u) ({DCell _d=(d); UCell _u=(u); \
                    175:                        ((_u==0) ? \
                    176:                         _d : \
                    177:                         (DCell){(_d.hi<<_u)|(_d.lo>>(CELL_BITS-_u)), \
                    178:                                  _d.lo<<_u});})
                    179: 
1.80      anton     180: #define UDLSHIFT(ud,u) D2UD(DLSHIFT(UD2D(ud),u))
1.78      anton     181: 
1.39      anton     182: #if SMALL_OFF_T
                    183: #define OFF2UD(o) ({UDCell _ud; _ud.hi=0; _ud.lo=(Cell)(o); _ud;})
                    184: #define UD2OFF(ud) ((ud).lo)
                    185: #else /* !SMALL_OFF_T */
                    186: #define OFF2UD(o) ({UDCell _ud; off_t _o=(o); _ud.hi=_o>>CELL_BITS; _ud.lo=(Cell)_o; _ud;})
1.36      anton     187: #define UD2OFF(ud) ({UDCell _ud=(ud); (((off_t)_ud.hi)<<CELL_BITS)+_ud.lo;})
1.39      anton     188: #endif /* !SMALL_OFF_T */
1.1       anton     189: #define DZERO          ((DCell){0,0})
                    190: 
1.93      anton     191: #else /* !defined(BUGGY_LONG_LONG) */
1.1       anton     192: 
                    193: /* DCell and UDCell must be twice as large as Cell */
                    194: typedef DOUBLE_CELL_TYPE DCell;
1.63      pazsan    195: typedef DOUBLE_UCELL_TYPE UDCell;
1.1       anton     196: 
1.93      anton     197: #define DHI(x) ({ Double_Store _d; _d.d=(x); _d.cells.high; })
                    198: #define DLO(x) ({ Double_Store _d; _d.d=(x); _d.cells.low;  })
                    199: 
                    200: /* beware with the assignment: x is referenced twice! */
                    201: #define DHI_IS(x,y) ({ Double_Store _d; _d.d=(x); _d.cells.high=(y); (x)=_d.d; })
                    202: #define DLO_IS(x,y) ({ Double_Store _d; _d.d=(x); _d.cells.low =(y); (x)=_d.d; })
                    203: 
                    204: #define UD2D(ud)       ((DCell)(ud))
                    205: #define D2UD(d)                ((UDCell)(d))
1.36      anton     206: #define OFF2UD(o)      ((UDCell)(o))
                    207: #define UD2OFF(ud)     ((off_t)(ud))
1.16      anton     208: #define DZERO          ((DCell)0)
1.80      anton     209: /* shifts by less than CELL_BITS */
                    210: #define DLSHIFT(d,u)  ((d)<<(u))
                    211: #define UDLSHIFT(d,u)  ((d)<<(u))
1.16      anton     212: 
1.93      anton     213: #endif /* !defined(BUGGY_LONG_LONG) */
1.16      anton     214: 
1.1       anton     215: typedef union {
                    216:   struct {
1.16      anton     217: #if defined(WORDS_BIGENDIAN)||defined(BUGGY_LONG_LONG)
1.1       anton     218:     Cell high;
                    219:     UCell low;
                    220: #else
                    221:     UCell low;
                    222:     Cell high;
1.20      crook     223: #endif
1.1       anton     224:   } cells;
1.16      anton     225:   DCell d;
                    226:   UDCell ud;
1.1       anton     227: } Double_Store;
1.64      pazsan    228: 
1.16      anton     229: #define FETCH_DCELL_T(d_,lo,hi,t_)     ({ \
1.1       anton     230:                                     Double_Store _d; \
                    231:                                     _d.cells.low = (lo); \
                    232:                                     _d.cells.high = (hi); \
1.16      anton     233:                                     (d_) = _d.t_; \
1.1       anton     234:                                 })
                    235: 
1.16      anton     236: #define STORE_DCELL_T(d_,lo,hi,t_)     ({ \
1.1       anton     237:                                     Double_Store _d; \
1.16      anton     238:                                     _d.t_ = (d_); \
1.1       anton     239:                                     (lo) = _d.cells.low; \
                    240:                                     (hi) = _d.cells.high; \
                    241:                                 })
                    242: 
1.28      anton     243: #define vm_twoCell2d(lo,hi,d_)  FETCH_DCELL_T(d_,lo,hi,d);
                    244: #define vm_twoCell2ud(lo,hi,d_) FETCH_DCELL_T(d_,lo,hi,ud);
1.1       anton     245: 
1.28      anton     246: #define vm_d2twoCell(d_,lo,hi)  STORE_DCELL_T(d_,lo,hi,d);
                    247: #define vm_ud2twoCell(d_,lo,hi) STORE_DCELL_T(d_,lo,hi,ud);
1.1       anton     248: 
                    249: typedef Label *Xt;
                    250: 
                    251: /* PFA gives the parameter field address corresponding to a cfa */
                    252: #define PFA(cfa)       (((Cell *)cfa)+2)
                    253: /* PFA1 is a special version for use just after a NEXT1 */
                    254: #define PFA1(cfa)      PFA(cfa)
                    255: /* CODE_ADDRESS is the address of the code jumped to through the code field */
                    256: #define CODE_ADDRESS(cfa)      (*(Xt)(cfa))
                    257: 
                    258: /* DOES_CODE is the Forth code does jumps to */
                    259: #if !defined(DOUBLY_INDIRECT)
                    260: #  define DOES_CA (symbols[DODOES])
                    261: #else /* defined(DOUBLY_INDIRECT) */
1.24      anton     262: #  define DOES_CA ((Label)&xts[DODOES])
1.1       anton     263: #endif /* defined(DOUBLY_INDIRECT) */
                    264: 
                    265: 
                    266: 
                    267: #define DOES_CODE1(cfa)        ((Xt *)(cfa[1]))
                    268: /* MAKE_CF creates an appropriate code field at the cfa;
                    269:    ca is the code address */
                    270: #define MAKE_CF(cfa,ca) ((*(Label *)(cfa)) = ((Label)ca))
                    271: /* make a code field for a defining-word-defined word */
                    272: 
                    273: #define CF(const)      (-const-2)
                    274: 
                    275: #define CF_NIL -1
                    276: 
                    277: #ifndef FLUSH_ICACHE
                    278: #warning flush-icache probably will not work (see manual)
                    279: #      define FLUSH_ICACHE(addr,size)
1.45      anton     280: #warning no FLUSH_ICACHE, turning off dynamic native code by default
                    281: #undef NO_DYNAMIC_DEFAULT
                    282: #define NO_DYNAMIC_DEFAULT 1
1.1       anton     283: #endif
                    284: 
1.113     dvdkhlng  285: #ifndef CHECK_PRIM
                    286: #define CHECK_PRIM(start,len) 0
                    287: #endif
                    288: 
1.67      anton     289: #if defined(GFORTH_DEBUGGING) || defined(INDIRECT_THREADED) || defined(DOUBLY_INDIRECT) || defined(VM_PROFILING)
                    290: #define STACK_CACHE_DEFAULT 0
1.1       anton     291: #else
1.67      anton     292: #define STACK_CACHE_DEFAULT STACK_CACHE_DEFAULT_FAST
1.1       anton     293: #endif
                    294: 
                    295: #ifdef USE_FTOS
1.14      anton     296: #define IF_fpTOS(x) x
1.1       anton     297: #else
1.14      anton     298: #define IF_fpTOS(x)
                    299: #define fpTOS (fp[0])
1.1       anton     300: #endif
                    301: 
1.15      anton     302: #define IF_rpTOS(x)
                    303: #define rpTOS (rp[0])
                    304: 
1.10      anton     305: typedef struct {
1.125     pazsan    306:   Cell next_task;
                    307:   Cell prev_task;
                    308:   Cell save_task;
                    309:   Cell* sp0;
                    310:   Cell* rp0;
                    311:   Float* fp0;
                    312:   Address lp0;
                    313:   Xt *throw_entry;
                    314: } user_area;
                    315: 
                    316: typedef struct {
1.10      anton     317:   Address base;                /* base address of image (0 if relocatable) */
                    318:   UCell checksum;      /* checksum of ca's to protect against some
                    319:                           incompatible binary/executable combinations
                    320:                           (0 if relocatable) */
                    321:   UCell image_size;    /* all sizes in bytes */
                    322:   UCell dict_size;
                    323:   UCell data_stack_size;
                    324:   UCell fp_stack_size;
                    325:   UCell return_stack_size;
                    326:   UCell locals_stack_size;
                    327:   Xt *boot_entry;      /* initial ip for booting (in BOOT) */
                    328:   Xt *throw_entry;     /* ip after signal (in THROW) */
1.127     pazsan    329:   Xt *quit_entry;
                    330:   Xt *execute_entry;
1.129     pazsan    331:   Xt *find_entry;
1.24      anton     332:   Label *xt_base;         /* base of DOUBLE_INDIRECT xts[], for comp-i.fs */
1.10      anton     333: } ImageHeader;
                    334: /* the image-header is created in main.fs */
                    335: 
1.82      pazsan    336: #ifdef HAS_F83HEADERSTRING
                    337: struct F83Name {
                    338:   struct F83Name *next;  /* the link field for old hands */
                    339:   char         countetc;
                    340:   char         name[0];
                    341: };
                    342: 
                    343: #define F83NAME_COUNT(np)      ((np)->countetc & 0x1f)
                    344: #endif
1.48      anton     345: struct Longname {
                    346:   struct Longname *next;  /* the link field for old hands */
                    347:   Cell         countetc;
                    348:   char         name[0];
                    349: };
                    350: 
1.106     anton     351: #define LONGNAME_COUNT(np)     ((np)->countetc & (((~((UCell)0))<<4)>>4))
1.48      anton     352: 
                    353: struct Cellpair {
                    354:   Cell n1;
                    355:   Cell n2;
                    356: };
                    357: 
                    358: struct Cellquad {
                    359:   Cell n1;
                    360:   Cell n2;
                    361:   Cell n3;
                    362:   Cell n4;
                    363: };
1.49      anton     364: 
                    365: #define IOR(flag)      ((flag)? -512-errno : 0)
1.48      anton     366: 
1.91      anton     367: #ifdef GFORTH_DEBUGGING
                    368: #if defined(GLOBALS_NONRELOC)
                    369: /* if globals cause non-relocatable primitives, keep saved_ip and rp
                    370:    in a structure and access it through locals */
                    371: typedef struct saved_regs {
                    372:   Xt *sr_saved_ip;
                    373:   Cell *sr_rp;
                    374: } saved_regs;
1.120     pazsan    375: extern saved_regs saved_regs_v;
1.122     pazsan    376: extern PER_THREAD saved_regs *saved_regs_p;
1.91      anton     377: #define saved_ip (saved_regs_p->sr_saved_ip)
                    378: #define rp       (saved_regs_p->sr_rp)
                    379: /* for use in gforth_engine header */
1.94      anton     380: #error sr_proto not passed in fflib.fs callbacks (solution: disable GLOBALS_NONRELOC)
1.92      anton     381: #define sr_proto , struct saved_regs *saved_regs_p0
1.91      anton     382: #define sr_call  , saved_regs_p
                    383: #else /* !defined(GLOBALS_NONRELOC) */
1.122     pazsan    384: extern PER_THREAD Xt *saved_ip;
                    385: extern PER_THREAD Cell *rp;
1.91      anton     386: #define sr_proto
                    387: #define sr_call
                    388: #endif /* !defined(GLOBALS_NONRELOC) */
                    389: #else /* !defined(GFORTH_DEBUGGING) */
                    390: #define sr_proto
                    391: #define sr_call
                    392: #endif /* !defined(GFORTH_DEBUGGING) */
                    393: 
1.126     pazsan    394: Label *gforth_engine(Xt *ip sr_proto);
                    395: Label *gforth_engine2(Xt *ip sr_proto);
                    396: Label *gforth_engine3(Xt *ip sr_proto);
1.48      anton     397: 
1.125     pazsan    398: 
1.124     pazsan    399: int gforth_main(int argc, char **argv, char **env);
1.125     pazsan    400: void gforth_args(int argc, char ** argv, char ** path, char ** imagename);
                    401: Address gforth_loader(char* imagename, char* path);
                    402: user_area* gforth_stacks(Cell dsize, Cell rsize, Cell fsize, Cell lsize);
1.131     pazsan    403: void gforth_free_stacks(user_area* t);
                    404: void gforth_free();
1.129     pazsan    405: Cell gforth_go(Xt* ip0);
1.128     pazsan    406: int gforth_boot(int argc, char** argv, char* path);
1.130     pazsan    407: int gforth_start(int argc, char ** argv);
1.128     pazsan    408: int gforth_quit();
1.129     pazsan    409: Xt gforth_find(Char * name);
                    410: int gforth_execute(Xt xt);
1.125     pazsan    411: void gforth_cleanup();
                    412: void gforth_printmetrics();
1.132     pazsan    413: #if defined(DOUBLY_INDIRECT)
                    414: int gforth_make_image(int debugflag);
                    415: #endif
1.124     pazsan    416: 
1.110     anton     417: /* for ABI-CODE and ;ABI-CODE */
1.109     anton     418: typedef Cell *abifunc(Cell *sp, Float **fpp);
1.110     anton     419: typedef Cell *semiabifunc(Cell *sp, Float **fpp, Address body);
1.109     anton     420: 
1.48      anton     421: /* engine/prim support routines */
1.71      pazsan    422: Address gforth_alloc(Cell size);
1.118     pazsan    423: char *cstr(Char *from, UCell size);
                    424: char *tilde_cstr(Char *from, UCell size);
1.85      anton     425: Cell opencreate_file(char *s, Cell wfam, int flags, Cell *wiorp);
1.35      anton     426: DCell timeval2us(struct timeval *tvp);
1.115     pazsan    427: DCell timespec2ns(struct timespec *tvp);
1.48      anton     428: void cmove(Char *c_from, Char *c_to, UCell u);
                    429: void cmove_up(Char *c_from, Char *c_to, UCell u);
                    430: Cell compare(Char *c_addr1, UCell u1, Char *c_addr2, UCell u2);
                    431: struct Longname *listlfind(Char *c_addr, UCell u, struct Longname *longname1);
                    432: struct Longname *hashlfind(Char *c_addr, UCell u, Cell *a_addr);
                    433: struct Longname *tablelfind(Char *c_addr, UCell u, Cell *a_addr);
                    434: UCell hashkey1(Char *c_addr, UCell u, UCell ubits);
                    435: struct Cellpair parse_white(Char *c_addr1, UCell u1);
                    436: Cell rename_file(Char *c_addr1, UCell u1, Char *c_addr2, UCell u2);
1.105     anton     437: struct Cellquad read_line(Char *c_addr, UCell u1, FILE *wfileid);
1.48      anton     438: struct Cellpair file_status(Char *c_addr, UCell u);
1.123     pazsan    439: Cell to_float(Char *c_addr, UCell u, Float *r_p, Char dot);
1.48      anton     440: Float v_star(Float *f_addr1, Cell nstride1, Float *f_addr2, Cell nstride2, UCell ucount);
                    441: void faxpy(Float ra, Float *f_x, Cell nstridex, Float *f_y, Cell nstridey, UCell ucount);
1.60      pazsan    442: UCell lshift(UCell u1, UCell n);
                    443: UCell rshift(UCell u1, UCell n);
1.61      anton     444: int gforth_system(Char *c_addr, UCell u);
1.83      anton     445: void gforth_ms(UCell u);
1.102     pazsan    446: UCell gforth_dlopen(Char *c_addr, UCell u);
1.72      pazsan    447: Cell capscompare(Char *c_addr1, UCell u1, Char *c_addr2, UCell u2);
1.105     anton     448: int gf_ungetc(int c, FILE *stream);
                    449: void gf_regetc(FILE *stream);
                    450: int gf_ungottenc(FILE *stream);
1.1       anton     451: 
1.50      anton     452: /* signal handler stuff */
                    453: void install_signal_handlers(void);
1.75      anton     454: void throw(int code);
1.76      anton     455: /* throw codes */
                    456: #define BALL_DIVZERO     -10
                    457: #define BALL_RESULTRANGE -11
                    458: 
1.50      anton     459: typedef void Sigfunc(int);
                    460: Sigfunc *bsd_signal(int signo, Sigfunc *func);
                    461: 
1.1       anton     462: /* dblsub routines */
                    463: DCell dnegate(DCell d1);
                    464: UDCell ummul (UCell a, UCell b);
                    465: DCell mmul (Cell a, Cell b);
                    466: UDCell umdiv (UDCell u, UCell v);
                    467: DCell smdiv (DCell num, Cell denom);
                    468: DCell fmdiv (DCell num, Cell denom);
                    469: 
1.7       pazsan    470: Cell memcasecmp(const Char *s1, const Char *s2, Cell n);
1.1       anton     471: 
1.18      anton     472: void vm_print_profile(FILE *file);
                    473: void vm_count_block(Xt *ip);
1.17      anton     474: 
1.22      anton     475: /* dynamic superinstruction stuff */
1.33      anton     476: void compile_prim1(Cell *start);
                    477: void finish_code(void);
1.34      anton     478: int forget_dyncode(Address code);
                    479: Label decompile_code(Label prim);
1.17      anton     480: 
1.1       anton     481: extern int offset_image;
1.5       anton     482: extern int die_on_signal;
1.74      anton     483: extern int ignore_async_signals;
1.10      anton     484: extern UCell pagesize;
                    485: extern ImageHeader *gforth_header;
1.19      anton     486: extern Label *vm_prims;
1.24      anton     487: extern Label *xts;
1.25      anton     488: extern Cell npriminfos;
1.2       pazsan    489: 
1.31      anton     490: #ifdef HAS_DEBUG
                    491: extern int debug;
                    492: #else
                    493: # define debug 0
                    494: #endif
                    495: 
1.122     pazsan    496: extern PER_THREAD Cell *gforth_SP;
                    497: extern PER_THREAD Cell *gforth_RP;
                    498: extern PER_THREAD Address gforth_LP;
                    499: extern PER_THREAD Float *gforth_FP;
1.125     pazsan    500: extern PER_THREAD user_area* gforth_UP;
1.35      anton     501: 
1.121     pazsan    502: extern void * gforth_pointers(Cell n);
1.118     pazsan    503: 
1.53      pazsan    504: #ifdef HAS_FFCALL
1.71      pazsan    505: extern void gforth_callback(Xt* fcall, void * alist);
1.53      pazsan    506: #endif
                    507: 
1.35      anton     508: #ifdef NO_IP
                    509: extern Label next_code;
                    510: #endif
                    511: 
                    512: #ifdef HAS_FILE
                    513: extern char* fileattr[6];
                    514: extern char* pfileattr[6];
                    515: extern int ufileattr[6];
1.9       anton     516: #endif
                    517: 
1.27      anton     518: #ifdef PRINT_SUPER_LENGTHS
                    519: Cell prim_length(Cell prim);
                    520: void print_super_lengths();
                    521: #endif
1.9       anton     522: 
1.2       pazsan    523: /* declare all the functions that are missing */
                    524: #ifndef HAVE_ATANH
                    525: extern double atanh(double r1);
                    526: extern double asinh(double r1);
                    527: extern double acosh(double r1);
                    528: #endif
                    529: #ifndef HAVE_ECVT
1.4       anton     530: /* extern char* ecvt(double x, int len, int* exp, int* sign);*/
1.2       pazsan    531: #endif
                    532: #ifndef HAVE_MEMMOVE
1.3       anton     533: /* extern char *memmove(char *dest, const char *src, long n); */
1.2       pazsan    534: #endif
                    535: #ifndef HAVE_POW10
                    536: extern double pow10(double x);
                    537: #endif
                    538: #ifndef HAVE_STRERROR
                    539: extern char *strerror(int err);
                    540: #endif
                    541: #ifndef HAVE_STRSIGNAL
                    542: extern char *strsignal(int sig);
                    543: #endif
                    544: #ifndef HAVE_STRTOUL
1.3       anton     545: extern unsigned long int strtoul(const char *nptr, char **endptr, int base);
1.2       pazsan    546: #endif
                    547: 
1.37      pazsan    548: #define GROUP(x, n)
1.53      pazsan    549: #define GROUPADD(n)
1.112     pazsan    550: 
                    551: #ifdef HAVE_ENDIAN_H
                    552: #include <endian.h>
                    553: #else
                    554: #define BSWAP16(x) ((((x) >> 8) & 0xff | (((x) & 0xff) << 8)))
                    555: #define BSWAP32(x) ((BSWAP16((x) >> 16) | (BSWAP16(x) << 16)))
                    556: #define BSWAP64(x) ((BSWAP32((x) >> 32) | (BSWAP32(x) << 32)))
                    557: #ifdef WORDS_BIGENDIAN
                    558: #define htobe16(x) (x)
                    559: #define htobe32(x) (x)
                    560: #define htobe64(x) (x)
                    561: #define be16toh(x) (x)
                    562: #define be32toh(x) (x)
                    563: #define be64toh(x) (x)
                    564: #define htole16(x) BSWAP16(x)
                    565: #define htole32(x) BSWAP32(x)
                    566: #define htole64(x) BSWAP64(x)
                    567: #define le16toh(x) BSWAP16(x)
                    568: #define le32toh(x) BSWAP32(x)
                    569: #define le64toh(x) BSWAP64(x)
                    570: #else
                    571: #define htobe16(x) BSWAP16(x)
                    572: #define htobe32(x) BSWAP32(x)
                    573: #define htobe64(x) BSWAP64(x)
                    574: #define be16toh(x) BSWAP16(x)
                    575: #define be32toh(x) BSWAP32(x)
                    576: #define be64toh(x) BSWAP64(x)
                    577: #define htole16(x) (x)
                    578: #define htole32(x) (x)
                    579: #define htole64(x) (x)
                    580: #define le16toh(x) (x)
                    581: #define le32toh(x) (x)
                    582: #define le64toh(x) (x)
                    583: #endif
                    584: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>