Author: leo
Date: Sat Apr 23 05:19:22 2005
New Revision: 7918

Added:
   trunk/t/pmc/builtin.t   (contents, props changed)
Modified:
   trunk/MANIFEST
   trunk/classes/parrotio.pmc
   trunk/lib/Parrot/Pmc2c.pm
   trunk/src/builtin.c
   trunk/src/call_list.txt
   trunk/t/pmc/object-meths.t
Log:
builtins 3 - differing argument count

* create new builtin test file
* new ParrotIO.say method
  handles call as class method or with PIO invocant
* fix method signatures I, N signature chars



Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Sat Apr 23 05:19:22 2005
@@ -1712,6 +1712,7 @@
 t/pmc/array.t                                     []
 t/pmc/bigint.t                                    []
 t/pmc/boolean.t                                   []
+t/pmc/builtin.t                                   []
 t/pmc/complex.t                                   []
 t/pmc/coroutine.t                                 []
 t/pmc/delegate.t                                  []

Modified: trunk/classes/parrotio.pmc
==============================================================================
--- trunk/classes/parrotio.pmc  (original)
+++ trunk/classes/parrotio.pmc  Sat Apr 23 05:19:22 2005
@@ -26,6 +26,15 @@
 
 pmclass ParrotIO need_ext {
 
+    METHOD INTVAL say(STRING *s) {
+        PMC *p2  = interpreter->ctx.current_object;
+        PMC *out = p2 == Parrot_base_vtables[enum_class_ParrotIO]->class ?
+            PIO_STDOUT(INTERP) : p2;
+        INTVAL r = PIO_putps(INTERP, out, s);
+        r  += PIO_puts(INTERP, out, "\n");
+        return r;
+    }
+
 /*
 
 =item C<void class_init()>

Modified: trunk/lib/Parrot/Pmc2c.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c.pm   (original)
+++ trunk/lib/Parrot/Pmc2c.pm   Sat Apr 23 05:19:22 2005
@@ -455,9 +455,9 @@
   "char"     => "c",
   "short"    => "s",
   "int"      => "i",
-  "INTVAL"   => "l",
+  "INTVAL"   => "I",
   "float"    => "f",
-  "FLOATVAL" => "d",
+  "FLOATVAL" => "N",
   "double"   => "d",
   "STRING*"  => "S",
   "char*"    => "t",

Modified: trunk/src/builtin.c
==============================================================================
--- trunk/src/builtin.c (original)
+++ trunk/src/builtin.c Sat Apr 23 05:19:22 2005
@@ -36,7 +36,9 @@
     { "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 }
+    { "puts",  "I!OS",         "ParrotIO",     0, 0 },
+    { "say",   "I!S",          "ParrotIO",     0, 0 },
+    { "say",   "I!OS",         "ParrotIO",     0, 0 }
 };
 
 /*
@@ -140,13 +142,25 @@
 int
 Parrot_is_builtin(Interp *interpreter, char *func, char *sig)
 {
-    int i;
+    int i, n;
 
     i = find_builtin(interpreter, func);
     if (i < 0)
         return -1;
-    if (sig && !check_builtin_sig(interpreter, i, sig))
-        return -1;
+    if (!sig)
+        return i;
+    n = sizeof(builtins) / sizeof(builtins[0]);
+    while (!check_builtin_sig(interpreter, i, sig)) {
+        if (i < n - 1) {
+            /* try next with same name */
+            ++i;
+            if (strcmp(func, builtins[i].c_name))
+                return -1;
+        }
+        else
+            return -1;
+    }
+
     return i;
 }
 

Modified: trunk/src/call_list.txt
==============================================================================
--- trunk/src/call_list.txt     (original)
+++ trunk/src/call_list.txt     Sat Apr 23 05:19:22 2005
@@ -57,6 +57,7 @@
 d                # t/pmc/nci.t
 d      d
 d      JOd      # Parrot builtins
+I       JOS
 d      v
 I      JI       # Parrot_is_char_*
 

