Permalink
Browse files

[Builtins] Add new builtins to create some common datastructures. Use…

… them in a few places.
  • Loading branch information...
1 parent a6217db commit f6d5cf83db82f6fcc71dbe29cf1bbd51d3d50fa0 @Whiteknight committed Mar 31, 2012
View
@@ -59,8 +59,10 @@ function setup_stable_libraries(var rosella)
// The Rosella "core" library. Does very little on its own but is
// required by other libraries in the sequence
setup_winxed_lib(rosella, "core", [],
+ "core/Includes",
"core/Rosella",
"core/Error",
+ "core/Hash",
"core/Function",
"core/IO",
"core/IteratorBase",
@@ -36,7 +36,7 @@ class Rosella.Container
// Constructor
function Container()
{
- self.type_registry = Rosella.get_pmc_keyed_hash();
+ self.type_registry = pmc_keyed_hash();
self.aliases = {};
}
@@ -76,7 +76,7 @@ class Rosella.Container.LifetimeManager.Thread : Rosella.Container.LifetimeManag
function Thread()
{
- self.lookup = Rosella.get_pmc_keyed_hash();
+ self.lookup = pmc_keyed_hash();
}
function has_instance()
@@ -4,7 +4,7 @@ class Rosella.Container.ServiceLocator
function ServiceLocator()
{
- self.registry = Rosella.get_pmc_keyed_hash();
+ self.registry = pmc_keyed_hash();
}
function register(var type, var instance)
View
@@ -0,0 +1,13 @@
+namespace Rosella
+{
+ // Get a PMC-keyed hash
+ function get_pmc_keyed_hash()
+ {
+ return pmc_keyed_hash();
+ }
+
+ function get_int_keyed_hash()
+ {
+ return int_keyed_hash();
+ }
+}
@@ -0,0 +1 @@
+
@@ -217,13 +217,5 @@ namespace Rosella
yield i;
}
}
-
- // Get a PMC-keyed hash
- function get_pmc_keyed_hash()
- {
- var h = {};
- h.set_key_type(3);
- return h;
- }
}
@@ -69,7 +69,7 @@ class Rosella.Dumper
// Get the default set of type dumpers
function default_type_dumpers()
{
- var type_dumpers = Rosella.get_pmc_keyed_hash();
+ var type_dumpers = pmc_keyed_hash();
return type_dumpers;
}
@@ -240,6 +240,19 @@ inline get_codepoint(string s, int i) return int
return value;
}
+inline codepoint_is_whitespace(int c) return int
+{
+ return (c <= 0x20 || c >= 127); // Any non-printable characters and all whitespace
+ // We can be more precise, but this is fastest.
+}
+
+inline codepoint_is_alphanumeric(int c) return int
+{
+ return ((c >= 0x30 && c <= 0x39) || // '0' <= c <= '9'
+ (c >= 0x41 && c <= 0x5A) || // 'A' <= c <= 'Z'
+ (c >= 0x61 && c <= 0x7A)); // 'a' <= c <= 'A'
+}
+
/* Namespaces
*/
@@ -266,3 +279,48 @@ inline get_context() return var
${ get_context cc };
return cc;
}
+
+/* Data Structures
+*/
+
+$include_const "hash_key_type.pasm";
+
+inline pmc_keyed_hash() return var
+{
+ var h = new 'Hash';
+ //h =: Hash_key_type_PMC;
+ h.set_key_type(Hash_key_type_PMC);
+ return h;
+}
+
+inline int_keyed_hash() return var
+{
+ var h = new 'Hash';
+ //h =: Hash_key_type_int;
+ h.set_key_type(Hash_key_type_int);
+ return h;
+}
+
+inline fixed_integer_array(int i) return var
+{
+ var a = new 'FixedIntegerArray';
+ //a =: i;
+ ${ assign a, i };
+ return a;
+}
+
+inline fixed_string_array(int i) return var
+{
+ var a = new 'FixedStringArray';
+ //a =: i;
+ ${ assign a, i };
+ return a;
+}
+
+inline fixed_pmc_array(int i) return var
+{
+ var a = new 'FixedPMCArray';
+ //a =: i;
+ ${ assign a, i };
+ return a;
+}
@@ -28,7 +28,7 @@ class Rosella.Query.Iterable.Factory : Rosella.ObjectFactory
function get_type_map()
{
- return Rosella.get_pmc_keyed_hash();
+ return pmc_keyed_hash();
}
// Create the provider for the given data
@@ -22,10 +22,8 @@ class Rosella.Net.MimeBase64
if (self.eight_to_six != null && self.six_to_eight != null)
return;
- var six_to_eight = new 'FixedIntegerArray';
- six_to_eight =: 64;
- var eight_to_six = new 'FixedIntegerArray';
- eight_to_six =: 256;
+ var six_to_eight = fixed_integer_array(64);
+ var eight_to_six = fixed_integer_array(256);
eight_to_six[0] = 0;
for (int i = 1; i < 256; i++)

0 comments on commit f6d5cf8

Please sign in to comment.