[pure-lang-svn] SF.net SVN: pure-lang: [317] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-06-27 00:11:49
|
Revision: 317 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=317&view=rev Author: agraef Date: 2008-06-26 17:11:58 -0700 (Thu, 26 Jun 2008) Log Message: ----------- Fix up completion support, second attempt. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/interpreter.cc pure/trunk/lexer.ll pure/trunk/pure.cc pure/trunk/symtable.hh Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-06-26 23:12:44 UTC (rev 316) +++ pure/trunk/ChangeLog 2008-06-27 00:11:58 UTC (rev 317) @@ -1,3 +1,9 @@ +2008-06-27 Albert Graef <Dr....@t-...> + + * pure.cc, interpreter.cc, lexer.ll: Fix up completion support, + second attempt (constructor symbols without any rules were + still missing). + 2008-06-26 Albert Graef <Dr....@t-...> * lexer.ll: Fix up list command to properly deal with the new Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-06-26 23:12:44 UTC (rev 316) +++ pure/trunk/interpreter.cc 2008-06-27 00:11:58 UTC (rev 317) @@ -926,8 +926,21 @@ delete ids; throw err("conflicting fixity declaration for symbol '"+id+"'"); } - } else - symtab.sym(*it, prec, fix); + } else { + int32_t tag = symtab.sym(*it, prec, fix).f; + /* KLUDGE: Already create a globalvars entry here, so that the symbol is + properly recognized by the completion routines. */ + pure_expr *cv = pure_const(tag); + assert(JIT); + GlobalVar& v = globalvars[tag]; + if (!v.v) { + v.v = new llvm::GlobalVariable + (ExprPtrTy, false, llvm::GlobalVariable::InternalLinkage, 0, + mkvarlabel(tag), module); + JIT->addGlobalMapping(v.v, &v.x); + } + if (v.x) pure_free(v.x); v.x = pure_new(cv); + } } delete ids; } Modified: pure/trunk/lexer.ll =================================================================== --- pure/trunk/lexer.ll 2008-06-26 23:12:44 UTC (rev 316) +++ pure/trunk/lexer.ll 2008-06-27 00:11:58 UTC (rev 317) @@ -136,12 +136,13 @@ "run", "save", "stats", "underride", "using", 0 }; +typedef map<string, symbol> symbol_map; + static char * command_generator(const char *text, int state) { static int list_index, len; - static env::iterator it, end; - static extmap::iterator xit, xend; + static symbol_map::iterator it, end; const char *name; assert(interpreter::g_interp); interpreter& interp = *interpreter::g_interp; @@ -149,10 +150,11 @@ /* New match. */ if (!state) { list_index = 0; - it = interp.globenv.begin(); - end = interp.globenv.end(); - xit = interp.externals.begin(); - xend = interp.externals.end(); + /* Must do this here, so that symbols are entered into the globalvars + table. */ + interp.compile(); + it = interp.symtab.tab.begin(); + end = interp.symtab.tab.end(); len = strlen(text); } @@ -167,22 +169,19 @@ /* Return the next name which partially matches from the symbol list. */ while (it != end) { - assert(it->first > 0); - symbol& sym = interp.symtab.sym(it->first); + int32_t f = it->second.f; + /* Skip non-toplevel symbols. */ + if (interp.globalvars.find(f) == interp.globalvars.end() && + interp.externals.find(f) == interp.externals.end()) { + it++; + continue; + } + const string& s = it->first; it++; - if (strncmp(sym.s.c_str(), text, len) == 0) - return strdup(sym.s.c_str()); + if (strncmp(s.c_str(), text, len) == 0) + return strdup(s.c_str()); } - /* Also process the declared externals which don't have any rules yet. */ - while (xit != xend) { - assert(xit->first > 0); - symbol& sym = interp.symtab.sym(xit->first); - xit++; - if (strncmp(sym.s.c_str(), text, len) == 0) - return strdup(sym.s.c_str()); - } - /* If no names matched, then return NULL. */ return 0; } Modified: pure/trunk/pure.cc =================================================================== --- pure/trunk/pure.cc 2008-06-26 23:12:44 UTC (rev 316) +++ pure/trunk/pure.cc 2008-06-27 00:11:58 UTC (rev 317) @@ -54,14 +54,13 @@ /* Generator functions for command completion. */ -typedef map<int32_t,ExternInfo> extmap; +typedef map<string, symbol> symbol_map; static char * command_generator(const char *text, int state) { static int list_index, len; - static env::iterator it, end; - static extmap::iterator xit, xend; + static symbol_map::iterator it, end; const char *name; assert(interpreter::g_interp); interpreter& interp = *interpreter::g_interp; @@ -69,10 +68,11 @@ /* New match. */ if (!state) { list_index = 0; - it = interp.globenv.begin(); - end = interp.globenv.end(); - xit = interp.externals.begin(); - xend = interp.externals.end(); + /* Must do this here, so that symbols are entered into the globalvars + table. */ + interp.compile(); + it = interp.symtab.tab.begin(); + end = interp.symtab.tab.end(); len = strlen(text); } @@ -87,22 +87,19 @@ /* Return the next name which partially matches from the symbol list. */ while (it != end) { - assert(it->first > 0); - symbol& sym = interp.symtab.sym(it->first); + int32_t f = it->second.f; + /* Skip non-toplevel symbols. */ + if (interp.globalvars.find(f) == interp.globalvars.end() && + interp.externals.find(f) == interp.externals.end()) { + it++; + continue; + } + const string& s = it->first; it++; - if (strncmp(sym.s.c_str(), text, len) == 0) - return strdup(sym.s.c_str()); + if (strncmp(s.c_str(), text, len) == 0) + return strdup(s.c_str()); } - /* Also process the declared externals which don't have any rules yet. */ - while (xit != xend) { - assert(xit->first > 0); - symbol& sym = interp.symtab.sym(xit->first); - xit++; - if (strncmp(sym.s.c_str(), text, len) == 0) - return strdup(sym.s.c_str()); - } - /* If no names matched, then return NULL. */ return 0; } @@ -111,39 +108,36 @@ symbol_generator(const char *text, int state) { static int len; - static env::iterator it, end; - static extmap::iterator xit, xend; + static symbol_map::iterator it, end; assert(interpreter::g_interp); interpreter& interp = *interpreter::g_interp; /* New match. */ if (!state) { - it = interp.globenv.begin(); - end = interp.globenv.end(); - xit = interp.externals.begin(); - xend = interp.externals.end(); + /* Must do this here, so that symbols are entered into the globalvars + table. */ + interp.compile(); + it = interp.symtab.tab.begin(); + end = interp.symtab.tab.end(); len = strlen(text); } /* Return the next name which partially matches from the symbol list. */ while (it != end) { - assert(it->first > 0); - symbol& sym = interp.symtab.sym(it->first); + int32_t f = it->second.f; + /* Skip non-toplevel symbols. */ + if (interp.globalvars.find(f) == interp.globalvars.end() && + interp.externals.find(f) == interp.externals.end()) { + it++; + continue; + } + const string& s = it->first; it++; - if (strncmp(sym.s.c_str(), text, len) == 0) - return strdup(sym.s.c_str()); + if (strncmp(s.c_str(), text, len) == 0) + return strdup(s.c_str()); } - /* Also process the declared externals which don't have any rules yet. */ - while (xit != xend) { - assert(xit->first > 0); - symbol& sym = interp.symtab.sym(xit->first); - xit++; - if (strncmp(sym.s.c_str(), text, len) == 0) - return strdup(sym.s.c_str()); - } - /* If no names matched, then return NULL. */ return 0; } Modified: pure/trunk/symtable.hh =================================================================== --- pure/trunk/symtable.hh 2008-06-26 23:12:44 UTC (rev 316) +++ pure/trunk/symtable.hh 2008-06-27 00:11:58 UTC (rev 317) @@ -32,9 +32,9 @@ class symtable { int32_t fno; +public: map<string, symbol> tab; vector<symbol*> rtab; -public: symtable(); // add default declarations for the builtin constants and operators (to be // invoked *after* possibly reading the prelude) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |