Update procedures
[shapes.git] / source / astvalues.h
blob39dae0e508a238a4c88ac7755eb6c8ee2a6f8bf1
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
6 * any later version.
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, 2014 Henrik Tidefelt
19 #pragma once
21 #include "ast.h"
23 namespace Shapes
25 namespace Ast
28 class Constant : public Expression
30 Kernel::VariableHandle val_;
31 public:
32 Constant( const Ast::SourceLocation & loc, const Kernel::VariableHandle & val );
33 Constant( const Ast::SourceLocation & loc, RefCountPtr< const Lang::Value > val );
34 Constant( const Ast::SourceLocation & loc, const Lang::Value * val );
35 virtual ~Constant( );
36 virtual void analyze_impl( Ast::Node * parent, Ast::AnalysisEnvironment * env, Ast::StateIDSet * freeStatesDst );
37 virtual void eval( Kernel::EvalState * evalState ) const;
38 const Kernel::VariableHandle & val( ) const { return val_; }
41 class PolarHandle2DExpr : public Expression
43 Ast::Expression * rExpr_;
44 Ast::Expression * aExpr_;
45 public:
46 PolarHandle2DExpr( const Ast::SourceLocation & loc, Ast::Expression * rExpr, Ast::Expression * aExpr );
47 virtual ~PolarHandle2DExpr( );
48 virtual void analyze_impl( Ast::Node * parent, Ast::AnalysisEnvironment * env, Ast::StateIDSet * freeStatesDst );
49 virtual void eval( Kernel::EvalState * evalState ) const;
52 class PolarHandle2DExprFree_a : public Expression
54 Ast::Expression * rExpr_;
55 public:
56 PolarHandle2DExprFree_a( const Ast::SourceLocation & loc, Ast::Expression * rExpr );
57 virtual ~PolarHandle2DExprFree_a( );
58 virtual void analyze_impl( Ast::Node * parent, Ast::AnalysisEnvironment * env, Ast::StateIDSet * freeStatesDst );
59 virtual void eval( Kernel::EvalState * evalState ) const;
62 class SpanLastExpr : public Expression
64 public:
65 SpanLastExpr( const Ast::SourceLocation & loc );
66 virtual ~SpanLastExpr( );
67 virtual void analyze_impl( Ast::Node * parent, Ast::AnalysisEnvironment * env, Ast::StateIDSet * freeStatesDst );
68 virtual void eval( Kernel::EvalState * evalState ) const;
71 /* This class really doesn't fit in any file, but here it is!
73 class EmptyExpression : public Expression
75 public:
76 EmptyExpression( const Ast::SourceLocation & loc );
77 virtual ~EmptyExpression( );
78 virtual void analyze_impl( Ast::Node * parent, Ast::AnalysisEnvironment * env, Ast::StateIDSet * freeStatesDst );
79 virtual void eval( Kernel::EvalState * evalState ) const;
84 namespace Kernel
87 class PolarHandle2DCont : public Kernel::Continuation
89 RefCountPtr< Kernel::PolarHandlePromise > rPromise_;
90 Kernel::ContRef cont_;
91 public:
92 PolarHandle2DCont( const Ast::SourceLocation & _traceLoc, const RefCountPtr< Kernel::PolarHandlePromise > & rPromise, const Kernel::ContRef & cont );
93 virtual ~PolarHandle2DCont( );
94 virtual void takeValue( const RefCountPtr< const Lang::Value > & val, Kernel::EvalState * evalState, bool dummy ) const;
95 virtual Kernel::ContRef up( ) const;
96 virtual RefCountPtr< const char > description( ) const;
97 virtual void gcMark( Kernel::GCMarkedSet & marked );
102 namespace Helpers
105 /* Relax evaluation and let the evaluation engine unwind its call chain and return to the
106 * main evaluation loop.
107 * This is useful if lengthy computations involving lots of continuations never encounter the
108 * evaluation of expressions. For example, sorting a large amount of data using a built-in
109 * comparion function.
110 * The effect of calling relax is that the given value will be passed to the current continuation,
111 * but via an expression. The caller must allow the call chain to unwind after the call to relax,
112 * so that the main evaluation loop will evaluate the evalState->expr_ set by relax.
113 * Note that relax may change the dynamic environment.
115 void relax( const RefCountPtr< const Lang::Value > & val, Kernel::EvalState * evalState );