Author: fperrad
Date: Wed Mar  8 23:43:00 2006
New Revision: 11832

Modified:
   trunk/languages/lua/lib/luabasic.pir
   trunk/languages/lua/pmc/luaboolean.pmc
   trunk/languages/lua/pmc/luafunction.pmc
   trunk/languages/lua/pmc/luanil.pmc
   trunk/languages/lua/pmc/luanumber.pmc
   trunk/languages/lua/pmc/luastring.pmc
   trunk/languages/lua/pmc/luatable.pmc
   trunk/languages/lua/pmc/luathread.pmc
   trunk/languages/lua/pmc/luauserdata.pmc
   trunk/languages/lua/t/basic.t

Log:
Lua :
 - add rawequal (basic library)
 - and tests

Modified: trunk/languages/lua/lib/luabasic.pir
==============================================================================
--- trunk/languages/lua/lib/luabasic.pir        (original)
+++ trunk/languages/lua/lib/luabasic.pir        Wed Mar  8 23:43:00 2006
@@ -558,16 +558,16 @@
 Checks whether C<v1> is equal to C<v2>, without invoking any metamethod.
 Returns a boolean.
 
-NOT YET IMPLEMENTED.
-
 =cut
 
 .sub _lua_rawequal :anon
     .param pmc v1 :optional
     .param pmc v2 :optional
+    .local pmc ret
     checkany(v1)
     checkany(v2)
-    not_implemented()
+     ret = v1."rawequal"(v2)
+    .return (ret)
 .end
 
 =item C<rawget (table, index)>
@@ -583,7 +583,6 @@
     .local pmc ret
     checktype(table, "table")
     checkany(index)
-#    ret = table[index]
      ret = table."rawget"(index)
     .return (ret)
 .end
@@ -603,7 +602,6 @@
     checktype(table, "table")
     checkany(index)
     checkany(value)
-#    table[index] = value
     table."rawset"(index, value)
     .return ()
 .end

Modified: trunk/languages/lua/pmc/luaboolean.pmc
==============================================================================
--- trunk/languages/lua/pmc/luaboolean.pmc      (original)
+++ trunk/languages/lua/pmc/luaboolean.pmc      Wed Mar  8 23:43:00 2006
@@ -26,6 +26,7 @@
 static STRING *false_string;

 static STRING *true_string;

 static STRING *luaboolean_name;

+static INTVAL dynpmc_LuaBoolean;

 

 pmclass LuaBoolean

     extends LuaBase

@@ -46,21 +47,16 @@
             false_string = const_string(INTERP, "false");

             true_string = const_string(INTERP, "true");

             luaboolean_name = const_string(INTERP, "boolean");

+            dynpmc_LuaBoolean = pmc_type(INTERP,

+              string_from_const_cstring(INTERP, "LuaBoolean", 0));

 

             /* namespace hack */

             meth = Parrot_find_global(INTERP,

                 const_string(INTERP, "LuaBoolean"),

-                const_string(INTERP, "tostring"));

+                const_string(INTERP, "rawequal"));

             Parrot_store_global(INTERP,

                 const_string(INTERP, "boolean"),

-                const_string(INTERP, "tostring"),

-                meth);

-            meth = Parrot_find_global(INTERP,

-                const_string(INTERP, "LuaBoolean"),

-                const_string(INTERP, "tonumber"));

-            Parrot_store_global(INTERP,

-                const_string(INTERP, "boolean"),

-                const_string(INTERP, "tonumber"),

+                const_string(INTERP, "rawequal"),

                 meth);

         }

     }

@@ -248,6 +244,31 @@
         }

     }

 

+/*

+

+=back

+

+=head2 Specific Methods

+

+=over 4

+

+=item C<PMC* rawequal (PMC* value)>

+

+=cut

+

+*/

+    METHOD PMC* rawequal (PMC* value) {

+        PMC *retval;

+       

+        retval = pmc_new(INTERP, dynpmc_LuaBoolean);

+        if (SELF->vtable->base_type == value->vtable->base_type

+         && PMC_int_val(SELF) == PMC_int_val(value))

+            PMC_int_val(retval) = 1;

+        else

+            PMC_int_val(retval) = 0;

+        return retval;

+    }

