Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merge optional_args branch, fix conflicts

  • Loading branch information...
commit 62477478cbb41c1787149b696cd63ed252859e95 2 parents 1b518b2 + a30588d
@Whiteknight authored
Showing with 240 additions and 358 deletions.
  1. +7 −16 src/action/Action.winxed
  2. +2 −2 src/commandline/Arguments.winxed
  3. +4 −9 src/core/IO.winxed
  4. +2 −5 src/core/ObjectFactory.winxed
  5. +2 −3 src/core/Parrot.winxed
  6. +2 −3 src/core/Rosella.winxed
  7. +1 −3 src/dumper/Dumper.winxed
  8. +3 −6 src/filesystem/Directory.winxed
  9. +8 −8 src/filesystem/File.winxed
  10. +9 −11 src/harness/Harness.winxed
  11. +2 −4 src/harness/View.winxed
  12. +11 −11 src/include/Dumper.winxed
  13. +12 −12 src/include/Event.winxed
  14. +14 −14 src/include/Memoize.winxed
  15. +19 −19 src/include/MockObject.winxed
  16. +1 −3 src/memoize/Memoize.winxed
  17. +3 −12 src/proxy/Factory.winxed
  18. +19 −29 src/query/Iterable.winxed
  19. +2 −6 src/query/Provider.winxed
  20. +2 −2 src/query/Query.winxed
  21. +23 −28 src/query/Queryable.winxed
  22. +6 −7 src/query/provider/Array.winxed
  23. +8 −11 src/query/provider/Hash.winxed
  24. +1 −1  src/query/provider/Scalar.winxed
  25. +5 −18 src/string/String.winxed
  26. +1 −4 src/string/Tokenizer.winxed
  27. +3 −8 src/string/tokenizer/CClass.winxed
  28. +1 −3 src/string/tokenizer/DelimiterRegion.winxed
  29. +5 −8 src/template/Engine.winxed
  30. +4 −6 src/template/node/Factory.winxed
  31. +5 −10 src/test/Builder.winxed
  32. +1 −3 src/test/SuiteFactory.winxed
  33. +1 −3 src/test/TestFactory.winxed
  34. +51 −70 src/unstable/prototype/Manager.winxed
