[pure-lang-svn] SF.net SVN: pure-lang:[447] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-08-05 04:34:57
|
Revision: 447 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=447&view=rev Author: agraef Date: 2008-08-05 04:35:06 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Automatic resizing of FMap structure. Modified Paths: -------------- pure/trunk/interpreter.cc pure/trunk/interpreter.hh pure/trunk/lexer.ll Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-04 06:59:40 UTC (rev 446) +++ pure/trunk/interpreter.cc 2008-08-05 04:35:06 UTC (rev 447) @@ -2280,8 +2280,6 @@ // build the maps for a global function definition assert(info.t == env_info::fun); // we need a separate submap for each rule - size_t n = info.rules->size(); - fmap.resize(n); rulel::const_iterator r = info.rules->begin(); while (r != info.rules->end()) { build_map(r->rhs); Modified: pure/trunk/interpreter.hh =================================================================== --- pure/trunk/interpreter.hh 2008-08-04 06:59:40 UTC (rev 446) +++ pure/trunk/interpreter.hh 2008-08-05 04:35:06 UTC (rev 447) @@ -86,28 +86,30 @@ #define Builder llvm::IRBuilder typedef list<Env*> EnvStack; +typedef map<int32_t,Env> EnvMap; typedef pair<int32_t,uint8_t> xmap_key; struct FMap { // manage local function environments - vector< map<int32_t,Env> > m; + vector<EnvMap*> m; // current map index size_t idx; // constructor (create one empty map by default) - FMap() : m(1), idx(0) {} + FMap() : m(1), idx(0) { m[0] = new EnvMap; } // assignment FMap& operator= (const FMap& f) { m = f.m; idx = f.idx; return *this; } // clear local environments - void clear() { m.clear(); idx = 0; } - // resize (set number of maps) - void resize(size_t n) { m.resize(n); } + void clear() + { for (size_t i = 0, n = m.size(); i < n; i++) delete m[i]; + m.clear(); idx = 0; } // set index to first, next and given map void first() { idx = 0; } - void next() { idx++; } + void next() + { if (++idx >= m.size()) { m.resize(idx+1); m[idx] = new EnvMap; } } void set(size_t n) { if (m.size() > 1) idx = n; } // access the current map - map<int32_t,Env>& act() { return m[idx]; } + EnvMap& act() { return *m[idx]; } }; struct Env { Modified: pure/trunk/lexer.ll =================================================================== --- pure/trunk/lexer.ll 2008-08-04 06:59:40 UTC (rev 446) +++ pure/trunk/lexer.ll 2008-08-05 04:35:06 UTC (rev 447) @@ -942,8 +942,8 @@ if (h && h != f) h->print(os); f->print(os); for (size_t i = 0, n = fmap.m.size(); i < n; i++) { - for (map<int32_t,Env>::const_iterator f = fmap.m[i].begin(), - end = fmap.m[i].end(); f != end; f++) + for (EnvMap::const_iterator f = fmap.m[i]->begin(), + end = fmap.m[i]->end(); f != end; f++) f->second.print(os); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |