File:  [gforth] / gforth / vmgen-ex / engine.c
Revision 1.1: download - view: text, annotated - select for diffs
Sun Apr 29 11:28:23 2001 UTC (22 years, 11 months ago) by anton
Branches: MAIN
CVS tags: HEAD
added vmgen-ex

    1: /* vm interpreter wrapper
    2: 
    3:   Copyright (C) 2001 Free Software Foundation, Inc.
    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
    9:   as published by the Free Software Foundation; either version 2
   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
   18:   along with this program; if not, write to the Free Software
   19:   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
   20: */
   21: 
   22: #include "mini.h"
   23: 
   24: /* type change macros; these are specific to the types you use, so you
   25:    have to change this part */
   26: #define vm_Cell2i(x) ((Cell)(x))
   27: #define vm_i2Cell(x) (x)
   28: #define vm_Cell2target(x) ((Inst *)(x))
   29: #define vm_target2Cell(x) ((Cell)(x))
   30: #define vm_Cell2a(x) ((char *)(x))
   31: #define vm_a2Cell(x) ((Cell)(x))
   32: 
   33: #ifdef USE_spTOS
   34: #define IF_spTOS(x) x
   35: #else
   36: #define IF_spTOS(x)
   37: #endif
   38: 
   39: #ifdef VM_DEBUG
   40: #define NAME(_x) if (vm_debug) {fprintf(vm_out, "%lx: %-20s, ", (long)(ip-1), _x); fprintf(vm_out,"fp=%p, sp=%p", fp, sp);}
   41: #else
   42: #define NAME(_x)
   43: #endif
   44: 
   45: /* different threading schemes for different architectures; for more,
   46:    look in ../engine/threaded.h, and 
   47:    look for THREADING_SCHEME in ../arch/.../machine.h */
   48: 
   49: #ifdef i386
   50: #define THREADING_SCHEME 8
   51: #else
   52: #define THREADING_SCHEME 5
   53: #endif
   54: 
   55: #if THREADING_SCHEME==5
   56: /* direct threading scheme 5: early fetching */
   57: #  define CFA_NEXT
   58: #  define NEXT_P0	({cfa=*ip;})
   59: #  define IP		((Cell *)ip)
   60: #  define SET_IP(p)	({ip=(Inst *)(p); NEXT_P0;})
   61: #  define NEXT_INST	((Cell)cfa)
   62: #  define INC_IP(const_inc)	({cfa=ip[const_inc]; ip+=(const_inc);})
   63: #  define DEF_CA
   64: #  define NEXT_P1	(ip++)
   65: #  define NEXT_P2	({goto *cfa;})
   66: #endif
   67: 
   68: #if THREADING_SCHEME==8
   69: /* direct threading scheme 8: i386 hack */
   70: #  define NEXT_P0
   71: #  define IP		(ip)
   72: #  define SET_IP(p)	({ip=(p); NEXT_P0;})
   73: #  define NEXT_INST	(*IP)
   74: #  define INC_IP(const_inc)	({ ip+=(const_inc);})
   75: #  define DEF_CA
   76: #  define NEXT_P1	(ip++)
   77: #  define NEXT_P2	({goto **(ip-1);})
   78: #endif
   79: 
   80: #define NEXT ({DEF_CA NEXT_P1; NEXT_P2;})
   81: #define IPTOS NEXT_INST
   82: 
   83: #ifdef VM_PROFILING
   84: #define SUPER_END  vm_count_block(IP)
   85: #else
   86: #define SUPER_END
   87: #endif
   88: 
   89: /* the return type can be anything you want it to */
   90: Cell engine(Inst *ip0, Cell *sp, char *fp)
   91: {
   92:   /* VM registers */
   93:   Inst * ip;
   94:   Inst * cfa;
   95: #ifdef USE_spTOS
   96:   Cell   spTOS;
   97: #else
   98: #define spTOS (sp[0])
   99: #endif
  100:   static Inst   labels[] = {
  101: #include "mini-labels.i"
  102:   };
  103: 
  104:   if (vm_debug)
  105:       fprintf(vm_out,"entering engine(%p,%p,%p)\n",ip0,sp,fp);
  106:   if (ip0 == NULL) {
  107:     vm_prim = labels;
  108:     return 0;
  109:   }
  110: 
  111:   /* I don't have a clue where these things come from,
  112:      but I've put them in macros.h for the moment */
  113:   IF_spTOS(spTOS = sp[0]);
  114: 
  115:   SET_IP(ip0);
  116:   NEXT;
  117: 
  118: #include "mini-vm.i"
  119: }

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