pure-lang-svn Mailing List for Pure (Page 10)
Status: Beta
Brought to you by:
agraef
You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
(5) |
May
(141) |
Jun
(184) |
Jul
(97) |
Aug
(232) |
Sep
(196) |
Oct
|
Nov
|
Dec
|
---|
From: <ag...@us...> - 2008-08-28 00:03:10
|
Revision: 645 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=645&view=rev Author: agraef Date: 2008-08-28 00:03:19 +0000 (Thu, 28 Aug 2008) Log Message: ----------- Update documentation. Modified Paths: -------------- pure/trunk/pure.1.in Modified: pure/trunk/pure.1.in =================================================================== --- pure/trunk/pure.1.in 2008-08-27 23:04:26 UTC (rev 644) +++ pure/trunk/pure.1.in 2008-08-28 00:03:19 UTC (rev 645) @@ -1465,12 +1465,27 @@ I/O. More stuff will likely be provided in future releases. .SH INTERACTIVE USAGE In interactive mode, the interpreter reads definitions and expressions and -processes them as usual. The input language is just the same as for source -scripts, and hence individual definitions and expressions \fImust\fP be -terminated with a semicolon before they are processed. For instance, here is a -simple interaction which defines the factorial and then uses that definition -in some evaluations. Input lines begin with ``>'', which is the interpreter's -default command prompt: +processes them as usual. If the +.B -i +option was used to force interactive mode when invoking the interpreter, the +last script specified on the command line determines the visible namespace +(i.e., all public symbols are visible, along with the private symbols of the +loaded script). Otherwise only the public symbols defined in the prelude are +available. Additional scripts can be loaded interactively using either a +.B using +declaration or the interactive +.B run +command (see the description of the +.B run +command below for the differences between these). Or you can just start typing +away, entering your own definitions and expressions to be evaluated. +.PP +The input language is just the same as for source scripts, and hence +individual definitions and expressions \fImust\fP be terminated with a +semicolon before they are processed. For instance, here is a simple +interaction which defines the factorial and then uses that definition in some +evaluations. Input lines begin with ``>'', which is the interpreter's default +command prompt: .sp .nf > fact 1 = 1; @@ -1496,8 +1511,9 @@ global variables). If no symbols are given, purge \fIall\fP definitions (after confirmation) made after the most recent .B save -command (or the beginning of the interactive session). See the DEFINITION -LEVELS AND OVERRIDE MODE section below for details. +command, or the beginning of the interactive session. (It might be a good +idea to first check your current definitions with \fBlist -t\fP before you do +this, though.) See the DEFINITION LEVELS section below for details. .TP .B "help \fR[\fIargs\fP]\fP" Display the @@ -1516,7 +1532,7 @@ .B override Enter ``override'' mode. This allows you to add equations ``above'' existing definitions in the source script, possibly overriding existing equations. See -the DEFINITION LEVELS AND OVERRIDE MODE section below for details. +the DEFINITION LEVELS section below for details. .TP .B pwd Print the current working dir (shell \fBpwd\fP(1) command). @@ -1532,23 +1548,25 @@ the script ``anonymously'', as if the contents of the script had been typed at the command prompt. That is, .B run -doesn't check whether the script is being used already and it puts the -definitions on the current temporary level (so that +will just put the definitions into the current namespace, giving you access to +all private symbols of the script. Also, the definitions are placed at the +current temporary level, so that .B clear -can be used to remove them again). This also gives you access to all private -symbols of the script, and it makes it possible to quickly reload a script -without exiting the interpreter, by issuing the +can be used to remove them again. In particular, this makes it possible to +quickly reload a script without exiting the interpreter, by issuing the .B clear command followed by .BR run . +(This works best if you start out from a clean environment, with no scripts +loaded on the command line.) .TP .B save Begin a new level of temporary definitions. A subsequent .B clear command (see above) will purge all definitions made after the most recent .B save -(or the beginning of the interactive session). See the DEFINITION LEVELS AND -OVERRIDE MODE section below for details. +(or the beginning of the interactive session). See the DEFINITION LEVELS +section below for details. .TP .B "stats \fR[on|off]\fP" Enables (default) or disables ``stats'' mode, in which various statistics are @@ -1559,7 +1577,7 @@ .B underride Exits ``override'' mode. This returns you to the normal mode of operation, where new equations are added `below'' previous rules of an existing function. -See the DEFINITION LEVELS AND OVERRIDE MODE section below for details. +See the DEFINITION LEVELS section below for details. .PP Note that these special commands are only recognized at the beginning of the interactive command line. (Thus you can escape a symbol looking like a command @@ -1611,6 +1629,12 @@ .B -m Print information about defined macros. .TP +.B -p[\fIflag\fP] +List only private symbols in the current module if \fIflag\fP is nonzero (the +default), otherwise (\fIflag\fP is zero) list only public symbols of all +modules. List both private and public symbols if -p is omitted. The +\fIflag\fP parameter, if given, must immediately follow the option character. +.TP .B -s Summary format, print just summary information about listed symbols. .TP @@ -1619,9 +1643,8 @@ current level by default) or above. The \fIlevel\fP parameter, if given, must immediately follow the option character. A \fIlevel\fP of 1 denotes all temporary definitions, whereas 0 indicates \fIall\fP definitions (which is the -default if \fB-t\fP is not specified). See the DEFINITION LEVELS AND OVERRIDE -MODE section below for information about the notion of temporary definition -levels. +default if \fB-t\fP is not specified). See the DEFINITION LEVELS section below +for information about the notion of temporary definition levels. .TP .B -v Print information about defined variables. @@ -1673,20 +1696,23 @@ the sources, the .B list command can easily do it for you. For instance, here's how you can list the -definitions of all list ``zipping'' operations from the prelude in one go: +definitions of all list ``fold'' operations from the prelude in one go: .sp .nf -> \fBlist\fP -g zip* -zip (x:xs) (y:ys) = (x,y):zip xs ys; -zip _ _ = []; -zip3 (x:xs) (y:ys) (z:zs) = (x,y,z):zip3 xs ys zs; -zip3 _ _ _ = []; -zipwith f (x:xs) (y:ys) = f x y:zipwith f xs ys; -zipwith f _ _ = []; -zipwith3 f (x:xs) (y:ys) (z:zs) = f x y z:zipwith3 f xs ys zs; -zipwith3 f _ _ _ = []; +> \fBlist\fP -g fold* +foldl f a s::string = foldl f a (chars s); +foldl f a [] = a; +foldl f a (x:xs) = foldl f (f a x) xs; +foldl1 f s::string = foldl1 f (chars s); +foldl1 f (x:xs) = foldl f x xs; +foldr f a s::string = foldr f a (chars s); +foldr f a [] = a; +foldr f a (x:xs) = f x (foldl (flip f) a (reverse xs)); +foldr1 f s::string = foldr1 f (chars s); +foldr1 f [x] = x; +foldr1 f (x:xs) = f x (foldl1 (flip f) (reverse xs)); .fi -.SH DEFINITION LEVELS AND OVERRIDE MODE +.SH DEFINITION LEVELS To help with incremental development, the interpreter also offers some facilities to manipulate the current set of definitions interactively. To these ends, definitions are organized into different subsets called @@ -1700,7 +1726,8 @@ .B run command) and returns you to the previous one (if any). This gives you a ``stack'' of up to 255 temporary environments which enables you to ``plug and -play'' in a safe fashion, without affecting the rest of your program. Example: +play'' in a (more or less) safe fashion, without affecting the rest of your +program. Example: .sp .nf > foo (x:xs) = x+foo xs; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 23:04:18
|
Revision: 644 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=644&view=rev Author: agraef Date: 2008-08-27 23:04:26 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Add option -p to list only private/public symbols to the 'list' command. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/lexer.ll Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-08-27 22:40:51 UTC (rev 643) +++ pure/trunk/ChangeLog 2008-08-27 23:04:26 UTC (rev 644) @@ -1,3 +1,8 @@ +2008-08-28 Albert Graef <Dr....@t-...> + + * lexer.ll: Add option -p to list only private/public symbols to + the 'list' command. + 2008-08-27 Albert Graef <Dr....@t-...> * lib/: Clean up the public namespace. Modified: pure/trunk/lexer.ll =================================================================== --- pure/trunk/lexer.ll 2008-08-27 22:40:51 UTC (rev 643) +++ pure/trunk/lexer.ll 2008-08-27 23:04:26 UTC (rev 644) @@ -361,7 +361,7 @@ // list command is only permitted in interactive mode if (!interp.interactive) REJECT; uint8_t s_verbose = interpreter::g_verbose; - uint8_t tflag = 0; + uint8_t tflag = 0; int pflag = -1; bool aflag = false, dflag = false, eflag = false; bool cflag = false, fflag = false, mflag = false, vflag = false; bool gflag = false, lflag = false, sflag = false; @@ -374,7 +374,7 @@ // process option arguments for (arg = args.l.begin(); arg != args.l.end(); arg++) { const char *s = arg->c_str(); - if (s[0] != '-' || !s[1] || !strchr("acdefghlmstv", s[1])) break; + if (s[0] != '-' || !s[1] || !strchr("acdefghlmpstv", s[1])) break; while (*++s) { switch (*s) { case 'a': aflag = true; break; @@ -385,6 +385,13 @@ case 'g': gflag = true; break; case 'l': lflag = true; break; case 'm': mflag = true; break; + case 'p': + if (isdigit(s[1])) { + pflag = strtoul(s+1, 0, 10)>0; + while (isdigit(s[1])) ++s; + } else + pflag = 1; + break; case 's': sflag = true; break; case 'v': vflag = true; break; case 't': @@ -410,6 +417,9 @@ -l Long format, prints definitions along with the summary symbol\n\ information. This implies -s.\n\ -m Print information about defined macros.\n\ +-p[flag] List only private symbols in the current module if flag is\n\ + nonzero (the default), otherwise list only public symbols of all\n\ + modules. List both private and public symbols if -p is omitted.\n\ -s Summary format, print just summary information about listed symbols.\n\ -t[level] List only symbols and definitions at the given temporary level\n\ (the current level by default) or above. Level 1 denotes all temporary\n\ @@ -439,6 +449,7 @@ const env_info& e = it->second; const symbol& sym = interp.symtab.sym(f); if (sym.modno >= 0 && sym.modno != interp.modno || + pflag >= 0 && (pflag > 0) != (sym.modno >= 0) || !((e.t == env_info::fun)?fflag: (e.t == env_info::cvar)?cflag: (e.t == env_info::fvar)?vflag:0)) @@ -480,7 +491,9 @@ int32_t f = it->first; if (syms.find(f) == syms.end()) { const symbol& sym = interp.symtab.sym(f); - if (sym.modno >= 0 && sym.modno != interp.modno) continue; + if (sym.modno >= 0 && sym.modno != interp.modno || + pflag >= 0 && (pflag > 0) != (sym.modno >= 0)) + continue; bool matches = true; if (!args.l.empty()) { matches = false; @@ -508,7 +521,9 @@ if (syms.find(f) == syms.end()) { const env_info& e = it->second; const symbol& sym = interp.symtab.sym(f); - if (sym.modno >= 0 && sym.modno != interp.modno) continue; + if (sym.modno >= 0 && sym.modno != interp.modno || + pflag >= 0 && (pflag > 0) != (sym.modno >= 0)) + continue; bool matches = e.temp >= tflag; if (!matches && !sflag && args.l.empty()) { // if not in summary mode, also list temporary rules for a This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <ag...@us...> - 2008-08-27 21:31:29
|
Revision: 642 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=642&view=rev Author: agraef Date: 2008-08-27 21:31:38 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Update documentation. Modified Paths: -------------- pure/trunk/pure.1.in Modified: pure/trunk/pure.1.in =================================================================== --- pure/trunk/pure.1.in 2008-08-27 21:25:37 UTC (rev 641) +++ pure/trunk/pure.1.in 2008-08-27 21:31:38 UTC (rev 642) @@ -1535,8 +1535,9 @@ doesn't check whether the script is being used already and it puts the definitions on the current temporary level (so that .B clear -can be used to remove them again). In particular, this makes it possible to -quickly reload a script without exiting the interpreter, by issuing the +can be used to remove them again). This also gives you access to all private +symbols of the script, and it makes it possible to quickly reload a script +without exiting the interpreter, by issuing the .B clear command followed by .BR run . This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 21:25:28
|
Revision: 641 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=641&view=rev Author: agraef Date: 2008-08-27 21:25:37 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Bugfixes. Modified Paths: -------------- pure/trunk/interpreter.cc Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-27 21:07:30 UTC (rev 640) +++ pure/trunk/interpreter.cc 2008-08-27 21:25:37 UTC (rev 641) @@ -631,7 +631,7 @@ source = s; declare_op = false; source_s = 0; srcdir = dirname(fname); - modno = modctr++; + if (!l_interactive || check) modno = modctr++; errmsg.clear(); if (check && !interactive) temp = 0; bool ok = lex_begin(fname); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 21:07:21
|
Revision: 640 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=640&view=rev Author: agraef Date: 2008-08-27 21:07:30 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Keep the namespace clean. Modified Paths: -------------- pure/trunk/lib/array.pure pure/trunk/lib/dict.pure pure/trunk/lib/heap.pure pure/trunk/lib/set.pure Modified: pure/trunk/lib/array.pure =================================================================== --- pure/trunk/lib/array.pure 2008-08-27 20:35:47 UTC (rev 639) +++ pure/trunk/lib/array.pure 2008-08-27 21:07:30 UTC (rev 640) @@ -55,9 +55,12 @@ *************************************************************************/ -/* Empty tree constant, consider this private. */ -nullary nil; +/* Tree constructors. */ +private nullary nil; +private tip bin; +private mkbin; + // array type check arrayp (Array _) = 1; arrayp _ = 0; @@ -76,7 +79,7 @@ with mkarray x n::int = nil if n <= 0; = tip x if n == 1; - = array_mkbin (n mod 2) + = mkbin (n mod 2) (mkarray x (n - n div 2)) (mkarray x (n div 2)); end; @@ -150,16 +153,16 @@ rmfirst (Array a) = Array (rmfirst a) with rmfirst (tip _) = nil; - rmfirst (bin 0 a1 a2) = array_mkbin 1 a2 (rmfirst a1); - rmfirst (bin 1 a1 a2) = array_mkbin 0 a2 (rmfirst a1); + rmfirst (bin 0 a1 a2) = mkbin 1 a2 (rmfirst a1); + rmfirst (bin 1 a1 a2) = mkbin 0 a2 (rmfirst a1); end; // remove the last member from an array rmlast (Array a) = Array (rmlast a) with rmlast (tip _) = nil; - rmlast (bin 0 a1 a2) = array_mkbin 1 a1 (rmlast a2); - rmlast (bin 1 a1 a2) = array_mkbin 0 (rmlast a1) a2; + rmlast (bin 0 a1 a2) = mkbin 1 a1 (rmlast a2); + rmlast (bin 1 a1 a2) = mkbin 0 (rmlast a1) a2; end; // insert a new member at the beginning of an array @@ -167,8 +170,8 @@ with insert nil y = tip y; insert (tip x) y = bin 0 (tip y) (tip x); - insert (bin 0 a1 a2) y = array_mkbin 1 (insert a2 y) a1; - insert (bin 1 a1 a2) y = array_mkbin 0 (insert a2 y) a1; + insert (bin 0 a1 a2) y = mkbin 1 (insert a2 y) a1; + insert (bin 1 a1 a2) y = mkbin 0 (insert a2 y) a1; end; // append a new member at the end of an array @@ -176,8 +179,8 @@ with append nil y = tip y; append (tip x) y = bin 0 (tip x) (tip y); - append (bin 0 a1 a2) y = array_mkbin 1 (append a1 y) a2; - append (bin 1 a1 a2) y = array_mkbin 0 a1 (append a2 y); + append (bin 0 a1 a2) y = mkbin 1 (append a1 y) a2; + append (bin 1 a1 a2) y = mkbin 0 a1 (append a2 y); end; // update a given array position with a new value @@ -225,9 +228,9 @@ = b1 != b2 || neq a1 a3 || neq a2 a4; end; -/* Private functions, don't invoke these directly. */ +/* Private functions. */ // construct a binary array node -array_mkbin _ nil a2 = a2; -array_mkbin _ a1 nil = a1; -array_mkbin b::int a1 a2 = bin b a1 a2; +mkbin _ nil a2 = a2; +mkbin _ a1 nil = a1; +mkbin b::int a1 a2 = bin b a1 a2; Modified: pure/trunk/lib/dict.pure =================================================================== --- pure/trunk/lib/dict.pure 2008-08-27 20:35:47 UTC (rev 639) +++ pure/trunk/lib/dict.pure 2008-08-27 21:07:30 UTC (rev 640) @@ -30,8 +30,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -/* Empty tree constant, consider this private. */ -nullary nil; +/* Tree constructors. */ +private nullary nil; +private bin; /***** Tree for dict and hdict is either: @@ -69,6 +70,7 @@ *************************************************************************/ +private adjustd avl_geq; // Dict and hdict type checks dictp (Dict _) = 1; @@ -148,7 +150,7 @@ rebal 0 (bin k v _ l r) b = bin k v b l r; - rebal 1 oldTree _ = (Dict_avl_geq oldTree)!0; + rebal 1 oldTree _ = (avl_geq oldTree)!0; /* // Balance rules for insertions @@ -187,7 +189,7 @@ = [l, 1] if key == k; deleted (bin k _ b (bin kl vl bl rl ll) r ) key - = Dict_adjustd leftHasChanged (bin lastk lastv b newl r) (-1) + = adjustd leftHasChanged (bin lastk lastv b newl r) (-1) when [lastk, lastv] = last (bin kl vl bl rl ll); [newl, leftHasChanged] @@ -196,14 +198,14 @@ if key == k; deleted (bin k v b l r) key - = Dict_adjustd leftHasChanged (bin k v b newl r) (-1) + = adjustd leftHasChanged (bin k v b newl r) (-1) when [newl, leftHasChanged] = deleted l key end if key < k; deleted (bin k v b l r) key - = Dict_adjustd rightHasChanged (bin k v b l newr) ( 1) + = adjustd rightHasChanged (bin k v b l newr) ( 1) when [newr, rightHasChanged] = deleted r key end @@ -230,7 +232,7 @@ if k == key; deleteh (bin k::int xys b (bin kl vl bl rl ll) r) key::int x - = Dict_adjustd leftHasChanged (bin lastk lastv b newl r) (-1) + = adjustd leftHasChanged (bin lastk lastv b newl r) (-1) when [lastk, lastv] = last (bin kl vl bl rl ll); [newl, leftHasChanged] = rmlast (bin kl vl bl rl ll) @@ -242,14 +244,14 @@ if k == key; deleteh (bin k::int v b l r) key::int x - = Dict_adjustd leftHasChanged (bin k v b newl r) (-1) + = adjustd leftHasChanged (bin k v b newl r) (-1) when [newl, leftHasChanged] = deleteh l key x end if key < k; deleteh (bin k::int v b l r) key::int x - = Dict_adjustd rightHasChanged (bin k v b l newr) ( 1) + = adjustd rightHasChanged (bin k v b l newr) ( 1) when [newr, rightHasChanged] = deleteh r key x end @@ -262,7 +264,7 @@ rmlast nil = [nil, 0]; rmlast (bin _ _ _ l nil) = [l, 1]; rmlast (bin k v b::int l r ) - = Dict_adjustd rightHasChanged (bin k v b l newr) ( 1) + = adjustd rightHasChanged (bin k v b l newr) ( 1) when [newr, rightHasChanged] = rmlast r end; last (bin x y _ _ nil) = [x, y]; @@ -356,7 +358,7 @@ rmfirst nil = [nil, 0]; rmfirst (bin _ _ _ nil r) = [r, 1]; rmfirst (bin k v b l r) - = Dict_adjustd leftHasChanged (bin k v b newl r) (-1) + = adjustd leftHasChanged (bin k v b newl r) (-1) when [newl, leftHasChanged] = rmfirst l end @@ -368,7 +370,7 @@ rmlast nil = [nil 0]; rmlast (bin _ _ _ l nil) = [l, 1]; rmlast (bin k v b l r) - = Dict_adjustd rightHasChanged (bin k v b l newr) ( 1) + = adjustd rightHasChanged (bin k v b l newr) ( 1) when [newr, rightHasChanged] = rmlast r end @@ -489,9 +491,9 @@ d1@(Dict _) != d2@(Dict _) = (members d1) != (members d2); d1@(Hdict _) != d2@(Hdict _) = not (d1 == d2); -/* Private functions, don't invoke these directly. */ +/* Private functions. */ -Dict_adjustd ToF::int tree LoR::int +adjustd ToF::int tree LoR::int = adjust ToF tree LoR with adjust 0 oldTree _ = [oldTree, 0]; @@ -505,7 +507,7 @@ rebal 0 (bin k v _ l r) b whatHasChanged = [bin k v b l r, whatHasChanged]; - rebal 1 oldTree _ _ = Dict_avl_geq oldTree; + rebal 1 oldTree _ _ = avl_geq oldTree; /* // Balance rules for deletions @@ -543,7 +545,7 @@ deletion any pattern can occur and so we return 1 or 0 as a flag of a height change. */ -Dict_avl_geq d = avl_geq d +avl_geq d = avl_geq d with avl_geq (bin a va (-1) alpha (bin b vb (-1) beta gamma)) = [bin b vb ( 0) (bin a va ( 0) alpha beta) gamma, 1]; Modified: pure/trunk/lib/heap.pure =================================================================== --- pure/trunk/lib/heap.pure 2008-08-27 20:35:47 UTC (rev 639) +++ pure/trunk/lib/heap.pure 2008-08-27 21:07:30 UTC (rev 640) @@ -41,8 +41,9 @@ *************************************************************************/ -/* Empty tree constant, consider this private. */ -nullary nil; +/* Tree constructors. */ +private nullary nil; +private bin; // create an empty heap emptyheap = Heap nil; Modified: pure/trunk/lib/set.pure =================================================================== --- pure/trunk/lib/set.pure 2008-08-27 20:35:47 UTC (rev 639) +++ pure/trunk/lib/set.pure 2008-08-27 21:07:30 UTC (rev 640) @@ -50,8 +50,9 @@ *************************************************************************/ -/* Empty tree constant, consider this private. */ -nullary nil; +/* Tree constructors. */ +private nullary nil; +private bin; /***** Tree for set and bag is either: @@ -62,6 +63,8 @@ Balance: ( 1), ( 0), or (-1) denoting |L|-|R| = 1, 0, or -1, respectively *****/ +private adjustd avl_geq; + // set and bag type checks bagp (Bag _) = 1; bagp _ = 0; @@ -109,7 +112,7 @@ = bin k b l r; rebal 1 oldTree _ - = (Set_avl_geq oldTree)!0; + = (avl_geq oldTree)!0; /* // Balance rules for insertions // balance where balance whole tree to be @@ -145,7 +148,7 @@ = [l, 1] if key == k; delete (bin k b::int x@(bin kl bl::int rl ll) r) key - = Set_adjustd leftHasChanged (bin lk b newL r) (-1) + = adjustd leftHasChanged (bin lk b newL r) (-1) when lk = last x; [newL, leftHasChanged] = rmlast x @@ -153,14 +156,14 @@ if key == k; delete (bin k b::int l r) key - = Set_adjustd leftHasChanged (bin k b newL r) (-1) + = adjustd leftHasChanged (bin k b newL r) (-1) when [newL, leftHasChanged] = delete l key end if key < k; delete (bin k b::int l r) key - = Set_adjustd rightHasChanged (bin k b l newR) ( 1) + = adjustd rightHasChanged (bin k b l newR) ( 1) when [newR, rightHasChanged] = delete r key end @@ -169,7 +172,7 @@ rmlast nil = [nil, 0]; rmlast (bin _ _ l nil) = [l, 1]; rmlast (bin k b::int l r ) - = Set_adjustd rightHasChanged (bin k b l newR) ( 1) + = adjustd rightHasChanged (bin k b l newR) ( 1) when [newR, rightHasChanged] = rmlast r end; last (bin x _ _ nil) = x; @@ -245,7 +248,7 @@ rmfirst nil = [nil, 0]; rmfirst (bin _ _ nil r) = [r, 1]; rmfirst (bin k b::int l r) - = Set_adjustd leftHasChanged (bin k b newL r) (-1) + = adjustd leftHasChanged (bin k b newL r) (-1) when [newL, leftHasChanged] = rmfirst l end end; @@ -257,7 +260,7 @@ rmlast nil = [nil, 0]; rmlast (bin _ _ l nil) = [l, 1]; rmlast (bin k b::int l r ) - = Set_adjustd rightHasChanged (bin k b l newR) ( 1) + = adjustd rightHasChanged (bin k b l newR) ( 1) when [newR, rightHasChanged] = rmlast r end end; @@ -300,9 +303,9 @@ = m1 - (m1 - m2); -/* Private functions, don't invoke these directly. */ +/* Private functions. */ -Set_adjustd ToF::int tree LoR::int +adjustd ToF::int tree LoR::int = adjust ToF tree LoR with adjust 0 oldTree _ = [oldTree, 0]; @@ -321,7 +324,7 @@ rebal 0 (bin k _ l r) b::int whatHasChanged = [bin k b l r, whatHasChanged]; - rebal 1 oldTree _ _ = Set_avl_geq oldTree; + rebal 1 oldTree _ _ = avl_geq oldTree; // Balance rules for deletions /* @@ -360,7 +363,7 @@ a height change. */ -Set_avl_geq x = avl_geq x +avl_geq x = avl_geq x with avl_geq (bin a (-1) alpha (bin b (-1) beta gamma)) = [bin b ( 0) (bin a ( 0) alpha beta) gamma, 1]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 20:35:38
|
Revision: 639 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=639&view=rev Author: agraef Date: 2008-08-27 20:35:47 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Keep the namespace clean. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/lib/math.pure pure/trunk/lib/primitives.pure pure/trunk/lib/strings.pure pure/trunk/lib/system.pure Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-08-27 19:33:15 UTC (rev 638) +++ pure/trunk/ChangeLog 2008-08-27 20:35:47 UTC (rev 639) @@ -1,5 +1,7 @@ 2008-08-27 Albert Graef <Dr....@t-...> + * lib/: Clean up the public namespace. + * lexer.ll: Added limited support for unicode symbols. These can now be declared as operator or nullary symbols. Modified: pure/trunk/lib/math.pure =================================================================== --- pure/trunk/lib/math.pure 2008-08-27 19:33:15 UTC (rev 638) +++ pure/trunk/lib/math.pure 2008-08-27 20:35:47 UTC (rev 639) @@ -32,6 +32,7 @@ /* Exponential function and logarithms. */ +private c_log; extern double exp(double), double log(double) = c_log; ln x::double = c_log x; @@ -71,12 +72,9 @@ /* Hyperbolic functions. */ extern double sinh(double), double cosh(double), double tanh(double); -extern double __asinh(double), double __acosh(double), double __atanh(double); +extern double __asinh(double) = asinh, double __acosh(double) = acosh, + double __atanh(double) = atanh; -asinh x::double = __asinh x; -acosh x::double = __acosh x; -atanh x::double = __atanh x; - sinh x::int | sinh x::bigint = sinh (double x); cosh x::int | cosh x::bigint = cosh (double x); tanh x::int | tanh x::bigint = tanh (double x); @@ -376,8 +374,6 @@ /* Conversions. */ -extern expr* pure_rational(double); - rational x@(_%_) = x; rational x::int | rational x::bigint = x%1; @@ -385,6 +381,8 @@ /* The conversion from double doesn't do any rounding, so it is guaranteed that converting the resulting rational back to double reconstructs the original value. */ +private pure_rational; +extern expr* pure_rational(double); rational x::double = n%d when n,d = pure_rational x end; rational (x+:y) = rational x +: rational y; Modified: pure/trunk/lib/primitives.pure =================================================================== --- pure/trunk/lib/primitives.pure 2008-08-27 19:33:15 UTC (rev 638) +++ pure/trunk/lib/primitives.pure 2008-08-27 20:35:47 UTC (rev 639) @@ -77,6 +77,7 @@ /* Conversions between the different numeric and pointer types. */ +private pure_intval pure_dblval pure_bigintval pure_pointerval; extern expr* pure_intval(expr*), expr* pure_dblval(expr*), expr* pure_bigintval(expr*), expr* pure_pointerval(expr*); @@ -221,6 +222,8 @@ /* Bigint arithmetic. */ +private bigint_neg bigint_not bigint_add bigint_sub bigint_mul bigint_div + bigint_mod bigint_shl bigint_shr bigint_and bigint_or bigint_cmp; extern expr* bigint_neg(void*); extern expr* bigint_not(void*); extern expr* bigint_add(void*, void*); @@ -322,6 +325,7 @@ /* The gcd and lcm functions from the GMP library. These return a bigint if at least one of the arguments is a bigint, a machine int otherwise. */ +private bigint_gcd bigint_lcm; extern expr* bigint_gcd(void*, void*); extern expr* bigint_lcm(void*, void*); @@ -340,6 +344,7 @@ always a bigint. Note that y must always be nonnegative here, but see math.pure which deals with the case y<0 using rational numbers. */ +private bigint_pow; extern expr* bigint_pow(void*, int); pow x::int y::int = bigint_pow (bigint x) y if y>=0; @@ -352,6 +357,7 @@ /* The ^ operator. Computes inexact powers for any combination of int, bigint and double operands. The result is always a double. */ +private c_pow; extern double pow(double, double) = c_pow; x::double^y::double = c_pow x y; @@ -382,6 +388,8 @@ /* Direct memory accesses. Use with care ... or else! */ +private pointer_get_byte pointer_get_int pointer_get_double + pointer_get_string pointer_get_pointer; extern int pointer_get_byte(void *ptr); extern int pointer_get_int(void *ptr); extern double pointer_get_double(void *ptr); @@ -394,6 +402,8 @@ get_string x::pointer = pointer_get_string x; get_pointer x::pointer = pointer_get_pointer x; +private pointer_put_byte pointer_put_int pointer_put_double + pointer_put_string pointer_put_pointer; extern void pointer_put_byte(void *ptr, int x); // IMPURE! extern void pointer_put_int(void *ptr, int x); // IMPURE! extern void pointer_put_double(void *ptr, double x); // IMPURE! Modified: pure/trunk/lib/strings.pure =================================================================== --- pure/trunk/lib/strings.pure 2008-08-27 19:33:15 UTC (rev 638) +++ pure/trunk/lib/strings.pure 2008-08-27 20:35:47 UTC (rev 639) @@ -28,6 +28,7 @@ was encountered during the most recent invokation of eval(). In that case each reported error message is terminated with a newline character. */ +private pure_str; extern void* str(expr*) = pure_str; extern expr* eval(char*); // IMPURE! extern char* lasterr(); @@ -36,6 +37,7 @@ /* Convert between Unicode character codes and single character strings. */ +private string_chr string_ord; extern expr* string_chr(int); extern expr* string_ord(void*); @@ -51,6 +53,7 @@ to be malloc'ed). The _cstring routines also convert from the system encoding. */ +private pure_string pure_cstring pure_string_dup pure_cstring_dup; extern expr* pure_string(void* s); extern expr* pure_cstring(void* s); extern expr* pure_string_dup(void* s); @@ -68,6 +71,7 @@ char* (employing pointer arithmetic etc.; the usual caveats apply), and has to be freed explicitly by the caller when no longer needed. */ +private pure_byte_string pure_byte_cstring; extern expr* pure_byte_string(void *s); extern expr* pure_byte_cstring(void *s); @@ -86,6 +90,7 @@ string takes quadratic time; as a remedy, we also offer a linear-time operation to determine the list of all characters of a string in one go. */ +private string_null string_size string_concat string_char_at string_chars; extern bool string_null(void*); extern int string_size(void*); extern expr* string_concat(void*, void*); @@ -100,6 +105,7 @@ /* Lexicographic string comparison. */ +private strcmp; extern int strcmp(void*, void*); x::string<y::string = strcmp x y < 0; @@ -111,6 +117,7 @@ /* Compute and find substrings of a string. */ +private string_substr string_index; extern expr* string_substr(void*, int, int); extern int string_index(void*, void*); @@ -122,6 +129,7 @@ /* Concatenate a list of strings. */ +private string_concat_list; extern expr* string_concat_list(expr*); strcat xs = string_concat_list xs if listp xs && all stringp xs; Modified: pure/trunk/lib/system.pure =================================================================== --- pure/trunk/lib/system.pure 2008-08-27 19:33:15 UTC (rev 638) +++ pure/trunk/lib/system.pure 2008-08-27 20:35:47 UTC (rev 639) @@ -34,6 +34,7 @@ regex functions. After loading this module, see list -v for a list of these. */ +private pure_sys_vars; extern void pure_sys_vars(); pure_sys_vars; /* errno and friends. This value and the related routines are indispensable to @@ -41,12 +42,9 @@ by its very nature, errno is a fairly volatile value, don't expect it to survive a return to the command line in interactive sessions. */ -extern int pure_errno(), void pure_set_errno(int); +extern int pure_errno() = errno, void pure_set_errno(int) = set_errno; extern void perror(char*), char* strerror(int); -errno = pure_errno; -set_errno val::int = pure_set_errno val; - /* Signal handling. The action parameter of 'trap' can be one of the predefined integer values SIG_TRAP, SIG_IGN and SIG_DFL. SIG_TRAP causes the given signal to be handled by mapping it to a Pure exception of the @@ -125,6 +123,7 @@ routines are actually overridden with more convenient Pure wrappers below. */ +private c_fgets c_gets; extern FILE* fopen(char* name, char* mode); extern FILE* popen(char* cmd, char* mode); extern int fflush(FILE* fp), int fclose(FILE* fp), int pclose(FILE* fp); @@ -176,12 +175,16 @@ case of an abnormal condition in the wrapper function (error in format string, argument mismatch), they will throw an exception. */ +private pure_fprintf pure_fprintf_int pure_fprintf_double + pure_fprintf_string pure_fprintf_pointer; extern int pure_fprintf(FILE *fp, char *format); extern int pure_fprintf_int(FILE *fp, char *format, int x); extern int pure_fprintf_double(FILE *fp, char *format, double x); extern int pure_fprintf_string(FILE *fp, char *format, char *x); extern int pure_fprintf_pointer(FILE *fp, char *format, void *x); +private printf_split_format printf_format_spec printf_format_str; + printf format::string args = fprintf stdout format args; fprintf fp::pointer format::string args = count when @@ -237,6 +240,8 @@ as with printf/fprintf. The implementation actually uses snprintf for safety, a suitable output buffer is provided automatically. */ +private pure_snprintf pure_snprintf_int pure_snprintf_double + pure_snprintf_string pure_snprintf_pointer; extern int pure_snprintf(void *buf, int, char *format); extern int pure_snprintf_int(void *buf, int, char *format, int x); extern int pure_snprintf_double(void *buf, int, char *format, double x); @@ -292,12 +297,16 @@ "assignment suppression" flag "*" is understood; the corresponding items will not be returned. */ +private pure_fscanf pure_fscanf_int pure_fscanf_double + pure_fscanf_string pure_fscanf_pointer; extern int pure_fscanf(FILE *fp, char *format); extern int pure_fscanf_int(FILE *fp, char *format, int *x); extern int pure_fscanf_double(FILE *fp, char *format, double *x); extern int pure_fscanf_string(FILE *fp, char *format, void *x); extern int pure_fscanf_pointer(FILE *fp, char *format, void **x); +private scanf_split_format scanf_format_spec scanf_format_str; + scanf format::string = fscanf stdin format; fscanf fp::pointer format::string = tuple $ reverse ret when @@ -385,6 +394,8 @@ /* sscanf: This works exactly like fscanf, but input comes from a string (first argument) rather than a file. */ +private pure_sscanf pure_sscanf_int pure_sscanf_double + pure_sscanf_string pure_sscanf_pointer; extern int pure_sscanf(char *buf, char *format); extern int pure_sscanf_int(char *buf, char *format, int *x); extern int pure_sscanf_double(char *buf, char *format, double *x); @@ -455,6 +466,7 @@ return value.) We also provide readline's companion, the add_history function, which you need to add strings to readline's history. */ +private c_readline; extern void* readline(char* prompt) = c_readline; extern void add_history(char* s); @@ -472,6 +484,7 @@ extension to POSIX, Pure also provides the constant GLOB_SIZE which indicates the buffer size required for glob's globptr argument. */ +private c_fnmatch c_glob globfree globlist; extern int fnmatch(char* pat, char* s, int flags) = c_fnmatch; extern int glob(char* pat, int flags, void* errfunc, void* globptr) = c_glob; extern void globfree(void* globptr); @@ -491,6 +504,7 @@ difficult calling sequence, hence we provide a couple of high-level wrapper functions for use in Pure programs below. */ +private regcomp regexec regerror regfree regmatches reglist; extern int regcomp(void* regptr, char* pat, int cflags); extern int regexec(void* regptr, char* s, int n, void* matches, int eflags); extern int regerror(int errcode, void* regptr, void* buf, int size); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 19:33:05
|
Revision: 638 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=638&view=rev Author: agraef Date: 2008-08-27 19:33:15 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Fix typo in comment. Modified Paths: -------------- pure/trunk/lib/prelude.pure Modified: pure/trunk/lib/prelude.pure =================================================================== --- pure/trunk/lib/prelude.pure 2008-08-27 19:31:19 UTC (rev 637) +++ pure/trunk/lib/prelude.pure 2008-08-27 19:33:15 UTC (rev 638) @@ -98,8 +98,8 @@ def (f . g) x = f (g x); /* "Mapsto" operator. This constructor is declared here so that it can be used - in other standard library modules to denote special kind of pairs which map - keys to values. Here we only define equality of such pairs. */ + in other standard library modules to denote special kinds of pairs which + map keys to values. Here we only define equality of such pairs. */ (x=>v)==(y=>w) = if x==y then v==w else 0; (x=>v)!=(y=>w) = if x!=y then 1 else v!=w; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 19:31:10
|
Revision: 637 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=637&view=rev Author: agraef Date: 2008-08-27 19:31:19 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Update documentation. Modified Paths: -------------- pure/trunk/pure.1.in Modified: pure/trunk/pure.1.in =================================================================== --- pure/trunk/pure.1.in 2008-08-27 19:02:39 UTC (rev 636) +++ pure/trunk/pure.1.in 2008-08-27 19:31:19 UTC (rev 637) @@ -343,22 +343,29 @@ The case of identifiers is significant, but it doesn't carry any meaning (that's in contrast to languages like Prolog and Q, where variables must be capitalized). Instead, Pure distinguishes function and variable symbols by -their position on the left-hand side of an equation, using the ``head = -function'' rule: Any symbol (except the anonymous variable) which occurs as -the head symbol of a function application is a function symbol, all other -symbols are variables (except symbols explicitly declared as ``constant'' -a.k.a. +their position on the left-hand side of an equation, using the following +.I head = function +rule: Any symbol (except the anonymous variable) which occurs as the head +symbol of a function application is a function symbol, all other symbols are +variables (except symbols explicitly declared as ``constant'' a.k.a. .B nullary symbols, see below). .TP .B Operator and constant symbols: \fRx+y, x==y, \fBnot\fP\ x, [] -As indicated, these take the form of an identifier or a sequence of ASCII -punctuation symbols, as defined in the source using corresponding -\fBprefix\fP, \fBpostfix\fP, \fBinfix\fP and \fBnullary\fP declarations, which -are discussed in section DECLARATIONS. Enclosing an operator in parentheses, -such as (+) or (\fBnot\fP), turns it into an ordinary function symbol. Symbols -declared as \fBnullary\fP denote special constant symbols which simply stand -for themselves. Technically, these are just ordinary identifiers; however, the +As indicated, these take the form of an identifier or a sequence of +punctuation symbols. As of Pure 0.6, operator and constant symbols may also +contain arbitrary extended (non-ASCII) Unicode characters, which makes it +possible, e.g., to use symbols from the math and APL symbol sets offered by +Unicode. +.sp +Operator and constant symbols must always be declared before they can be used, +using corresponding \fBprefix\fP, \fBpostfix\fP, \fBinfix\fP and \fBnullary\fP +declarations, which are discussed in section DECLARATIONS. +.sp +Note that enclosing an operator in parentheses, such as (+) or (\fBnot\fP), +turns it into an ordinary function symbol. Symbols declared as \fBnullary\fP +denote special constant symbols which simply stand for themselves. +Technically, these are just ordinary identifiers; however, the .B nullary attribute tells the compiler that when such an identifier occurs on the left-hand side of an equation, it is to be interpreted as a constant rather This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 19:02:28
|
Revision: 636 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=636&view=rev Author: agraef Date: 2008-08-27 19:02:39 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Added limited support for unicode symbols. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/lexer.ll Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-08-27 18:35:59 UTC (rev 635) +++ pure/trunk/ChangeLog 2008-08-27 19:02:39 UTC (rev 636) @@ -1,5 +1,8 @@ 2008-08-27 Albert Graef <Dr....@t-...> + * lexer.ll: Added limited support for unicode symbols. These can + now be declared as operator or nullary symbols. + * parser.yy, etc.: Symbols can now be declared 'private'. These aren't visible anywhere except in the module that declares them. Modified: pure/trunk/lexer.ll =================================================================== --- pure/trunk/lexer.ll 2008-08-27 18:35:59 UTC (rev 635) +++ pure/trunk/lexer.ll 2008-08-27 19:02:39 UTC (rev 636) @@ -929,7 +929,7 @@ } [@=|;()\[\]\\] return yy::parser::token_type(yytext[0]); "->" return token::MAPSTO; -[[:punct:]]+ { +([[:punct:]]|[\200-\377])+ { if (yytext[0] == '/' && yytext[1] == '*') REJECT; // comment starter while (yyleng > 1 && yytext[yyleng-1] == ';') yyless(yyleng-1); if (interp.declare_op) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 18:35:51
|
Revision: 635 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=635&view=rev Author: agraef Date: 2008-08-27 18:35:59 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Bugfixes. Modified Paths: -------------- pure/trunk/interpreter.cc pure/trunk/lexer.ll pure/trunk/parser.yy pure/trunk/pure.cc Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-27 18:27:08 UTC (rev 634) +++ pure/trunk/interpreter.cc 2008-08-27 18:35:59 UTC (rev 635) @@ -631,7 +631,7 @@ source = s; declare_op = false; source_s = 0; srcdir = dirname(fname); - modno = (temp == 0 && !s.empty())?modctr++:-1; + modno = modctr++; errmsg.clear(); if (check && !interactive) temp = 0; bool ok = lex_begin(fname); @@ -701,7 +701,7 @@ source = ""; declare_op = false; source_s = s.c_str(); srcdir = ""; - modno = -1; + modno = modctr++; errmsg.clear(); bool ok = lex_begin(); if (ok) { Modified: pure/trunk/lexer.ll =================================================================== --- pure/trunk/lexer.ll 2008-08-27 18:27:08 UTC (rev 634) +++ pure/trunk/lexer.ll 2008-08-27 18:35:59 UTC (rev 635) @@ -170,7 +170,8 @@ symbol list. */ while (f <= n) { /* Skip non-toplevel symbols. */ - if (interp.symtab.sym(f).modno >= 0 || + const symbol& sym = interp.symtab.sym(f); + if (sym.modno >= 0 && sym.modno != interp.modno || interp.globenv.find(f) == interp.globenv.end() && interp.macenv.find(f) == interp.macenv.end() && interp.globalvars.find(f) == interp.globalvars.end() && @@ -178,7 +179,7 @@ f++; continue; } - const string& s = interp.symtab.sym(f).s; + const string& s = sym.s; f++; if (strncmp(s.c_str(), text, len) == 0) return strdup(s.c_str()); @@ -437,7 +438,7 @@ int32_t f = it->first; const env_info& e = it->second; const symbol& sym = interp.symtab.sym(f); - if (sym.modno >= 0 || // skip private symbols + if (sym.modno >= 0 && sym.modno != interp.modno || !((e.t == env_info::fun)?fflag: (e.t == env_info::cvar)?cflag: (e.t == env_info::fvar)?vflag:0)) @@ -479,7 +480,7 @@ int32_t f = it->first; if (syms.find(f) == syms.end()) { const symbol& sym = interp.symtab.sym(f); - if (sym.modno >= 0) continue; // skip private symbols + if (sym.modno >= 0 && sym.modno != interp.modno) continue; bool matches = true; if (!args.l.empty()) { matches = false; @@ -507,7 +508,7 @@ if (syms.find(f) == syms.end()) { const env_info& e = it->second; const symbol& sym = interp.symtab.sym(f); - if (sym.modno >= 0) continue; // skip private symbols + if (sym.modno >= 0 && sym.modno != interp.modno) continue; bool matches = e.temp >= tflag; if (!matches && !sflag && args.l.empty()) { // if not in summary mode, also list temporary rules for a @@ -737,7 +738,7 @@ else if (args.c > 0) { list<string>::iterator s; for (s = args.l.begin(); s != args.l.end(); s++) { - const symbol *sym = interp.symtab.lookup(*s); + const symbol *sym = interp.symtab.lookup(*s, interp.modno); if (sym && sym->f > 0) interp.clear(sym->f); else Modified: pure/trunk/parser.yy =================================================================== --- pure/trunk/parser.yy 2008-08-27 18:27:08 UTC (rev 634) +++ pure/trunk/parser.yy 2008-08-27 18:35:59 UTC (rev 635) @@ -294,7 +294,7 @@ { if ($1->priv && $1->prec > 10 || !$1->priv && $1->fix != nullary && $1->prec > 9) { error(yylloc, "invalid fixity declaration"); YYERROR; - } else + } else if ($1->fix == nullary || $1->prec < 10) interp.declare_op = true; } ids { interp.declare_op = false; Modified: pure/trunk/pure.cc =================================================================== --- pure/trunk/pure.cc 2008-08-27 18:27:08 UTC (rev 634) +++ pure/trunk/pure.cc 2008-08-27 18:35:59 UTC (rev 635) @@ -94,7 +94,8 @@ symbol list. */ while (f <= n) { /* Skip non-toplevel symbols. */ - if (interp.symtab.sym(f).modno >= 0 || + const symbol& sym = interp.symtab.sym(f); + if (sym.modno >= 0 && sym.modno != interp.modno || interp.globenv.find(f) == interp.globenv.end() && interp.macenv.find(f) == interp.macenv.end() && interp.globalvars.find(f) == interp.globalvars.end() && @@ -102,7 +103,7 @@ f++; continue; } - const string& s = interp.symtab.sym(f).s; + const string& s = sym.s; f++; if (strncmp(s.c_str(), text, len) == 0) return strdup(s.c_str()); @@ -133,7 +134,8 @@ symbol list. */ while (f <= n) { /* Skip non-toplevel symbols. */ - if (interp.symtab.sym(f).modno >= 0 || + const symbol& sym = interp.symtab.sym(f); + if (sym.modno >= 0 && sym.modno != interp.modno || interp.globenv.find(f) == interp.globenv.end() && interp.macenv.find(f) == interp.macenv.end() && interp.globalvars.find(f) == interp.globalvars.end() && @@ -141,7 +143,7 @@ f++; continue; } - const string& s = interp.symtab.sym(f).s; + const string& s = sym.s; f++; if (strncmp(s.c_str(), text, len) == 0) return strdup(s.c_str()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 18:26:57
|
Revision: 634 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=634&view=rev Author: agraef Date: 2008-08-27 18:27:08 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Update documentation. Modified Paths: -------------- pure/trunk/pure.1.in Modified: pure/trunk/pure.1.in =================================================================== --- pure/trunk/pure.1.in 2008-08-27 10:38:09 UTC (rev 633) +++ pure/trunk/pure.1.in 2008-08-27 18:27:08 UTC (rev 634) @@ -957,11 +957,13 @@ .fi .PP The `timex' macro also provides a useful example of how you can use macros to -define your own special forms, since the (expanded) macro arguments are -effectively called by name at runtime. (Note that the above definition of -`timex' wouldn't work as an ordinary function definition, since the x -parameter would have been evaluated already before it is passed to `timex', -making `timex' always return a zero time value. Try it.) +define your own special forms, since the macro arguments will only be +evaluated at runtime and can thus be passed to built-in special forms and +other constructs which defer their evaluation. (Note that the above definition +of `timex' wouldn't work as an ordinary function definition, since by virtue +of Pure's basic eager evaluation strategy the x parameter would have been +evaluated already before it is passed to `timex', making `timex' always return +a zero time value. Try it.) .PP Finally, note that Pure macros are lexically scoped, i.e., symbols on the right-hand-side of a macro definition can never refer to anything outside the @@ -984,20 +986,47 @@ macros are a good way to shoot yourself in the foot. So use them thoughtfully and with care. .SH DECLARATIONS -You probably noticed by now that Pure is a very terse language. That's -because, in contrast to hopelessly verbose languages like Java, you don't -declare much stuff in Pure, you just define it and be done with it. Usually, -all necessary information about the defined symbols is inferred -automatically. However, there are a few toplevel constructs which let you -declare special symbol attributes and manage programs consisting of several -source modules. These are: operator and constant symbol declarations, +Pure is a very terse language by design; you don't declare much stuff, you +just define it and be done with it. Usually, all necessary information about +the defined symbols is inferred automatically. However, there are a few +toplevel constructs which let you declare special symbol attributes and manage +programs consisting of several source modules. These are: +.BR private , +fixity (operator) and +.B nullary +(constant symbol) declarations, .B extern declarations for external C functions (described in the C INTERFACE section), and .B using -clauses which provide a simple include file mechanism. +clauses which let you include other scripts in a Pure script. .TP -.B Operator and constant declarations: infix \fIlevel\fP \fIop\fP\fR ...;\fP nullary \fIsymbol\fP\fR ...;\fP +.B Private symbol declarations: private \fIsymbol\fP\fR ...;\fP +Declares the listed symbols as +.IR private . +Pure programs usually consist of several source scripts (see the description +of the +.B using +clauses below). By default, all global symbols are +.I public +symbols which are visible throughout the entire Pure program. Symbols +explicitly declared as private are only visible in the script which declares +them. This must be done before using these symbols. Example: +.sp +.nf +\fBprivate\fP foo bar; +foo (bar x) = x+1; // foo and bar symbols are private here +.fi +.sp +Note that to declare multiple symbols in a single declaration, you just list +them all with whitespace in between. The same applies to the other types of +symbol declarations discussed below. +.TP +.B Operator declarations: infix \fIlevel\fP \fIop\fP\fR ...;\fP +These may also be prefixed with the keyword +.B private +to indicate a private operator symbol (see above). +.sp Ten different precedence levels are available for user-defined operators, numbered 0 (lowest) thru 9 (highest). On each precedence level, you can declare (in order of increasing precedence) @@ -1013,34 +1042,92 @@ \fBinfixl\fP 7 * / div mod ; .fi .sp -Note that to declare multiple symbols in a single declaration, you just list -them all with whitespace in between. -.sp -Similarly, constant symbols are introduced using a +One thing worth noting here is that unary minus plays a special role in the +syntax. Like in Haskell, unary minus is the only prefix operator symbol which +is also used as an infix operator, and it always has the same precedence as +binary minus (whose precedence may be chosen freely in the prelude). Thus, +with the standard prelude, -x+y will be parsed as (-x)+y, whereas -x*y is the +same as -(x*y). Also note that the notation `(-)' always denotes the binary +minus operator; the unary minus operation can be denoted using the built-in +`neg' function. +.TP +.B Constant symbol declarations: nullary \fIsymbol\fP\fR ...;\fP +Constant symbols are introduced using a .B nullary -declaration, e.g.: +declaration (again, a +.B private +prefix may be used to denote private constant symbols), e.g.: .sp .nf -\fBnullary\fP [] () nil; +\fBnullary\fP [] (); +\fBprivate\fP \fBnullary\fP nil; .fi .sp -Examples for all of these can be found in the prelude which declares a bunch -of standard (arithmetic, relational, logical) operator symbols as well as the -list and pair constructors `:' and `,' and the constant symbols `[]' and `()' -denoting the empty list and tuple, respectively. +As explained in the PURE OVERVIEW section, +.B nullary +symbols are like ordinary identifiers, but are treated as constants rather +than variables when they occur on the left-hand side of an equation. +.sp +Examples for all types of symbol declarations can be found in the prelude +which declares a bunch of standard (arithmetic, relational, logical) operator +symbols as well as the list and pair constructors `:' and `,' and the empty +list and tuple constants `[]' and `()'. .TP .B Using clause: using \fIname\fR, ...; -Causes each given script to be included, at the position of the +Causes each given script to be included in the Pure program. Each included +script is loaded only +.IR once , +when the first .B using -clause, but only if the script was not included already. Note that the -constants, variables, functions and macros defined by the included script are -then available anywhere in the program, not just the module that contains the +clause for the script is encountered. This kind of clause is discussed in +further detail below. +.sp +Note that the .B using -clause. +clause also has an alternative form which allows dynamic libraries to be +loaded, this will be discussed in the C INTERFACE section. +.PP +The +.B using +declaration provides a simple but effective way to assemble a Pure program +from several source modules. The Pure program is just the concatenation of all +the source modules listed as command line arguments and included through +.B using +clauses. Public constants, variables, functions and macros defined anywhere in +the program share one big happy namespace and are available throughout the +entire program (not just the module that contains a +.B using +clause for the script containing a given symbol). This approach has its +drawbacks, but it makes it easy to define polymorphic functions and macros +across separate modules. +.PP +To facilitate modular development, each script also has a separate namespace +for private symbols which are only visible in the script which declares them +(see the explanation of the +.B private +declaration above). This makes it possible to hide away internal operations, +prevent name clashes between symbols of different modules, and keep the public +namespace tidy and clean. A +.B private +declaration shadows a public symbol with the same print name, but this takes +effect only +.I after +the +.B private +declaration of the symbol, so you can easily define yourself an alias for the +public symbol before that, e.g.: .sp -The script name can be specified either as a string denoting the proper -filename (possibly including path and/or filename extension), or as an -identifier. In the latter case, the +.nf +public_foo = foo; +\fBprivate\fP foo; +foo x = public_foo (bar x); +.fi +.PP +The script name in a +.B using +clause can be specified either as a string denoting the proper filename +(possibly including path and/or filename extension), or as an identifier. In +the latter case, the .B .pure filename extension is added automatically. In both cases, the interpreter performs a search to locate the script, unless an absolute pathname was @@ -1064,9 +1151,9 @@ to the command line, or by including `.' in the .B PURE_INCLUDE variable. -.sp -For the purpose of comparing and loading scripts, the interpreter always uses -the canonicalized full pathname of the script, following symbolic links to the +.PP +For the purpose of comparing script names, the interpreter always uses the +canonicalized full pathname of the script, following symbolic links to the destination file (albeit only one level). Thus different scripts with the same basename, such as .B foo/utils.pure @@ -1083,11 +1170,6 @@ be located in the script directory. This is the recommended practice for installing standalone Pure applications in source form which are to be run directly from the shell. -.PP -Note that the -.B using -clause also has an alternative form which allows dynamic libraries to be -loaded, this will be discussed in the C INTERFACE section below. .SH EXCEPTION HANDLING Pure also offers a useful exception handling facility. To raise an exception, you just invoke the built-in function This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 10:38:01
|
Revision: 633 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=633&view=rev Author: agraef Date: 2008-08-27 10:38:09 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Bugfix. Modified Paths: -------------- pure/trunk/lexer.ll Modified: pure/trunk/lexer.ll =================================================================== --- pure/trunk/lexer.ll 2008-08-27 10:20:43 UTC (rev 632) +++ pure/trunk/lexer.ll 2008-08-27 10:38:09 UTC (rev 633) @@ -479,6 +479,7 @@ int32_t f = it->first; if (syms.find(f) == syms.end()) { const symbol& sym = interp.symtab.sym(f); + if (sym.modno >= 0) continue; // skip private symbols bool matches = true; if (!args.l.empty()) { matches = false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 10:20:34
|
Revision: 632 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=632&view=rev Author: agraef Date: 2008-08-27 10:20:43 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Add 'private' declarations. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/parser.yy Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-08-27 10:10:15 UTC (rev 631) +++ pure/trunk/ChangeLog 2008-08-27 10:20:43 UTC (rev 632) @@ -1,3 +1,8 @@ +2008-08-27 Albert Graef <Dr....@t-...> + + * parser.yy, etc.: Symbols can now be declared 'private'. These + aren't visible anywhere except in the module that declares them. + 2008-08-26 Albert Graef <Dr....@t-...> * test/test022.pure: Add macro test script. Modified: pure/trunk/parser.yy =================================================================== --- pure/trunk/parser.yy 2008-08-27 10:10:15 UTC (rev 631) +++ pure/trunk/parser.yy 2008-08-27 10:20:43 UTC (rev 632) @@ -291,7 +291,8 @@ /* Lexical tie-in: We need to tell the lexer that we're defining new operator symbols (interp.declare_op = true) instead of searching for existing ones in the symbol table. */ -{ if ($1->fix != nullary && $1->prec > 9) { +{ if ($1->priv && $1->prec > 10 || + !$1->priv && $1->fix != nullary && $1->prec > 9) { error(yylloc, "invalid fixity declaration"); YYERROR; } else interp.declare_op = true; } @@ -307,6 +308,9 @@ fixity : FIX INT { $$ = new sym_info(false,$2,$1); } | NULLARY { $$ = new sym_info(false,10,nullary); } +| PRIVATE FIX INT { $$ = new sym_info(true,$3,$2); } +| PRIVATE NULLARY { $$ = new sym_info(true,10,nullary); } +| PRIVATE { $$ = new sym_info(true,10,infix); } ; ids This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 10:10:07
|
Revision: 631 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=631&view=rev Author: agraef Date: 2008-08-27 10:10:15 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Bugfix. Modified Paths: -------------- pure/trunk/symtable.cc Modified: pure/trunk/symtable.cc =================================================================== --- pure/trunk/symtable.cc 2008-08-27 09:16:10 UTC (rev 630) +++ pure/trunk/symtable.cc 2008-08-27 10:10:15 UTC (rev 631) @@ -47,8 +47,12 @@ sym_map& m = tab[modno]; sym_map::iterator it = m.find(s); if (it == m.end() && modno >= 0) { - m = tab[-1]; + sym_map& m = tab[-1]; it = m.find(s); + if (it == m.end()) + return 0; + else + return &it->second; } if (it == m.end()) return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 09:16:03
|
Revision: 630 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=630&view=rev Author: agraef Date: 2008-08-27 09:16:10 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Add 'private' keyword. Modified Paths: -------------- pure/trunk/etc/pure-mode.el.in pure/trunk/etc/pure.lang pure/trunk/etc/pure.vim pure/trunk/etc/pure.xml pure/trunk/lexer.ll pure/trunk/parser.yy pure/trunk/pure.1.in pure/trunk/pure.cc Modified: pure/trunk/etc/pure-mode.el.in =================================================================== --- pure/trunk/etc/pure-mode.el.in 2008-08-27 09:14:51 UTC (rev 629) +++ pure/trunk/etc/pure-mode.el.in 2008-08-27 09:16:10 UTC (rev 630) @@ -165,7 +165,7 @@ (list (concat "\\<\\(" "const\\|def\\|extern\\|infix[lr]?\\|" - "let\\|nullary\\|p\\(refix\\|ostfix\\)\\|" + "let\\|nullary\\|p\\(r\\(efix\\|ivate\\)\\|ostfix\\)\\|" "using" "\\)\\>") 0 'font-lock-keyword-face)) @@ -179,7 +179,7 @@ (list (concat "\\<\\(" "case\\|const\\|def\\|e\\(lse\\|nd\\|xtern\\)\\|i\\(f\\|nfix[lr]?\\)\\|" - "let\\|nullary\\|o\\(f\\|therwise\\)\\|p\\(refix\\|ostfix\\)\\|" + "let\\|nullary\\|o\\(f\\|therwise\\)\\|p\\(r\\(efix\\|ivate\\)\\|ostfix\\)\\|" "then\\|using\\|w\\(hen\\|ith\\)" "\\)\\>") 0 'font-lock-keyword-face)) Modified: pure/trunk/etc/pure.lang =================================================================== --- pure/trunk/etc/pure.lang 2008-08-27 09:14:51 UTC (rev 629) +++ pure/trunk/etc/pure.lang 2008-08-27 09:16:10 UTC (rev 630) @@ -4,8 +4,8 @@ $DESCRIPTION=Pure # Pure keywords. -$KW_LIST(kwa)=infix infixl infixr prefix postfix nullary case const def else -end extern if let of otherwise then using when with +$KW_LIST(kwa)=infix infixl infixr prefix postfix nullary private +case const def else end extern if let of otherwise then using when with # These aren't really keywords but we want them to stick out anyway. $KW_LIST(kwb)=catch throw Modified: pure/trunk/etc/pure.vim =================================================================== --- pure/trunk/etc/pure.vim 2008-08-27 09:14:51 UTC (rev 629) +++ pure/trunk/etc/pure.vim 2008-08-27 09:16:10 UTC (rev 630) @@ -32,7 +32,7 @@ syn region pureString start=+"+ skip=+\\"+ end=+"+ " keywords -syn keyword pureKeyword infix infixl infixr prefix postfix nullary +syn keyword pureKeyword infix infixl infixr prefix postfix nullary private syn keyword pureKeyword case const def else end extern if let of otherwise then syn keyword pureKeyword using when with syn keyword pureSpecial catch throw Modified: pure/trunk/etc/pure.xml =================================================================== --- pure/trunk/etc/pure.xml 2008-08-27 09:14:51 UTC (rev 629) +++ pure/trunk/etc/pure.xml 2008-08-27 09:16:10 UTC (rev 630) @@ -23,6 +23,7 @@ <item> nullary </item> <item> of </item> <item> otherwise </item> + <item> private </item> <item> prefix </item> <item> postfix </item> <item> then </item> Modified: pure/trunk/lexer.ll =================================================================== --- pure/trunk/lexer.ll 2008-08-27 09:14:51 UTC (rev 629) +++ pure/trunk/lexer.ll 2008-08-27 09:16:10 UTC (rev 630) @@ -134,7 +134,7 @@ static const char *commands[] = { "cd", "clear", "const", "def", "extern", "help", "infix", "infixl", "infixr", "let", "list", "ls", "nullary", "override", "postfix", "prefix", - "pwd", "quit", "run", "save", "stats", "underride", "using", 0 + "private", "pwd", "quit", "run", "save", "stats", "underride", "using", 0 }; typedef map<string, symbol> symbol_map; @@ -897,6 +897,7 @@ prefix yylval->fix = prefix; return token::FIX; postfix yylval->fix = postfix; return token::FIX; nullary return token::NULLARY; +private return token::PRIVATE; const return token::CONST; def return token::DEF; let return token::LET; Modified: pure/trunk/parser.yy =================================================================== --- pure/trunk/parser.yy 2008-08-27 09:14:51 UTC (rev 629) +++ pure/trunk/parser.yy 2008-08-27 09:16:10 UTC (rev 630) @@ -96,6 +96,7 @@ #include "interpreter.hh" %} +%token PRIVATE "private" %token NULLARY "nullary" %token <fix> FIX "fixity" Modified: pure/trunk/pure.1.in =================================================================== --- pure/trunk/pure.1.in 2008-08-27 09:14:51 UTC (rev 629) +++ pure/trunk/pure.1.in 2008-08-27 09:16:10 UTC (rev 630) @@ -217,7 +217,7 @@ .PP There are a few reserved keywords which cannot be used as identifiers. These are: case const def else end extern if infix infixl infixr let nullary of -otherwise postfix prefix then using when with. +otherwise postfix prefix private then using when with. .PP Pure is a terse language. You won't see many declarations, and often your programs will read more like a collection of algebraic specifications (which Modified: pure/trunk/pure.cc =================================================================== --- pure/trunk/pure.cc 2008-08-27 09:14:51 UTC (rev 629) +++ pure/trunk/pure.cc 2008-08-27 09:16:10 UTC (rev 630) @@ -56,7 +56,7 @@ static const char *commands[] = { "cd", "clear", "const", "def", "extern", "help", "infix", "infixl", "infixr", "let", "list", "ls", "nullary", "override", "postfix", "prefix", - "pwd", "quit", "run", "save", "stats", "underride", "using", 0 + "private", "pwd", "quit", "run", "save", "stats", "underride", "using", 0 }; /* Generator functions for command completion. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 09:14:41
|
Revision: 629 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=629&view=rev Author: agraef Date: 2008-08-27 09:14:51 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Generate module keys. Modified Paths: -------------- pure/trunk/interpreter.cc pure/trunk/interpreter.hh Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-27 08:42:15 UTC (rev 628) +++ pure/trunk/interpreter.cc 2008-08-27 09:14:51 UTC (rev 629) @@ -59,8 +59,8 @@ : verbose(0), interactive(false), ttymode(false), override(false), stats(false), temp(0), ps("> "), libdir(""), histfile("/.pure_history"), modname("pure"), - nerrs(0), modno(-1), source_s(0), result(0), mem(0), exps(0), tmps(0), - module(0), JIT(0), FPM(0), fptr(0) + nerrs(0), modno(-1), modctr(0), source_s(0), result(0), mem(0), exps(0), + tmps(0), module(0), JIT(0), FPM(0), fptr(0) { if (!g_interp) { g_interp = this; @@ -618,6 +618,7 @@ uint8_t l_temp = temp; const char *l_source_s = source_s; string l_srcdir = srcdir; + int32_t l_modno = modno; // save global data uint8_t s_verbose = g_verbose; bool s_interactive = g_interactive; @@ -630,6 +631,7 @@ source = s; declare_op = false; source_s = 0; srcdir = dirname(fname); + modno = (temp == 0 && !s.empty())?modctr++:-1; errmsg.clear(); if (check && !interactive) temp = 0; bool ok = lex_begin(fname); @@ -656,6 +658,7 @@ temp = l_temp; source_s = l_source_s; srcdir = l_srcdir; + modno = l_modno; // return last computed result, if any return result; } @@ -685,6 +688,7 @@ int l_nerrs = nerrs; const char *l_source_s = source_s; string l_srcdir = srcdir; + int32_t l_modno = modno; // save global data uint8_t s_verbose = g_verbose; bool s_interactive = g_interactive; @@ -697,6 +701,7 @@ source = ""; declare_op = false; source_s = s.c_str(); srcdir = ""; + modno = -1; errmsg.clear(); bool ok = lex_begin(); if (ok) { @@ -718,6 +723,7 @@ nerrs = l_nerrs; source_s = l_source_s; srcdir = l_srcdir; + modno = l_modno; // return last computed result, if any return result; } Modified: pure/trunk/interpreter.hh =================================================================== --- pure/trunk/interpreter.hh 2008-08-27 08:42:15 UTC (rev 628) +++ pure/trunk/interpreter.hh 2008-08-27 09:14:51 UTC (rev 629) @@ -324,6 +324,7 @@ int nerrs; // current error count string errmsg; // last reported error (runstr) int32_t modno; // current module key + int32_t modctr; // next available module key string source; // the source being parsed const char *source_s; // source pointer if input comes from a string set<string> sources; // the list of all scripts which have been loaded This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 08:49:41
|
Revision: 628 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=628&view=rev Author: agraef Date: 2008-08-27 08:42:15 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Fix up linkage type and mangle names for private symbols. Modified Paths: -------------- pure/trunk/interpreter.cc Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-27 08:07:35 UTC (rev 627) +++ pure/trunk/interpreter.cc 2008-08-27 08:42:15 UTC (rev 628) @@ -2612,8 +2612,14 @@ } GlobalVar& v = globalvars[tag]; if (!v.v) { - v.v = new GlobalVariable - (ExprPtrTy, false, GlobalVariable::ExternalLinkage, 0, sym.s, module); + if (sym.modno >= 0) + v.v = new GlobalVariable + (ExprPtrTy, false, GlobalVariable::InternalLinkage, 0, + "$$private."+sym.s, module); + else + v.v = new GlobalVariable + (ExprPtrTy, false, GlobalVariable::ExternalLinkage, 0, + sym.s, module); JIT->addGlobalMapping(v.v, &v.x); } if (v.x) pure_free(v.x); v.x = pure_new(x); @@ -4016,9 +4022,14 @@ const symbol& sym = symtab.sym(tag); GlobalVar& v = globalvars[tag]; if (!v.v) { - v.v = new GlobalVariable - (ExprPtrTy, false, GlobalVariable::ExternalLinkage, 0, sym.s, - module); + if (sym.modno >= 0) + v.v = new GlobalVariable + (ExprPtrTy, false, GlobalVariable::InternalLinkage, 0, + "$$private."+sym.s, module); + else + v.v = new GlobalVariable + (ExprPtrTy, false, GlobalVariable::ExternalLinkage, 0, + sym.s, module); JIT->addGlobalMapping(v.v, &v.x); } if (v.x) pure_free(v.x); @@ -4071,8 +4082,14 @@ const symbol& sym = symtab.sym(tag); GlobalVar& v = globalvars[tag]; if (!v.v) { - v.v = new GlobalVariable - (ExprPtrTy, false, GlobalVariable::ExternalLinkage, 0, sym.s, module); + if (sym.modno >= 0) + v.v = new GlobalVariable + (ExprPtrTy, false, GlobalVariable::InternalLinkage, 0, + "$$private."+sym.s, module); + else + v.v = new GlobalVariable + (ExprPtrTy, false, GlobalVariable::ExternalLinkage, 0, + sym.s, module); JIT->addGlobalMapping(v.v, &v.x); } if (v.x) call("pure_free", f.builder.CreateLoad(v.v)); @@ -5511,29 +5528,35 @@ whether global or local) we create a C-callable function in LLVM IR. (This is necessary also for local functions, since these might need to be called from the runtime.) In the case of a global function, this - function is also externally visible, *unless* there's already a - callable C function of that name (in which case we also mangle the name - to prevent name collisions). However, in order to enable tail call - elimination (on platforms where LLVM supports this), suitable functions - are internally implemented using the fast calling convention (if - enabled, which it is by default). In this case, the C-callable function - is just a stub calling the internal function. */ + function is also externally visible, *unless* the function symbol is + private or there's already a callable C function of that name (in which + case we also mangle the name to prevent name collisions). However, in + order to enable tail call elimination (on platforms where LLVM supports + this), suitable functions are internally implemented using the fast + calling convention (if enabled, which it is by default). In this case, + the C-callable function is just a stub calling the internal + function. */ Function::LinkageTypes scope = Function::ExternalLinkage; CallingConv::ID cc = CallingConv::C; if (f.local || // global Pure functions use internal linkage if they would shadow a C // function: have_c_func || - // anonymous functions and operators use internal linkage, too: - f.tag == 0 || symtab.sym(f.tag).prec < 10) + // anonymous and private functions and operators use internal linkage, + // too: + f.tag == 0 || symtab.sym(f.tag).modno >= 0 || + symtab.sym(f.tag).prec < 10) scope = Function::InternalLinkage; #if USE_FASTCC if (!name.empty()) cc = CallingConv::Fast; #endif - /* Mangle the name of the C-callable wrapper if it would shadow another C - function. */ + /* Mangle the name of the C-callable wrapper if it's private, or would + shadow another C function. */ string pure_name = name; - if (have_c_func) pure_name = "$$pure."+name; + if (f.tag > 0 && symtab.sym(f.tag).modno >= 0) + pure_name = "$$private."+name; + else if (have_c_func) + pure_name = "$$pure."+name; if (cc == CallingConv::Fast) { // create the function f.f = Function::Create(ft, Function::InternalLinkage, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 08:07:28
|
Revision: 627 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=627&view=rev Author: agraef Date: 2008-08-27 08:07:35 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Allow externals to be bound to private Pure symbols. Modified Paths: -------------- pure/trunk/interpreter.cc Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-27 08:01:20 UTC (rev 626) +++ pure/trunk/interpreter.cc 2008-08-27 08:07:35 UTC (rev 627) @@ -3403,14 +3403,10 @@ argt[i] = Type::Int64Ty; if (asname.empty()) asname = name; symbol& sym = symtab.sym(asname, modno); - if (sym.modno >= 0) - // We don't allow private externals for now. - throw err("symbol '"+name+"' is private in this context"); - else if (globenv.find(sym.f) != globenv.end() && - externals.find(sym.f) == externals.end()) - // There already is a Pure function or global variable for this - // symbol. This is an error (unless the symbol is already declared as an - // external, too). + if (globenv.find(sym.f) != globenv.end() && + externals.find(sym.f) == externals.end()) + // There already is a Pure function or global variable for this symbol. + // This is an error (unless the symbol is already declared as an external). throw err("symbol '"+name+"' is already defined as a Pure "+ ((globenv[sym.f].t == env_info::fun) ? "function" : (globenv[sym.f].t == env_info::fvar) ? "variable" : This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 08:01:11
|
Revision: 626 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=626&view=rev Author: agraef Date: 2008-08-27 08:01:20 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Cosmetic changes. Modified Paths: -------------- pure/trunk/interpreter.cc Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-27 07:59:01 UTC (rev 625) +++ pure/trunk/interpreter.cc 2008-08-27 08:01:20 UTC (rev 626) @@ -3495,7 +3495,7 @@ vector<const Type*> argt2(n, ExprPtrTy); FunctionType *ft2 = FunctionType::get(ExprPtrTy, argt2, false); Function *f = Function::Create(ft2, Function::InternalLinkage, - "$$wrap."+asname, module); + "$$wrap."+asname, module); vector<Value*> args(n), unboxed(n); Function::arg_iterator a = f->arg_begin(); for (size_t i = 0; a != f->arg_end(); ++a, ++i) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 07:58:52
|
Revision: 625 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=625&view=rev Author: agraef Date: 2008-08-27 07:59:01 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Cosmetic changes. Modified Paths: -------------- pure/trunk/interpreter.cc Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-27 07:58:07 UTC (rev 624) +++ pure/trunk/interpreter.cc 2008-08-27 07:59:01 UTC (rev 625) @@ -3427,8 +3427,7 @@ // the definition of a Pure function of the same name. In this case the C // function won't be accessible in the Pure program at all. if (it == externals.end() && g && !g->isDeclaration()) - throw err("symbol '"+name+ - "' is already defined as a Pure function"); + throw err("symbol '"+name+"' is already defined as a Pure function"); if (it == externals.end() && g) { // Cross-check with a builtin declaration. assert(g->isDeclaration() && gt); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 07:57:58
|
Revision: 624 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=624&view=rev Author: agraef Date: 2008-08-27 07:58:07 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Cosmetic changes to error messages. Modified Paths: -------------- pure/trunk/interpreter.cc Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-27 07:54:52 UTC (rev 623) +++ pure/trunk/interpreter.cc 2008-08-27 07:58:07 UTC (rev 624) @@ -3428,7 +3428,7 @@ // function won't be accessible in the Pure program at all. if (it == externals.end() && g && !g->isDeclaration()) throw err("symbol '"+name+ - "' is already defined as a Pure function or variable"); + "' is already defined as a Pure function"); if (it == externals.end() && g) { // Cross-check with a builtin declaration. assert(g->isDeclaration() && gt); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 07:54:43
|
Revision: 623 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=623&view=rev Author: agraef Date: 2008-08-27 07:54:52 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Cosmetic changes to error messages. Modified Paths: -------------- pure/trunk/interpreter.cc Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-27 07:37:26 UTC (rev 622) +++ pure/trunk/interpreter.cc 2008-08-27 07:54:52 UTC (rev 623) @@ -1424,7 +1424,7 @@ throw err("symbol '"+sym.s+"' is already defined as a variable"); else if (it->second.argc != argc) { ostringstream msg; - msg << "symbol '" << sym.s + msg << "function '" << sym.s << "' was previously defined with " << it->second.argc << " args"; throw err(msg.str()); } @@ -1432,7 +1432,7 @@ map<int32_t,ExternInfo>::const_iterator it = externals.find(f); if (it != externals.end() && it->second.argtypes.size() != argc) { ostringstream msg; - msg << "symbol '" << sym.s + msg << "function '" << sym.s << "' was previously declared as an external with " << it->second.argtypes.size() << " args"; throw err(msg.str()); @@ -1482,7 +1482,7 @@ } else if (it != macenv.end()) { if (it->second.argc != argc) { ostringstream msg; - msg << "symbol '" << sym.s + msg << "macro '" << sym.s << "' was previously defined with " << it->second.argc << " args"; throw err(msg.str()); } @@ -3402,17 +3402,20 @@ else if (argt[i] == Type::Int32Ty && sizeof(int) > 4) argt[i] = Type::Int64Ty; if (asname.empty()) asname = name; - // First check whether there already is a Pure function or global variable - // for this symbol. This is an error (unless it's already declared as an - // external, too). symbol& sym = symtab.sym(asname, modno); if (sym.modno >= 0) - throw err("symbol '"+name+ - "' is private in this context"); + // We don't allow private externals for now. + throw err("symbol '"+name+"' is private in this context"); else if (globenv.find(sym.f) != globenv.end() && externals.find(sym.f) == externals.end()) - throw err("symbol '"+name+ - "' is already defined as a Pure function or variable"); + // There already is a Pure function or global variable for this + // symbol. This is an error (unless the symbol is already declared as an + // external, too). + throw err("symbol '"+name+"' is already defined as a Pure "+ + ((globenv[sym.f].t == env_info::fun) ? "function" : + (globenv[sym.f].t == env_info::fvar) ? "variable" : + (globenv[sym.f].t == env_info::cvar) ? "constant" : + "gizmo" /* this can't happen, or at least it shouldn't ;-) */)); // Create the function type and check for an existing declaration of the // external. FunctionType *ft = FunctionType::get(type, argt, false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 07:37:17
|
Revision: 622 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=622&view=rev Author: agraef Date: 2008-08-27 07:37:26 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Add private symbol infrastructure. Modified Paths: -------------- pure/trunk/interpreter.cc pure/trunk/interpreter.hh pure/trunk/lexer.ll pure/trunk/parser.yy pure/trunk/pure.cc Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-27 07:12:55 UTC (rev 621) +++ pure/trunk/interpreter.cc 2008-08-27 07:37:26 UTC (rev 622) @@ -59,7 +59,7 @@ : verbose(0), interactive(false), ttymode(false), override(false), stats(false), temp(0), ps("> "), libdir(""), histfile("/.pure_history"), modname("pure"), - nerrs(0), source_s(0), result(0), mem(0), exps(0), tmps(0), + nerrs(0), modno(-1), source_s(0), result(0), mem(0), exps(0), tmps(0), module(0), JIT(0), FPM(0), fptr(0) { if (!g_interp) { @@ -1166,11 +1166,11 @@ } } -void interpreter::declare(prec_t prec, fix_t fix, list<string> *ids) +void interpreter::declare(bool priv, prec_t prec, fix_t fix, list<string> *ids) { for (list<string>::const_iterator it = ids->begin(); it != ids->end(); ++it) { - symbol* sym = symtab.lookup(*it); + symbol* sym = symtab.xlookup(*it, priv?modno:-1); if (sym) { // crosscheck declarations if (sym->prec != prec || sym->fix != fix) { @@ -1179,7 +1179,7 @@ throw err("conflicting fixity declaration for symbol '"+id+"'"); } } else { - int32_t tag = symtab.sym(*it, prec, fix).f; + int32_t tag = symtab.xsym(*it, prec, fix, priv?modno:-1).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); @@ -2352,7 +2352,7 @@ expr *interpreter::mksym_expr(string *s, int8_t tag) { expr *x; - const symbol &sym = symtab.sym(*s); + const symbol &sym = symtab.sym(*s, modno); if (tag == 0) if (*s == "_") // Return a new instance here, since the anonymous variable may have @@ -2373,7 +2373,7 @@ expr *interpreter::mkas_expr(string *s, expr *x) { - const symbol &sym = symtab.sym(*s); + const symbol &sym = symtab.sym(*s, modno); if (sym.f <= 0 || sym.prec < 10 || sym.fix == nullary) throw err("error in pattern (bad variable symbol '"+sym.s+"')"); if (x->tag() > 0) { @@ -3405,10 +3405,13 @@ // First check whether there already is a Pure function or global variable // for this symbol. This is an error (unless it's already declared as an // external, too). - symbol& sym = symtab.sym(asname); - if (globenv.find(sym.f) != globenv.end() && - externals.find(sym.f) == externals.end()) + symbol& sym = symtab.sym(asname, modno); + if (sym.modno >= 0) throw err("symbol '"+name+ + "' is private in this context"); + else if (globenv.find(sym.f) != globenv.end() && + externals.find(sym.f) == externals.end()) + throw err("symbol '"+name+ "' is already defined as a Pure function or variable"); // Create the function type and check for an existing declaration of the // external. Modified: pure/trunk/interpreter.hh =================================================================== --- pure/trunk/interpreter.hh 2008-08-27 07:12:55 UTC (rev 621) +++ pure/trunk/interpreter.hh 2008-08-27 07:37:26 UTC (rev 622) @@ -323,6 +323,7 @@ // Interpreter state. For internal use only. int nerrs; // current error count string errmsg; // last reported error (runstr) + int32_t modno; // current module key string source; // the source being parsed const char *source_s; // source pointer if input comes from a string set<string> sources; // the list of all scripts which have been loaded @@ -434,7 +435,7 @@ void build_env(env& vars, expr x); void mark_dirty(int32_t f); void compile(expr x); - void declare(prec_t prec, fix_t fix, list<string> *ids); + void declare(bool priv, prec_t prec, fix_t fix, list<string> *ids); void define(rule *r); void define_const(rule *r); void exec(expr *x); Modified: pure/trunk/lexer.ll =================================================================== --- pure/trunk/lexer.ll 2008-08-27 07:12:55 UTC (rev 621) +++ pure/trunk/lexer.ll 2008-08-27 07:37:26 UTC (rev 622) @@ -170,7 +170,8 @@ symbol list. */ while (f <= n) { /* Skip non-toplevel symbols. */ - if (interp.globenv.find(f) == interp.globenv.end() && + if (interp.symtab.sym(f).modno >= 0 || + interp.globenv.find(f) == interp.globenv.end() && interp.macenv.find(f) == interp.macenv.end() && interp.globalvars.find(f) == interp.globalvars.end() && interp.externals.find(f) == interp.externals.end()) { @@ -436,7 +437,8 @@ int32_t f = it->first; const env_info& e = it->second; const symbol& sym = interp.symtab.sym(f); - if (!((e.t == env_info::fun)?fflag: + if (sym.modno >= 0 || // skip private symbols + !((e.t == env_info::fun)?fflag: (e.t == env_info::cvar)?cflag: (e.t == env_info::fvar)?vflag:0)) continue; @@ -504,6 +506,7 @@ if (syms.find(f) == syms.end()) { const env_info& e = it->second; const symbol& sym = interp.symtab.sym(f); + if (sym.modno >= 0) continue; // skip private symbols bool matches = e.temp >= tflag; if (!matches && !sflag && args.l.empty()) { // if not in summary mode, also list temporary rules for a @@ -912,7 +915,7 @@ yylval->sval = new string(yytext); return token::ID; } - symbol* sym = interp.symtab.lookup(yytext); + symbol* sym = interp.symtab.lookup(yytext, interp.modno); if (sym && sym->prec >= 0 && sym->prec < 10) { yylval->xval = new expr(sym->x); return optoken[sym->prec][sym->fix]; @@ -930,12 +933,12 @@ yylval->sval = new string(yytext); return token::ID; } - symbol* sym = interp.symtab.lookup(yytext); + symbol* sym = interp.symtab.lookup(yytext, interp.modno); while (!sym && yyleng > 1) { if (yyleng == 2 && yytext[0] == '-' && yytext[1] == '>') return token::MAPSTO; yyless(yyleng-1); - sym = interp.symtab.lookup(yytext); + sym = interp.symtab.lookup(yytext, interp.modno); } if (sym) { if (sym->prec < 10) { Modified: pure/trunk/parser.yy =================================================================== --- pure/trunk/parser.yy 2008-08-27 07:12:55 UTC (rev 621) +++ pure/trunk/parser.yy 2008-08-27 07:37:26 UTC (rev 622) @@ -54,9 +54,10 @@ %{ struct sym_info { + bool priv; prec_t prec; fix_t fix; - sym_info(prec_t p, fix_t f) : prec(p), fix(f) { } + sym_info(bool v, prec_t p, fix_t f) : priv(v), prec(p), fix(f) { } }; struct rule_info { exprl l; @@ -295,15 +296,16 @@ interp.declare_op = true; } ids { interp.declare_op = false; - action(interp.declare($1->prec, $1->fix, $3), delete $3); delete $1; } + action(interp.declare($1->priv, $1->prec, $1->fix, $3), delete $3); + delete $1; } | USING names { action(interp.run(*$2), {}); delete $2; } | EXTERN prototypes ; fixity -: FIX INT { $$ = new sym_info($2,$1); } -| NULLARY { $$ = new sym_info(10,nullary); } +: FIX INT { $$ = new sym_info(false,$2,$1); } +| NULLARY { $$ = new sym_info(false,10,nullary); } ; ids Modified: pure/trunk/pure.cc =================================================================== --- pure/trunk/pure.cc 2008-08-27 07:12:55 UTC (rev 621) +++ pure/trunk/pure.cc 2008-08-27 07:37:26 UTC (rev 622) @@ -94,7 +94,8 @@ symbol list. */ while (f <= n) { /* Skip non-toplevel symbols. */ - if (interp.globenv.find(f) == interp.globenv.end() && + if (interp.symtab.sym(f).modno >= 0 || + interp.globenv.find(f) == interp.globenv.end() && interp.macenv.find(f) == interp.macenv.end() && interp.globalvars.find(f) == interp.globalvars.end() && interp.externals.find(f) == interp.externals.end()) { @@ -132,7 +133,8 @@ symbol list. */ while (f <= n) { /* Skip non-toplevel symbols. */ - if (interp.globenv.find(f) == interp.globenv.end() && + if (interp.symtab.sym(f).modno >= 0 || + interp.globenv.find(f) == interp.globenv.end() && interp.macenv.find(f) == interp.macenv.end() && interp.globalvars.find(f) == interp.globalvars.end() && interp.externals.find(f) == interp.externals.end()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-08-27 07:12:45
|
Revision: 621 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=621&view=rev Author: agraef Date: 2008-08-27 07:12:55 +0000 (Wed, 27 Aug 2008) Log Message: ----------- Create global rather than private symbols by default. Modified Paths: -------------- pure/trunk/symtable.cc Modified: pure/trunk/symtable.cc =================================================================== --- pure/trunk/symtable.cc 2008-08-27 00:32:31 UTC (rev 620) +++ pure/trunk/symtable.cc 2008-08-27 07:12:55 UTC (rev 621) @@ -59,7 +59,7 @@ symbol& symtable::sym(const string& s, int32_t modno) { symbol* _symp = lookup(s, modno); - if (_symp) modno = _symp->modno; + modno = _symp?_symp->modno:-1; symbol& _sym = tab[modno][s]; if (_sym.f == 0) { if ((uint32_t)++fno > rtab.capacity()) @@ -75,7 +75,7 @@ { assert(prec <= 10); symbol* _symp = lookup(s, modno); - if (_symp) modno = _symp->modno; + modno = _symp?_symp->modno:-1; symbol& _sym = tab[modno][s]; if (_sym.f == 0) { if ((uint32_t)++fno > rtab.capacity()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |