Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Whiteknight
Created July 22, 2011 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Whiteknight/1099564 to your computer and use it in GitHub Desktop.
Save Whiteknight/1099564 to your computer and use it in GitHub Desktop.
What the whiteknight/pbc_pbc branch can do
namespace Rosella {
class ObjectFactory;
class Version;
extern function alloc;
extern function build;
extern function construct;
extern function get_type_name;
extern function get_type_class;
extern function isa_type;
extern function find_named_method;
extern function invoke_method;
extern function get_unique_count;
extern function __get_globals;
extern function get_global;
extern function register_global;
extern function get_default_factory;
extern function get_version_hash;
extern function get_version;
extern function internal_set_version;
}
namespace Rosella.Error {
extern function must_subclass;
extern function not_implemented;
extern function invalid;
extern function invalid_type;
extern function throw_error;
}
namespace Rosella.IO {
extern function swap_handles;
extern function sayf;
extern function printf;
}
namespace Rosella.ObjectFactory {
extern function Winxed_class_init;
}
namespace Rosella.Parrot {
extern function get_config_hash;
extern function get_backtrace_strings;
extern function get_backtrace_ex_strings;
extern function try_report;
extern function __format_backtrace;
}
namespace Rosella.Version {
extern function Winxed_class_init;
}
namespace Rosella.__PRIVATE_Versions {
extern function __SET_VERSIONS;
}
class NamespaceEntry {
var classes;
var subs;
function NamespaceEntry()
{
self.classes = {};
self.subs = [];
}
function add_class(string c) { self.classes[c] = 1; }
function add_sub(var sub) { push(self.subs, sub); }
}
function main[main]()
{
var corelib;
${ load_bytecode corelib, "rosella/core.pbc" };
var all_subs = corelib.all_subs();
var all_namespaces = {};
for (var sub in all_subs) {
var nsname = sub.get_namespace().get_name();
nsname.shift(); // drop HLL namespace
string ns = join(".", nsname);
if (!(exists all_namespaces[ns]))
all_namespaces[ns] = new NamespaceEntry();
int flags = sub.comp_flags();
if ((flags & 0x04) != 0) {
string classname = nsname.pop();
string basename = join(".", nsname);
if (!(exists all_namespaces[basename]))
all_namespaces[ns] = new NamespaceEntry();
all_namespaces[basename].add_class(classname);
}
else
all_namespaces[ns].add_sub(sub);
}
for (var ns in all_namespaces) {
say(sprintf("namespace %s {", [ns]));
for (var c in all_namespaces[ns].classes)
say(sprintf("\tclass %s;", [c]));
for (var sub in all_namespaces[ns].subs)
say(sprintf("\textern function %s;", [sub]));
say("}\n");
}
}
@leto
Copy link

leto commented Jul 22, 2011

This is awesome! What is the flags & 0x04 about?

@Whiteknight
Copy link
Author

That's the :method flag. That checks of the Sub is a method, and if it is the containing namespace is going to be a Class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment