[Gd-chatter] r11064 - in trunk/src: common/common-dylan common/common-dylan/tests common/io common/system d2c/runtime/dylan/tests tools/melange

agent at gwydiondylan.org agent at gwydiondylan.org
Tue Dec 12 08:12:58 CET 2006


Author: agent
Date: Tue Dec 12 08:12:54 2006
New Revision: 11064

Modified:
   trunk/src/common/common-dylan/common-dylan-exports.dylan
   trunk/src/common/common-dylan/common-extensions.dylan
   trunk/src/common/common-dylan/extensions.dylan
   trunk/src/common/common-dylan/tests/functions.dylan
   trunk/src/common/common-dylan/tests/macros.dylan
   trunk/src/common/io/library.dylan
   trunk/src/common/system/library.dylan
   trunk/src/d2c/runtime/dylan/tests/module.dylan
   trunk/src/tools/melange/c-exports.dylan
Log:
Job: gd
Added table() macro to GD common-dylan library common-extensions module.
Not added to OD, because OD has a bug where "define table" gets confused by the
table macro.

The addition of the table macro conflicts with some parameter or local variable
names. In those modules, the table macro was excluded from import. In the
common-extensions module itself, variable names were changed.



Modified: trunk/src/common/common-dylan/common-dylan-exports.dylan
==============================================================================
--- trunk/src/common/common-dylan/common-dylan-exports.dylan	(original)
+++ trunk/src/common/common-dylan/common-dylan-exports.dylan	Tue Dec 12 08:12:54 2006
@@ -219,6 +219,7 @@
 
 #if (~mindy)
   export
+		\table,
     \table-definer,
     \iterate,
     \when;

Modified: trunk/src/common/common-dylan/common-extensions.dylan
==============================================================================
--- trunk/src/common/common-dylan/common-extensions.dylan	(original)
+++ trunk/src/common/common-dylan/common-extensions.dylan	Tue Dec 12 08:12:54 2006
@@ -223,18 +223,18 @@
 end method find-element;
 
 define function fill-table!
-    (table :: <table>, keys-and-elements :: <sequence>)
- => (table :: <table>)
+    (tab :: <table>, keys-and-elements :: <sequence>)
+ => (tab :: <table>)
   let key = #f;
   for (object in keys-and-elements)
     if (key)
-      table[key] := object;
+      tab[key] := object;
       key := #f;
     else
       key := object
     end
   end;
