Author: leo
Date: Sun Apr 24 03:10:53 2005
New Revision: 7922

Modified:
   trunk/imcc/parser_util.c
   trunk/include/parrot/builtin.h
   trunk/src/builtin.c
   trunk/t/pmc/builtin.t
Log:
builtins 4 - enable void calls for functions that return a result

Modified: trunk/imcc/parser_util.c
==============================================================================
--- trunk/imcc/parser_util.c    (original)
+++ trunk/imcc/parser_util.c    Sun Apr 24 03:10:53 2005
@@ -271,6 +271,7 @@
     char sig[16];
     int i, bi, is_class_meth;
     SymReg *sub, *meth, *rr[10];
+    int first_arg, is_void;
 
     assert(n < 15);
     UNUSED(unit);
@@ -287,37 +288,35 @@
      * cos Px, Py  => Px = Py.cos()
      */
     is_class_meth = Parrot_builtin_is_class_method(interpreter, bi);
+    is_void = Parrot_builtin_is_void(interpreter, bi);
+    meth = mk_sub_address(interpreter, str_dup(name));
     if (is_class_meth) {    /* ParrotIO.open() */
         const char *ns = Parrot_builtin_get_c_namespace(interpreter, bi);
         SymReg *ns_sym;
 
         ns_sym = mk_const(interpreter, str_dup(ns), 'S');
-        meth = mk_sub_address(interpreter, str_dup(name));
         ins = IMCC_create_itcall_label(interpreter);
         sub = ins->r[0];
         IMCC_itcall_sub(interpreter, meth);
         sub->pcc_sub->object = ns_sym;
-        sub->pcc_sub->nci = 1;
-        for (i = 1; i < n; ++i) {
-            add_pcc_arg(sub, rr[i]);
-        }
-        add_pcc_result(sub, rr[0]);
-        return ins;
+        first_arg = 1;
     }
     else {    /* method y = x."cos"() */
-        meth = mk_sub_address(interpreter, str_dup(name));
         ins = IMCC_create_itcall_label(interpreter);
         sub = ins->r[0];
         IMCC_itcall_sub(interpreter, meth);
-        sub->pcc_sub->object = rr[1];
-        sub->pcc_sub->nci = 1;
-        for (i = 2; i < n; ++i) {
-            add_pcc_arg(sub, rr[i]);
-        }
-        add_pcc_result(sub, rr[0]);
-        return ins;
+        sub->pcc_sub->object = rr[is_void ? 0 : 1];
+        first_arg = 2;
     }
-    return NULL;
+    sub->pcc_sub->nci = 1;
+    if (is_void)
+        first_arg--;
+    for (i = first_arg; i < n; ++i) {
+        add_pcc_arg(sub, rr[i]);
+    }
+    if (!is_void)
+        add_pcc_result(sub, rr[0]);
+    return ins;
 }
 
 /*

Modified: trunk/include/parrot/builtin.h
==============================================================================
--- trunk/include/parrot/builtin.h      (original)
+++ trunk/include/parrot/builtin.h      Sun Apr 24 03:10:53 2005
@@ -18,6 +18,7 @@
 PMC* Parrot_find_builtin(Interp *interpreter, STRING *func);
 const char * Parrot_builtin_get_c_namespace(Interp *, int bi);
 int Parrot_builtin_is_class_method(Interp *, int bi);
+int Parrot_builtin_is_void(Interp *, int bi);
 
 #endif /* PARROT_BUILTIN_H_GUARD */
 

Modified: trunk/src/builtin.c
==============================================================================
--- trunk/src/builtin.c (original)
+++ trunk/src/builtin.c Sun Apr 24 03:10:53 2005
@@ -32,13 +32,15 @@
 } Builtins;
 
 static Builtins builtins[] = {
-    { "cos",   "P!O",          "Float",        0, 0 },
-    { "index",  "I!SS.I",       "String",       0, 0 },
-    { "lower",         "P!O",          "String",       0, 0 },
-    { "open",  "P!S.S",        "ParrotIO",     0, 0 },
-    { "puts",  "I!OS",         "ParrotIO",     0, 0 },
-    { "say",   "I!S",          "ParrotIO",     0, 0 },
-    { "say",   "I!OS",         "ParrotIO",     0, 0 }
+    { "cos",   "PJO",          "Float",        0, 0 },
+    { "index",  "IJSS.I",       "String",       0, 0 },
+    { "lower",         "PJO",          "String",       0, 0 },
+    { "open",  "PJS.S",        "ParrotIO",     0, 0 },
+    { "puts",  "IJOS",         "ParrotIO",     0, 0 },
+    { "say",   "IJS",          "ParrotIO",     0, 0 },
+    { "say",   "IJOS",         "ParrotIO",     0, 0 },
+    { "say",   "vJS",          "ParrotIO",     0, 0 },
+    { "say",   "vJOS",         "ParrotIO",     0, 0 }
 };
 
 /*
@@ -119,12 +121,15 @@
     const char *p;
     int opt = 0;
 
-    for (p = b->signature ; *p && *sig; ++sig, ++p) {
+    p = b->signature;
+    if (*p != *sig && *p == 'v')
+        ++p;
+    for (; *p && *sig; ++sig, ++p) {
         switch (*p) {
             case '.':   /* optional start */
                 opt = 1;
                 /* fall through */
-            case '!':   /* interpreter */
+            case 'J':   /* interpreter */
                 ++p;
         }
         if (*p == 'O' && *sig == 'P')
@@ -202,6 +207,16 @@
     return builtins[bi].signature[2] != 'O';
 }
 
+int
+Parrot_builtin_is_void(Interp *interpreter, int bi)
+{
+    int n;
+
+    n = sizeof(builtins) / sizeof(builtins[0]);
+    assert(bi >= 0 && bi < n);
+    return builtins[bi].signature[0] == 'v';
+}
+
 /*
 
 =back

Modified: trunk/t/pmc/builtin.t
==============================================================================
--- trunk/t/pmc/builtin.t       (original)
+++ trunk/t/pmc/builtin.t       Sun Apr 24 03:10:53 2005
@@ -92,10 +92,14 @@
     $I0 = say "ok 1"
     io = getstdout
     $I0 = say io, "ok 2"
+    say "ok 3"
+    say io, "ok 4"
 .end
 CODE
 ok 1
 ok 2
+ok 3
+ok 4
 OUT
 
 

Reply via email to