2 Copyright (C) 2003 by Walter Schreppers
3 Copyright (C) 2004 by Cies Breijs
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of version 2 of the GNU General Public
7 License as published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 typedef map
<QString
,Value
> symtable
;
30 typedef map
<QString
,TreeNode
*> functable
;
32 typedef stack
<Value
> runstack
;
35 class Executer
: public QObject
50 void ErrorMsg(Token
&, const QString
&, uint code
);
51 void setSelection(uint
, uint
, uint
, uint
);
53 void InputDialog(QString
& value
);
54 void MessageDialog(QString text
);
57 void Go(double x
, double y
);
60 void Forward(double x
);
61 void Backward(double x
);
62 void Direction(double x
);
63 void TurnLeft(double x
);
64 void TurnRight(double x
);
66 void SetPenWidth(int w
);
69 void SetFgColor(int r
, int g
, int b
);
70 void SetBgColor(int r
, int g
, int b
);
71 void ResizeCanvas(int x
, int y
);
75 void SpriteChange(int x
);
76 void Print(QString text
);
77 void FontType(QString family
, QString extra
);
78 void FontSize(int px
);
85 void execute (TreeNode
*);
87 void execBlock (TreeNode
*);
88 void execFor (TreeNode
*);
89 void execForEach (TreeNode
*);
90 void execWhile (TreeNode
*);
91 void execIf (TreeNode
*);
92 void execAssign (TreeNode
*);
93 void execExpression (/*TreeNode*/);
94 void execId (TreeNode
*);
95 void execConstant (/*TreeNode*/);
97 void createFunction (TreeNode
*);
98 void execFunction (TreeNode
*);
99 void execRetFunction (TreeNode
*);
100 void execReturn (TreeNode
*);
101 void execBreak (/*TreeNode*/);
103 void execAdd (TreeNode
*);
104 void execMul (TreeNode
*);
105 void execDiv (TreeNode
*);
106 void execSub (TreeNode
*);
107 void execNot (TreeNode
*);
109 void execGE (TreeNode
*);
110 void execGT (TreeNode
*);
111 void execLE (TreeNode
*);
112 void execLT (TreeNode
*);
113 void execNE (TreeNode
*);
114 void execEQ (TreeNode
*);
116 void execAnd (TreeNode
*);
117 void execOr (TreeNode
*);
118 void execMinus (TreeNode
*);
120 void execRun (TreeNode
*);
122 void execClear (TreeNode
*);
123 void execGo (TreeNode
*);
124 void execGoX (TreeNode
*);
125 void execGoY (TreeNode
*);
126 void execForward (TreeNode
*);
127 void execBackward (TreeNode
*);
128 void execDirection (TreeNode
*);
129 void execTurnLeft (TreeNode
*);
130 void execTurnRight (TreeNode
*);
131 void execCenter (TreeNode
*);
132 void execSetPenWidth (TreeNode
*);
133 void execPenUp (TreeNode
*);
134 void execPenDown (TreeNode
*);
135 void execSetFgColor (TreeNode
*);
136 void execSetBgColor (TreeNode
*);
137 void execResizeCanvas (TreeNode
*);
138 void execSpriteShow (TreeNode
*);
139 void execSpriteHide (TreeNode
*);
140 void execSpritePress (TreeNode
*);
141 void execSpriteChange (TreeNode
*);
143 void execMessage (TreeNode
*);
144 void execInputWindow (TreeNode
*);
145 void execPrint (TreeNode
*);
146 void execFontType (TreeNode
*);
147 void execFontSize (TreeNode
*);
148 void execRepeat (TreeNode
*);
149 void execRandom (TreeNode
*);
150 void execWait (TreeNode
*);
151 void execWrapOn (TreeNode
*);
152 void execWrapOff (TreeNode
*);
153 void execReset (TreeNode
*);
155 Value
exec2getValue (TreeNode
*);
157 QString
runCommand(const QString
&);
159 bool checkParameterQuantity(TreeNode
*, uint quantity
, int errorCode
);
160 bool checkParameterType(TreeNode
*, int valueType
, int errorCode
);
162 void slowDown(TreeNode
*);
163 void startWaiting(int msec
);
168 stack
<symtable
> symbolTables
;
169 functable functionTable
; // keep track of functionNode's
170 runstack runStack
; // stores parameters and return value of functions
173 bool bReturn
; // used for return statements
174 bool bBreak
; // used for break statement
175 bool bPause
; // used to pause execution
176 bool bAbort
; // used to abort execution
177 bool bStopWaiting
; // used for wait-command
181 void slotStopWaiting();
182 void slotChangeSpeed(int speed
);
183 void slotStopPausing();
186 #endif // _EXECUTER_H_