Committed SF patch #963120: Open tab in window on current desktop.
[nedit.git] / source / interpret.h
blobb1b35c0ae2961f3b0e64f9890d9309d633ce750a
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
6 #include "nedit.h"
7 #include "rbTree.h"
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};
18 #define N_OPS 43
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"
34 struct DataValueTag;
35 struct ProgramTag;
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 {
43 char *rep;
44 size_t len;
45 } NString;
47 typedef struct DataValueTag {
48 enum typeTags tag;
49 union {
50 int n;
51 struct NStringTag str;
52 BuiltInSubr subr;
53 struct ProgramTag* prog;
54 XtActionProc xtproc;
55 Inst* inst;
56 struct DataValueTag* dataval;
57 struct SparseArrayEntry *arrayPtr;
58 } val;
59 } DataValue;
61 typedef struct {
62 rbTreeNode nodePtrs; /* MUST BE FIRST ENTRY */
63 char *key;
64 DataValue value;
65 } SparseArrayEntry;
67 /* symbol table entry */
68 typedef struct SymbolRec {
69 char *name;
70 enum symTypes type;
71 DataValue value;
72 struct SymbolRec *next; /* to link to another */
73 } Symbol;
75 typedef struct ProgramTag {
76 Symbol *localSymList;
77 Inst *code;
78 } Program;
80 /* Information needed to re-start a preempted macro */
81 typedef struct {
82 DataValue *stack;
83 DataValue *stackP;
84 DataValue *frameP;
85 Inst *pc;
86 WindowInfo *runWindow;
87 WindowInfo *focusWindow;
88 } RestartData;
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);
109 Inst *GetPC(void);
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 */