svn diff
Index: src/call_list.txt
===================================================================
--- src/call_list.txt	(révision 11451)
+++ src/call_list.txt	(copie de travail)
@@ -341,3 +341,9 @@
 
 
 v	JOI
+
+# Added for Lua
+P	JOI
+
+
+
Index: languages/lua/pmc/luaboolean.pmc
===================================================================
--- languages/lua/pmc/luaboolean.pmc	(révision 11451)
+++ languages/lua/pmc/luaboolean.pmc	(copie de travail)
@@ -26,6 +26,8 @@
 static STRING *false_string;
 static STRING *true_string;
 static STRING *luaboolean_name;
+static INTVAL dynpmc_LuaNil;
+static INTVAL dynpmc_LuaString;
 
 
 pmclass LuaBoolean
@@ -43,6 +45,10 @@
             false_string = const_string(INTERP, "false");
             true_string = const_string(INTERP, "true");
             luaboolean_name = const_string(INTERP, "boolean");
+            dynpmc_LuaNil = pmc_type(INTERP,
+              string_from_const_cstring(INTERP, "LuaNil", 0));
+            dynpmc_LuaString = pmc_type(INTERP,
+              string_from_const_cstring(INTERP, "LuaString", 0));
         }
     }
 
@@ -75,6 +81,43 @@
             return false_string;
     }
 
