[pure-lang-svn] SF.net SVN: pure-lang:[643] pure/trunk
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-08-27 22:40:42
|
Revision: 643
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=643&view=rev
Author: agraef
Date: 2008-08-27 22:40:51 +0000 (Wed, 27 Aug 2008)
Log Message:
-----------
Bugfixes.
Modified Paths:
--------------
pure/trunk/interpreter.cc
pure/trunk/interpreter.hh
pure/trunk/lexer.ll
pure/trunk/pure.cc
Modified: pure/trunk/interpreter.cc
===================================================================
--- pure/trunk/interpreter.cc 2008-08-27 21:31:38 UTC (rev 642)
+++ pure/trunk/interpreter.cc 2008-08-27 22:40:51 UTC (rev 643)
@@ -583,7 +583,7 @@
#define DLLEXT ".so"
#endif
-pure_expr* interpreter::run(const string &_s, bool check)
+pure_expr* interpreter::run(const string &_s, bool check, bool sticky)
{
string s = unixize(_s);
// check for library modules
@@ -631,7 +631,10 @@
source = s; declare_op = false;
source_s = 0;
srcdir = dirname(fname);
- if (!l_interactive || check) modno = modctr++;
+ if (sticky)
+ ; // keep the current module
+ else
+ modno = modctr++;
errmsg.clear();
if (check && !interactive) temp = 0;
bool ok = lex_begin(fname);
@@ -663,7 +666,7 @@
return result;
}
-pure_expr* interpreter::run(const list<string> &sl, bool check)
+pure_expr* interpreter::run(const list<string> &sl, bool check, bool sticky)
{
uint8_t s_verbose = verbose;
// Temporarily suppress verbose output for using clause.
@@ -672,7 +675,7 @@
verbose = 0;
}
for (list<string>::const_iterator s = sl.begin(); s != sl.end(); s++)
- run(*s, check);
+ run(*s, check, sticky);
if (s_verbose) {
compile();
verbose = s_verbose;
Modified: pure/trunk/interpreter.hh
===================================================================
--- pure/trunk/interpreter.hh 2008-08-27 21:31:38 UTC (rev 642)
+++ pure/trunk/interpreter.hh 2008-08-27 22:40:51 UTC (rev 643)
@@ -344,20 +344,27 @@
*************************************************************************/
/* Parse and execute the given source file (stdin if empty), or the given
- list of files. If check is true (the default), a full search is performed
- for relative pathnames (checking include directories and PURELIB to
- locate the script file) and the script is only loaded if it wasn't
- included before. Returns the last computed expression (if any). (This
- expression is owned by the interpreter and must *not* be freed by the
- caller.) This is the main interface function. If interactive is true,
- readline is used to get interactive input from the user, using ps as the
- prompt string. Please note that due to some global data shared by
- different interpreter instances, you can't run two interpreters
- concurrently right now. (It is possible to run them sequentially,
- though.) */
- pure_expr *run(const string& source, bool check = true);
- pure_expr *run(const list<string>& sources, bool check = true);
+ list of files. If 'check' is true (the default), a full search is
+ performed for relative pathnames (checking include directories and
+ PURELIB to locate the script file) and the script is only loaded if it
+ wasn't included before. If 'sticky' is true (default is false), the
+ current module namespace is kept, otherwise a new namespace is created
+ for the loaded module. Using this option isn't recommended, but it is
+ used internally by the 'run' command and the '-i' option to give access
+ to the private symbols of the executed script when running interactively.
+ Returns the last computed expression (if any). (This expression is owned
+ by the interpreter and must *not* be freed by the caller.) This is the
+ main interface function. If interactive is true, readline is used to get
+ interactive input from the user, using ps as the prompt string. Please
+ note that due to some global data shared by different interpreter
+ instances, you can't run two interpreters concurrently right now. (It is
+ possible to run them sequentially, though.) */
+ pure_expr *run(const string& source, bool check = true,
+ bool sticky = false);
+ pure_expr *run(const list<string>& sources, bool check = true,
+ bool sticky = false);
+
/* This works like run() above, but takes the source directly from a
string. No error messages will be printed, instead any errors reported
during the most recent invokation of this method are available in
Modified: pure/trunk/lexer.ll
===================================================================
--- pure/trunk/lexer.ll 2008-08-27 21:31:38 UTC (rev 642)
+++ pure/trunk/lexer.ll 2008-08-27 22:40:51 UTC (rev 643)
@@ -773,7 +773,7 @@
else if (args.c > 1)
cerr << "run: extra parameter\n";
else
- interp.run(*args.l.begin(), false);
+ interp.run(*args.l.begin(), false, true);
}
^override.* {
// override command is only permitted in interactive mode
Modified: pure/trunk/pure.cc
===================================================================
--- pure/trunk/pure.cc 2008-08-27 21:31:38 UTC (rev 642)
+++ pure/trunk/pure.cc 2008-08-27 22:40:51 UTC (rev 643)
@@ -362,6 +362,7 @@
}
}
// load scripts specified on the command line
+ int32_t last_modno = interp.modno;
for (; *argv; ++argv)
if (string(*argv).substr(0,2) == "-v") {
uint8_t level = 1;
@@ -371,6 +372,7 @@
} else if (*argv == string("-x")) {
if (*++argv) {
count++; interp.modname = *argv;
+ last_modno = interp.modctr;
interp.run(*argv, false);
} else {
interp.error(prog + ": missing script name");
@@ -387,6 +389,7 @@
;
else if (**argv) {
if (count++ == 0) interp.modname = *argv;
+ last_modno = interp.modctr;
interp.run(*argv, false);
}
if (count > 0 && !force_interactive) {
@@ -420,7 +423,9 @@
histfile = strdup(interp.histfile.c_str());
}
interp.temp = 1;
- interp.run("", false);
+ if (last_modno < 0) force_interactive = false;
+ if (force_interactive) interp.modno = last_modno;
+ interp.run("", false, force_interactive);
if (interp.ttymode) cout << endl;
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|