1 /* $Id: interpret.h,v 1.16 2004/07/21 11:32:05 yooden Exp $ */
2 /*******************************************************************************
4 * interpret.h -- Nirvana Editor Interpreter Header File *
6 * Copyright 2004 The NEdit Developers *
8 * This is free software; you can redistribute it and/or modify it under the *
9 * terms of the GNU General Public License as published by the Free Software *
10 * Foundation; either version 2 of the License, or (at your option) any later *
11 * version. In addition, you may distribute version of this program linked to *
12 * Motif or Open Motif. See README for details. *
14 * This software is distributed in the hope that it will be useful, but WITHOUT *
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
19 * You should have received a copy of the GNU General Public License along with *
20 * software; if not, write to the Free Software Foundation, Inc., 59 Temple *
21 * Place, Suite 330, Boston, MA 02111-1307 USA *
23 * Nirvana Text Editor *
26 *******************************************************************************/
28 #ifndef NEDIT_INTERPRET_H_INCLUDED
29 #define NEDIT_INTERPRET_H_INCLUDED
34 #define MAX_ARGS 9 /* Maximum number of subroutine arguments */
35 #define STACK_SIZE 1024 /* Maximum stack size */
36 #define MAX_SYM_LEN 100 /* Max. symbol name length */
37 #define MACRO_EVENT_MARKER 2 /* Special value for the send_event field of
38 events passed to action routines. Tells
39 them that they were called from a macro */
41 enum symTypes
{CONST_SYM
, GLOBAL_SYM
, LOCAL_SYM
, ARG_SYM
, PROC_VALUE_SYM
,
42 C_FUNCTION_SYM
, MACRO_FUNCTION_SYM
, ACTION_ROUTINE_SYM
};
44 enum operations
{OP_RETURN_NO_VAL
, OP_RETURN
, OP_PUSH_SYM
, OP_DUP
, OP_ADD
,
45 OP_SUB
, OP_MUL
, OP_DIV
, OP_MOD
, OP_NEGATE
, OP_INCR
, OP_DECR
, OP_GT
, OP_LT
,
46 OP_GE
, OP_LE
, OP_EQ
, OP_NE
, OP_BIT_AND
, OP_BIT_OR
, OP_AND
, OP_OR
, OP_NOT
,
47 OP_POWER
, OP_CONCAT
, OP_ASSIGN
, OP_SUBR_CALL
, OP_FETCH_RET_VAL
, OP_BRANCH
,
48 OP_BRANCH_TRUE
, OP_BRANCH_FALSE
, OP_BRANCH_NEVER
, OP_ARRAY_REF
,
49 OP_ARRAY_ASSIGN
, OP_BEGIN_ARRAY_ITER
, OP_ARRAY_ITER
, OP_IN_ARRAY
,
50 OP_ARRAY_DELETE
, OP_PUSH_ARRAY_SYM
, OP_ARRAY_REF_ASSIGN_SETUP
, OP_PUSH_ARG
,
51 OP_PUSH_ARG_COUNT
, OP_PUSH_ARG_ARRAY
};
53 enum typeTags
{NO_TAG
, INT_TAG
, STRING_TAG
, ARRAY_TAG
};
55 enum execReturnCodes
{MACRO_TIME_LIMIT
, MACRO_PREEMPT
, MACRO_DONE
, MACRO_ERROR
};
57 #define ARRAY_DIM_SEP "\034"
62 typedef int (*Inst
)(void);
64 typedef int (*BuiltInSubr
)(WindowInfo
*window
, struct DataValueTag
*argList
,
65 int nArgs
, struct DataValueTag
*result
, char **errMsg
);
67 typedef struct NStringTag
{
72 typedef struct DataValueTag
{
76 struct NStringTag str
;
78 struct ProgramTag
* prog
;
81 struct DataValueTag
* dataval
;
82 struct SparseArrayEntry
*arrayPtr
;
87 rbTreeNode nodePtrs
; /* MUST BE FIRST ENTRY */
92 /* symbol table entry */
93 typedef struct SymbolRec
{
97 struct SymbolRec
*next
; /* to link to another */
100 typedef struct ProgramTag
{
101 Symbol
*localSymList
;
105 /* Information needed to re-start a preempted macro */
111 WindowInfo
*runWindow
;
112 WindowInfo
*focusWindow
;
115 void InitMacroGlobals(void);
117 SparseArrayEntry
*arrayIterateFirst(DataValue
*theArray
);
118 SparseArrayEntry
*arrayIterateNext(SparseArrayEntry
*iterator
);
119 struct SparseArrayEntry
*ArrayNew(void);
120 int ArrayInsert(DataValue
*theArray
, char *keyStr
, DataValue
*theValue
);
121 void ArrayDelete(DataValue
*theArray
, char *keyStr
);
122 void ArrayDeleteAll(DataValue
*theArray
);
123 int ArraySize(DataValue
*theArray
);
124 int ArrayGet(DataValue
*theArray
, char *keyStr
, DataValue
*theValue
);
125 int ArrayCopy(DataValue
*dstArray
, DataValue
*srcArray
);
127 /* Routines for creating a program, (accumulated beginning with
128 BeginCreatingProgram and returned via FinishCreatingProgram) */
129 void BeginCreatingProgram(void);
130 int AddOp(int op
, char **msg
);
131 int AddSym(Symbol
*sym
, char **msg
);
132 int AddImmediate(void *value
, char **msg
);
133 int AddBranchOffset(Inst
*to
, char **msg
);
135 Symbol
*InstallIteratorSymbol();
136 Symbol
*LookupStringConstSymbol(const char *value
);
137 Symbol
*InstallStringConstSymbol(const char *str
);
138 Symbol
*LookupSymbol(const char *name
);
139 Symbol
*InstallSymbol(const char *name
, enum symTypes type
, DataValue value
);
140 Program
*FinishCreatingProgram(void);
141 void SwapCode(Inst
*start
, Inst
*boundary
, Inst
*end
);
142 void StartLoopAddrList(void);
143 int AddBreakAddr(Inst
*addr
);
144 int AddContinueAddr(Inst
*addr
);
145 void FillLoopAddrs(Inst
*breakAddr
, Inst
*continueAddr
);
147 /* create a permanently allocated static string (only for use with static strings) */
148 #define PERM_ALLOC_STR(xStr) (((char *)("\001" xStr)) + 1)
150 /* Routines for executing programs */
151 int ExecuteMacro(WindowInfo
*window
, Program
*prog
, int nArgs
, DataValue
*args
,
152 DataValue
*result
, RestartData
**continuation
, char **msg
);
153 int ContinueMacro(RestartData
*continuation
, DataValue
*result
, char **msg
);
154 void RunMacroAsSubrCall(Program
*prog
);
155 void PreemptMacro(void);
156 char *AllocString(int length
);
157 char *AllocStringNCpy(const char *s
, int length
);
158 char *AllocStringCpy(const char *s
);
159 int AllocNString(NString
*string
, int length
);
160 int AllocNStringNCpy(NString
*string
, const char *s
, int length
);
161 int AllocNStringCpy(NString
*string
, const char *s
);
162 void GarbageCollectStrings(void);
163 void FreeRestartData(RestartData
*context
);
164 Symbol
*PromoteToGlobal(Symbol
*sym
);
165 void FreeProgram(Program
*prog
);
166 void ModifyReturnedValue(RestartData
*context
, DataValue dv
);
167 WindowInfo
*MacroRunWindow(void);
168 WindowInfo
*MacroFocusWindow(void);
169 void SetMacroFocusWindow(WindowInfo
*window
);
170 /* function used for implicit conversion from string to number */
171 int StringToNum(const char *string
, int *number
);
173 #endif /* NEDIT_INTERPRET_H_INCLUDED */