+

 }

 

 /*


Modified: trunk/languages/lua/pmc/luafunction.pmc
==============================================================================
--- trunk/languages/lua/pmc/luafunction.pmc     (original)
+++ trunk/languages/lua/pmc/luafunction.pmc     Wed Mar  8 23:43:00 2006
@@ -22,6 +22,7 @@
 #include "parrot/parrot.h"

 

 static STRING *luafunction_name;

+static INTVAL dynpmc_LuaBoolean;

 static INTVAL dynpmc_LuaNil;

 static INTVAL dynpmc_LuaString;

 

@@ -40,6 +41,8 @@
             PMC *meth;

 

             luafunction_name = const_string(INTERP, "function");

+            dynpmc_LuaBoolean = pmc_type(INTERP,

+              string_from_const_cstring(INTERP, "LuaBoolean", 0));

             dynpmc_LuaNil = pmc_type(INTERP,

               string_from_const_cstring(INTERP, "LuaNil", 0));

             dynpmc_LuaString = pmc_type(INTERP,

@@ -48,6 +51,13 @@
             /* namespace hack */

             meth = Parrot_find_global(INTERP,

                 const_string(INTERP, "LuaFunction"),

+                const_string(INTERP, "rawequal"));

+            Parrot_store_global(INTERP,

+                const_string(INTERP, "function"),

+                const_string(INTERP, "rawequal"),

+                meth);

+            meth = Parrot_find_global(INTERP,

+                const_string(INTERP, "LuaFunction"),

                 const_string(INTERP, "tostring"));

             Parrot_store_global(INTERP,

                 const_string(INTERP, "function"),

@@ -128,6 +138,25 @@
 

 =over 4

 

+=item C<PMC* rawequal (PMC* value)>

+

+=cut

+

+*/

+    METHOD PMC* rawequal (PMC* value) {

+        PMC *retval;

+       

+        retval = pmc_new(INTERP, dynpmc_LuaBoolean);

+        if (SELF->vtable->base_type == value->vtable->base_type

+         && SELF == value)

+            PMC_int_val(retval) = 1;

+        else

+            PMC_int_val(retval) = 0;

+        return retval;

+    }

+

+/*

+

 =item C<PMC* tonumber()>

 

 =cut


Modified: trunk/languages/lua/pmc/luanil.pmc
==============================================================================
--- trunk/languages/lua/pmc/luanil.pmc  (original)
+++ trunk/languages/lua/pmc/luanil.pmc  Wed Mar  8 23:43:00 2006
@@ -27,6 +27,7 @@
 #include "parrot/parrot.h"

 

 static STRING *string_representation;

+static INTVAL dynpmc_LuaBoolean;

 

 pmclass LuaNil

     extends LuaBase   

@@ -44,21 +45,16 @@
 

             Parrot_LuaBase_super_init(INTERP, NULL);

             string_representation = const_string(INTERP, "nil");

+            dynpmc_LuaBoolean = pmc_type(INTERP,

+              string_from_const_cstring(INTERP, "LuaBoolean", 0));

 

             /* namespace hack */

             meth = Parrot_find_global(INTERP,

                 const_string(INTERP, "LuaNil"),

-                const_string(INTERP, "tostring"));

+                const_string(INTERP, "rawequal"));

             Parrot_store_global(INTERP,

                 const_string(INTERP, "nil"),

-                const_string(INTERP, "tostring"),

-                meth);

-            meth = Parrot_find_global(INTERP,

-                const_string(INTERP, "LuaNil"),

-                const_string(INTERP, "tonumber"));

-            Parrot_store_global(INTERP,

-                const_string(INTERP, "nil"),

-                const_string(INTERP, "tonumber"),

+                const_string(INTERP, "rawequal"),

                 meth);

         }

     }

@@ -182,6 +178,30 @@
         }

     }

 

+/*

+

+=back

+

+=head2 Specific Methods

+

+=over 4

+

+=item C<PMC* rawequal (PMC* value)>

+

+=cut

+

+*/

+    METHOD PMC* rawequal (PMC* value) {

+        PMC *retval;

+       

+        retval = pmc_new(INTERP, dynpmc_LuaBoolean);

+        if (SELF->vtable->base_type == value->vtable->base_type)

+            PMC_int_val(retval) = 1;

+        else

+            PMC_int_val(retval) = 0;

+        return retval;

+    }

