[svn:parrot] r36767 - in trunk: src t/src
NotFound at svn.parrot.org
NotFound at svn.parrot.org
Sun Feb 15 17:52:50 UTC 2009
Author: NotFound
Date: Sun Feb 15 17:52:49 2009
New Revision: 36767
URL: https://trac.parrot.org/parrot/changeset/36767
Log:
[core] allow Parrot_compile_sub direct usage from embedding, modify embed.t to use it
Modified:
trunk/src/inter_misc.c
trunk/t/src/embed.t
Modified: trunk/src/inter_misc.c
==============================================================================
--- trunk/src/inter_misc.c Sun Feb 15 17:02:32 2009 (r36766)
+++ trunk/src/inter_misc.c Sun Feb 15 17:52:49 2009 (r36767)
@@ -168,6 +168,19 @@
ARGIN(const char *code), ARGOUT(STRING **error))
{
ASSERT_ARGS(Parrot_compile_string)
+
+ /* For the benefit of embedders that does not load any pbc
+ * before compiling a string
+ */
+ if (! interp->initial_pf) {
+ PackFile *pf = PackFile_new_dummy(interp, "compile_string");
+ /* Assumption: there is no valid reason to fail to create it.
+ * If the assumption changes, replace the assertio with a
+ * runtime check
+ */
+ PARROT_ASSERT(interp->initial_pf);
+ }
+
if (Parrot_str_compare(interp, CONST_STRING(interp, "PIR"), type) == 0)
return IMCC_compile_pir_s(interp, code, error);
Modified: trunk/t/src/embed.t
==============================================================================
--- trunk/t/src/embed.t Sun Feb 15 17:02:32 2009 (r36766)
+++ trunk/t/src/embed.t Sun Feb 15 17:52:49 2009 (r36767)
@@ -64,6 +64,7 @@
#include "parrot/embed.h"
#include "parrot/extend.h"
+#include "parrot/interpreter.h"
void fail(const char *msg);
@@ -76,17 +77,34 @@
int main(void)
{
Parrot_Interp interp;
+ Parrot_String compiler;
+ Parrot_String errstr;
+ Parrot_PMC *code;
+
+ /* Create the interprter and show a message using parrot io */
interp = Parrot_new(NULL);
if (! interp)
fail("Cannot create parrot interpreter");
-
Parrot_printf(interp, "Hello, parrot\n");
+ /* Compile and execute a pir sub */
+ compiler = Parrot_new_string(interp, "PIR", 3, (const char *)NULL, 0);
+ code = Parrot_compile_string(interp, compiler,
+".sub main\n"
+" say 'Hello, pir'\n"
+"\n"
+".end\n"
+"\n",
+ &errstr
+ );
+ Parrot_call_sub(interp, code, "");
+
Parrot_exit(interp, 0);
return 0;
}
CODE
Hello, parrot
+Hello, pir
OUTPUT
More information about the parrot-commits
mailing list