1 /* $Id: interpret.h,v 1.6 2001/04/06 13:03:31 amai Exp $ */
2 #define MAX_ARGS 9 /* Maximum number of subroutine arguments */
3 #define STACK_SIZE 1024 /* Maximum stack size */
4 #define MAX_SYM_LEN 100 /* Max. symbol name length */
5 #define MACRO_EVENT_MARKER 2 /* Special value for the send_event field of
6 events passed to action routines. Tells
7 them that they were called from a macro */
9 enum symTypes
{CONST_SYM
, GLOBAL_SYM
, LOCAL_SYM
, ARG_SYM
, PROC_VALUE_SYM
,
10 C_FUNCTION_SYM
, MACRO_FUNCTION_SYM
, ACTION_ROUTINE_SYM
};
12 enum operations
{OP_RETURN_NO_VAL
, OP_RETURN
, OP_PUSH_SYM
, OP_DUP
, OP_ADD
,
13 OP_SUB
, OP_MUL
, OP_DIV
, OP_MOD
, OP_NEGATE
, OP_INCR
, OP_DECR
, OP_GT
, OP_LT
,
14 OP_GE
, OP_LE
, OP_EQ
, OP_NE
, OP_BIT_AND
, OP_BIT_OR
, OP_AND
, OP_OR
, OP_NOT
,
15 OP_POWER
, OP_CONCAT
, OP_ASSIGN
, OP_SUBR_CALL
, OP_FETCH_RET_VAL
, OP_BRANCH
,
16 OP_BRANCH_TRUE
, OP_BRANCH_FALSE
, OP_BRANCH_NEVER
, OP_ARRAY_REF
,
17 OP_ARRAY_ASSIGN
, OP_BEGIN_ARRAY_ITER
, OP_ARRAY_ITER
, OP_IN_ARRAY
,
20 enum typeTags
{NO_TAG
, INT_TAG
, STRING_TAG
, ARRAY_TAG
};
22 enum execReturnCodes
{MACRO_TIME_LIMIT
, MACRO_PREEMPT
, MACRO_DONE
, MACRO_ERROR
};
24 #define ARRAY_DIM_SEP "\034"
32 struct SparseArrayEntry
*arrayPtr
;
37 rbTreeNode nodePtrs
; /* MUST BE FIRST ENTRY */
42 /* symbol table entry */
43 typedef struct SymbolRec
{
47 struct SymbolRec
*next
; /* to link to another */
50 typedef int (*Inst
)(void);
57 /* Information needed to re-start a preempted macro */
63 WindowInfo
*runWindow
;
64 WindowInfo
*focusWindow
;
67 typedef int (*BuiltInSubr
)(WindowInfo
*window
, DataValue
*argList
, int nArgs
,
68 DataValue
*result
, char **errMsg
);
70 void InitMacroGlobals(void);
72 SparseArrayEntry
*arrayIterateFirst(DataValue
*theArray
);
73 SparseArrayEntry
*arrayIterateNext(SparseArrayEntry
*iterator
);
74 struct SparseArrayEntry
*ArrayNew(void);
75 int ArrayInsert(DataValue
*theArray
, char *keyStr
, DataValue
*theValue
);
76 void ArrayDelete(DataValue
*theArray
, char *keyStr
);
77 void ArrayDeleteAll(DataValue
*theArray
);
78 int ArraySize(DataValue
*theArray
);
79 int ArrayGet(DataValue
*theArray
, char *keyStr
, DataValue
*theValue
);
80 int ArrayCopy(DataValue
*dstArray
, DataValue
*srcArray
);
82 /* Routines for creating a program, (accumulated beginning with
83 BeginCreatingProgram and returned via FinishCreatingProgram) */
84 void BeginCreatingProgram(void);
85 int AddOp(int op
, char **msg
);
86 int AddSym(Symbol
*sym
, char **msg
);
87 int AddImmediate(void *value
, char **msg
);
88 int AddBranchOffset(Inst
*to
, char **msg
);
90 Symbol
*InstallIteratorSymbol();
91 Symbol
*LookupStringConstSymbol(const char *value
);
92 Symbol
*LookupSymbol(const char *name
);
93 Symbol
*InstallSymbol(const char *name
, int type
, DataValue value
);
94 Program
*FinishCreatingProgram(void);
95 void SwapCode(Inst
*start
, Inst
*boundary
, Inst
*end
);
96 void StartLoopAddrList(void);
97 void AddBreakAddr(Inst
*addr
);
98 void AddContinueAddr(Inst
*addr
);
99 void FillLoopAddrs(Inst
*breakAddr
, Inst
*continueAddr
);
101 /* Routines for executing programs */
102 int ExecuteMacro(WindowInfo
*window
, Program
*prog
, int nArgs
, DataValue
*args
,
103 DataValue
*result
, RestartData
**continuation
, char **msg
);
104 int ContinueMacro(RestartData
*continuation
, DataValue
*result
, char **msg
);
105 void RunMacroAsSubrCall(Program
*prog
);
106 void PreemptMacro(void);
107 char *AllocString(int length
);
108 void GarbageCollectStrings(void);
109 void FreeRestartData(RestartData
*context
);
110 Symbol
*PromoteToGlobal(Symbol
*sym
);
111 void FreeProgram(Program
*prog
);
112 void ModifyReturnedValue(RestartData
*context
, DataValue dv
);
113 WindowInfo
*MacroRunWindow(void);
114 WindowInfo
*MacroFocusWindow(void);
115 void SetMacroFocusWindow(WindowInfo
*window
);