<commit_before>/* ====================================================================
   |
   |   Amber Smalltalk
   |   http://amber-lang.net
   |
   ======================================================================

   ======================================================================
   |
   | Copyright (c) 2010-2011
   | <NAME> <<EMAIL>>
   |
   | Amber is released under the MIT license
   |
   | Permission is hereby granted, free of charge, to any person obtaining
   | a copy of this software and associated documentation files (the
   | 'Software'), to deal in the Software without restriction, including
   | without limitation the rights to use, copy, modify, merge, publish,
   | distribute, sublicense, and/or sell copies of the Software, and to
   | permit persons to whom the Software is furnished to do so, subject to
   | the following conditions:
   |
   | The above copyright notice and this permission notice shall be
   | included in all copies or substantial portions of the Software.
   |
   | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
   | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   |
   ==================================================================== */

/* Global Smalltalk objects. */
// The globals below all begin with `global_' prefix.
// This prefix is to advice developers to avoid their usage,
// instead using local versions smalltalk, nil, _st that are
// provided by appropriate wrappers to each package.
// The plan is to use different module loader (and slightly change the wrappers)
// so that these globals are hidden completely inside the exports/imports of the module loader.
// DO NOT USE DIRECTLY! CAN DISAPPEAR AT ANY TIME.
var global_smalltalk, global_nil, global__st;

