1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008 Henrik Tidefelt
30 down_cast_ContinuationArgument( const RefCountPtr
< const Lang::Value
> & val
, const Kernel::Continuation
* locCont
, bool voidIsNull
= false )
32 RefCountPtr
< T
> res
= val
.down_cast
< T
>( );
33 if( res
== NullPtr
< T
>( ) )
36 dynamic_cast< const Lang::Void
* >( val
.getPtr( ) ) == 0 )
38 throw Exceptions::ContinuationTypeMismatch( locCont
, val
->getTypeName( ), T::staticTypeName( ) );
49 class ExitContinuation
: public Kernel::Continuation
53 ExitContinuation( bool * done
, const Ast::SourceLocation
& traceLoc
);
55 virtual void takeHandle( Kernel::VariableHandle val
, Kernel::EvalState
* evalState
, bool dummy
) const;
56 virtual Kernel::ContRef
up( ) const;
57 virtual RefCountPtr
< const char > description( ) const;
58 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
61 class DefaultErrorContinuation
: public Kernel::Continuation
64 DefaultErrorContinuation( const Ast::SourceLocation
& traceLoc
);
65 ~DefaultErrorContinuation( );
66 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & val
, Kernel::EvalState
* evalState
, bool dummy
) const;
67 virtual Kernel::ContRef
up( ) const;
68 virtual RefCountPtr
< const char > description( ) const;
69 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
72 class IfContinuation
: public Kernel::Continuation
74 Kernel::VariableHandle consequence_
;
75 Kernel::VariableHandle alternative_
;
76 Kernel::ContRef cont_
;
78 IfContinuation( const Kernel::VariableHandle
& consequence
, const Kernel::VariableHandle
& alternative
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
80 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & val
, Kernel::EvalState
* evalState
, bool dummy
) const;
81 virtual Kernel::ContRef
up( ) const;
82 virtual RefCountPtr
< const char > description( ) const;
83 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
86 /* DefineVariableContinuation is used by the expression DefineVariable.
88 class DefineVariableContinuation
: public Kernel::Continuation
90 Kernel::PassedEnv env_
;
92 Kernel::ContRef cont_
;
94 DefineVariableContinuation( const Kernel::PassedEnv
& _env
, size_t * _pos
, const Kernel::ContRef
& _cont
, const Ast::SourceLocation
& _traceLoc
);
95 ~DefineVariableContinuation( );
96 virtual void takeHandle( Kernel::VariableHandle val
, Kernel::EvalState
* evalState
, bool dummy
) const;
97 virtual Kernel::ContRef
up( ) const;
98 virtual RefCountPtr
< const char > description( ) const;
99 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
102 /* IntroduceStateContinuation is used by the expression IntroduceState.
104 class IntroduceStateContinuation
: public Kernel::Continuation
106 Kernel::PassedEnv env_
;
108 Kernel::ContRef cont_
;
110 IntroduceStateContinuation( const Kernel::PassedEnv
& _env
, size_t * _pos
, const Kernel::ContRef
& _cont
, const Ast::SourceLocation
& _traceLoc
);
111 ~IntroduceStateContinuation( );
112 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & val
, Kernel::EvalState
* evalState
, bool dummy
) const;
113 virtual Kernel::ContRef
up( ) const;
114 virtual RefCountPtr
< const char > description( ) const;
115 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
118 /* StoreValueContinuation will store the returned object at the specified address, and then pass it on
119 * to the next continuation.
120 * Note that it is the responsibility of someone else to make sure that *res still exists when the continuation is invoked.
121 * Generally, StoreVariableContinuation shall be preferred since it has no such problem.
123 class StoreValueContinuation
: public Kernel::Continuation
125 Kernel::ValueRef
* res_
;
126 Kernel::ContRef cont_
;
128 StoreValueContinuation( Kernel::ValueRef
* res
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
129 ~StoreValueContinuation( );
130 virtual void takeHandle( Kernel::VariableHandle val
, Kernel::EvalState
* evalState
, bool dummy
) const;
131 virtual Kernel::ContRef
up( ) const;
132 virtual RefCountPtr
< const char > description( ) const;
133 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
136 class StoreVariableContinuation
: public Kernel::Continuation
138 Kernel::VariableHandle dst_
;
139 Kernel::ContRef cont_
;
141 StoreVariableContinuation( const Kernel::VariableHandle
& res
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
142 ~StoreVariableContinuation( );
143 virtual void takeHandle( Kernel::VariableHandle val
, Kernel::EvalState
* evalState
, bool dummy
) const;
144 virtual Kernel::ContRef
up( ) const;
145 virtual RefCountPtr
< const char > description( ) const;
146 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
149 /* The InsertionContinuation sends the returned value to a warm variable, and passes THE_SLOT_VARIABLE (a null value) to the next continuation.
151 class InsertionContinuation
: public Kernel::Continuation
153 mutable Kernel::StateHandle dst_
; /* This being mutable is actually quite ugly... */
154 Kernel::PassedDyn dyn_
;
155 Kernel::ContRef cont_
;
157 InsertionContinuation( const Kernel::StateHandle
& dst
, const Kernel::ContRef
& cont
, const Kernel::PassedDyn
& dyn
, const Ast::SourceLocation
& traceLoc
);
158 ~InsertionContinuation( );
159 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & val
, Kernel::EvalState
* evalState
, bool dummy
) const;
160 virtual Kernel::ContRef
up( ) const;
161 virtual RefCountPtr
< const char > description( ) const;
162 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
165 /* StmtStoreValueContinuation is like StoreValueContinuation, except that it passes THE_SLOT_VARIABLE (a null value) to the next continuation.
167 class StmtStoreValueContinuation
: public Kernel::Continuation
169 Kernel::ValueRef
* res_
;
170 Kernel::ContRef cont_
;
172 StmtStoreValueContinuation( Kernel::ValueRef
* res
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
173 ~StmtStoreValueContinuation( );
174 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & val
, Kernel::EvalState
* evalState
, bool dummy
) const;
175 virtual Kernel::ContRef
up( ) const;
176 virtual RefCountPtr
< const char > description( ) const;
177 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
180 class StmtStoreVariableContinuation
: public Kernel::Continuation
182 Kernel::VariableHandle dst_
;
183 Kernel::ContRef cont_
;
185 StmtStoreVariableContinuation( const Kernel::VariableHandle
& res
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
186 ~StmtStoreVariableContinuation( );
187 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & val
, Kernel::EvalState
* evalState
, bool dummy
) const;
188 virtual Kernel::ContRef
up( ) const;
189 virtual RefCountPtr
< const char > description( ) const;
190 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
193 class ForcingContinuation
: public Kernel::Continuation
195 Kernel::ContRef cont_
;
197 ForcingContinuation( const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
198 ~ForcingContinuation( );
199 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & val
, Kernel::EvalState
* evalState
, bool dummy
) const;
200 virtual Kernel::ContRef
up( ) const;
201 virtual RefCountPtr
< const char > description( ) const;
202 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
205 class ForcingSingleListContinuation
: public Kernel::Continuation
207 Kernel::ContRef cont_
;
208 RefCountPtr
< const Lang::SingleList
> cdr_
;
210 ForcingSingleListContinuation( const RefCountPtr
< const Lang::SingleList
> & cdr
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
211 ~ForcingSingleListContinuation( );
212 virtual void takeHandle( Kernel::VariableHandle val
, Kernel::EvalState
* evalState
, bool dummy
) const;
213 virtual Kernel::ContRef
up( ) const;
214 virtual RefCountPtr
< const char > description( ) const;
215 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
218 class Transform2DCont
: public Kernel::Continuation
220 Lang::Transform2D tf_
;
221 Kernel::ContRef cont_
;
223 Transform2DCont( Lang::Transform2D tf
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
224 virtual ~Transform2DCont( );
225 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & val
, Kernel::EvalState
* evalState
, bool dummy
) const;
226 virtual Kernel::ContRef
up( ) const;
227 virtual RefCountPtr
< const char > description( ) const;
228 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
231 class Transform3DCont
: public Kernel::Continuation
233 Lang::Transform3D tf_
;
234 Kernel::ContRef cont_
;
236 Transform3DCont( Lang::Transform3D tf
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
237 virtual ~Transform3DCont( );
238 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & val
, Kernel::EvalState
* evalState
, bool dummy
) const;
239 virtual Kernel::ContRef
up( ) const;
240 virtual RefCountPtr
< const char > description( ) const;
241 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
244 class PathApplication2DCont
: public Kernel::Continuation
246 RefCountPtr
< const Lang::ElementaryPath2D
> path_
;
247 Kernel::ContRef cont_
;
249 PathApplication2DCont( RefCountPtr
< const Lang::ElementaryPath2D
> path
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
250 virtual ~PathApplication2DCont( );
251 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & val
, Kernel::EvalState
* evalState
, bool dummy
) const;
252 virtual Kernel::ContRef
up( ) const;
253 virtual RefCountPtr
< const char > description( ) const;
254 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
257 class PathApplication3DCont
: public Kernel::Continuation
259 RefCountPtr
< const Lang::ElementaryPath3D
> path_
;
260 Kernel::ContRef cont_
;
262 PathApplication3DCont( RefCountPtr
< const Lang::ElementaryPath3D
> path
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
263 virtual ~PathApplication3DCont( );
264 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & val
, Kernel::EvalState
* evalState
, bool dummy
) const;
265 virtual Kernel::ContRef
up( ) const;
266 virtual RefCountPtr
< const char > description( ) const;
267 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
270 class ComposedFunctionCall_cont
: public Kernel::Continuation
272 RefCountPtr
< const Lang::Function
> second_
;
273 Kernel::PassedDyn dyn_
;
274 Kernel::ContRef cont_
;
276 ComposedFunctionCall_cont( const RefCountPtr
< const Lang::Function
> & second
, const Kernel::PassedDyn
& dyn
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& callLoc
);
277 virtual ~ComposedFunctionCall_cont( );
278 virtual void takeHandle( Kernel::VariableHandle val
, Kernel::EvalState
* evalState
, bool dummy
) const;
279 virtual Kernel::ContRef
up( ) const;
280 virtual RefCountPtr
< const char > description( ) const;
281 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
284 class ForceFunctionAndCall_2_args_cont
: public Kernel::Continuation
286 Kernel::VariableHandle arg1_
;
287 Kernel::VariableHandle arg2_
;
288 Kernel::PassedDyn dyn_
;
289 Kernel::ContRef cont_
;
291 ForceFunctionAndCall_2_args_cont( const Kernel::VariableHandle
& arg1
, const Kernel::VariableHandle
& arg2
, const Kernel::PassedDyn
& dyn
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& callLoc
);
292 virtual ~ForceFunctionAndCall_2_args_cont( );
293 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & val
, Kernel::EvalState
* evalState
, bool dummy
) const;
294 virtual Kernel::ContRef
up( ) const;
295 virtual RefCountPtr
< const char > description( ) const;
296 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
299 class SingleFoldLCont
: public Kernel::Continuation
301 RefCountPtr
< const Lang::SingleList
> cdr_
;
302 RefCountPtr
< const Lang::Function
> op_
;
303 Kernel::PassedDyn dyn_
;
304 Kernel::ContRef cont_
;
306 SingleFoldLCont( const RefCountPtr
< const Lang::SingleList
> & cdr
, const RefCountPtr
< const Lang::Function
> & op
, const Kernel::PassedDyn
& dyn
, Kernel::ContRef cont
, const Ast::SourceLocation
& traceLoc
);
307 virtual ~SingleFoldLCont( );
308 virtual void takeHandle( Kernel::VariableHandle val
, Kernel::EvalState
* evalState
, bool dummy
) const;
309 virtual Kernel::ContRef
up( ) const;
310 virtual RefCountPtr
< const char > description( ) const;
311 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
314 class SingleFoldRCont
: public Kernel::Continuation
316 Kernel::VariableHandle car_
;
317 RefCountPtr
< const Lang::Function
> op_
;
318 Kernel::PassedDyn dyn_
;
319 Kernel::ContRef cont_
;
321 SingleFoldRCont( const Kernel::VariableHandle
& car
, const RefCountPtr
< const Lang::Function
> & op
, const Kernel::PassedDyn
& dyn
, Kernel::ContRef cont
, const Ast::SourceLocation
& traceLoc
);
322 virtual ~SingleFoldRCont( );
323 virtual void takeHandle( Kernel::VariableHandle val
, Kernel::EvalState
* evalState
, bool dummy
) const;
324 virtual Kernel::ContRef
up( ) const;
325 virtual RefCountPtr
< const char > description( ) const;
326 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
329 class SingleFoldSLCont
: public Kernel::Continuation
331 RefCountPtr
< const Lang::SingleList
> cdr_
;
332 RefCountPtr
< const Lang::Function
> op_
;
333 Kernel::StateHandle state_
;
334 Kernel::PassedDyn dyn_
;
335 Kernel::ContRef cont_
;
337 SingleFoldSLCont( const RefCountPtr
< const Lang::SingleList
> & cdr
, const RefCountPtr
< const Lang::Function
> & op
, Kernel::StateHandle state
, const Kernel::PassedDyn
& dyn
, Kernel::ContRef cont
, const Ast::SourceLocation
& traceLoc
);
338 virtual ~SingleFoldSLCont( );
339 virtual void takeHandle( Kernel::VariableHandle val
, Kernel::EvalState
* evalState
, bool dummy
) const;
340 virtual Kernel::ContRef
up( ) const;
341 virtual RefCountPtr
< const char > description( ) const;
342 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
345 class SingleFoldSRCont
: public Kernel::Continuation
347 Kernel::VariableHandle car_
;
348 RefCountPtr
< const Lang::Function
> op_
;
349 Kernel::StateHandle state_
;
350 Kernel::PassedDyn dyn_
;
351 Kernel::ContRef cont_
;
353 SingleFoldSRCont( const Kernel::VariableHandle
& car
, const RefCountPtr
< const Lang::Function
> & op
, Kernel::StateHandle state
, const Kernel::PassedDyn
& dyn
, Kernel::ContRef cont
, const Ast::SourceLocation
& traceLoc
);
354 virtual ~SingleFoldSRCont( );
355 virtual void takeHandle( Kernel::VariableHandle val
, Kernel::EvalState
* evalState
, bool dummy
) const;
356 virtual Kernel::ContRef
up( ) const;
357 virtual RefCountPtr
< const char > description( ) const;
358 virtual void gcMark( Kernel::GCMarkedSet
& marked
);