[pure-lang-svn] SF.net SVN: pure-lang: [292] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-06-24 00:31:27
|
Revision: 292 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=292&view=rev Author: agraef Date: 2008-06-23 17:31:37 -0700 (Mon, 23 Jun 2008) Log Message: ----------- Overhaul of the str function. Modified Paths: -------------- pure/trunk/lib/strings.pure pure/trunk/runtime.cc pure/trunk/runtime.h pure/trunk/test/prelude.log Modified: pure/trunk/lib/strings.pure =================================================================== --- pure/trunk/lib/strings.pure 2008-06-23 23:38:50 UTC (rev 291) +++ pure/trunk/lib/strings.pure 2008-06-24 00:31:37 UTC (rev 292) @@ -22,12 +22,14 @@ the print representation of an expression in Pure syntax, as a string. The eval function does the opposite, by parsing and returning the value of an expression specified as a string in Pure syntax. (In fact, eval goes well - beyond this, as it can parse and execute arbitrary Pure code. But in that - case you will not always get a result expression.) */ + beyond this, as it can parse and execute arbitrary Pure code. In that case + it will return the last computed expression, if any.) */ -extern expr* str(expr*); +extern void* str(expr*) = pure_str; extern expr* eval(char*); // IMPURE! +str x = cstring (pure_str x); + /* Convert between Unicode character codes and single character strings. */ extern expr* string_chr(int); Modified: pure/trunk/runtime.cc =================================================================== --- pure/trunk/runtime.cc 2008-06-23 23:38:50 UTC (rev 291) +++ pure/trunk/runtime.cc 2008-06-24 00:31:37 UTC (rev 292) @@ -1494,13 +1494,13 @@ } extern "C" -pure_expr *str(const pure_expr *x) +char *str(const pure_expr *x) { assert(x); ostringstream os; try { os << x; - return pure_string_dup(os.str().c_str()); + return strdup(os.str().c_str()); } catch (err &e) { return 0; } Modified: pure/trunk/runtime.h =================================================================== --- pure/trunk/runtime.h 2008-06-23 23:38:50 UTC (rev 291) +++ pure/trunk/runtime.h 2008-06-24 00:31:37 UTC (rev 292) @@ -400,9 +400,10 @@ /* Convert a Pure expression to a string and vice versa. Note that eval() will actually parse and execute any Pure source, so it can be used, e.g., to add new rules to the executing program at runtime. The result of eval() is the - last computed expression (NULL if none). */ + last computed expression (NULL if none). The result of str() is a malloc'ed + string in the system encoding which must be freed by the caller. */ -pure_expr *str(const pure_expr *x); +char *str(const pure_expr *x); pure_expr *eval(const char *s); /* Compute a 32 bit hash code of a Pure expression. This makes it possible to Modified: pure/trunk/test/prelude.log =================================================================== --- pure/trunk/test/prelude.log 2008-06-23 23:38:50 UTC (rev 291) +++ pure/trunk/test/prelude.log 2008-06-24 00:31:37 UTC (rev 292) @@ -235,6 +235,7 @@ put_string x/*0:01*/ y/*0:1*/::string = pointer_put_string x/*0:01*/ y/*0:1*/; put_pointer x/*0:01*/ y/*0:1*/::string = pointer_put_pointer x/*0:01*/ y/*0:1*/; put_pointer x/*0:01*/ y/*0:1*/ = pointer_put_pointer x/*0:01*/ y/*0:1*/; +str x/*0:1*/ = cstring (pure_str x/*0:1*/); chr n/*0:1*/::int = string_chr n/*0:1*/ if n/*0:1*/>0; ord s/*0:1*/::string = string_ord s/*0:1*/ if #s/*0:1*/==1; string s/*0:1*/ = pure_string s/*0:1*/; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |