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 Transform2DCont
: public Kernel::Continuation
207 Lang::Transform2D tf_
;
208 Kernel::ContRef cont_
;
210 Transform2DCont( Lang::Transform2D tf
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
211 virtual ~Transform2DCont( );
212 virtual void takeValue( const RefCountPtr
< const Lang::Value
> & 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 Transform3DCont
: public Kernel::Continuation
220 Lang::Transform3D tf_
;
221 Kernel::ContRef cont_
;
223 Transform3DCont( Lang::Transform3D tf
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
224 virtual ~Transform3DCont( );
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 PathApplication2DCont
: public Kernel::Continuation
233 RefCountPtr
< const Lang::ElementaryPath2D
> path_
;
234 Kernel::ContRef cont_
;
236 PathApplication2DCont( RefCountPtr
< const Lang::ElementaryPath2D
> path
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
237 virtual ~PathApplication2DCont( );
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 PathApplication3DCont
: public Kernel::Continuation
246 RefCountPtr
< const Lang::ElementaryPath3D
> path_
;
247 Kernel::ContRef cont_
;
249 PathApplication3DCont( RefCountPtr
< const Lang::ElementaryPath3D
> path
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& traceLoc
);
250 virtual ~PathApplication3DCont( );
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 ComposedFunctionCall_cont
: public Kernel::Continuation
259 RefCountPtr
< const Lang::Function
> second_
;
260 Kernel::PassedDyn dyn_
;
261 Kernel::ContRef cont_
;
263 ComposedFunctionCall_cont( const RefCountPtr
< const Lang::Function
> & second
, const Kernel::PassedDyn
& dyn
, const Kernel::ContRef
& cont
, const Ast::SourceLocation
& callLoc
);
264 virtual ~ComposedFunctionCall_cont( );
265 virtual void takeHandle( Kernel::VariableHandle val
, Kernel::EvalState
* evalState
, bool dummy
) const;
266 virtual Kernel::ContRef
up( ) const;
267 virtual RefCountPtr
< const char > description( ) const;
268 virtual void gcMark( Kernel::GCMarkedSet
& marked
);