1 /* $Id: interpret.h,v 1.13 2003/05/05 16:25:55 edg Exp $ */
3 #ifndef NEDIT_INTERPRET_H_INCLUDED
4 #define NEDIT_INTERPRET_H_INCLUDED
9 #define MAX_ARGS 9 /* Maximum number of subroutine arguments */
10 #define STACK_SIZE 1024 /* Maximum stack size */
11 #define MAX_SYM_LEN 100 /* Max. symbol name length */
12 #define MACRO_EVENT_MARKER 2 /* Special value for the send_event field of
13 events passed to action routines. Tells
14 them that they were called from a macro */
16 enum symTypes
{CONST_SYM
, GLOBAL_SYM
, LOCAL_SYM
, ARG_SYM
, PROC_VALUE_SYM
,
17 C_FUNCTION_SYM
, MACRO_FUNCTION_SYM
, ACTION_ROUTINE_SYM
};
19 enum operations
{OP_RETURN_NO_VAL
, OP_RETURN
, OP_PUSH_SYM
, OP_DUP
, OP_ADD
,
20 OP_SUB
, OP_MUL
, OP_DIV
, OP_MOD
, OP_NEGATE
, OP_INCR
, OP_DECR
, OP_GT
, OP_LT
,
21 OP_GE
, OP_LE
, OP_EQ
, OP_NE
, OP_BIT_AND
, OP_BIT_OR
, OP_AND
, OP_OR
, OP_NOT
,
22 OP_POWER
, OP_CONCAT
, OP_ASSIGN
, OP_SUBR_CALL
, OP_FETCH_RET_VAL
, OP_BRANCH
,
23 OP_BRANCH_TRUE
, OP_BRANCH_FALSE
, OP_BRANCH_NEVER
, OP_ARRAY_REF
,
24 OP_ARRAY_ASSIGN
, OP_BEGIN_ARRAY_ITER
, OP_ARRAY_ITER
, OP_IN_ARRAY
,
25 OP_ARRAY_DELETE
, OP_PUSH_ARRAY_SYM
, OP_ARRAY_REF_ASSIGN_SETUP
};
27 enum typeTags
{NO_TAG
, INT_TAG
, STRING_TAG
, ARRAY_TAG
};
29 enum execReturnCodes
{MACRO_TIME_LIMIT
, MACRO_PREEMPT
, MACRO_DONE
, MACRO_ERROR
};
31 #define ARRAY_DIM_SEP "\034"
36 typedef int (*Inst
)(void);
38 typedef int (*BuiltInSubr
)(WindowInfo
*window
, struct DataValueTag
*argList
,
39 int nArgs
, struct DataValueTag
*result
, char **errMsg
);
41 typedef struct DataValueTag
{
47 struct ProgramTag
* prog
;
50 struct DataValueTag
* dataval
;
51 struct SparseArrayEntry
*arrayPtr
;
56 rbTreeNode nodePtrs
; /* MUST BE FIRST ENTRY */
61 /* symbol table entry */
62 typedef struct SymbolRec
{
66 struct SymbolRec
*next
; /* to link to another */
69 typedef struct ProgramTag
{
74 /* Information needed to re-start a preempted macro */
80 WindowInfo
*runWindow
;
81 WindowInfo
*focusWindow
;
84 void InitMacroGlobals(void);
86 SparseArrayEntry
*arrayIterateFirst(DataValue
*theArray
);
87 SparseArrayEntry
*arrayIterateNext(SparseArrayEntry
*iterator
);
88 struct SparseArrayEntry
*ArrayNew(void);
89 int ArrayInsert(DataValue
*theArray
, char *keyStr
, DataValue
*theValue
);
90 void ArrayDelete(DataValue
*theArray
, char *keyStr
);
91 void ArrayDeleteAll(DataValue
*theArray
);
92 int ArraySize(DataValue
*theArray
);
93 int ArrayGet(DataValue
*theArray
, char *keyStr
, DataValue
*theValue
);
94 int ArrayCopy(DataValue
*dstArray
, DataValue
*srcArray
);
96 /* Routines for creating a program, (accumulated beginning with
97 BeginCreatingProgram and returned via FinishCreatingProgram) */
98 void BeginCreatingProgram(void);
99 int AddOp(int op
, char **msg
);
100 int AddSym(Symbol
*sym
, char **msg
);
101 int AddImmediate(void *value
, char **msg
);
102 int AddBranchOffset(Inst
*to
, char **msg
);
104 Symbol
*InstallIteratorSymbol();
105 Symbol
*LookupStringConstSymbol(const char *value
);
106 Symbol
*InstallStringConstSymbol(const char *str
);
107 Symbol
*LookupSymbol(const char *name
);
108 Symbol
*InstallSymbol(const char *name
, enum symTypes type
, DataValue value
);
109 Program
*FinishCreatingProgram(void);
110 void SwapCode(Inst
*start
, Inst
*boundary
, Inst
*end
);
111 void StartLoopAddrList(void);
112 int AddBreakAddr(Inst
*addr
);
113 int AddContinueAddr(Inst
*addr
);
114 void FillLoopAddrs(Inst
*breakAddr
, Inst
*continueAddr
);
116 /* create a permanently allocated static string (only for use with static strings) */
117 #define PERM_ALLOC_STR(xStr) (((char *)("\001" xStr)) + 1)
119 /* Routines for executing programs */
120 int ExecuteMacro(WindowInfo
*window
, Program
*prog
, int nArgs
, DataValue
*args
,
121 DataValue
*result
, RestartData
**continuation
, char **msg
);
122 int ContinueMacro(RestartData
*continuation
, DataValue
*result
, char **msg
);
123 void RunMacroAsSubrCall(Program
*prog
);
124 void PreemptMacro(void);
125 char *AllocString(int length
);
126 char *AllocStringNCpy(const char *s
, int length
);
127 char *AllocStringCpy(const char *s
);
128 void GarbageCollectStrings(void);
129 void FreeRestartData(RestartData
*context
);
130 Symbol
*PromoteToGlobal(Symbol
*sym
);
131 void FreeProgram(Program
*prog
);
132 void ModifyReturnedValue(RestartData
*context
, DataValue dv
);
133 WindowInfo
*MacroRunWindow(void);
134 WindowInfo
*MacroFocusWindow(void);
135 void SetMacroFocusWindow(WindowInfo
*window
);
136 /* function used for implicit conversion from string to number */
137 int StringToNum(const char *string
, int *number
);
139 #endif /* NEDIT_INTERPRET_H_INCLUDED */