Added: trunk/t/pmc/builtin.t
==============================================================================
--- (empty file)
+++ trunk/t/pmc/builtin.t       Sat Apr 23 05:19:22 2005
@@ -0,0 +1,101 @@
+#! perl -w
+# Copyright: 2005 The Perl Foundation.  All Rights Reserved.
+# $Id$
+
+=head1 NAME
+
+t/pmc/builtin.t - Builtin Methods
+
+=head1 SYNOPSIS
+
+       % perl -Ilib t/pmc/builtin.t
+
+=head1 DESCRIPTION
+
+Tests builtin opcode-like methods.
+
+=cut
+
+use Parrot::Test tests => 3;
+
+pir_output_is(<<'CODE', <<'OUT', "six ways to call a method");
+.sub main @MAIN
+    .local pmc x, y, cl, m
+    x = new Float
+    x = 1.0
+    # opcode syntax
+    print "opcode        "
+    y = cos x
+    print y
+    print "\n"
+    # function call syntax
+    print "function      "
+    y = "cos"(x)
+    print y
+    print "\n"
+    # method call
+    print "method        "
+    y = x."cos"()
+    print y
+    print "\n"
+    # same as class method
+    cl = getclass "Float"
+    print "class method  "
+    y = cl."cos"(x)
+    print y
+    print "\n"
+    # bound class nethod
+    print "bound class m "
+    m = getattribute cl, "cos" # m = Float.cos
+    y = m(x)
+    print y
+    print "\n"
+    # bound object nethod
+    m = getattribute x, "cos"  # m = x.cos
+    print "bound obj met "
+    y = m()
+    print y
+    print "\n"
+.end
+CODE
+opcode        0.540302
+function      0.540302
+method        0.540302
+class method  0.540302
+bound class m 0.540302
+bound obj met 0.540302
+OUT
+
+pir_output_is(<<'CODE', <<'OUT', "ParrotIO.puts");
+.sub main @MAIN
+    .local pmc o, m, cl
+    o = getstdout
+    $I0 = o."puts"("ok 1\n")
+    puts $I0, o, "ok 2\n"
+    $I0 = "puts"(o, "ok 3\n")
+    m = getattribute o, "puts"
+    $I0 = m("ok 4\n")
+    cl = getclass "ParrotIO"
+    $I0 = cl."puts"(o, "ok 5\n")
+.end
+CODE
+ok 1
+ok 2
+ok 3
+ok 4
+ok 5
+OUT
+
+pir_output_is(<<'CODE', <<'OUT', "say");
+.sub main @MAIN
+    .local pmc io
+    $I0 = say "ok 1"
+    io = getstdout
+    $I0 = say io, "ok 2"
+.end
+CODE
+ok 1
+ok 2
+OUT
+
+

Modified: trunk/t/pmc/object-meths.t
==============================================================================
--- trunk/t/pmc/object-meths.t  (original)
+++ trunk/t/pmc/object-meths.t  Sat Apr 23 05:19:22 2005
@@ -16,7 +16,7 @@
 
 =cut
 
-use Parrot::Test tests => 29;
+use Parrot::Test tests => 27;
 use Test::More;
 
 output_like(<<'CODE', <<'OUTPUT', "callmethod - unknown method");
@@ -888,71 +888,3 @@
 abc
 OUTPUT
 
-pir_output_is(<<'CODE', <<'OUTPUT', "six ways to call a method");
-.sub main @MAIN
-    .local pmc x, y, cl, m
-    x = new Float
-    x = 1.0
-    # opcode syntax
-    print "opcode        "
-    y = cos x
-    print y
-    print "\n"
-    # function call syntax
-    print "function      "
-    y = "cos"(x)
-    print y
-    print "\n"
-    # method call
-    print "method        "
-    y = x."cos"()
-    print y
-    print "\n"
-    # same as class method
-    cl = getclass "Float"
-    print "class method  "
-    y = cl."cos"(x)
-    print y
-    print "\n"
-    # bound class nethod
-    print "bound class m "
-    m = getattribute cl, "cos" # m = Float.cos
-    y = m(x)
-    print y
-    print "\n"
-    # bound object nethod
-    m = getattribute x, "cos"  # m = x.cos
-    print "bound obj met "
-    y = m()
-    print y
-    print "\n"
-.end
-CODE
-opcode        0.540302
-function      0.540302
-method        0.540302
-class method  0.540302
-bound class m 0.540302
-bound obj met 0.540302
-OUTPUT
-
-pir_output_is(<<'CODE', <<'OUTPUT', "ParrotIO.puts");
-.sub main @MAIN
-    .local pmc o, m, cl
-    o = getstdout
-    $I0 = o."puts"("ok 1\n")
-    puts $I0, o, "ok 2\n"
-    $I0 = "puts"(o, "ok 3\n")
-    m = getattribute o, "puts"
-    $I0 = m("ok 4\n")
-    cl = getclass "ParrotIO"
-    $I0 = cl."puts"(o, "ok 5\n")
-.end
-CODE
-ok 1
-ok 2
-ok 3
-ok 4
-ok 5
-OUTPUT
-

Reply via email to