View
23 src/action/Action.winxed
@@ -17,18 +17,13 @@ namespace Rosella
/* Constructor
*/
- function Action(var method,
- var args [optional], int has_args [opt_flag])
+ function Action(var method, var args = [])
{
if (method == null)
Rosella.Error.invalid(__FUNCTION__, "Subroutine is null");
self.method = method;
- if (has_args) {
- using Rosella.Action.Argument.verify_all_arguments;
- verify_all_arguments(__FUNCTION__, args);
- self.args = args;
- } else
- self.args = [];
+ Rosella.Action.Argument.verify_all_arguments(__FUNCTION__, args);
+ self.args = args;
}
/* Public Functions
@@ -38,14 +33,12 @@ namespace Rosella
// arguments and a hash of named arguments. In addition to the
// pre-defined Argument objects, take an optional list of Argument
// overrides.
- function prepare_args(var pos, var named,
- var overrides [optional], int has_overrides [opt_flag])
+ function prepare_args(var pos, var named, var overrides = null)
{
for (var arg in self.args)
arg.resolve_to(pos, named);
- if (has_overrides) {
- using Rosella.Action.Argument.verify_all_arguments;
- verify_all_arguments(__FUNCTION__, overrides);
+ if (overrides != null) {
+ Rosella.Action.Argument.verify_all_arguments(__FUNCTION__, overrides);
for (var override in overrides)
override.resolve_to(pos, named);
}
@@ -54,12 +47,10 @@ namespace Rosella
// Execute the action on the given object. Take an optional list of
// Argument overrides to change the default behavior.
function execute(var obj,
- var overrides [optional], int has_overrides [opt_flag])
+ var overrides = [])
{
var pos = [];
var named = {};
- if (!has_overrides)
- overrides = [];
self.prepare_args(pos, named, overrides);
self.execute_initializer(obj, pos, named);
}
View
4 src/commandline/Arguments.winxed
@@ -235,10 +235,10 @@ class Rosella.CommandLine.Arguments
}
// Fetch a positional argument, which may be a flag or anything else.
- function fetch_positional(string name, int keep, int idx [optional], int has_idx [opt_flag])
+ function fetch_positional(string name, int keep, int idx = -1)
{
string arg = "";
- if (has_idx) {
+ if (idx >= 0) {
if (idx >= elements(self.args)) {
self.cache[name] = "";
return "";
View
13 src/core/IO.winxed
@@ -30,9 +30,7 @@ namespace Rosella.IO
return save_handles;
}
- // Execute a callback, capturing all output to the standard output handles
- function capture_output(int together, var func,
- var err_func [optional], int has_err [opt_flag])
+ function capture_output(int together, var func, var err_func = null)
{
var stdout = new "StringHandle";
stdout.open("blah", "rw");
@@ -52,7 +50,7 @@ namespace Rosella.IO
exception = e;
}
swap_handles(save_handles);
- if (exception != null && has_err && err_func != null)
+ if (exception != null && err_func != null)
err_func(exception);
if (together)
return stdout;
@@ -60,15 +58,12 @@ namespace Rosella.IO
return stdout, stderr;
}
- // Execute a commandline command, returning the output text. If the command
- // fails, optionally execute an error handling callback.
- function execute_pipe(string cmd,
- var on_err [optional], int has_err [opt_flag])
+ function execute_pipe(string cmd, var on_err = null)
{
var pipe = open_pipe(cmd);
string output = pipe.readall();
int exit_status = close_pipe(pipe);
- if (exit_status != 0 && has_err && on_err != null)
+ if (exit_status != 0 && on_err != null)
on_err(exit_status);
return output;
}
View
7 src/core/ObjectFactory.winxed
@@ -11,12 +11,9 @@ class Rosella.ObjectFactory
{
var target_type;
- function ObjectFactory(var target_type [optional], int has_type [opt_flag])
+ function ObjectFactory(var target_type = null)
{
- if (has_type)
- self.target_type = target_type;
- else
- self.target_type = null;
+ self.target_type = target_type;
}
// If the default target type is set, call .create_typed with it.
View
5 src/core/Parrot.winxed
@@ -45,10 +45,9 @@ namespace Rosella.Parrot
// Execute a function. Catch any exceptions and print the message and
// backtrace out to a specified handle. If no handle is specified,
// use stdout.
- function try_report(var sub, var handle [optional],
- int has_handle [opt_flag])
+ function try_report(var sub, var handle = null)
{
- if (!has_handle)
+ if (handle == null)
handle = getstdout();
try {
sub();
View
5 src/core/Rosella.winxed
@@ -155,11 +155,10 @@ namespace Rosella
}
// Load in the bytecode library, executing the given trigger, if any.
- function load_bytecode_file(string file,
- string trigger [optional], int has_trigger [opt_flag])
+ function load_bytecode_file(string file, string trigger = null)
{
var pf = load_packfile(file);
- if (has_trigger && trigger != "" && trigger != null)
+ if (trigger != "" && trigger != null)
init_bytecode(pf, trigger);
return pf;
}
View
4 src/dumper/Dumper.winxed
@@ -83,10 +83,8 @@ class Rosella.Dumper
}
// Add a new type dumper to the list
- function add_type_dumper(var type, var dumper [optional], int has_dumper [opt_flag])
+ function add_type_dumper(var type, var dumper = new Rosella.Dumper.DumpHandler())
{
- if (!has_dumper)
- dumper = new Rosella.Dumper.DumpHandler();
self.type_dumpers[type] = dumper;
}
View
9 src/filesystem/Directory.winxed
@@ -17,7 +17,7 @@ namespace Rosella.FileSystem.Directory
class Rosella.FileSystem.Directory : Rosella.FileSystem.Entry
{
// Constructor. Build a directory with the given path name
- function Directory(string path, var parent_dir [optional], int has_parent [opt_flag])
+ function Directory(string path, var parent_dir = null)
{
if (path == null || path == "")
Rosella.Error.error("Directory needs a valid path");
@@ -27,7 +27,7 @@ class Rosella.FileSystem.Directory : Rosella.FileSystem.Entry
string lastchar = substr(path, len - 1);
if (lastchar != path_sep)
path = path + path_sep;
- if (has_parent)
+ if (parent_dir != null)
path = string(parent_dir) + path;
self.Entry(path);
}
@@ -72,11 +72,8 @@ class Rosella.FileSystem.Directory : Rosella.FileSystem.Entry
}
// Walk this directory recursively using a Visitor object.
- function walk(var visitor [optional], int has_v [opt_flag])
+ function walk(var visitor = new Rosella.FileSystem.Visitor.List())
{
- if (!has_v)
- visitor = new Rosella.FileSystem.Visitor.List();
-
visitor.begin_directory(self);
var files = self.get_files();
for (var file in files)
View
16 src/filesystem/File.winxed
@@ -31,20 +31,20 @@ namespace Rosella.FileSystem.File
class Rosella.FileSystem.File : Rosella.FileSystem.Entry
{
// Constructor
- function File(string filepath, var parent_dir [optional], int has_dir [opt_flag])
+ function File(string filepath, var parent_dir = null)
{
- if (has_dir)
+ if (parent_dir != null)
filepath = string(parent_dir) + filepath;
self.Entry(filepath);
}
// Open the file for reading, returning the open FileHandle. The user
// must close the filehandle themselves.
- function open_read(string encoding [optional], int has_e [opt_flag])
+ function open_read(string encoding = null)
{
int is_binary = 0;
var filehandle = get_filehandle();
- if (has_e) {
+ if (encoding != null) {
string mode = (encoding == "binary") ? "rb" : "r";
filehandle.open(self.path, mode);
filehandle.encoding(encoding);
@@ -55,10 +55,10 @@ class Rosella.FileSystem.File : Rosella.FileSystem.Entry
// Open the file for writing, returning the open FileHandle. The user
// must close the FileHandle themselves.
- function open_write(string encoding [optional], int has_e [opt_flag])
+ function open_write(string encoding = null)
{
var filehandle = get_filehandle();
- if (has_e) {
+ if (encoding != null) {
string mode = (encoding == "binary") ? "wb" : "w";
filehandle.open(self.path, mode);
filehandle.encoding(encoding);
@@ -76,10 +76,10 @@ class Rosella.FileSystem.File : Rosella.FileSystem.Entry
}
// Return all text from the file in a single string.
- function read_all_text(string encoding [optional], int has_e [opt_flag])
+ function read_all_text(string encoding = null)
{
var filehandle;
- if (has_e && encoding != null)
+ if (encoding != null)
filehandle = self.open_read(encoding);
else
filehandle = self.open_read();
View
20 src/harness/Harness.winxed
@@ -60,11 +60,14 @@ class Rosella.Harness
return self;
}
+ function set_view(var view)
+ {
+ self.view = view;
+ }
+
// Set a view to use
- function view(var view [optional], int has_view [opt_flag])
+ function view()
{
- if (has_view)
- self.view = view;
if (self.view == null)
self.view = new Rosella.Harness.View();
return self.view;
@@ -90,11 +93,8 @@ class Rosella.Harness
}
// Return the current test run
- function setup_test_run(var view [optional], int has_view [opt_flag],
- var options [named,slurpy])
+ function setup_test_run(var view = self.view(), var options [named,slurpy])
{
- if (!has_view || view == null)
- view = self.view();
var run = self.testrun_factory.create(options:[flat,named]);
view.add_run(run, 0);
push(self.saved_runs, run);
@@ -111,7 +111,7 @@ class Rosella.Harness
*/
// Run the harness. Get argument values and pass them to run_internal
- function run(var test_runs [optional], int has_runs [opt_flag],
+ function run(var test_runs = self.saved_runs,
var test_executor [named,optional], int has_te [opt_flag],
int debug [named,optional], int has_dbg [opt_flag])
{
@@ -119,9 +119,7 @@ class Rosella.Harness
test_executor = self.container.resolve(class Rosella.Harness.TestExecutor);
if (!has_dbg)
debug = 0;
- if (has_runs == false || test_runs == null || elements(test_runs) == 0)
- test_runs = self.saved_runs;
- else if (has_runs == true && test_runs instanceof Rosella.Harness.TestRun)
+ if (test_runs instanceof Rosella.Harness.TestRun)
test_runs = [test_runs];
var fileresult_factory = self.container.resolve(class Rosella.Harness.FileResult.Factory);
View
6 src/harness/View.winxed
@@ -17,11 +17,9 @@ class Rosella.Harness.View
var need_backspaces;
// Constructor
- function View(var handle [optional], int has_h [opt_flag])
+ function View(var handle = null)
{
- if (!has_h)
- handle = getstdout();
- self.handle = handle;
+ self.handle = handle == null ? getstdout() : handle;
self.test_runs = [];
self.line_length = 0;
self.total_files = 0;
View
22 src/include/Dumper.winxed
@@ -1,21 +1,21 @@
namespace Rosella.Dumper {
- class DumpHandler;
- class Emitter;
- class Handle;
- extern function default_dumper;
- extern function set_default_dumper;
+ class DumpHandler;
+ class Emitter;
+ class Handle;
+ extern function default_dumper;
+ extern function set_default_dumper;
}
namespace Rosella {
- class Dumper;
+ class Dumper;
}
namespace Rosella.Dumper.DumpHandler {
- class Array;
- class Hash;
- class InspectAttrs;
- class Object;
- class Null;
+ class Array;
+ class Hash;
+ class InspectAttrs;
+ class Object;
+ class Null;
}
function __include_dumper [anon] ()
View
24 src/include/Event.winxed
@@ -1,25 +1,25 @@
namespace Rosella.Event {
- class Dispatcher;
- class Manager;
- class Payload;
- class Subscriber;
- extern function default_subscriber_factory;
- extern function payload_factory;
+ class Dispatcher;
+ class Manager;
+ class Payload;
+ class Subscriber;
+ extern function default_subscriber_factory;
+ extern function payload_factory;
}
namespace Rosella {
- class Event;
+ class Event;
}
namespace Rosella.Event.Dispatcher {
- class Immediate;
- class Task;
- class Thread;
- class Factory;
+ class Immediate;
+ class Task;
+ class Thread;
+ class Factory;
}
namespace Rosella.Event.Subscriber {
- class Factory;
+ class Factory;
}
function __include_event [anon] ()
View
28 src/include/Memoize.winxed
@@ -1,21 +1,21 @@
namespace Rosella.Memoize {
- class Cache;
- class Controller;
- class Factory;
- extern function memoize;
- extern function Y;
- extern function memoize_proxy;
- extern function proxy_cache;
- extern function proxy_function;
- extern function is_memoize_proxy;
- extern function memoize_method;
- extern function unmemoize_method;
- extern function private_get_memoize_factory;
+ class Cache;
+ class Controller;
+ class Factory;
+ extern function memoize;
+ extern function Y;
+ extern function memoize_proxy;
+ extern function proxy_cache;
+ extern function proxy_function;
+ extern function is_memoize_proxy;
+ extern function memoize_method;
+ extern function unmemoize_method;
+ extern function private_get_memoize_factory;
}
namespace Rosella.Memoize.Cache {
- class Item;
- class SimpleString;
+ class Item;
+ class SimpleString;
}
function __include_memoize [anon] ()
View
38 src/include/MockObject.winxed
@@ -1,35 +1,35 @@
namespace Rosella.MockObject {
- class Controller;
- class Expectation;
- class Factory;
- extern function default_mock_factory;
- extern function set_default_mock_factory;
- extern function get_controller;
+ class Controller;
+ class Expectation;
+ class Factory;
+ extern function default_mock_factory;
+ extern function set_default_mock_factory;
+ extern function get_controller;
}
namespace Rosella.MockObject.Controller {
- class Ordered;
+ class Ordered;
}
namespace Rosella.MockObject.Expectation {
- class Get;
- class Set;
- class Method;
- class Invoke;
- class Will;
- class With;
+ class Get;
+ class Set;
+ class Method;
+ class Invoke;
+ class Will;
+ class With;
}
namespace Rosella.MockObject.Expectation.Will {
- class Return;
- class Throw;
- class Do;
+ class Return;
+ class Throw;
+ class Do;
}
namespace Rosella.MockObject.Expectation.With {
- class Args;
- class Any;
- class None;
+ class Args;
+ class Any;
+ class None;
}
function __include_mockobject [anon] ()
View
4 src/memoize/Memoize.winxed
@@ -21,10 +21,8 @@ namespace Rosella.Memoize
// Create a simple memoizer. In the simple case, the user cannot get
// access to the cache or the memoized function after the memoizer has
// been created
- function memoize(var func, var cache [optional], int has_cache [opt_flag])
+ function memoize(var func, var cache = new Rosella.Memoize.Cache.SimpleString())
{
- if (!has_cache)
- cache = new Rosella.Memoize.Cache.SimpleString();
var _cache = cache;
var f = func;
View
15 src/proxy/Factory.winxed
@@ -41,12 +41,8 @@ class Rosella.Proxy.Factory : Rosella.ObjectFactory
// little bit of other metadata on it. Execute all the builders on it
// for any per-instance settings that need to be changed, and then
// tell the controller to initialize it. p and n are unused
- function create(var controller,
- var target [optional], int has_target [opt_flag],
- var p [slurpy], var n [slurpy,named])
+ function create(var controller, var target = null, var p [slurpy], var n [slurpy,named])
{
- if (!has_target)
- target = null;
var proxy_class = self.get_proxy_class_for();
return self.create_proxy_internal(proxy_class, controller, target);
}
@@ -56,19 +52,14 @@ class Rosella.Proxy.Factory : Rosella.ObjectFactory
// The same list of builders is executed on the new proxy class and
// the new proxy.
function create_typed(var target_type, var controller,
- var target [optional], int has_target [opt_flag],
- var p [slurpy], var n [slurpy,named])
+ var target = null, var p [slurpy], var n [slurpy,named])
{
- if (!has_target)
- target = null;
var proxy_class = self.get_proxy_class_for(target_type);
return self.create_proxy_internal(proxy_class, controller, target);
}
- function get_proxy_class_for(var target_type [optional], int has_type [opt_flag])
+ function get_proxy_class_for(var target_type = self.target_type)
{
- if (!has_type)
- target_type = self.target_type;
var target_class = Rosella.get_type_class(target_type);
string type_name = Rosella.get_type_name(target_type);
if (exists self.proxy_classes[type_name])
View
48 src/query/Iterable.winxed
@@ -116,8 +116,7 @@ class Rosella.Query.Iterable : Rosella.IteratorBase
// Read the source to exhaustion, returning all results as a hash. Takes a
// function reference used to generate the hash key and optionally a
// function reference to generate the data
- function to_hash(var key_f [optional], int has_kf [opt_flag],
- var value_f [optional], int has_vf [opt_flag])
+ function to_hash(var key_f = null, var value_f = null)
{
var d = {};
if (!self.has_more())
@@ -125,7 +124,7 @@ class Rosella.Query.Iterable : Rosella.IteratorBase
:(var v, int m) = self.next_and_more();
- if (!has_kf) {
+ if (key_f == null) {
if (v instanceof Rosella.Query.Iterable.KeyValuePair) {
do {
d[v.key()] = v.value();
@@ -143,7 +142,7 @@ class Rosella.Query.Iterable : Rosella.IteratorBase
var key = key_f(v);
- if (has_vf) {
+ if (value_f != null) {
d[key] = value_f(v);
while (m == true) {
:(v, m) = self.next_and_more();
@@ -234,27 +233,21 @@ class Rosella.Query.Iterable : Rosella.IteratorBase
// Take only the first N items in the sequence, or the first N items which
// satisfy the optional predicate
- function take(int count, var f [optional], int has_f [opt_flag])
+ function take(int count, var f = null)
{
- if (!has_f)
- f = null;
return new Rosella.Query.Iterable.TakeSkip(self, f, count, 0);
}
// Skip the first N items in the sequence, or the first N items which
// satisfy the optional predicate
- function skip(int count, var f [optional], int has_f [opt_flag])
+ function skip(int count, var f = null)
{
- if (!has_f)
- f = null;
return new Rosella.Query.Iterable.TakeSkip(self, f, -1, count);
}
// Flatten the data source completely
- function flatten(int levels [optional], int has_levels [opt_flag])
+ function flatten(int levels = -1)
{
- if (!has_levels)
- levels = -1;
return new Rosella.Query.Iterable.Flatten(self, -1);
}
@@ -272,21 +265,18 @@ class Rosella.Query.Iterable : Rosella.IteratorBase
// Read all the data into an array, sort the array, and return a new
// iterator for it.
- function sort(var f [optional], int has_f [opt_flag],
- int is_sorted [optional], int has_is [opt_flag])
+ function sort(var f = null, int is_sorted = false)
{
- if (!has_is)
- is_sorted = false;
- if (!has_f)
+ if (f == null)
f = Rosella.Query.Sort.get_default_comparer();
return new Rosella.Query.Iterable.Sort(self, f, is_sorted);
}
// Read all the data into an array and perform a schwartzian transform sort
// on the array. Return a new iterator for the result.
- function cache_sort(var get_key, var compare_key [optional], int has_comparer [opt_flag])
+ function cache_sort(var get_key, var compare_key = null)
{
- if (!has_comparer)
+ if (compare_key == null)
compare_key = Rosella.Query.get_default_comparer();
return self
.map(function(i) { return [get_key(i), i]; })
@@ -314,13 +304,13 @@ class Rosella.Query.Iterable : Rosella.IteratorBase
// Read all the data, counting items. If provided, only data items matching
// the optional predicate are counted.
- function count(var f [optional], int has_f [opt_flag])
+ function count(var f = null)
{
if (!self.has_more())
return 0;
int i = 0;
- if (has_f) {
+ if (f != null) {
:(var v, int m) = self.next_and_more();
if (f(v))
i++;
@@ -343,12 +333,12 @@ class Rosella.Query.Iterable : Rosella.IteratorBase
// Return true if the iterator contains any items, false otherwise. If
// provided, return true only if any data items match the given predicate.
- function any(var f [optional], int has_f [opt_flag])
+ function any(var f = null)
{
if (!self.has_more())
return false;
:(var v, int m) = self.next_and_more();
- if (has_f) {
+ if (f != null) {
if (f(v))
return true;
while (m == true) {
@@ -365,7 +355,7 @@ class Rosella.Query.Iterable : Rosella.IteratorBase
// Expect the iterator to contain exactly one item, and return that. If
// given, expect the iterator to contain exactly one item matching the
// optional predicate and return that item.
- function single(var f [optional], int has_f [opt_flag])
+ function single()
{
if (!self.has_more())
self.__empty();
@@ -378,11 +368,11 @@ class Rosella.Query.Iterable : Rosella.IteratorBase
// Return the first item in the iterator (or the first item matching the
// optional predicate). Throw an error if the iterator contains no suitable
// items to return.
- function first(var f [optional], int has_f [opt_flag])
+ function first(var f = null)
{
if (!self.has_more())
self.__empty();
- if (has_f) {
+ if (f != null) {
:(var d, int m) = self.next_and_more();
if (f(d))
return d;
@@ -400,14 +390,14 @@ class Rosella.Query.Iterable : Rosella.IteratorBase
// Return the first item in the iterator or the first item matching the
// optional predicate. Return a default value (null, usually) if no matching
// items are found.
- function first_or_default(var f [optional], int has_f [opt_flag],
+ function first_or_default(var f = null,
var def [named("default"),optional], int has_def [opt_flag])
{
if (!has_def)
def = null;
if (!self.has_more())
return def;
- if (has_f) {
+ if (f != null) {
:(var d, int m) = self.next_and_more();
if (f(d))
return d;
View
8 src/query/Provider.winxed
@@ -58,8 +58,7 @@ class Rosella.Query.Provider
}
// Filter the data
- function filter(var data, var func,
- int limit [optional], int has_limit [opt_flag])
+ function filter(var data, var func, int limit = 0)
{
Rosella.Error.must_subclass(__CLASS__);
}
@@ -132,10 +131,7 @@ class Rosella.Query.Provider
}
// Combine two aggregates
- function combine(var a, var b,
- var filter [optional], int has_filter [opt_flag],
- var key_func [optional], int has_key_func [opt_flag],
- var dispute [optional], int has_dispute [opt_flag])
+ function combine(var a, var b, var filter = null, var key_func = null, var dispute = null)
{
Rosella.Error.must_subclass(__CLASS__);
}
View
4 src/query/Query.winxed
@@ -79,10 +79,10 @@ namespace Rosella.Query
// Sort an array in-place. Optionally take a comparison function and a
// hint flag that says whether the array should be considered already
// mostly-sorted or mostly-reverse-sorted
- function sort_array(var d, var cmp [optional], int has_cmp [opt_flag],
+ function sort_array(var d, var cmp = null,
int is_sorted [optional,named], int has_is [opt_flag])
{
- if (!has_cmp || cmp == null)
+ if (cmp == null)
cmp = Rosella.Query.Sort.get_default_comparer();
if (has_is && is_sorted)
Rosella.Query.Sort.timsort(d, cmp);
View
51 src/query/Queryable.winxed
@@ -12,12 +12,10 @@ class Rosella.Query.Queryable
// Constructor. Store the data and get a suitable provider. It is
// probably better to use Rosella.Query.as_queryable instead of
// creating this directly.
- function Queryable(var data, var factory [optional], int has_f [opt_flag])
+ function Queryable(var data, var factory = null)
{
self.data = data;
- if (!has_f)
- factory = Rosella.Query.default_provider_factory();
- self.factory = factory;
+ self.factory = factory == null ? Rosella.Query.default_provider_factory() : factory;
self.provider = factory.create(data);
}
@@ -91,10 +89,8 @@ class Rosella.Query.Queryable
// Combine elements from the aggregate into a single value and
// return that.
- function fold(var func, var seed [optional], int has_seed [opt_flag])
+ function fold(var func, var seed = null)
{
- if (!has_seed)
- seed = null;
var value = self.provider.fold(seed, self.data, func);
return self.as_queryable(value);
}
@@ -102,18 +98,18 @@ class Rosella.Query.Queryable
// Sort the data using a given comparison routine. The data is not sorted
// in place, but instead a new array is created for the data and the new
// array is sorted (the old one is left as it was)
- function sort(var func [optional], int has_func [opt_flag])
+ function sort(var func = null)
{
- if (!has_func)
+ if (func == null)
func = Rosella.Query.get_default_comparer();
var result = self.provider.sort(self.data, func);
return self.as_queryable(result);
}
// Sort the data in place. Do not create a copy.
- function sort_self(var func [optional], int has_func [opt_flag])
+ function sort_self(var func = null)
{
- if (!has_func)
+ if (func == null)
func = Rosella.Query.get_default_comparer();
self.provider.sort_self(self.data, func);
return self;
@@ -122,9 +118,9 @@ class Rosella.Query.Queryable
// Schwartzian transform. Sort complex data using a derived key for each
// element. Cache the computed key values so we aren't recreating them for
// each comparison
- function cache_sort(var get_key, var compare_key [optional], int has_comparer [opt_flag])
+ function cache_sort(var get_key, var compare_key = null)
{
- if (!has_comparer)
+ if (compare_key == null)
compare_key = Rosella.Query.get_default_comparer();
var d = self
.map(function(x) { return [get_key(x), x]; })
@@ -144,57 +140,56 @@ class Rosella.Query.Queryable
}
// Return a count of elements
- function count(var func [optional], int has_func [opt_flag])
+ function count(var func = null)
{
- return self.provider.count(self.data, has_func ? func : null);
+ return self.provider.count(self.data, func);
}
// Return true if any element in the aggregate satisfies the predicate
// false otherwise. Short-circuits
- function any(var func [optional], int has_func [opt_flag])
+ function any(var func = null)
{
- return self.provider.any(self.data, has_func ? func : null);
+ return self.provider.any(self.data, func);
}
// Return the first item in the aggregate if the aggregate contains
// only one item. If it contains more items, throw an exception
- function single(var func [optional], int has_func [opt_flag])
+ function single(var func = null)
{
- var data = self.provider.single(self.data, has_func ? func : null);
+ var data = self.provider.single(self.data, null);
return self.as_queryable(data);
}
// Return the first item in the aggregate, throwing an exception if
// it is empty.
- function first(var func [optional], int has_func [opt_flag])
+ function first(var func = null)
{
- var data = self.provider.first(self.data, has_func ? func : null);
+ var data = self.provider.first(self.data, func);
return self.as_queryable(data);
}
// Return the first item in the aggregate, returning a default value
// if empty
- function first_or_default(var func [optional], int has_func [opt_flag],
- var def [optional], int has_def [opt_flag])
+ function first_or_default(var func = null, var def = null)
{
- var data = self.provider.first_or_default(self.data, has_func ? func : null, has_def ? def : null);
+ var data = self.provider.first_or_default(self.data, func, def);
return self.as_queryable(data);
}
// Return an aggregate of the first N elements in the data. If a
// predicate is provided, return the first N which satisfy the
// prediate
- function take(int count, var func [optional], int has_func [opt_flag])
+ function take(int count, var func = null)
{
- var data = self.provider.take(self.data, count, has_func ? func : null);
+ var data = self.provider.take(self.data, count, func);
return self.as_queryable(data);
}
// Return all but the first N elements. If a predicate is provided,
// return all by the first N elements which satisfy the predicate.
- function skip(int count, var func [optional], int has_func [opt_flag])
+ function skip(int count, var func = null)
{
- var data = self.provider.skip(self.data, count, has_func ? func : null);
+ var data = self.provider.skip(self.data, count, func);
return self.as_queryable(data);
}
View
13 src/query/provider/Array.winxed
@@ -30,10 +30,9 @@ class Rosella.Query.Provider.Array : Rosella.Query.Provider
// Return a new array with only the elements from the original array
// which satisfy the predicate. If provided, only return up to N items
- function filter(var data, var func,
- int limit [optional], int has_limit [opt_flag])
+ function filter(var data, var func, int limit = -1)
{
- if (!has_limit)
+ if (limit < 0)
limit = elements(data);
var new_data = [];
if (limit <= 0)
@@ -87,15 +86,15 @@ class Rosella.Query.Provider.Array : Rosella.Query.Provider
// Combine
function combine(var a, var b,
- var filter [optional], int has_filter [opt_flag],
- var key_func [optional], int has_key_func [opt_flag],
+ var filter = null,
+ var key_func = null,
var dispute [optional], int has_dispute [opt_flag])
{
- if (has_filter) {
+ if (filter != null) {
a = self.filter(a, filter);
b = self.filter(b, filter);
}
- if (has_key_func) {
+ if (key_func != null) {
if (!has_dispute)
dispute = function (data_a, data_b) { return data_a; };
return self.join_key(a, b, key_func, dispute);
View
19 src/query/provider/Hash.winxed
@@ -27,10 +27,9 @@ class Rosella.Query.Provider.Hash : Rosella.Query.Provider
// Return a new hash with the key/value pairs that satisfy the
// predicate
- function filter(var data, var func,
- int limit [optional], int has_limit [opt_flag])
+ function filter(var data, var func, int limit = -1)
{
- if (!has_limit)
+ if (limit < 0)
limit = elements(data);
var new_data = {};
int count = 0;
@@ -105,19 +104,17 @@ class Rosella.Query.Provider.Hash : Rosella.Query.Provider
}
// Combine
- function combine(var a, var b,
- var filter [optional], int has_filter [opt_flag],
- var key_func [optional], int has_key_func [opt_flag],
- var dispute [optional], int has_dispute [opt_flag])
+ function combine(var a, var b, var filter = null, var key_func = null,
+ var dispute = null)
{
- if (has_filter) {
+ if (filter != null) {
a = self.filter(a, filter);
b = self.filter(b, filter);
}
- if (!has_dispute)
+ if (dispute == null)
dispute = function(key, data_a, data_b) { return data_a; };
- if (has_key_func)
- Rosella.Error.error("Cannot combine hashes by keys");
+ if (key_func == null)
+ Rosella.Error.invalid(__FUNCTION__, "Cannot combine hashes by keys");
var new_data = {};
var conflict = 0;
View
2  src/query/provider/Scalar.winxed
@@ -24,7 +24,7 @@ class Rosella.Query.Provider.Scalar : Rosella.Query.Provider
// Return the scalar if it matches, null otherwise
function filter(var data, var func,
- int limit [optional], int has_limit [opt_flag])
+ int limit = 1)
{
if (func(data))
return data;
View
23 src/string/String.winxed
@@ -58,11 +58,8 @@ namespace Rosella.String
// Trim items off the start of the string that match the given cclass.
// defaults to CCLASS_WHITESPACE
- function trim_start(string str, int cclass [optional], int has_cclass [opt_flag])
+ function trim_start(string str, int cclass = CCLASS_WHITESPACE)
{
- if (!has_cclass)
- cclass = CCLASS_WHITESPACE;
-
int idx = first_not_cclass(str, cclass);
if (idx == -1)
return "";
@@ -88,11 +85,8 @@ namespace Rosella.String
// Trim items off the end of the string which match the given cclass.
// defaults to CCLASS_WHITESPACE
- function trim_end(string str, int cclass [optional], int has_cclass [opt_flag])
+ function trim_end(string str, int cclass = CCLASS_WHITESPACE)
{
- if (!has_cclass)
- cclass = CCLASS_WHITESPACE;
-
int len = length(str);
int idx = last_not_cclass(str, cclass);
@@ -111,10 +105,8 @@ namespace Rosella.String
// Trim characters from both the start and end of the string which
// match the given character class. Defaults to CCLASS_WHITESPACE
- function trim(string str, int cclass [optional], int has_cclass [opt_flag])
+ function trim(string str, int cclass = CCLASS_WHITESPACE)
{
- if (!has_cclass)
- cclass = CCLASS_WHITESPACE;
int start_idx = first_not_cclass(str, cclass);
if (start_idx == -1)
return "";
@@ -147,11 +139,8 @@ namespace Rosella.String
// Pad the start of the string with the given substring. Default
// pad is " "
- function pad_start(string str, int total_width,
- string char [optional], int has_char [opt_flag])
+ function pad_start(string str, int total_width, string char = " ")
{
- if (!has_char)
- char = " ";
string pad = __create_pad(str, total_width, char);
return pad + str;
}
@@ -159,10 +148,8 @@ namespace Rosella.String
// Pad the end of the string with the given substring. Default
// pad is " "
function pad_end(string str, int total_width,
- string char [optional], int has_char [opt_flag])
+ string char = " ")
{
- if (!has_char)
- char = " ";
string pad = __create_pad(str, total_width, char);
return str + pad;
}
View
5 src/string/Tokenizer.winxed
@@ -127,8 +127,7 @@ class Rosella.String.Tokenizer
// Helper routine. Get the first n characters from the front of the
// input data.
- function __get_chars(int count,
- int skip [optional], int has_skip [opt_flag])
+ function __get_chars(int count, int skip = 0)
{
string str = self.data;
int len = length(str);
@@ -136,8 +135,6 @@ class Rosella.String.Tokenizer
self.data = null;
return str;
}
- if (!has_skip)
- skip = 0;
self.data = substr(str, count + skip);
return substr(str, 0, count);
}
View
11 src/string/tokenizer/CClass.winxed
@@ -17,10 +17,8 @@ namespace Rosella.String.Tokenizer.CClass
// From the provided list, determine the first character class that
// matches the first character in the string
- function __get_first_cclass(string str, var cclasses [optional], int has_cclasses [opt_flag])
+ function __get_first_cclass(string str, var cclasses = __get_default_cclasses())
{
- if (!has_cclasses || cclasses == null)
- cclasses = __get_default_cclasses();
int num_classes = elements(cclasses);
for (int i = 0; i < num_classes; i++) {
int cclass = cclasses[i];
@@ -39,15 +37,12 @@ class Rosella.String.Tokenizer.CClass : Rosella.String.Tokenizer
var cclasses; // Array of CCLASS identifiers to search for.
// Constructor
- function CClass(var cclasses [optional], int has_cclasses [opt_flag])
+ function CClass(var cclasses = __get_default_cclasses())
{
self.Tokenizer();
self.tokens = [];
self.data = null;
- if (has_cclasses)
- self.cclasses = cclasses;
- else
- self.cclasses = __get_default_cclasses();
+ self.cclasses = cclasses;
}
// Lex a new token
View
4 src/string/tokenizer/DelimiterRegion.winxed
@@ -12,12 +12,10 @@ class Rosella.String.Tokenizer.DelimiterRegion : Rosella.String.Tokenizer
var default_key; // The key to use for tokens which are not in a region
// Constructor
- function DelimiterRegion(var default_key [optional], int has_key [opt_flag])
+ function DelimiterRegion(var default_key = null)
{
self.Tokenizer();
self.regions = [];
- if (!has_key)
- default_key = null;
self.default_key = default_key;
}
View
13 src/template/Engine.winxed
@@ -112,7 +112,8 @@ class Rosella.Template.Engine
return self.__generate_internal(tmpl, context);
}
- function compile_to_winxed(string tmpl, var builder [optional], int has_builder [opt_flag], int recurse [named,optional], int has_recurse [opt_flag])
+
+ function compile_to_winxed(string tmpl, var builder = new 'StringBuilder', int recurse [named,optional], int has_recurse [opt_flag])
{
if (int(self.recurse_level) == 0)
return;
@@ -125,18 +126,14 @@ class Rosella.Template.Engine
self.setup_region_types(tokenizer, node_factory);
var nodes_array = self.__get_nodes_array(tokenizer, node_factory, tmpl);
var node = self.__create_node_tree(nodes_array);
- if (!has_builder)
- builder = new ['StringBuilder'];
node.*(recurse ? "to_winxed_recurse" : "to_winxed")(self, builder);
self.recurse_level++;
return string(builder);
}
- function compile_to_winxed_from_file(string filename, var builder [optional], int has_builder [opt_flag], int recurse [named,optional], int has_recurse [opt_flag])
+ function compile_to_winxed_from_file(string filename, var builder = new 'StringBuilder', int recurse [named,optional], int has_recurse [opt_flag])
{
string tmpl = self.__get_template_from_file(filename);
- if (!has_builder)
- builder = new ['StringBuilder'];
if (!has_recurse)
recurse = 0;
return self.compile_to_winxed(tmpl, builder, recurse:[named("recurse")]);
@@ -149,10 +146,10 @@ class Rosella.Template.Engine
return wx.compile(wx_code)[0];
}
- function compile_from_file(string filename, var builder [optional], int has_builder [opt_flag], int recurse [named,optional], int has_recurse [opt_flag])
+ function compile_from_file(string filename, var builder = new 'StringBuilder', int recurse [named,optional], int has_recurse [opt_flag])
{
string tmpl = self.__get_template_from_file(filename);
- return self.compile(tmpl);
+ return self.compile(tmpl, builder);
}
/* Private Helper Methods
View
10 src/template/node/Factory.winxed
@@ -16,11 +16,10 @@ class Rosella.Template.Node.Factory : Rosella.ObjectFactory
// Register a new node type, with a key and optionally a list of the
// kinds of handlers that node can use.
- function register_type(string key, var type,
- var handlers [optional], int has_handlers [opt_flag])
+ function register_type(string key, var type, var handlers = null)
{
self.types[key] = Rosella.get_type_class(type);
- if (has_handlers)
+ if (handlers != null)
self.handler_factories[key] = new Rosella.Template.Handler.Factory(handlers);
}
@@ -38,11 +37,10 @@ class Rosella.Template.Node.Factory : Rosella.ObjectFactory
}
// Create a Node given the type.
- function create_typed(var type_class, var token,
- var handler_factory [optional], int has_factory [opt_flag])
+ function create_typed(var type_class, var token, var handler_factory = null)
{
var node;
- if (has_factory)
+ if (handler_factory != null)
node = Rosella.construct(type_class, token.data(), token.metadata(), handler_factory);
else
node = Rosella.construct(type_class, token.data(), token.metadata());
View
15 src/test/Builder.winxed
@@ -12,12 +12,12 @@ class Rosella.Test.Builder
var nest_level; // The level of TAP nesting
// Constructor
- function Builder(int nest_level, var output [optional], int has_out [opt_flag])
+ function Builder(int nest_level, var output = null)
{
+ if (output == null)
+ output = getstdout();
self.test_number = 0;
self.nest_level = nest_level;
- if (!has_out)
- output = getstdout();
self.output = output;
}
@@ -37,23 +37,18 @@ class Rosella.Test.Builder
// Display a todo result. pass=1 means an unexpected pass. pass=0 is
// an expected failure
- function todo(int pass, string msg,
- string todo [optional], int has_todo [opt_flag])
+ function todo(int pass, string msg, string todo = "")
{
self.test_number = self.test_number + 1;
string output = self._get_result_text(self.test_number, pass, msg);
- if (!has_todo)
- todo = "";
self._printf("%s # TODO %s\n", output, todo);
}
// Display a normal result. pass=1 is an expected test pass. pass=0
// is an unexpected failure
- function ok(int pass, string msg [optional], int has_msg [opt_flag])
+ function ok(int pass, string msg = null)
{
self.test_number = self.test_number + 1;
- if (!has_msg)
- msg = null;
string result_text = self._get_result_text(self.test_number, pass, msg);
self._printf("%s\n", result_text);
}
View
4 src/test/SuiteFactory.winxed
@@ -5,10 +5,8 @@
class Rosella.Test.SuiteFactory : Rosella.ObjectFactory
{
// Constructor. Take the test proto object and a few other options
- function SuiteFactory(var suite_type [optional], int has_suite_type [opt_flag])
+ function SuiteFactory(var suite_type = class Rosella.Test.Suite)
{
- if (!has_suite_type)
- suite_type = class Rosella.Test.Suite;
self.target_type = suite_type;
}
View
4 src/test/TestFactory.winxed
@@ -7,10 +7,8 @@ class Rosella.Test.TestFactory : Rosella.ObjectFactory
{
// Set up the factory with the type to create (TestCase or look-alike)
// and the TestContext object to use.
- function TestFactory(var testcase_type [optional], int has_type [opt_flag])
+ function TestFactory(var testcase_type = class Rosella.Test.TestCase)
{
- if (!has_type)
- testcase_type = class Rosella.Test.TestCase;
self.target_type = testcase_type;
}
View
121 src/unstable/prototype/Manager.winxed
@@ -1,80 +1,61 @@
-namespace Rosella { namespace Prototype
+class Rosella.Prototype.Manager
{
- class Manager
- {
- var library;
- var cloner;
-
- function Manager(var cloner [optional], int has_c [opt_flag])
- {
- self.library = {};
- if (has_c)
- self.cloner = cloner;
- else
- self.cloner = new Rosella.Prototype.Manager.ObjectCloner;
- }
-
- function add_prototype(var type, var proto,
- var sub [optional], int has_sub [opt_flag])
- {
- using Rosella.get_type_name;
-
- string type_name = get_type_name(type);
- if (!has_sub)
- sub = null;
- var entry = new Rosella.Prototype.Manager.Entry(proto, sub);
- self.library[type_name] = entry;
- }
+ var library;
+ var cloner;
- // Get a fresh instance
- function instance(var type, var pos [slurpy], var named [slurpy,named])
- {
- using Rosella.get_type_name;
-
- string type_name = get_type_name(type);
- if (exists self.library[type_name]) {
- var entry = self.library[type_name];
- var proto = entry.prototype;
- var object = self.cloner.clone(proto);
- entry.construct(object, pos, named);
- return object;
- }
- return null;
- }
+ function Manager(var cloner = new Rosella.Prototype.Manager.ObjectCloner)
+ {
+ self.library = {};
+ self.cloner = cloner;
+ }
- // Get a fresh instance, and run it through a specified constructor
- // instead of any already-registered constructors.
- function instance_constructor(var type, var constructor,
- var pos [slurpy], var named [slurpy,named])
- {
- using Rosella.get_type_name;
+ function add_prototype(var type, var proto, var sub = null)
+ {
+ string type_name = Rosella.get_type_name(type);
+ var entry = new Rosella.Prototype.Manager.Entry(proto, sub);
+ self.library[type_name] = entry;
+ }
- string type_name = get_type_name(type);
- if (exists self.library[type_name]) {
- var entry = self.library[type_name];
- var proto = entry.prototype;
- var object = self.cloner.clone(proto);
- if (object != null && constructor != null)
- object.*constructor(pos:[flat], named:[flat,named]);
- return object;
- }
- return null;
+ // Get a fresh instance
+ function instance(var type, var pos [slurpy], var named [slurpy,named])
+ {
+ string type_name = Rosella.get_type_name(type);
+ if (exists self.library[type_name]) {
+ var entry = self.library[type_name];
+ var proto = entry.prototype;
+ var object = self.cloner.clone(proto);
+ entry.construct(object, pos, named);
+ return object;
}
+ return null;
+ }
- function get_prototype(var type)
- {
- using Rosella.get_type_name;
-
- string type_name = get_type_name(type);
- return self.library[type_name].prototype;
+ // Get a fresh instance, and run it through a specified constructor
+ // instead of any already-registered constructors.
+ function instance_constructor(var type, var constructor,
+ var pos [slurpy], var named [slurpy,named])
+ {
+ string type_name = Rosella.get_type_name(type);
+ if (exists self.library[type_name]) {
+ var entry = self.library[type_name];
+ var proto = entry.prototype;
+ var object = self.cloner.clone(proto);
+ if (object != null && constructor != null)
+ object.*constructor(pos:[flat], named:[flat,named]);
+ return object;
}
+ return null;
+ }
- function get_constructor(var type)
- {
- using Rosella.get_type_name;
+ function get_prototype(var type)
+ {
+ string type_name = Rosella.get_type_name(type);
+ return self.library[type_name].prototype;
+ }
- string type_name = get_type_name(type);
- return self.library[type_name].constructor;
- }
+ function get_constructor(var type)
+ {
+ string type_name = Rosella.get_type_name(type);
+ return self.library[type_name].constructor;
}
-}}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.