+/*
+
+=back
+
+=head2 Specific Methods
+
+=over 4
+
+=item C<PMC* tonumber(INTVAL base)>
+
+=cut
+
+*/
+    METHOD PMC* tonumber(INTVAL base) {
+        PMC *retval;
+
+        retval = pmc_new(INTERP, dynpmc_LuaNil);
+        return retval;
+    }
+
+/*
+
+=item C<PMC* tostring()>
+
+=cut
+
+*/
+    METHOD PMC* tostring() {
+        PMC *retval;
+        STRING *rep;
+
+        retval = pmc_new(INTERP, dynpmc_LuaString);
+        rep = VTABLE_get_string(INTERP, SELF);
+        PMC_str_val(retval) = rep;
+        return retval;
+    }
+
 }
 
 /*
Index: languages/lua/pmc/luanil.pmc
===================================================================
--- languages/lua/pmc/luanil.pmc	(révision 11451)
+++ languages/lua/pmc/luanil.pmc	(copie de travail)
@@ -27,6 +27,7 @@
 #include "parrot/parrot.h"
 
 static STRING *string_representation;
+static INTVAL dynpmc_LuaNil;
 static INTVAL dynpmc_LuaNumber;
 static INTVAL dynpmc_LuaString;
 static INTVAL dynpmc_LuaBoolean;
@@ -42,6 +43,8 @@
     void class_init() {
         if (pass) {
             string_representation = const_string(INTERP, "nil");
+            dynpmc_LuaNil = pmc_type(INTERP,
+                    string_from_const_cstring(INTERP, "LuaNil", 0));
             dynpmc_LuaNumber = pmc_type(INTERP,
                     string_from_const_cstring(INTERP, "LuaNumber", 0));
             dynpmc_LuaString = pmc_type(INTERP,
@@ -223,6 +226,43 @@
         }
     }
 
+/*
+
+=back
+
+=head2 Specific Methods
+
+=over 4
+
+=item C<PMC* tonumber(INTVAL base)>
+
+=cut
+
+*/
+    METHOD PMC* tonumber(INTVAL base) {
+        PMC *retval;
+
+        retval = pmc_new(INTERP, dynpmc_LuaNil);
+        return retval;
+    }
+
+/*
+
+=item C<PMC* tostring()>
+
+=cut
+
+*/
+    METHOD PMC* tostring() {
+        PMC *retval;
+        STRING *rep;
+
+        retval = pmc_new(INTERP, dynpmc_LuaString);
+        rep = VTABLE_get_string(INTERP, SELF);
+        PMC_str_val(retval) = rep;
+        return retval;
+    }
+
 }
 
 /*
Index: languages/lua/pmc/luafunction.pmc
===================================================================
--- languages/lua/pmc/luafunction.pmc	(révision 11451)
+++ languages/lua/pmc/luafunction.pmc	(copie de travail)
@@ -22,7 +22,10 @@
 #include "parrot/parrot.h"
 
 static STRING *luafunction_name;
+static INTVAL dynpmc_LuaNil;
+static INTVAL dynpmc_LuaString;
 
+
 pmclass LuaFunction
     extends Sub
     does sub
@@ -35,6 +38,10 @@
     void class_init() {
         if (pass) {
             luafunction_name = const_string(INTERP, "function");
+            dynpmc_LuaNil = pmc_type(INTERP,
+              string_from_const_cstring(INTERP, "LuaNil", 0));
+            dynpmc_LuaString = pmc_type(INTERP,
+              string_from_const_cstring(INTERP, "LuaString", 0));
         }
     }
 
@@ -95,6 +102,43 @@
         return dest;
     }
 
+/*
+
+=back
+
+=head2 Specific Methods
+
+=over 4
+
+=item C<PMC* tonumber(INTVAL base)>
+
+=cut
+
+*/
+    METHOD PMC* tonumber(INTVAL base) {
+        PMC *retval;
+
+        retval = pmc_new(INTERP, dynpmc_LuaNil);
+        return retval;
+    }
+
+/*
+
+=item C<PMC* tostring()>
+
+=cut
+
+*/
+    METHOD PMC* tostring() {
+        PMC *retval;
+        STRING *rep;
+
+        retval = pmc_new(INTERP, dynpmc_LuaString);
+        rep = VTABLE_get_string(INTERP, SELF);
+        PMC_str_val(retval) = rep;
+        return retval;
+    }
+
 }
 
 /*
Index: languages/lua/pmc/luastring.pmc
===================================================================
--- languages/lua/pmc/luastring.pmc	(révision 11451)
+++ languages/lua/pmc/luastring.pmc	(copie de travail)
@@ -22,6 +22,7 @@
 #include "parrot/parrot.h"
 
 static STRING *luastring_name;
+static INTVAL dynpmc_LuaNumber;
 
 pmclass LuaString
     extends String
@@ -35,7 +36,9 @@
     void class_init() {
         if (pass) {
             luastring_name = const_string(INTERP, "string");
-        }
+            dynpmc_LuaNumber = pmc_type(INTERP,
+              string_from_const_cstring(INTERP, "LuaNumber", 0));
+        }           
     }
 
 /*
@@ -140,6 +143,43 @@
         }
     }
 
+/*
+
+=back
+
+=head2 Specific Methods
+
+=over 4
+
+=item C<PMC* tonumber(INTVAL base)>
+
+=cut
+
+*/
+    METHOD PMC* tonumber(INTVAL base) {
+        PMC *retval;
+        STRING *rep;
+
+        retval = pmc_new(INTERP, dynpmc_LuaNumber);
+        rep = VTABLE_get_string(INTERP, SELF);
+        PMC_num_val(retval) = string_to_num(INTERP, rep);
+        return retval;
+    }
+
+/*
+
+=item C<PMC* tostring()>
+
+=cut
+
+*/
+    METHOD PMC* tostring() {
+        PMC *retval;
+
+        retval = VTABLE_clone(INTERP, SELF); 
+        return retval;
+    }
+
 }
 
 /*
Index: languages/lua/pmc/luatable.pmc
===================================================================
--- languages/lua/pmc/luatable.pmc	(révision 11451)
+++ languages/lua/pmc/luatable.pmc	(copie de travail)
@@ -26,6 +26,7 @@
 
 static STRING *luatable_name;
 static INTVAL dynpmc_LuaNil;
+static INTVAL dynpmc_LuaString;
 
 pmclass LuaTable
     extends Hash
@@ -41,6 +42,8 @@
             luatable_name = const_string(INTERP, "table");
             dynpmc_LuaNil = pmc_type(INTERP,
               string_from_const_cstring(INTERP, "LuaNil", 0));
+            dynpmc_LuaString = pmc_type(INTERP,
+              string_from_const_cstring(INTERP, "LuaString", 0));
         }
     }
 
@@ -244,6 +247,43 @@
         return (INTVAL)0;
     }
 
+/*
+
+=back
+
+=head2 Specific Methods
+
+=over 4
+
+=item C<PMC* tonumber(INTVAL base)>
+
+=cut
+
+*/
+    METHOD PMC* tonumber(INTVAL base) {
+        PMC *retval;
+
+        retval = pmc_new(INTERP, dynpmc_LuaNil);
+        return retval;
+    }
+
+/*
+
+=item C<PMC* tostring()>
+
+=cut
+
+*/
+    METHOD PMC* tostring() {
+        PMC *retval;
+        STRING *rep;
+
+        retval = pmc_new(INTERP, dynpmc_LuaString);
+        rep = VTABLE_get_string(INTERP, SELF);
+        PMC_str_val(retval) = rep;
+        return retval;
+    }
+
 }
 
 /*
Index: languages/lua/pmc/luathread.pmc
===================================================================
--- languages/lua/pmc/luathread.pmc	(révision 11451)
+++ languages/lua/pmc/luathread.pmc	(copie de travail)
@@ -22,7 +22,10 @@
 #include "parrot/parrot.h"
 
 static STRING *luathread_name;
+static INTVAL dynpmc_LuaNil;
+static INTVAL dynpmc_LuaString;
 
+
 pmclass LuaThread
     extends Coroutine
     does sub
@@ -35,6 +38,10 @@
     void class_init() {
         if (pass) {
             luathread_name = const_string(INTERP, "thread");
+            dynpmc_LuaNil = pmc_type(INTERP,
+              string_from_const_cstring(INTERP, "LuaNil", 0));
+            dynpmc_LuaString = pmc_type(INTERP,
+              string_from_const_cstring(INTERP, "LuaString", 0));
         }
     }
 
@@ -95,6 +102,43 @@
         return dest;
     }
 
+/*
+
+=back
+
+=head2 Specific Methods
+
+=over 4
+
+=item C<PMC* tonumber(INTVAL base)>
+
+=cut
+
+*/
+    METHOD PMC* tonumber(INTVAL base) {
+        PMC *retval;
+
+        retval = pmc_new(INTERP, dynpmc_LuaNil);
+        return retval;
+    }
+
+/*
+
+=item C<PMC* tostring()>
+
+=cut
+
+*/
+    METHOD PMC* tostring() {
+        PMC *retval;
+        STRING *rep;
+
+        retval = pmc_new(INTERP, dynpmc_LuaString);
+        rep = VTABLE_get_string(INTERP, SELF);
+        PMC_str_val(retval) = rep;
+        return retval;
+    }
+
 }
 
 /*
Index: languages/lua/pmc/luanumber.pmc
===================================================================
--- languages/lua/pmc/luanumber.pmc	(révision 11451)
+++ languages/lua/pmc/luanumber.pmc	(copie de travail)
@@ -22,6 +22,7 @@
 #include "parrot/parrot.h"
 
 static STRING *luanumber_name;
+static INTVAL dynpmc_LuaString;
 
 pmclass LuaNumber
     extends Float
@@ -35,6 +36,8 @@
     void class_init() {
         if (pass) {
             luanumber_name = const_string(INTERP, "number");
+            dynpmc_LuaString = pmc_type(INTERP,
+              string_from_const_cstring(INTERP, "LuaString", 0));
         }
     }
 
@@ -143,6 +146,43 @@
         }
     }
 
+/*
+
+=back
+
+=head2 Specific Methods
+
+=over 4
+
+=item C<PMC* tonumber()>
+
+=cut
+
+*/
+    METHOD PMC* tonumber(INTVAL base) {
+        PMC *retval;
+
+        retval = VTABLE_clone(INTERP, SELF); 
+        return retval;
+    }
+
+/*
+
+=item C<PMC* tostring()>
+
+=cut
+
+*/
+    METHOD PMC* tostring() {
+        PMC *retval;
+        STRING *rep;
+
+        retval = pmc_new(INTERP, dynpmc_LuaString);
+        rep = VTABLE_get_string(INTERP, SELF);
+        PMC_str_val(retval) = rep;
+        return retval;
+    }
+
 }
 
 /*
Index: languages/lua/pmc/luauserdata.pmc
===================================================================
--- languages/lua/pmc/luauserdata.pmc	(révision 11451)
+++ languages/lua/pmc/luauserdata.pmc	(copie de travail)
@@ -22,7 +22,10 @@
 #include "parrot/parrot.h"
 
 static STRING *luauserdata_name;
+static INTVAL dynpmc_LuaNil;
+static INTVAL dynpmc_LuaString;
 
+
 pmclass LuaUserdata 
     extends String
     dynpmc 
@@ -34,6 +37,10 @@
     void class_init() {
         if (pass) {
             luauserdata_name = const_string(INTERP, "userdata");
+            dynpmc_LuaNil = pmc_type(INTERP,
+              string_from_const_cstring(INTERP, "LuaNil", 0));
+            dynpmc_LuaString = pmc_type(INTERP,
+              string_from_const_cstring(INTERP, "LuaString", 0));
         }
     }
 
@@ -77,6 +84,43 @@
         return 1;
     }
 
+/*
+
+=back
+
+=head2 Specific Methods
+
+=over 4
+
+=item C<PMC* tonumber(INTVAL base)>
+
+=cut
+
+*/
+    METHOD PMC* tonumber(INTVAL base) {
+        PMC *retval;
+
+        retval = pmc_new(INTERP, dynpmc_LuaNil);
+        return retval;
+    }
+
+/*
+
+=item C<PMC* tostring()>
+
+=cut
+
+*/
+    METHOD PMC* tostring() {
+        PMC *retval;
+        STRING *rep;
+
+        retval = pmc_new(INTERP, dynpmc_LuaString);
+        rep = VTABLE_get_string(INTERP, SELF);
+        PMC_str_val(retval) = rep;
+        return retval;
+    }
+
 }
 
 /*
Index: languages/lua/t/pmc/number.t
===================================================================
--- languages/lua/t/pmc/number.t	(révision 11451)
+++ languages/lua/t/pmc/number.t	(copie de travail)
@@ -17,7 +17,7 @@
 
 =cut
 
-use Parrot::Test tests => 9;
+use Parrot::Test tests => 10;
 use Test::More;
 
 pir_output_is(<< 'CODE', << 'OUTPUT', "check inheritance");
@@ -213,3 +213,22 @@
 1
 OUTPUT
 
+pir_output_is(<< 'CODE', << 'OUTPUT', "check tostring");
+.HLL "Lua", "lua_group"
+.sub _main
+    .const .LuaNumber cst1 = "3.14"
+    print cst1
+    print "\n"
+    $P0 = cst1."tostring"()
+    print $P0
+    print "\n"
+    $S0 = typeof $P0
+    print $S0
+    print "\n"
+.end
+CODE
+3.14
+3.14
+string
+OUTPUT
+
Index: languages/lua/lib/luabasic.pir
===================================================================
--- languages/lua/lib/luabasic.pir	(révision 11451)
+++ languages/lua/lib/luabasic.pir	(copie de travail)
@@ -716,29 +716,8 @@
     .param pmc base :optional
     .local pmc ret
     $I0 = optint(base, 10)
-    unless $I0 == 10 goto L0
-    checkany(e)
-    $I1 = isa e, "LuaNumber"
-    unless $I1 goto L1
-    ret = clone e
+    ret = e."tonumber"($I0)
     .return (ret)
-L1:
-    $I1 = isa e, "LuaString"
-    unless $I1 goto L2
-    $S0 = e
-#    print $S0
-#    print "\n"
-    $N0 = $S0
-#    print $N0
-#    print "\n"
-    new ret, .LuaNumber
-    ret = $N0
-    .return (ret)
-L2:
-    new ret, .LuaNil
-    .return (ret)
-L0:
-    not_implemented()
 .end
 
 =item C<tostring (e)>
@@ -759,13 +738,7 @@
     .local pmc ret
     checkany(e)
     # TODO: __tostring
-    $I1 = isa e, "LuaString"
-    unless $I1 goto L1
-    .return (e)
-L1:
-    $S0 = e
-    new ret, .LuaString
-    ret = $S0
+    ret = e."tostring"()
     .return (ret)
 .end
 