(function () {

/* Reconfigurable micro composition system, https://github.com/herby/brikz */

function Brikz(api, apiKey, initKey) {
	var brikz = this, backup = {};
	apiKey = apiKey || 'exports';
	initKey = initKey || '__init__';

	function mixin(src, target, what) {
		for (var keys = Object.keys(what||src), l=keys.length, i=0; i<l; ++i) {
			var value = src[keys[i]];
			if (typeof value !== "undefined") { target[keys[i]] = value; }
		}
		return target;
	}

	var d={value: null, enumerable: false, configurable: true, writable: true};
	Object.defineProperties(this, { ensure: d, rebuild: d });

	this.rebuild = function () {
		Object.keys(backup).forEach(function (key) {
			mixin({}, api, (backup[key]||0)[apiKey]);
		});
		var oapi = mixin(api, {}), order = [], chk = {};
		brikz.ensure = function(key) {
			var b = brikz[key], bak = backup[key];
			mixin({}, api, api);
			while (typeof b === "function") { b = new b(brikz, api, bak); }
			if (b && !chk[key]) { chk[key]=true; order.push(b); }
			if (b && !b[apiKey]) { b[apiKey] = mixin(api, {}); }
			return brikz[key] = b;
		};
		Object.keys(brikz).forEach(function (key) { brikz.ensure(key); });
		brikz.ensure = null;
		mixin(oapi, mixin({}, api, api));
		order.forEach(function(brik) { mixin(brik[apiKey] || {}, api); });
		order.forEach(function(brik) { brik[initKey] && brik[initKey](); });
		backup = mixin(brikz, {});
	};
}

/* Brikz end */

function inherits(child, parent) {
	child.prototype = Object.create(parent.prototype, {
		constructor: { value: child,
			enumerable: false, configurable: true, writable: true }
	});
	return child;
}

/* Smalltalk foundational objects */

function SmalltalkObject() {}

function Smalltalk() {}
inherits(Smalltalk, SmalltalkObject);

var api = new Smalltalk;
var brikz = new Brikz(api);

function RootBrik(brikz, st) {

	function SmalltalkNil() {}
	inherits(SmalltalkNil, SmalltalkObject);

	this.nil = new SmalltalkNil;

	this.__init__ = function () {
		st.wrapClassName("Object", "Kernel-Objects", SmalltalkObject, undefined, false);
		st.wrapClassName("Smalltalk", "Kernel-Objects", Smalltalk, st.Object, false);
		st.wrapClassName("UndefinedObject", "Kernel-Objects", SmalltalkNil, st.Object, false);
	};
}

function OrganizeBrik(brikz, st) {

	brikz.ensure("augments");
	brikz.ensure("root");

	function SmalltalkOrganizer () {}
	function SmalltalkPackageOrganizer () {
		this.elements = [];
	}
	function SmalltalkClassOrganizer () {
		this.elements = [];
	}

	inherits(SmalltalkOrganizer, SmalltalkObject);
	inherits(SmalltalkPackageOrganizer, SmalltalkOrganizer);
	inherits(SmalltalkClassOrganizer, SmalltalkOrganizer);

	this.__init__ = function () {
		st.wrapClassName("Organizer", "Kernel-Objects", SmalltalkOrganizer, st.Object, false);
		st.wrapClassName("PackageOrganizer", "Kernel-Objects", SmalltalkPackageOrganizer, st.Organizer, false);
		st.wrapClassName("ClassOrganizer", "Kernel-Objects", SmalltalkClassOrganizer, st.Organizer, false);
	};

	this.setupClassOrganization = function (klass) {
		klass.organization = new SmalltalkClassOrganizer;
		klass.organization.theClass = klass;
	};

	this.setupPackageOrganization = function (pkg) {
		pkg.organization = new SmalltalkPackageOrganizer;
	};

	this.addOrganizationElement = function (owner, element) {
		owner.organization.elements.addElement(element);
	};

	this.removeOrganizationElement = function (owner, element) {
		owner.organization.elements.removeElement(element);
	};
}

function DNUBrik(brikz, st) {

	brikz.ensure("selectorConversion");
	brikz.ensure("messageSend");
	var manip = brikz.ensure("manipulation");

	/* Method not implemented handlers */

	var methods = [], checker = Object.create(null);
	this.selectors = [];

	this.get = function (string) {
		var index = this.selectors.indexOf(string);
		if(index !== -1) {
			return methods[index];
		}
		this.selectors.push(string);
		var selector = st.selector(string);
		checker[selector] = true;
		var method = {jsSelector: selector, fn: this.createHandler(selector)};
		methods.push(method);
		return method;
	};

	this.isSelector = function (selector) {
		return checker[selector];
	};

	/* Dnu handler method */

	this.createHandler = function (selector) {
		var handler = function() {
			var args = Array.prototype.slice.call(arguments);
			return brikz.messageSend.messageNotUnderstood(this, selector, args);
		};

		return handler;
	}

	this.installHandlers = function (klass) {
		for(var i=0; i<methods.length; i++) {
			manip.installMethodIfAbsent(methods[i], klass);
		}
	};
}

function ClassInitBrik(brikz, st) {

	var dnu = brikz.ensure("dnu");
	var manip = brikz.ensure("manipulation");
	var nil = brikz.ensure("root").nil;

	/* Initialize a class in its class hierarchy. Handle both classes and
	 metaclasses. */

	st.init = function(klass) {
		st.initClass(klass);
		if(klass.klass && !klass.meta) {
			st.initClass(klass.klass);
		}
	};

	st.initClass = function(klass) {
		if(klass.wrapped) {
			copySuperclass(klass);
		}

		if(klass === st.Object || klass.wrapped) {
			dnu.installHandlers(klass);
		}
	};

	function copySuperclass(klass, superclass) {
		var inheritedMethods = {};
		deinstallAllMethods(klass);
		for (superclass = superclass || klass.superclass;
			 superclass && superclass !== nil;
			 superclass = superclass.superclass) {
			for (var keys = Object.keys(superclass.methods), i = 0; i < keys.length; i++) {
				inheritMethodIfAbsent(superclass.methods[keys[i]]);
			}
		}
		manip.reinstallMethods(klass);

		function inheritMethodIfAbsent(method) {
			var selector = method.selector;

			//TODO: prepare klass methods into inheritedMethods to only test once
			//TODO: Object.create(null) to ditch hasOwnProperty call (very slow)
			if(klass.methods.hasOwnProperty(selector) || inheritedMethods.hasOwnProperty(selector)) {
				return;
			}

			manip.installMethod(method, klass);
			inheritedMethods[method.selector] = true;
		}

	}

	function deinstallAllMethods(klass) {
		var proto = klass.fn.prototype;
		for(var keys = Object.getOwnPropertyNames(proto), i=0; i<keys.length; i++) {
			var key = keys[i];
			if (dnu.isSelector(key)) {
				proto[key] = null;
			}
		}
	}
}

function ManipulationBrik(brikz, st) {

	this.installMethodIfAbsent = function (handler, klass) {
		if(!klass.fn.prototype[handler.jsSelector]) {
			installMethod(handler, klass);
		}
	};

	function installMethod (method, klass) {
		Object.defineProperty(klass.fn.prototype, method.jsSelector, {
			value: method.fn,
			enumerable: false, configurable: true, writable: true
		});
	}
	this.installMethod = installMethod;

	this.wireKlass = function (klass) {
		Object.defineProperty(klass.fn.prototype, "klass", {
			value: klass,
			enumerable: false, configurable: true, writable: true
		});
	};

	this.reinstallMethods = function (klass) {
		var methods = klass.methods;
		for(var keys = Object.keys(methods), i=0; i<keys.length; i++) {
			installMethod(methods[keys[i]], klass);
		}
	};
}

function ClassesBrik(brikz, st) {

	var org = brikz.ensure("organize");
	var manip = brikz.ensure("manipulation");
	var nil = brikz.ensure("root").nil;

	function SmalltalkPackage() {}
	function SmalltalkBehavior() {}
	function SmalltalkClass() {}
	function SmalltalkMetaclass() {
		this.meta = true;
	}

	inherits(SmalltalkPackage, SmalltalkObject);
	inherits(SmalltalkBehavior, SmalltalkObject);
	inherits(SmalltalkClass, SmalltalkBehavior);
	inherits(SmalltalkMetaclass, SmalltalkBehavior);

	this.__init__ = function () {
		st.wrapClassName("Behavior", "Kernel-Classes", SmalltalkBehavior, st.Object, false);
		st.wrapClassName("Metaclass", "Kernel-Classes", SmalltalkMetaclass, st.Behavior, false);
		st.wrapClassName("Class", "Kernel-Classes", SmalltalkClass, st.Behavior, false);

		st.Object.klass.superclass = st.Class;

		st.wrapClassName("Package", "Kernel-Objects", SmalltalkPackage, st.Object, false);
	};

	/* Smalltalk classes */

	var classes = [];
	var wrappedClasses = [];

	/* We hold all Packages in a separate Object */

	st.packages = {};

	/* Smalltalk package creation. To add a Package, use smalltalk.addPackage() */

	function pkg(spec) {
		var that = new SmalltalkPackage();
		that.pkgName = spec.pkgName;
		org.setupPackageOrganization(that);
		that.properties = spec.properties || {};
		return that;
	}

	/* Smalltalk class creation. A class is an instance of an automatically
		created metaclass object. Newly created classes (not their metaclass)
		should be added to the smalltalk object, see smalltalk.addClass().
		Superclass linking is *not* handled here, see smalltalk.init()  */

	function klass(spec) {
		spec = spec || {};
		var meta = metaclass(spec);
		var that = meta.instanceClass;
		that.fn = spec.fn || inherits(function () {}, spec.superclass.fn);
		setupClass(that, spec);

		that.className = spec.className;
		that.wrapped   = spec.wrapped || false;
		meta.className = spec.className + ' class';
		if(spec.superclass) {
			that.superclass = spec.superclass;
			meta.superclass = spec.superclass.klass;
		}
		return that;
	}

	function metaclass(spec) {
		spec = spec || {};
		var that = new SmalltalkMetaclass();
		that.fn = inherits(function () {}, spec.superclass ? spec.superclass.klass.fn : SmalltalkClass);
		that.instanceClass = new that.fn();
		setupClass(that);
		return that;
	}

	function setupClass(klass, spec) {
		spec = spec || {};
		klass.iVarNames = spec.iVarNames || [];
		klass.pkg = spec.pkg;

		Object.defineProperty(klass, "toString", {
			value: function() { return 'Smalltalk ' + this.className; },
			enumerable:false, configurable: true, writable: false
		});
		org.setupClassOrganization(klass);
		Object.defineProperty(klass, "methods", {
			value: {},
			enumerable: false, configurable: true, writable: true
		});
		manip.wireKlass(klass);
	}

	/* Add a package to the smalltalk.packages object, creating a new one if needed.
	 If pkgName is null or empty we return nil, which is an allowed package for a class.<commit_msg>Only one toString for all Behaviors<commit_after>/* ====================================================================
   |
   |   Amber Smalltalk
   |   http://amber-lang.net
   |
   ======================================================================

   ======================================================================
   |
   | Copyright (c) 2010-2011
   | <NAME> <<EMAIL>>
   |
   | Amber is released under the MIT license
   |
   | Permission is hereby granted, free of charge, to any person obtaining
   | a copy of this software and associated documentation files (the
   | 'Software'), to deal in the Software without restriction, including
   | without limitation the rights to use, copy, modify, merge, publish,
   | distribute, sublicense, and/or sell copies of the Software, and to
   | permit persons to whom the Software is furnished to do so, subject to
   | the following conditions:
   |
   | The above copyright notice and this permission notice shall be
   | included in all copies or substantial portions of the Software.
   |
   | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
   | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   |
   ==================================================================== */

/* Global Smalltalk objects. */
// The globals below all begin with `global_' prefix.
// This prefix is to advice developers to avoid their usage,
// instead using local versions smalltalk, nil, _st that are
// provided by appropriate wrappers to each package.
// The plan is to use different module loader (and slightly change the wrappers)
// so that these globals are hidden completely inside the exports/imports of the module loader.
// DO NOT USE DIRECTLY! CAN DISAPPEAR AT ANY TIME.
var global_smalltalk, global_nil, global__st;

(function () {

/* Reconfigurable micro composition system, https://github.com/herby/brikz */

function Brikz(api, apiKey, initKey) {
	var brikz = this, backup = {};
	apiKey = apiKey || 'exports';
	initKey = initKey || '__init__';

	function mixin(src, target, what) {
		for (var keys = Object.keys(what||src), l=keys.length, i=0; i<l; ++i) {
			var value = src[keys[i]];
			if (typeof value !== "undefined") { target[keys[i]] = value; }
		}
		return target;
	}

	var d={value: null, enumerable: false, configurable: true, writable: true};
	Object.defineProperties(this, { ensure: d, rebuild: d });

	this.rebuild = function () {
		Object.keys(backup).forEach(function (key) {
			mixin({}, api, (backup[key]||0)[apiKey]);
		});
		var oapi = mixin(api, {}), order = [], chk = {};
		brikz.ensure = function(key) {
			var b = brikz[key], bak = backup[key];
			mixin({}, api, api);
			while (typeof b === "function") { b = new b(brikz, api, bak); }
			if (b && !chk[key]) { chk[key]=true; order.push(b); }
			if (b && !b[apiKey]) { b[apiKey] = mixin(api, {}); }
			return brikz[key] = b;
		};
		Object.keys(brikz).forEach(function (key) { brikz.ensure(key); });
		brikz.ensure = null;
		mixin(oapi, mixin({}, api, api));
		order.forEach(function(brik) { mixin(brik[apiKey] || {}, api); });
		order.forEach(function(brik) { brik[initKey] && brik[initKey](); });
		backup = mixin(brikz, {});
	};
}

/* Brikz end */

function inherits(child, parent) {
	child.prototype = Object.create(parent.prototype, {
		constructor: { value: child,
			enumerable: false, configurable: true, writable: true }
	});
	return child;
}

/* Smalltalk foundational objects */

function SmalltalkObject() {}

function Smalltalk() {}
inherits(Smalltalk, SmalltalkObject);

var api = new Smalltalk;
var brikz = new Brikz(api);

function RootBrik(brikz, st) {

	function SmalltalkNil() {}
	inherits(SmalltalkNil, SmalltalkObject);

	this.nil = new SmalltalkNil;

	this.__init__ = function () {
		st.wrapClassName("Object", "Kernel-Objects", SmalltalkObject, undefined, false);
		st.wrapClassName("Smalltalk", "Kernel-Objects", Smalltalk, st.Object, false);
		st.wrapClassName("UndefinedObject", "Kernel-Objects", SmalltalkNil, st.Object, false);
	};
}

function OrganizeBrik(brikz, st) {

	brikz.ensure("augments");
	brikz.ensure("root");

	function SmalltalkOrganizer () {}
	function SmalltalkPackageOrganizer () {
		this.elements = [];
	}
	function SmalltalkClassOrganizer () {
		this.elements = [];
	}

	inherits(SmalltalkOrganizer, SmalltalkObject);
	inherits(SmalltalkPackageOrganizer, SmalltalkOrganizer);
	inherits(SmalltalkClassOrganizer, SmalltalkOrganizer);

	this.__init__ = function () {
		st.wrapClassName("Organizer", "Kernel-Objects", SmalltalkOrganizer, st.Object, false);
		st.wrapClassName("PackageOrganizer", "Kernel-Objects", SmalltalkPackageOrganizer, st.Organizer, false);
		st.wrapClassName("ClassOrganizer", "Kernel-Objects", SmalltalkClassOrganizer, st.Organizer, false);
	};

	this.setupClassOrganization = function (klass) {
		klass.organization = new SmalltalkClassOrganizer;
		klass.organization.theClass = klass;
	};

	this.setupPackageOrganization = function (pkg) {
		pkg.organization = new SmalltalkPackageOrganizer;
	};

	this.addOrganizationElement = function (owner, element) {
		owner.organization.elements.addElement(element);
	};

	this.removeOrganizationElement = function (owner, element) {
		owner.organization.elements.removeElement(element);
	};
}

function DNUBrik(brikz, st) {

	brikz.ensure("selectorConversion");
	brikz.ensure("messageSend");
	var manip = brikz.ensure("manipulation");

	/* Method not implemented handlers */

	var methods = [], checker = Object.create(null);
	this.selectors = [];

	this.get = function (string) {
		var index = this.selectors.indexOf(string);
		if(index !== -1) {
			return methods[index];
		}
		this.selectors.push(string);
		var selector = st.selector(string);
		checker[selector] = true;
		var method = {jsSelector: selector, fn: this.createHandler(selector)};
		methods.push(method);
		return method;
	};

	this.isSelector = function (selector) {
		return checker[selector];
	};

	/* Dnu handler method */

	this.createHandler = function (selector) {
		var handler = function() {
			var args = Array.prototype.slice.call(arguments);
			return brikz.messageSend.messageNotUnderstood(this, selector, args);
		};

		return handler;
	}

	this.installHandlers = function (klass) {
		for(var i=0; i<methods.length; i++) {
			manip.installMethodIfAbsent(methods[i], klass);
		}
	};
}

function ClassInitBrik(brikz, st) {

	var dnu = brikz.ensure("dnu");
	var manip = brikz.ensure("manipulation");
	var nil = brikz.ensure("root").nil;

	/* Initialize a class in its class hierarchy. Handle both classes and
	 metaclasses. */

	st.init = function(klass) {
		st.initClass(klass);
		if(klass.klass && !klass.meta) {
			st.initClass(klass.klass);
		}
	};

	st.initClass = function(klass) {
		if(klass.wrapped) {
			copySuperclass(klass);
		}

		if(klass === st.Object || klass.wrapped) {
			dnu.installHandlers(klass);
		}
	};

	function copySuperclass(klass, superclass) {
		var inheritedMethods = {};
		deinstallAllMethods(klass);
		for (superclass = superclass || klass.superclass;
			 superclass && superclass !== nil;
			 superclass = superclass.superclass) {
			for (var keys = Object.keys(superclass.methods), i = 0; i < keys.length; i++) {
				inheritMethodIfAbsent(superclass.methods[keys[i]]);
			}
		}
		manip.reinstallMethods(klass);

		function inheritMethodIfAbsent(method) {
			var selector = method.selector;

			//TODO: prepare klass methods into inheritedMethods to only test once
			//TODO: Object.create(null) to ditch hasOwnProperty call (very slow)
			if(klass.methods.hasOwnProperty(selector) || inheritedMethods.hasOwnProperty(selector)) {
				return;
			}

			manip.installMethod(method, klass);
			inheritedMethods[method.selector] = true;
		}

	}

	function deinstallAllMethods(klass) {
		var proto = klass.fn.prototype;
		for(var keys = Object.getOwnPropertyNames(proto), i=0; i<keys.length; i++) {
			var key = keys[i];
			if (dnu.isSelector(key)) {
				proto[key] = null;
			}
		}
	}
}

function ManipulationBrik(brikz, st) {

	this.installMethodIfAbsent = function (handler, klass) {
		if(!klass.fn.prototype[handler.jsSelector]) {
			installMethod(handler, klass);
		}
	};

	function installMethod (method, klass) {
		Object.defineProperty(klass.fn.prototype, method.jsSelector, {
			value: method.fn,
			enumerable: false, configurable: true, writable: true
		});
	}
	this.installMethod = installMethod;

	this.wireKlass = function (klass) {
		Object.defineProperty(klass.fn.prototype, "klass", {
			value: klass,
			enumerable: false, configurable: true, writable: true
		});
	};

	this.reinstallMethods = function (klass) {
		var methods = klass.methods;
		for(var keys = Object.keys(methods), i=0; i<keys.length; i++) {
			installMethod(methods[keys[i]], klass);
		}
	};
}

function ClassesBrik(brikz, st) {

	var org = brikz.ensure("organize");
	var manip = brikz.ensure("manipulation");
	var nil = brikz.ensure("root").nil;

	function SmalltalkPackage() {}
	function SmalltalkBehavior() {}
	function SmalltalkClass() {}
	function SmalltalkMetaclass() {
		this.meta = true;
	}

	inherits(SmalltalkPackage, SmalltalkObject);
	inherits(SmalltalkBehavior, SmalltalkObject);
	inherits(SmalltalkClass, SmalltalkBehavior);
	inherits(SmalltalkMetaclass, SmalltalkBehavior);

	this.__init__ = function () {
		st.wrapClassName("Behavior", "Kernel-Classes", SmalltalkBehavior, st.Object, false);
		st.wrapClassName("Metaclass", "Kernel-Classes", SmalltalkMetaclass, st.Behavior, false);
		st.wrapClassName("Class", "Kernel-Classes", SmalltalkClass, st.Behavior, false);

		st.Object.klass.superclass = st.Class;

		st.wrapClassName("Package", "Kernel-Objects", SmalltalkPackage, st.Object, false);
	};

	/* Smalltalk classes */

	var classes = [];
	var wrappedClasses = [];

	/* We hold all Packages in a separate Object */

	st.packages = {};

	/* Smalltalk package creation. To add a Package, use smalltalk.addPackage() */

	function pkg(spec) {
		var that = new SmalltalkPackage();
		that.pkgName = spec.pkgName;
		org.setupPackageOrganization(that);
		that.properties = spec.properties || {};
		return that;
	}

	/* Smalltalk class creation. A class is an instance of an automatically
		created metaclass object. Newly created classes (not their metaclass)
		should be added to the smalltalk object, see smalltalk.addClass().
		Superclass linking is *not* handled here, see smalltalk.init()  */

	function klass(spec) {
		spec = spec || {};
		var meta = metaclass(spec);
		var that = meta.instanceClass;
		that.fn = spec.fn || inherits(function () {}, spec.superclass.fn);
		setupClass(that, spec);

		that.className = spec.className;
		that.wrapped   = spec.wrapped || false;
		meta.className = spec.className + ' class';
		if(spec.superclass) {
			that.superclass = spec.superclass;
			meta.superclass = spec.superclass.klass;
		}
		return that;
	}

	function metaclass(spec) {
		spec = spec || {};
		var that = new SmalltalkMetaclass();
		that.fn = inherits(function () {}, spec.superclass ? spec.superclass.klass.fn : SmalltalkClass);
		that.instanceClass = new that.fn();
		setupClass(that);
		return that;
	}

	SmalltalkBehavior.prototype.toString = function () {
		return 'Smalltalk ' + this.className;
	};

	function setupClass(klass, spec) {
		spec = spec || {};
		klass.iVarNames = spec.iVarNames || [];
		klass.pkg = spec.pkg;

		org.setupClassOrganization(klass);
		Object.defineProperty(klass, "methods", {
			value: {},
			enumerable: false, configurable: true, writable: true
		});
		manip.wireKlass(klass);
	}

	/* Add a package to the smalltalk.packages object, creating a new one if needed.
	 If pkgName is null or empty we return nil, which is an allowed package for a class.
{'fraction_non_alphanumeric': 0.15371544614364457, 'fraction_numerical': 0.0012433171702101206, 'mean_word_length': 4.3562708102108765, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '605018', 'n_tokens_mistral': 8050, 'n_tokens_neox': 7504, 'n_words': 1945}