+

 }

 

 /*


Modified: trunk/languages/lua/pmc/luanumber.pmc
==============================================================================
--- trunk/languages/lua/pmc/luanumber.pmc       (original)
+++ trunk/languages/lua/pmc/luanumber.pmc       Wed Mar  8 23:43:00 2006
@@ -25,6 +25,7 @@
 #define LUA_NUMBER_FMT         "%.14g"

 

 static STRING *luanumber_name;

+static INTVAL dynpmc_LuaBoolean;

 static INTVAL dynpmc_LuaNil;

 static INTVAL dynpmc_LuaString;

 

@@ -44,6 +45,8 @@
 

             Parrot_LuaBase_super_init(INTERP, NULL);

             luanumber_name = const_string(INTERP, "number");

+            dynpmc_LuaBoolean = pmc_type(INTERP,

+              string_from_const_cstring(INTERP, "LuaBoolean", 0));

             dynpmc_LuaNil = pmc_type(INTERP,

               string_from_const_cstring(INTERP, "LuaNil", 0));

             dynpmc_LuaString = pmc_type(INTERP,

@@ -52,10 +55,10 @@
             /* namespace hack */

             meth = Parrot_find_global(INTERP,

                 const_string(INTERP, "LuaNumber"),

-                const_string(INTERP, "tostring"));

