summaryrefslogtreecommitdiff
path: root/expr.cc
diff options
context:
space:
mode:
Diffstat (limited to 'expr.cc')
-rw-r--r--expr.cc17
1 files changed, 15 insertions, 2 deletions
diff --git a/expr.cc b/expr.cc
index c326944f..37433179 100644
--- a/expr.cc
+++ b/expr.cc
@@ -44,7 +44,7 @@ expr_t::expr_t() : compiled(false)
}
expr_t::expr_t(const expr_t& other)
- : ptr(other.ptr), str(other.str), compiled(false)
+ : ptr(other.ptr), str(other.str), compiled(other.compiled)
{
TRACE_CTOR(expr_t, "copy");
}
@@ -109,7 +109,7 @@ void expr_t::parse(std::istream& in, const unsigned int flags)
void expr_t::compile(scope_t& scope)
{
- if (ptr.get()) {
+ if (ptr.get() && ! compiled) {
ptr = ptr->compile(scope);
compiled = true;
}
@@ -127,9 +127,16 @@ value_t expr_t::calc(scope_t& scope)
bool expr_t::is_constant() const
{
+ assert(compiled);
return ptr.get() && ptr->is_value();
}
+bool expr_t::is_function() const
+{
+ assert(compiled);
+ return ptr.get() && ptr->is_function();
+}
+
value_t& expr_t::constant_value()
{
assert(is_constant());
@@ -142,6 +149,12 @@ const value_t& expr_t::constant_value() const
return ptr->as_value();
}
+function_t& expr_t::get_function()
+{
+ assert(is_function());
+ return ptr->as_function_lval();
+}
+
value_t expr_t::eval(const string& _expr, scope_t& scope)
{
return expr_t(_expr).calc(scope);