Permalink
Browse files

Convert most raw pirops to inline/builtins

  • Loading branch information...
1 parent 97e8ef4 commit a01fa2ff7cbe235afc4407c179a0ff5b330bfa53 @Whiteknight committed Nov 27, 2011
Showing with 275 additions and 236 deletions.
  1. +3 −3 setup.winxed
  2. +2 −4 src/action/Argument.winxed
  3. +1 −1 src/container/Option.winxed
  4. +1 −1 src/core/Rosella.winxed
  5. +1 −1 src/event/Dispatcher.winxed
  6. +2 −6 src/filesystem/FileSystem.winxed
  7. +1 −2 src/harness/TestExecutor.winxed
  8. +3 −6 src/harness/View.winxed
  9. +141 −0 src/include/Builtins.winxed
  10. +27 −0 src/include/Math_Builtins.winxed
  11. +1 −1 src/memoize/Memoize.winxed
  12. +3 −3 src/memoize/cache/SimpleString.winxed
  13. +1 −3 src/path/searcher/Hash.winxed
  14. +1 −1 src/proxy/Controller.winxed
  15. +2 −4 src/proxy/Factory.winxed
  16. +3 −6 src/proxy/Proxy.winxed
  17. +1 −1 src/proxy/builder/AttributeIntercept.winxed
  18. +1 −4 src/query/Queryable.winxed
  19. +2 −6 src/query/Stage.winxed
  20. +2 −6 src/query/provider/Factory.winxed
  21. +3 −8 src/string/String.winxed
  22. +2 −6 src/string/Tokenizer.winxed
  23. +2 −5 src/string/tokenizer/CClass.winxed
  24. +1 −3 src/template/Engine.winxed
  25. +2 −5 src/template/handler/For.winxed
  26. +1 −3 src/template/handler/If.winxed
  27. +1 −1 src/template/node/Logic.winxed
  28. +13 −30 src/test/Asserter.winxed
  29. +1 −3 src/test/Suite.winxed
  30. +1 −1 src/test/TestCase.winxed
  31. +5 −4 src/test/TestFactory.winxed
  32. +2 −5 src/test/suitefactory/List.winxed
  33. +2 −4 src/test/suitefactory/Vector.winxed
  34. +2 −6 src/unstable/assert/Interface.winxed
  35. +1 −1 src/unstable/benchmark/Result.winxed
  36. +5 −9 src/unstable/decorate/Decorator.winxed
  37. +1 −2 src/unstable/dumper/Dumper.winxed
  38. +1 −2 src/unstable/dumper/dumphandler/Array.winxed
  39. +1 −2 src/unstable/dumper/dumphandler/Hash.winxed
  40. +2 −4 src/unstable/dumper/dumphandler/InspectAttrs.winxed
  41. +1 −2 src/unstable/dumper/dumphandler/Object.winxed
  42. +2 −3 src/unstable/lazy/Controller.winxed
  43. +10 −19 src/unstable/prototype/Object.winxed
  44. +1 −4 src/unstable/prototype/manager/Entry.winxed
  45. +1 −3 src/unstable/prototype/manager/ObjectCloner.winxed
  46. +1 −14 src/unstable/random/Includes.winxed
  47. +1 −10 src/unstable/random/randomnumber/MersenneTwister.winxed
  48. +1 −2 src/unstable/reflect/Class.winxed
  49. +1 −2 src/utilities/mk_winxed_header.winxed
  50. +3 −6 src/winxed/Distutils.winxed
  51. +2 −4 src/winxed/repl/Commands.winxed
  52. +3 −4 src/winxed/repl/View.winxed