+                const_string(INTERP, "rawequal"));

             Parrot_store_global(INTERP,

                 const_string(INTERP, "number"),

-                const_string(INTERP, "tostring"),

+                const_string(INTERP, "rawequal"),

                 meth);

             meth = Parrot_find_global(INTERP,

                 const_string(INTERP, "LuaNumber"),

@@ -866,6 +869,25 @@
 

 =over 4

 

+=item C<PMC* rawequal (PMC* value)>

+

+=cut

+

+*/

+    METHOD PMC* rawequal (PMC* value) {

+        PMC *retval;

+       

+        retval = pmc_new(INTERP, dynpmc_LuaBoolean);

+        if (SELF->vtable->base_type == value->vtable->base_type

+         && PMC_num_val(SELF) == PMC_num_val(value))

+            PMC_int_val(retval) = 1;

+        else

+            PMC_int_val(retval) = 0;

+        return retval;

+    }

+

+/*

+

 =item C<PMC* tonumber()>

 

 =cut


Modified: trunk/languages/lua/pmc/luastring.pmc
==============================================================================
--- trunk/languages/lua/pmc/luastring.pmc       (original)
+++ trunk/languages/lua/pmc/luastring.pmc       Wed Mar  8 23:43:00 2006
@@ -23,6 +23,7 @@
 #include "pmc_luanumber.h"

 

 static STRING *luastring_name;

+static INTVAL dynpmc_LuaBoolean;

 static INTVAL dynpmc_LuaNil;

 static INTVAL dynpmc_LuaNumber;

 

@@ -42,6 +43,8 @@
 

             Parrot_LuaBase_super_init(INTERP, NULL);

             luastring_name = const_string(INTERP, "string");

+            dynpmc_LuaBoolean = pmc_type(INTERP,

+              string_from_const_cstring(INTERP, "LuaBoolean", 0));

             dynpmc_LuaNil = pmc_type(INTERP,

               string_from_const_cstring(INTERP, "LuaNil", 0));

             dynpmc_LuaNumber = pmc_type(INTERP,

@@ -57,6 +60,13 @@
                 meth);

             meth = Parrot_find_global(INTERP,

                 const_string(INTERP, "LuaString"),

+                const_string(INTERP, "rawequal"));

+            Parrot_store_global(INTERP,

+                const_string(INTERP, "string"),

+                const_string(INTERP, "rawequal"),

+                meth);

+            meth = Parrot_find_global(INTERP,

+                const_string(INTERP, "LuaString"),

                 const_string(INTERP, "tostring"));

             Parrot_store_global(INTERP,

                 const_string(INTERP, "string"),

@@ -994,6 +1004,25 @@
 

 /*

 

+=item C<PMC* rawequal (PMC* value)>

+

+=cut

+

+*/

+    METHOD PMC* rawequal (PMC* value) {

+        PMC *retval;

+       

+        retval = pmc_new(INTERP, dynpmc_LuaBoolean);

+        if (SELF->vtable->base_type == value->vtable->base_type

+         && 0 == string_equal(INTERP, PMC_str_val(SELF), PMC_str_val(value)))

+            PMC_int_val(retval) = 1;

+        else

+            PMC_int_val(retval) = 0;

+        return retval;

+    }

+

+/*

+

 =item C<PMC* tonumber()>

 

 =cut


Modified: trunk/languages/lua/pmc/luatable.pmc
==============================================================================
--- trunk/languages/lua/pmc/luatable.pmc        (original)
+++ trunk/languages/lua/pmc/luatable.pmc        Wed Mar  8 23:43:00 2006
@@ -25,6 +25,7 @@
 #include "parrot/parrot.h"

 

 static STRING *luatable_name;

+static INTVAL dynpmc_LuaBoolean;

 static INTVAL dynpmc_LuaNil;

 static INTVAL dynpmc_LuaNumber;

 static INTVAL dynpmc_LuaString;

@@ -59,6 +60,8 @@
 

             Parrot_LuaBase_super_init(INTERP, NULL);

             luatable_name = const_string(INTERP, "table");

+            dynpmc_LuaBoolean = pmc_type(INTERP,

+              string_from_const_cstring(INTERP, "LuaBoolean", 0));

             dynpmc_LuaNil = pmc_type(INTERP,

               string_from_const_cstring(INTERP, "LuaNil", 0));

             dynpmc_LuaNumber = pmc_type(INTERP,

@@ -92,6 +95,13 @@
                 meth);

             meth = Parrot_find_global(INTERP,

                 const_string(INTERP, "LuaTable"),

+                const_string(INTERP, "rawequal"));

+            Parrot_store_global(INTERP,

+                const_string(INTERP, "table"),

+                const_string(INTERP, "rawequal"),

+                meth);

+            meth = Parrot_find_global(INTERP,

+                const_string(INTERP, "LuaTable"),

                 const_string(INTERP, "rawget"));

             Parrot_store_global(INTERP,

                 const_string(INTERP, "table"),

@@ -460,6 +470,25 @@
 

 /*

 

+=item C<PMC* rawequal (PMC* value)>

+

+=cut

+

+*/

+    METHOD PMC* rawequal (PMC* value) {

+        PMC *retval;

+       

+        retval = pmc_new(INTERP, dynpmc_LuaBoolean);

+        if (SELF->vtable->base_type == value->vtable->base_type

+         && SELF == value)

+            PMC_int_val(retval) = 1;

+        else

+            PMC_int_val(retval) = 0;

+        return retval;

+    }

+

+/*

+

 =item C<PMC* rawget (PMC* key)>

 

 =cut


Modified: trunk/languages/lua/pmc/luathread.pmc
==============================================================================
--- trunk/languages/lua/pmc/luathread.pmc       (original)
+++ trunk/languages/lua/pmc/luathread.pmc       Wed Mar  8 23:43:00 2006
@@ -22,6 +22,7 @@
 #include "parrot/parrot.h"

 

 static STRING *luathread_name;

+static INTVAL dynpmc_LuaBoolean;

 static INTVAL dynpmc_LuaNil;

 static INTVAL dynpmc_LuaString;

 

@@ -40,6 +41,8 @@
             PMC *meth;

 

             luathread_name = const_string(INTERP, "thread");

+            dynpmc_LuaBoolean = pmc_type(INTERP,

+              string_from_const_cstring(INTERP, "LuaBoolean", 0));

             dynpmc_LuaNil = pmc_type(INTERP,

               string_from_const_cstring(INTERP, "LuaNil", 0));

             dynpmc_LuaString = pmc_type(INTERP,

@@ -48,6 +51,13 @@
             /* namespace hack */

             meth = Parrot_find_global(INTERP,

                 const_string(INTERP, "LuaThread"),

+                const_string(INTERP, "rawequal"));

+            Parrot_store_global(INTERP,

+                const_string(INTERP, "thread"),

+                const_string(INTERP, "rawequal"),

+                meth);

+            meth = Parrot_find_global(INTERP,

+                const_string(INTERP, "LuaThread"),

                 const_string(INTERP, "tostring"));

             Parrot_store_global(INTERP,

                 const_string(INTERP, "thread"),

@@ -128,6 +138,25 @@
 

 =over 4

 

+=item C<PMC* rawequal (PMC* value)>

+

+=cut

+

+*/

+    METHOD PMC* rawequal (PMC* value) {

+        PMC *retval;

+       

+        retval = pmc_new(INTERP, dynpmc_LuaBoolean);

+        if (SELF->vtable->base_type == value->vtable->base_type

+         && SELF == value)

+            PMC_int_val(retval) = 1;

+        else

+            PMC_int_val(retval) = 0;

+        return retval;

+    }

+

+/*

+

 =item C<PMC* tonumber()>

 

 =cut


Modified: trunk/languages/lua/pmc/luauserdata.pmc
==============================================================================
--- trunk/languages/lua/pmc/luauserdata.pmc     (original)
+++ trunk/languages/lua/pmc/luauserdata.pmc     Wed Mar  8 23:43:00 2006
@@ -22,6 +22,7 @@
 #include "parrot/parrot.h"

 

 static STRING *luauserdata_name;

+static INTVAL dynpmc_LuaBoolean;

 static INTVAL dynpmc_LuaString;

 

 

@@ -40,23 +41,18 @@
 

             Parrot_LuaBase_super_init(INTERP, NULL);

             luauserdata_name = const_string(INTERP, "userdata");

+            dynpmc_LuaBoolean = pmc_type(INTERP,

+              string_from_const_cstring(INTERP, "LuaBoolean", 0));

             dynpmc_LuaString = pmc_type(INTERP,

               string_from_const_cstring(INTERP, "LuaString", 0));

 

             /* namespace hack */

             meth = Parrot_find_global(INTERP,

                 const_string(INTERP, "LuaUserdata"),

-                const_string(INTERP, "tostring"));

+                const_string(INTERP, "rawequal"));

             Parrot_store_global(INTERP,

                 const_string(INTERP, "userdata"),

-                const_string(INTERP, "tostring"),

-                meth);

-            meth = Parrot_find_global(INTERP,

-                const_string(INTERP, "LuaUserdata"),

-                const_string(INTERP, "tonumber"));

-            Parrot_store_global(INTERP,

-                const_string(INTERP, "userdata"),

-                const_string(INTERP, "tonumber"),

+                const_string(INTERP, "rawequal"),

                 meth);

         }

     }