-  table
+  tab
 end function fill-table!;
 
 /*

Modified: trunk/src/common/common-dylan/extensions.dylan
==============================================================================
--- trunk/src/common/common-dylan/extensions.dylan	(original)
+++ trunk/src/common/common-dylan/extensions.dylan	Tue Dec 12 08:12:54 2006
@@ -293,6 +293,25 @@
 
 #if (~mindy)
 
+// Table constructor. Syntax:
+// let my-table = table("red"=>"stop", "green"=>"go");
+// let my-table = table(<string-table>, "red"=>"stop", "green"=>"go");
+define macro table 
+
+	// Matches when optional class included.
+  { table(?table-class:expression, ?table-contents) }
+    => { let ht = make(?table-class); ?table-contents; ht; }
+
+	// Matches without optional class.
+	{ table(?rest:*) } => { table(<table>, ?rest); }
+
+  table-contents:
+  { } => { }
+  { ?key:expression => ?value:expression, ... }
+    => { ht[?key] := ?value; ... }
+end macro table;
+
+
 define macro table-definer
   { define table ?:name ?eq:token { ?keys-and-values } }
     => { define constant ?name :: <table> ?eq make(<table>);

Modified: trunk/src/common/common-dylan/tests/functions.dylan
==============================================================================
--- trunk/src/common/common-dylan/tests/functions.dylan	(original)
+++ trunk/src/common/common-dylan/tests/functions.dylan	Tue Dec 12 08:12:54 2006
@@ -364,14 +364,14 @@
 end function-test subclass;
 
 define common-extensions function-test fill-table! ()
-  let table = make(<table>);
+  let my-table = make(<table>);
   check-equal("fill-table(...) returns the table",
-              fill-table!(table, #[0, "Zero", 1, "One"]),
-              table);
+              fill-table!(my-table, #[0, "Zero", 1, "One"]),
+              my-table);
   check-equal("table(...)[0] = \"Zero\"",
-              table[0], "Zero");
+              my-table[0], "Zero");
   check-equal("table(...)[1] = \"One\"",
-              table[1], "One");
+              my-table[1], "One");
 end function-test fill-table!;
 
 define common-extensions function-test application-name ()

Modified: trunk/src/common/common-dylan/tests/macros.dylan
==============================================================================
--- trunk/src/common/common-dylan/tests/macros.dylan	(original)
+++ trunk/src/common/common-dylan/tests/macros.dylan	Tue Dec 12 08:12:54 2006
@@ -42,6 +42,32 @@
 	       & $test-table[2] == #"two")
 end macro-test table-definer-test;
 
+define common-extensions macro-test table-test ()
+	check-true("table produces correct table",
+		begin
+			let true? = #f;
+			let test-table = table(0 => #"zero", 1 => #"one", 2 => #"two");
+			true? := subtype?(test-table.object-class, <table>)
+					& test-table.size = 3
+					& test-table[0] == #"zero"
+					& test-table[1] == #"one"
+					& test-table[2] == #"two";
+			true?;
+		end);
+	check-true("table with class produces correct table",
+		begin
+			let true? = #f;
+			let test-table = table(<string-table>,
+					"0" => "zero", "1" => "one", "2" => "two");
+			true? := instance?(test-table, <string-table>)
+					& test-table.size = 3
+					& test-table["0"] == "zero"
+					& test-table["1"] == "one"
+					& test-table["2"] == "two";
+			true?;
+		end);
+end macro-test table-test;
+
 define simple-profiling macro-test profiling-test ()
   check-true("profiling macro returns two integer values",
 	     begin

Modified: trunk/src/common/io/library.dylan
==============================================================================
--- trunk/src/common/io/library.dylan	(original)
+++ trunk/src/common/io/library.dylan	Tue Dec 12 08:12:54 2006
@@ -280,7 +280,7 @@
 end module print;
 
 define module print-internals
-  use common-dylan;
+  use common-dylan, exclude: { table };
   use extensions;
   use introspection,
     rename: { subclass-of => subclass-class,

Modified: trunk/src/common/system/library.dylan
==============================================================================
--- trunk/src/common/system/library.dylan	(original)
+++ trunk/src/common/system/library.dylan	Tue Dec 12 08:12:54 2006
@@ -346,7 +346,7 @@
 end module settings-internals;
 
 define module system-internals
-  use common-dylan;
+  use common-dylan, exclude: { table };
   use melange-support;
   use functional-objects-extras;
   use machine-words;

Modified: trunk/src/d2c/runtime/dylan/tests/module.dylan
==============================================================================
--- trunk/src/d2c/runtime/dylan/tests/module.dylan	(original)
+++ trunk/src/d2c/runtime/dylan/tests/module.dylan	Tue Dec 12 08:12:54 2006
@@ -11,7 +11,7 @@
   //use dylan-extensions,
   use dylan;
   use extensions;
-  use common-dylan;
+  use common-dylan, exclude: { table };
   use testworks;
   use testworks-specs;
 

Modified: trunk/src/tools/melange/c-exports.dylan
==============================================================================
--- trunk/src/tools/melange/c-exports.dylan	(original)
+++ trunk/src/tools/melange/c-exports.dylan	Tue Dec 12 08:12:54 2006
@@ -189,7 +189,7 @@
 end module c-parse;
 
 define module c-declarations
-  use common-dylan, exclude: { format-to-string, split };
+  use common-dylan, exclude: { format-to-string, split, table };
   use table-extensions;
   use regular-expressions;
   use streams;



More information about the chatter mailing list