View
@@ -204,7 +204,7 @@ function setup_stable_libraries(var rosella)
);
// A library for working with files and directories
- setup_winxed_lib(rosella, "filesystem", ["Core"],
+ setup_winxed_lib(rosella, "filesystem", ["Core", "Math_Builtins"],
"filesystem/Includes",
"filesystem/Entry",
"filesystem/Directory",
@@ -294,7 +294,7 @@ function setup_experimental_libraries(var rosella)
"lazy/Factory"
);
- setup_unstable_lib(rosella, "benchmark", [],
+ setup_unstable_lib(rosella, "benchmark", ["Core", "Math_Builtins"],
"benchmark/Benchmark",
"benchmark/Result"
);
@@ -323,7 +323,7 @@ function setup_experimental_libraries(var rosella)
"commandline/ProgramMode"
);
- setup_unstable_lib(rosella, "random", [],
+ setup_unstable_lib(rosella, "random", ["Math_Builtins"],
"random/Includes",
"random/Random",
"random/RandomNumber",
@@ -7,9 +7,7 @@ namespace Rosella { namespace Action
function verify_all_arguments(string caller, var args)
{
for (var arg in args) {
- int is_argument = 0;
- ${ can is_argument, arg, "resolve_to" };
- if (!is_argument)
+ if (!can(arg, "resolve_to"))
Rosella.Error.invalid_type(__FUNCTION__, class Rosella.Action.Argument, typeof(arg));
}
}
@@ -66,7 +64,7 @@ namespace Rosella { namespace Action
else if (self.position >= 0)
pos[self.position] = value;
else
- ${ push pos, value };
+ push(pos, value);
}
// Get the actual value. This happens in a subclass.
@@ -98,7 +98,7 @@ class Rosella.Container.Option.Property : Rosella.Container.Option
var value = self.value;
if (value instanceof Rosella.Container.Argument)
value = value.get_value(container);
- ${ setprop instance, prop, value };
+ setprop(instance, prop, value);
}
}
View
@@ -89,7 +89,7 @@ namespace Rosella
else if (type instanceof "Class")
type = type.get_namespace();
else if (type instanceof "Key")
- ${ get_namespace type, type };
+ type = get_namespace(type);
if (type instanceof "NameSpace")
return join(";", type.get_name());
@@ -24,7 +24,7 @@ class Rosella.Event.Dispatcher.Task : Rosella.Event.Dispatcher
{
var t = new 'Task'(cb);
t.data(e);
- ${ schedule t };
+ schedule(t);
}
}
@@ -36,9 +36,7 @@ namespace Rosella.FileSystem
return 0;
var stat = os.stat(path);
int mode = stat[2];
- int isfile = 0;
- ${ band isfile, mode, STAT_ISREG };
- return isfile;
+ return band(mode, STAT_ISREG);
}
// Determine if the given path is a directory. Returns non-zero if it
@@ -50,9 +48,7 @@ namespace Rosella.FileSystem
return 0;
var stat = os.stat(path);
int mode = stat[2];
- int isdir = 0;
- ${ band isdir, mode, STAT_ISDIR };
- return isdir;
+ return band(mode, STAT_ISDIR);
}
// Get the path separator for this system
@@ -86,8 +86,7 @@ namespace Rosella.Harness
int exit_code = stream.on_data(function(ih) {
var handle = ih.handle();
handle.close();
- int can_exit_status;
- ${ can can_exit_status, handle, "exit_status" };
+ int can_exit_status = can(handle, "exit_status");
return can_exit_status == 1 ? handle.exit_status() : 0;
});
file.cleanup_spawn();
View
@@ -55,8 +55,7 @@ namespace Rosella.Harness
int len = length(name);
int line_length = self.line_length;
int diff = line_length - len + 3;
- string elipses = "";
- ${ repeat elipses, '.', diff };
+ string elipses = repeat(".", diff);
Rosella.IO.printf("%s %s ", name, elipses, self.handle:[named("handle")]);
}
@@ -65,8 +64,7 @@ namespace Rosella.Harness
{
if (self.need_backspaces > 0) {
int num_b = int(self.need_backspaces);
- string b;
- ${ repeat b, "\b", num_b };
+ string b = repeat("\b", num_b);
print(b + " ");
//print("\b\b\b\b\b\b\b\b\b\b");
self.need_backspaces = 0;
@@ -167,8 +165,7 @@ namespace Rosella.Harness
{
if (self.need_backspaces > 0) {
int num_b = int(self.need_backspaces);
- string b;
- ${ repeat b, "\b", num_b };
+ string b = repeat("\b", num_b);
print(b + " ");
//print("\b\b\b\b\b\b\b\b\b\b");
self.need_backspaces = 0;
View
@@ -15,6 +15,13 @@ inline isa(var obj, var class_obj) return int
return isa_class;
}
+inline isa_s(var obj, string type) return int
+{
+ int isa_class;
+ ${ isa isa_class, obj, type };
+ return isa_class;
+}
+
inline does(var obj, string role) return int
{
int does_role;
@@ -28,3 +35,137 @@ inline new_pmc(var class_obj) return var
${ new obj, class_obj };
return obj;
}
+
+inline iter(var obj) return var
+{
+ var i;
+ ${ iter i, obj };
+ return i;
+}
+
+inline schedule(var task)
+{
+ ${ schedule task };
+}
+
+inline time_i(int dummy) return int
+{
+ int t;
+ ${ time t };
+ return t;
+}
+
+inline getattribute_private(var obj, var target_class, string attr) return var
+{
+ var value;
+ ${ getattribute value, obj, target_class, attr };
+ return value;
+}
+
+inline setattribute_private(var obj, var target_class, string attr, var value)
+{
+ ${ setattribute obj, target_class, attr, value };
+}
+
+inline shift_p(var obj) return var
+{
+ var value;
+ ${ shift value, obj };
+ return value;
+}
+
+inline pop_p(var obj) return var
+{
+ var value;
+ ${ pop value, obj };
+ return value;
+}
+
+inline inspect(var obj) return var
+{
+ var value;
+ ${ inspect value, obj };
+ return value;
+}
+
+inline inspect_s(var obj, string property) return var
+{
+ var value;
+ ${ inspect value, obj, property };
+ return value;
+}
+
+inline newclass(string name) return var
+{
+ var c;
+ ${ newclass c, name };
+ return c;
+}
+
+inline is_cclass(int cclass, string str, int start) return int
+{
+ int is;
+ ${ is_cclass is, cclass, str, start };
+ return is;
+}
+
+inline find_not_cclass(int cclass, string s, int start_idx, int len) return int
+{
+ int idx;
+ ${ find_not_cclass idx, cclass, s, start_idx, len };
+ return idx;
+}
+
+inline find_cclass(int cclass, string s, int start_idx, int len) return int
+{
+ int idx;
+ ${ find_cclass idx, cclass, s, start_idx, len };
+ return idx;
+}
+
+inline repeat(string s, int c) return string
+{
+ string value;
+ ${ repeat value, s, c };
+ return value;
+}
+
+inline get_namespace(var key) return var
+{
+ var value;
+ ${ get_namespace value, key };
+ return value;
+}
+
+inline get_hll_namespace(var key) return var
+{
+ var value;
+ ${ get_hll_namespace value, key };
+ return value;
+}
+
+inline getprop(var obj, string name) return var
+{
+ var value;
+ ${ getprop value, name, obj };
+ return value;
+}
+
+inline setprop(var obj, string name, var value)
+{
+ ${ setprop obj, name, value };
+}
+
+inline defined(var obj) return int
+{
+ int value;
+ ${ defined value, obj };
+ return value;
+}
+
+inline index(string s, string n) return int
+{
+ int value;
+ ${ index value, s, n };
+ return value;
+}
@@ -0,0 +1,27 @@
+inline abs_f(float value) return float
+{
+ ${ abs value };
+ return value;
+}
+
+inline logical_shift_right(int d, int y) return int
+{
+ int result;
+ ${ lsr result, d, y };
+ return result;
+}
+
+// Square-root helper function.
+inline sqrt(float val) return float
+{
+ float result;
+ ${ sqrt result, val };
+ return result;
+}
+
+inline band(int a, int b) return int
+{
+ int value;
+ ${ band value, a, b };
+ return value;
+}
@@ -109,7 +109,7 @@ namespace Rosella
var cache = Rosella.Proxy.get_proxy_private_attr(obj, "memoize_cache");
if (cache != null) {
var cache_class = class Rosella.Memoize.Cache;
- ${ isa is_mp, cache, cache_class };
+ is_mp = isa(cache, cache_class);
}
} catch (e) {
is_mp = 0;
@@ -47,11 +47,11 @@ namespace Rosella { namespace Memoize { namespace Cache
{
var sb = new "StringBuilder";
for (string ip in p)
- ${ push sb, ip };
+ push(sb, ip);
for (string key in n) {
- ${ push sb, key };
+ push(sb, key);
string val = n[key];
- ${ push sb, key };
+ push(sb, key);
}
return string(sb);
}
@@ -9,9 +9,7 @@ class Rosella.Path.Searcher.Hash
// by the "does 'hash'" role.
function can_search(var obj)
{
- int is_hash = 0;
- ${ does is_hash, obj, "hash" };
- return is_hash;
+ return does(obj, "hash");
}
// Search the hash for the given item
@@ -48,7 +48,7 @@ class Rosella.Proxy.Controller
var class_obj = Rosella.Proxy.get_proxy_private_attr(proxy, "target_class");
int isa_type = 0;
if (class_obj != null)
- ${ isa isa_type, class_obj, type };
+ isa_type = isa(class_obj, type);
return isa_type;
}
View
@@ -89,8 +89,7 @@ class Rosella.Proxy.Factory : Rosella.ObjectFactory
int id = Rosella.get_unique_count();
string proxy_class_name = sprintf("!!!PROXY_%s_%d", [string(target_class), id]);
- var proxy_class = null;
- ${ newclass proxy_class, proxy_class_name };
+ var proxy_class = newclass(proxy_class_name);
Rosella.Proxy.add_proxy_class_private_attr(proxy_class, "proxy_controller");
Rosella.Proxy.add_proxy_class_private_attr(proxy_class, "proxy_factory");
Rosella.Proxy.add_proxy_class_private_attr(proxy_class, "target_class");
@@ -103,8 +102,7 @@ class Rosella.Proxy.Factory : Rosella.ObjectFactory
// Create and instantiate the new proxy object.
function create_proxy_internal(var proxy_class, var controller, var target)
{
- var proxy = null;
- ${ new proxy, proxy_class };
+ var proxy = new_pmc(proxy_class);
Rosella.Proxy.set_proxy_private_attr(proxy, "proxy_factory", self);
Rosella.Proxy.set_proxy_private_attr(proxy, "proxy_controller", controller);
Rosella.Proxy.set_proxy_private_attr(proxy, "target_class", self.target_class);
Oops, something went wrong.

0 comments on commit a01fa2f

Please sign in to comment.