engine.h revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
#ifndef _FCODE_ENGINE_H
#define _FCODE_ENGINE_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_ORDER 32
#define CONVERT_HANDLES
#ifdef BIGSTACK
typedef long long fstack_t;
typedef unsigned long long ufstack_t;
#else
typedef long fstack_t;
typedef unsigned long ufstack_t;
#endif
typedef long *acf_t; /* pointer to execution token */
typedef long token_t; /* sizeof a forth token */
/* x@, x! type */
typedef uint64_t u_xforth_t;
typedef int64_t s_xforth_t;
/* l@, l! type */
typedef uint32_t u_lforth_t;
typedef int32_t s_lforth_t;
/* w@, w! type */
typedef uint16_t u_wforth_t;
typedef int16_t s_wforth_t;
/* Double type */
typedef uint64_t u_dforth_t;
typedef int64_t s_dforth_t;
typedef token_t variable_t;
typedef struct PROPERTY {
char *name;
int size;
} prop_t;
typedef struct RESOURCE {
void *data;
#define INIT_DATA 0
#define UINIT_DATA 1
typedef struct FCODE_ENV fcode_env_t;
typedef struct DEVICE_VECTOR {
/*
* If there is private data associated with a node this vector
* table contains the routines that will be called to augment the
* device.
* These two routines allow the interpreter to use a different
*
* Interface Note:
* Any routine installed here is assumed to have the standard forth
* call state. It must be a void function call taking a forth execution
* environment, returning any data on the stack. In general the
* vector call should have the same semantics as the original routine
* it is replacing. (see get_prop as an example).
*
* The caller has the responsibility of converting the resulting data
* back to a form it requires.
*
*/
void (*get_package_prop)(fcode_env_t *);
void (*get_inherited_prop)(fcode_env_t *);
#define MAX_MY_ADDR 4
struct DEVICE {
int data_size[2];
void *private; /* app private data */
};
typedef struct INSTANCE {
/*
* These are copies of the same structures from the device definition
* however changes here will be thrown away when the instance is
* destroyed.
*/
char *my_args;
int my_args_len;
} instance_t;
typedef struct FCODE_TOKEN {
char *name;
#ifdef DEBUG
int usage;
#endif
} fcode_token;
typedef struct {
char *buffer;
char *scanptr;
int maxlen;
int separator;
} input_typ;
typedef struct ERROR_FRAME {
struct ERROR_FRAME *next;
} error_frame;
struct FCODE_ENV {
char *name; /* last name */
long level; /* level */
long order_depth;
int last_token; /* last defined token */
int offset_incr; /* size of FCODE token offsets */
int fcode_incr; /* space between bytecodes */
int interpretting;
int fcode_debug;
int diagnostic_mode;
int interactive; /* DEBUG, interact variable */
int num_actions;
int action_count;
int strict_fcode;
char *picturebufpos; /* pictured string buffer position */
char *picturebuf; /* pictured string buffer */
int picturebuflen; /* pictured string buffer length */
#ifdef CONVERT_HANDLES
void (*allocate_phandle)(fcode_env_t *);
#endif
void *private; /* private data ptr for app use. */
};
typedef unsigned char flag_t;
#ifdef FCODE_INTERNAL
#endif
/*
* Note that sizeof (token_t) MUST equal sizeof (token_t *). If it doesn't,
* many things will break.
*/
#define _ALIGN(x, y) (((long)(x)) & ~(sizeof (y)-1))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))
/* values for flag_t */
#define ANSI_WORD 0x01
#define P1275_WORD 0x02
#define FLAG_NONAME 0x04
#define IMMEDIATE 0x08
#define FLAG_VALUE 0x10
#define FLAG_DEBUG 0x20
#ifdef CONVERT_HANDLES
#else
#define CONVERT_PHANDLE(e, x, y) x = (device_t *)(y)
#define REVERT_PHANDLE(e, x, y) x = (fstack_t)(y)
#define ALLOCATE_PHANDLE(e)
#endif
extern fcode_env_t *env;
extern int dict_size;
extern int in_forth_abort;
extern int stack_size;
extern void (*blit_ptr)(fcode_env_t *);
extern void (*create_ptr)(fcode_env_t *);
extern void (*do_bdo_ptr)(fcode_env_t *);
extern void (*do_bqdo_ptr)(fcode_env_t *);
extern void (*do_leave_ptr)(fcode_env_t *);
extern void (*do_loop_ptr)(fcode_env_t *);
extern void (*do_ploop_ptr)(fcode_env_t *);
extern void (*does_ptr)(fcode_env_t *);
extern void (*quote_ptr)(fcode_env_t *);
extern void (*quote_ptr)(fcode_env_t *);
extern void (*semi_ptr)(fcode_env_t *);
extern void (*tlit_ptr)(fcode_env_t *);
extern void (*to_ptr)(fcode_env_t *);
extern void (*to_ptr)(fcode_env_t *);
#ifdef __cplusplus
}
#endif
#endif /* _FCODE_ENGINE_H */