1 /* $Id: interpret.h,v 1.15 2004/04/30 14:35:16 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
, OP_PUSH_ARG
,
26 OP_PUSH_ARG_COUNT
, OP_PUSH_ARG_ARRAY
};
28 enum typeTags
{NO_TAG
, INT_TAG
, STRING_TAG
, ARRAY_TAG
};
30 enum execReturnCodes
{MACRO_TIME_LIMIT
, MACRO_PREEMPT
, MACRO_DONE
, MACRO_ERROR
};
32 #define ARRAY_DIM_SEP "\034"
37 typedef int (*Inst
)(void);
39 typedef int (*BuiltInSubr
)(WindowInfo
*window
, struct DataValueTag
*argList
,
40 int nArgs
, struct DataValueTag
*result
, char **errMsg
);
42 typedef struct NStringTag
{
47 typedef struct DataValueTag
{
51 struct NStringTag str
;
53 struct ProgramTag
* prog
;
56 struct DataValueTag
* dataval
;
57 struct SparseArrayEntry
*arrayPtr
;
62 rbTreeNode nodePtrs
; /* MUST BE FIRST ENTRY */
67 /* symbol table entry */
68 typedef struct SymbolRec
{
72 struct SymbolRec
*next
; /* to link to another */
75 typedef struct ProgramTag
{
80 /* Information needed to re-start a preempted macro */
86 WindowInfo
*runWindow
;
87 WindowInfo
*focusWindow
;
90 void InitMacroGlobals(void);
92 SparseArrayEntry
*arrayIterateFirst(DataValue
*theArray
);
93 SparseArrayEntry
*arrayIterateNext(SparseArrayEntry
*iterator
);
94 struct SparseArrayEntry
*ArrayNew(void);
95 int ArrayInsert(DataValue
*theArray
, char *keyStr
, DataValue
*theValue
);
96 void ArrayDelete(DataValue
*theArray
, char *keyStr
);
97 void ArrayDeleteAll(DataValue
*theArray
);
98 int ArraySize(DataValue
*theArray
);
99 int ArrayGet(DataValue
*theArray
, char *keyStr
, DataValue
*theValue
);
100 int ArrayCopy(DataValue
*dstArray
, DataValue
*srcArray
);
102 /* Routines for creating a program, (accumulated beginning with
103 BeginCreatingProgram and returned via FinishCreatingProgram) */
104 void BeginCreatingProgram(void);
105 int AddOp(int op
, char **msg
);
106 int AddSym(Symbol
*sym
, char **msg
);
107 int AddImmediate(void *value
, char **msg
);
108 int AddBranchOffset(Inst
*to
, char **msg
);
110 Symbol
*InstallIteratorSymbol();
111 Symbol
*LookupStringConstSymbol(const char *value
);
112 Symbol
*InstallStringConstSymbol(const char *str
);
113 Symbol
*LookupSymbol(const char *name
);
114 Symbol
*InstallSymbol(const char *name
, enum symTypes type
, DataValue value
);
115 Program
*FinishCreatingProgram(void);
116 void SwapCode(Inst
*start
, Inst
*boundary
, Inst
*end
);
117 void StartLoopAddrList(void);
118 int AddBreakAddr(Inst
*addr
);
119 int AddContinueAddr(Inst
*addr
);
120 void FillLoopAddrs(Inst
*breakAddr
, Inst
*continueAddr
);
122 /* create a permanently allocated static string (only for use with static strings) */
123 #define PERM_ALLOC_STR(xStr) (((char *)("\001" xStr)) + 1)
125 /* Routines for executing programs */
126 int ExecuteMacro(WindowInfo
*window
, Program
*prog
, int nArgs
, DataValue
*args
,
127 DataValue
*result
, RestartData
**continuation
, char **msg
);
128 int ContinueMacro(RestartData
*continuation
, DataValue
*result
, char **msg
);
129 void RunMacroAsSubrCall(Program
*prog
);
130 void PreemptMacro(void);
131 char *AllocString(int length
);
132 char *AllocStringNCpy(const char *s
, int length
);
133 char *AllocStringCpy(const char *s
);
134 int AllocNString(NString
*string
, int length
);
135 int AllocNStringNCpy(NString
*string
, const char *s
, int length
);
136 int AllocNStringCpy(NString
*string
, const char *s
);
137 void GarbageCollectStrings(void);
138 void FreeRestartData(RestartData
*context
);
139 Symbol
*PromoteToGlobal(Symbol
*sym
);
140 void FreeProgram(Program
*prog
);
141 void ModifyReturnedValue(RestartData
*context
, DataValue dv
);
142 WindowInfo
*MacroRunWindow(void);
143 WindowInfo
*MacroFocusWindow(void);
144 void SetMacroFocusWindow(WindowInfo
*window
);
145 /* function used for implicit conversion from string to number */
146 int StringToNum(const char *string
, int *number
);
148 #endif /* NEDIT_INTERPRET_H_INCLUDED */