[pure-lang-svn] SF.net SVN: pure-lang:[463] pure/trunk
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-08-11 10:01:48
|
Revision: 463
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=463&view=rev
Author: agraef
Date: 2008-08-11 10:01:55 +0000 (Mon, 11 Aug 2008)
Log Message:
-----------
More optimizations of toplevel expressions to avoid unnecessary evaluations of constants.
Modified Paths:
--------------
pure/trunk/interpreter.cc
pure/trunk/interpreter.hh
Modified: pure/trunk/interpreter.cc
===================================================================
--- pure/trunk/interpreter.cc 2008-08-10 21:33:41 UTC (rev 462)
+++ pure/trunk/interpreter.cc 2008-08-11 10:01:55 UTC (rev 463)
@@ -3076,6 +3076,8 @@
return pure_string_dup(x.sval());
case EXPR::PTR:
return pure_pointer(x.pval());
+ case EXPR::APP:
+ return const_app_value(x);
default: {
exprl xs;
if (x.tag() > 0) {
@@ -3114,6 +3116,42 @@
}
}
+pure_expr *interpreter::const_app_value(expr x)
+{
+ if (x.tag() == EXPR::APP) {
+ pure_expr *f = 0, *y = 0;
+ if ((f = const_app_value(x.xval1())) && (y = const_value(x.xval2())))
+ return pure_app(f, y);
+ else {
+ if (f) pure_freenew(f);
+ return 0;
+ }
+ } else if (x.tag() > 0) {
+ env::const_iterator it = globenv.find(x.tag());
+ map<int32_t,GlobalVar>::iterator v;
+ if (externals.find(x.tag()) != externals.end())
+ return 0;
+ else if (it == globenv.end())
+ // unbound symbol
+ return pure_const(x.tag());
+ else if (it->second.t == env_info::fvar &&
+ (v = globalvars.find(x.tag())) != globalvars.end()) {
+ // variable value
+ pure_expr *y = v->second.x;
+ // walk down the spine, if any
+ while (y->tag == EXPR::APP) y = y->data.x[0];
+ // check if we got a closure subject to evaluation
+ if (y->tag >= 0 && y->data.clos)
+ return 0;
+ else
+ // not a callable closure, so it must be a constructor term
+ return v->second.x;
+ } else
+ return 0;
+ } else
+ return 0;
+}
+
pure_expr *interpreter::doeval(expr x, pure_expr*& e)
{
char test;
Modified: pure/trunk/interpreter.hh
===================================================================
--- pure/trunk/interpreter.hh 2008-08-10 21:33:41 UTC (rev 462)
+++ pure/trunk/interpreter.hh 2008-08-11 10:01:55 UTC (rev 463)
@@ -494,6 +494,7 @@
Env& act_env() { assert(!envstk.empty()); return *envstk.front(); }
Builder& act_builder() { return act_env().builder; }
pure_expr *const_value(expr x);
+ pure_expr *const_app_value(expr x);
pure_expr *doeval(expr x, pure_expr*& e);
pure_expr *dodefn(env vars, expr lhs, expr rhs, pure_expr*& e);
llvm::Value *codegen(expr x);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|