@@ -143,6 +139,31 @@
         PMC_str_val(SELF) = value;

     }

 

+/*

+

+=back

+

+=head2 Specific Methods

+

+=over 4

+

+=item C<PMC* rawequal (PMC* value)>

+

+=cut

+

+*/

+    METHOD PMC* rawequal (PMC* value) {

+        PMC *retval;

+       

+        retval = pmc_new(INTERP, dynpmc_LuaBoolean);

+        if (SELF->vtable->base_type == value->vtable->base_type

+         && SELF == value)

+            PMC_int_val(retval) = 1;

+        else

+            PMC_int_val(retval) = 0;

+        return retval;

+    }

+

 }

 

 /*


Modified: trunk/languages/lua/t/basic.t
==============================================================================
--- trunk/languages/lua/t/basic.t       (original)
+++ trunk/languages/lua/t/basic.t       Wed Mar  8 23:43:00 2006
@@ -21,7 +21,7 @@
 use FindBin;

 use lib "$FindBin::Bin";

 

-use Parrot::Test tests => 20;

+use Parrot::Test tests => 22;

 use Test::More;

 

 language_output_like( 'lua', << 'CODE', << 'OUTPUT', "function assert(false, 
msg)");

@@ -131,6 +131,48 @@
 /value expected/

 OUTPUT

 

+language_output_is( 'lua', << 'CODE', << 'OUTPUT', "function rawequal (true)");

+t = {}

+a = t

+print(rawequal(nil, nil))

+print(rawequal(false, false))

+print(rawequal(3, 3))

+print(rawequal("text", "text"))

+print(rawequal(t, a))

+-- print(rawequal(print, print))

+CODE

+true

+true

+true

+true

+true

+OUTPUT

+

+language_output_is( 'lua', << 'CODE', << 'OUTPUT', "function rawequal 
(false)");

+t = {}

+print(rawequal(nil, 2))

+print(rawequal(false, true))

+print(rawequal(false, 2))

+print(rawequal(3, 2))

+print(rawequal(3, "2"))

+print(rawequal("text", "2"))

+print(rawequal("text", 2))

+print(rawequal(t, {}))

+print(rawequal(t, 2))

+-- print(rawequal(print, format))

+-- print(rawequal(print, 2))

+CODE

+false

+false

+false

+false

+false

+false

+false

+false

+false

+OUTPUT

+

 language_output_is( 'lua', << 'CODE', << 'OUTPUT', "function rawget");

 t = {a = "letter a", b = "letter b"}

 print(rawget(t, "a"))

Reply via email to