[pure-lang-svn] SF.net SVN: pure-lang:[444] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-08-04 06:36:03
|
Revision: 444 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=444&view=rev Author: agraef Date: 2008-08-04 06:36:13 +0000 (Mon, 04 Aug 2008) Log Message: ----------- Refactoring of FMap/Env printing code. Modified Paths: -------------- pure/trunk/interpreter.hh pure/trunk/lexer.ll Modified: pure/trunk/interpreter.hh =================================================================== --- pure/trunk/interpreter.hh 2008-08-02 07:07:44 UTC (rev 443) +++ pure/trunk/interpreter.hh 2008-08-04 06:36:13 UTC (rev 444) @@ -88,31 +88,28 @@ typedef list<Env*> EnvStack; typedef pair<int32_t,uint8_t> xmap_key; -class FMap { +struct FMap { // manage local function environments - vector< map<int32_t,Env> > fmap; + vector< map<int32_t,Env> > m; // current map index size_t idx; -public: // constructor (create one empty map by default) - FMap() : fmap(1), idx(0) {} + FMap() : m(1), idx(0) {} // assignment FMap& operator= (const FMap& f) - { fmap = f.fmap; idx = f.idx; return *this; } + { m = f.m; idx = f.idx; return *this; } // clear local environments - void clear() { fmap.clear(); idx = 0; } + void clear() { m.clear(); idx = 0; } // resize (set number of maps) - void resize(size_t n) { fmap.resize(n); } + void resize(size_t n) { m.resize(n); } // current size (number of maps) - size_t size() const { return fmap.size(); } + size_t size() const { return m.size(); } // set index to first, next and given map void first() { idx = 0; } void next() { idx++; } void set(size_t n) { idx = n; } // access the current map - map<int32_t,Env>& act() { return fmap[idx]; } - // access the given map (read-only) - const map<int32_t,Env>& act(size_t n) const { return fmap[n]; } + map<int32_t,Env>& act() { return m[idx]; } }; struct Env { @@ -180,6 +177,8 @@ // interface to CreateRet() which also takes care of collecting temporaries // and patching up tail calls llvm::ReturnInst *CreateRet(llvm::Value *v); + // print the code of all functions in an environment, recursively + void print_defs(ostream& os) const; // default constructor Env() : tag(0), n(0), m(0), f(0), h(0), fp(0), args(0), envs(0), @@ -580,7 +579,6 @@ // Interface to the lexer. public: bool declare_op; - void print_defs(ostream& os, const Env& e); private: bool lex_begin(); void lex_end(); Modified: pure/trunk/lexer.ll =================================================================== --- pure/trunk/lexer.ll 2008-08-02 07:07:44 UTC (rev 443) +++ pure/trunk/lexer.ll 2008-08-04 06:36:13 UTC (rev 444) @@ -543,7 +543,7 @@ sout << " " << rules << ";"; if (aflag && m) sout << endl << *m; if (dflag && fenv != interp.globalfuns.end() && fenv->second.f) - interp.print_defs(sout, fenv->second); + fenv->second.print_defs(sout); } else { sout << " " << argc << " args, " << rules.size() << " rules"; } @@ -560,7 +560,7 @@ if (n > 0) { if (aflag && m) sout << *m << endl; if (dflag && fenv != interp.globalfuns.end() && fenv->second.f) - interp.print_defs(sout, fenv->second); + fenv->second.print_defs(sout); nrules += n; ++nfuns; } @@ -936,14 +936,14 @@ result = k; } -void interpreter::print_defs(ostream& os, const Env& e) +void Env::print_defs(ostream& os) const { - if (!e.f) return; // not used, probably a shadowed rule - if (e.h && e.h != e.f) e.h->print(os); - e.f->print(os); - for (size_t i = 0, n = e.fmap.size(); i < n; i++) { - for (map<int32_t,Env>::const_iterator f = e.fmap.act(i).begin(), - end = e.fmap.act(i).end(); f != end; f++) - print_defs(os, f->second); + if (!f) return; // not used, probably a shadowed rule + 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++) + f->second.print_defs(os); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |