Thread: [pure-lang-svn] SF.net SVN: pure-lang: [306] pure/trunk/examples/poor.c
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-06-24 22:27:54
|
Revision: 306 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=306&view=rev Author: agraef Date: 2008-06-24 15:28:02 -0700 (Tue, 24 Jun 2008) Log Message: ----------- Comment changes. Modified Paths: -------------- pure/trunk/examples/poor.c Modified: pure/trunk/examples/poor.c =================================================================== --- pure/trunk/examples/poor.c 2008-06-24 15:57:36 UTC (rev 305) +++ pure/trunk/examples/poor.c 2008-06-24 22:28:02 UTC (rev 306) @@ -1,18 +1,24 @@ -/* Poor man's Pure interpreter. */ +/* Poor man's Pure interpreter. 2008-06-24 AG */ -/* This is an example for the C/C++->Pure interface. It implements a silly - little command loop which reads Pure code, evaluates it, and prints the - results. Compile this with 'gcc -o poor poor.c -lpure', and run as - './poor args...'. You can use the same command line options as with the - real Pure interpreter, including any Pure scripts to be loaded at startup. +/* This is an example for calling Pure from C/C++ applications. Using the + public runtime API of Pure 0.5 or later, it implements a little command + loop which reads lines of Pure code from standard input, evaluates them and + prints the results, until it encounters end-of-file. - Please note that the interface to the interpreter, as provided by the - public runtime API, is rather minimalistic right now. In particular, the - interpreter will always run in non-interactive mode (thus none of the - interactive commands will work) and eval() will only return the last - computed expression. */ + Compile this with 'gcc -o poor poor.c -lpure', and run the resulting + executable as './poor [args ...]'. You can use the same command line + arguments as with the real Pure interpreter, including any Pure scripts to + be loaded at startup. Input is line-oriented, so you can't continue + definitions across lines, but in return you don't have to terminate each + line with a ';' either, the eval() function already takes care of that. + Please note that the interpreter interface provided by the runtime API is + rather minimalistic right now. In particular, the interpreter always runs + in non-interactive mode (thus none of the interactive commands will work) + and eval() only returns the result of the last computed expression (this is + what gets printed in the read-eval-print loop). */ + #include <stdio.h> #include <pure/runtime.h> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-06-24 22:40:58
|
Revision: 307 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=307&view=rev Author: agraef Date: 2008-06-24 15:41:06 -0700 (Tue, 24 Jun 2008) Log Message: ----------- Comment changes. Modified Paths: -------------- pure/trunk/examples/poor.c Modified: pure/trunk/examples/poor.c =================================================================== --- pure/trunk/examples/poor.c 2008-06-24 22:28:02 UTC (rev 306) +++ pure/trunk/examples/poor.c 2008-06-24 22:41:06 UTC (rev 307) @@ -1,20 +1,23 @@ /* Poor man's Pure interpreter. 2008-06-24 AG */ -/* This is an example for calling Pure from C/C++ applications. Using the - public runtime API of Pure 0.5 or later, it implements a little command - loop which reads lines of Pure code from standard input, evaluates them and - prints the results, until it encounters end-of-file. +/* This is an example for calling Pure from a standalone C/C++ application + which is *not* hosted by the command line version of the Pure interpreter, + but uses the public runtime API of Pure 0.5 or later to create its own + interpreter instance. The program implements a little command loop which + reads Pure code from standard input, evaluates it and prints the results. Compile this with 'gcc -o poor poor.c -lpure', and run the resulting executable as './poor [args ...]'. You can use the same command line arguments as with the real Pure interpreter, including any Pure scripts to be loaded at startup. Input is line-oriented, so you can't continue definitions across lines, but in return you don't have to terminate each - line with a ';' either, the eval() function already takes care of that. + line with a ';' either, the eval() function already takes care of that. To + terminate the program just type the end-of-file character at the beginning + of a line. - Please note that the interpreter interface provided by the runtime API is - rather minimalistic right now. In particular, the interpreter always runs + Please note that the interface to interpreter instances created with the + runtime API is rather minimalistic right now. The interpreter always runs in non-interactive mode (thus none of the interactive commands will work) and eval() only returns the result of the last computed expression (this is what gets printed in the read-eval-print loop). */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ag...@us...> - 2008-06-24 22:44:55
|
Revision: 308 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=308&view=rev Author: agraef Date: 2008-06-24 15:45:02 -0700 (Tue, 24 Jun 2008) Log Message: ----------- String returned by str() is malloc'ed, must free it. Modified Paths: -------------- pure/trunk/examples/poor.c Modified: pure/trunk/examples/poor.c =================================================================== --- pure/trunk/examples/poor.c 2008-06-24 22:41:06 UTC (rev 307) +++ pure/trunk/examples/poor.c 2008-06-24 22:45:02 UTC (rev 308) @@ -33,8 +33,9 @@ while (fgets(buf, sizeof(buf), stdin)) { pure_expr *x = eval(buf); if (x) { - printf("%s\n", str(x)); - pure_freenew(x); + char *s = str(x); + printf("%s\n", s); + pure_freenew(x); free(s); } else if (lasterr()) fputs(lasterr(), stderr); fputs("? ", stdout); fflush(stdout); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |