Skip to content

Commit

Permalink
[Builtins] Add new builtins to create some common datastructures. Use…
Browse files Browse the repository at this point in the history
… them in a few places.
  • Loading branch information
Whiteknight committed Mar 31, 2012
1 parent a6217db commit f6d5cf8
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 17 deletions.
2 changes: 2 additions & 0 deletions setup.winxed
Expand Up @@ -59,8 +59,10 @@ function setup_stable_libraries(var rosella)
// The Rosella "core" library. Does very little on its own but is // The Rosella "core" library. Does very little on its own but is
// required by other libraries in the sequence // required by other libraries in the sequence
setup_winxed_lib(rosella, "core", [], setup_winxed_lib(rosella, "core", [],
"core/Includes",
"core/Rosella", "core/Rosella",
"core/Error", "core/Error",
"core/Hash",
"core/Function", "core/Function",
"core/IO", "core/IO",
"core/IteratorBase", "core/IteratorBase",
Expand Down
2 changes: 1 addition & 1 deletion src/container/Container.winxed
Expand Up @@ -36,7 +36,7 @@ class Rosella.Container
// Constructor // Constructor
function Container() function Container()
{ {
self.type_registry = Rosella.get_pmc_keyed_hash(); self.type_registry = pmc_keyed_hash();
self.aliases = {}; self.aliases = {};
} }


Expand Down
2 changes: 1 addition & 1 deletion src/container/LifetimeManager.winxed
Expand Up @@ -76,7 +76,7 @@ class Rosella.Container.LifetimeManager.Thread : Rosella.Container.LifetimeManag


function Thread() function Thread()
{ {
self.lookup = Rosella.get_pmc_keyed_hash(); self.lookup = pmc_keyed_hash();
} }


function has_instance() function has_instance()
Expand Down
2 changes: 1 addition & 1 deletion src/container/ServiceLocator.winxed
Expand Up @@ -4,7 +4,7 @@ class Rosella.Container.ServiceLocator


function ServiceLocator() function ServiceLocator()
{ {
self.registry = Rosella.get_pmc_keyed_hash(); self.registry = pmc_keyed_hash();
} }


function register(var type, var instance) function register(var type, var instance)
Expand Down
13 changes: 13 additions & 0 deletions src/core/Hash.winxed
@@ -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();
}
}
1 change: 1 addition & 0 deletions src/core/Includes.winxed
@@ -0,0 +1 @@

8 changes: 0 additions & 8 deletions src/core/Rosella.winxed
Expand Up @@ -217,13 +217,5 @@ namespace Rosella
yield i; yield i;
} }
} }

// Get a PMC-keyed hash
function get_pmc_keyed_hash()
{
var h = {};
h.set_key_type(3);
return h;
}
} }


2 changes: 1 addition & 1 deletion src/dumper/Dumper.winxed
Expand Up @@ -69,7 +69,7 @@ class Rosella.Dumper
// Get the default set of type dumpers // Get the default set of type dumpers
function default_type_dumpers() function default_type_dumpers()
{ {
var type_dumpers = Rosella.get_pmc_keyed_hash(); var type_dumpers = pmc_keyed_hash();
return type_dumpers; return type_dumpers;
} }


Expand Down
58 changes: 58 additions & 0 deletions src/include/Builtins.winxed
Expand Up @@ -240,6 +240,19 @@ inline get_codepoint(string s, int i) return int
return value; 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 /* Namespaces
*/ */


Expand All @@ -266,3 +279,48 @@ inline get_context() return var
${ get_context cc }; ${ get_context cc };
return 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;
}
2 changes: 1 addition & 1 deletion src/query/iterable/Factory.winxed
Expand Up @@ -28,7 +28,7 @@ class Rosella.Query.Iterable.Factory : Rosella.ObjectFactory


function get_type_map() function get_type_map()
{ {
return Rosella.get_pmc_keyed_hash(); return pmc_keyed_hash();
} }


// Create the provider for the given data // Create the provider for the given data
Expand Down
6 changes: 2 additions & 4 deletions src/unstable/net/MimeBase64.winxed
Expand Up @@ -22,10 +22,8 @@ class Rosella.Net.MimeBase64
if (self.eight_to_six != null && self.six_to_eight != null) if (self.eight_to_six != null && self.six_to_eight != null)
return; return;


var six_to_eight = new 'FixedIntegerArray'; var six_to_eight = fixed_integer_array(64);
six_to_eight =: 64; var eight_to_six = fixed_integer_array(256);
var eight_to_six = new 'FixedIntegerArray';
eight_to_six =: 256;


eight_to_six[0] = 0; eight_to_six[0] = 0;
for (int i = 1; i < 256; i++) for (int i = 1; i < 256; i++)
Expand Down

0 comments on commit f6d5cf8

Please sign in to comment.