Skip to content

Commit

Permalink
rename magic functions to helper or informative, clean up ugly namesp…
Browse files Browse the repository at this point in the history
…aces

--HG--
branch : com.mozilla.es4.smlnj
rename : builtins/Magic.es => builtins/Helper.es
extra : convert_revision : 3325c4dd7b8768cc3df872702c0f4cd40e64ab03
  • Loading branch information
graydon committed May 9, 2008
1 parent 70fc1ae commit 4997d30
Show file tree
Hide file tree
Showing 38 changed files with 229 additions and 298 deletions.
3 changes: 1 addition & 2 deletions ast-query.sml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ fun needFunctionType (t:Ast.TYPE)
fun resultTyOfFuncTy t =
case (#result (needFunctionType t)) of
SOME t => t
(* void case should never occur, I think *)

| NONE => error ["resultTyOfFuncTy: none found"]

val minArgsOfFuncTy = (#minArgs) o needFunctionType

Expand Down
10 changes: 4 additions & 6 deletions boot.sml
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ fun boot (baseDir:string) : Mach.REGS =
val (prog, otherFrags) =
loadFiles prog
[builtin "Namespace.es",
builtin "Magic.es",
builtin "Internal.es",
builtin "Helper.es",
builtin "Conversions.es",


Expand Down Expand Up @@ -324,11 +323,10 @@ fun boot (baseDir:string) : Mach.REGS =
builtin "RegExpEvaluator.es",
builtin "RegExp.es",
builtin "Date.es",
builtin "MetaObjects.es", (* before JSON *)
builtin "JSON.es",
builtin "MetaObjects.es"

(* builtin "Vector.es", *)
(* builtin "Map.es", *)
builtin "DecimalContext.es"
(* builtin "Map.es" *)
]

val glob =
Expand Down
2 changes: 0 additions & 2 deletions builtins/Array.es
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
* Status: not reviewed against specs.
*/

use default namespace public;
use namespace intrinsic;
use namespace ECMAScript4_Internal;

// Array "extras" from JS1.6 (@todo: and JS1.8 -- reduce/reduceRight)
// See http://developer.mozilla.org/en/docs/New_in_JavaScript_1.6#Array_extras
Expand Down
2 changes: 1 addition & 1 deletion builtins/Class.es
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

// intrinsic function superTypes() {
// // FIXME #158: don't use "let" here, "let function" is broken.
// var supers = []; // magic::superTypes(this);
// var supers = []; // helper::superTypes(this);
// var i = 0;
// // Clunky
// function next() {
Expand Down
6 changes: 3 additions & 3 deletions builtins/Conversions.es
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@

/*
intrinsic function IsPrimitive(value)
magic::isPrimitive(value);
helper::isPrimitive(value);
*/

/*
intrinsic function DefaultValue(obj, preferredType)
magic::defaultValue(obj, preferredType);
helper::defaultValue(obj, preferredType);
*/

intrinsic function ToPrimitive(value, preferredType)
magic::toPrimitive(value, preferredType);
helper::toPrimitive(value, preferredType);

/*
* ES-262-3 9.9: ToObject.
Expand Down
3 changes: 0 additions & 3 deletions builtins/Date.es
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@
* extensive use of expression functions.
*/

use namespace ECMAScript4_Internal;
use namespace helper;
use namespace informative;
use namespace intrinsic;

use default namespace public;

const NOARG = {};

dynamic class Date
Expand Down
2 changes: 0 additions & 2 deletions builtins/Error.es
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
* verified.
*/

use namespace ECMAScript4_Internal;

helper function isExactlyType(obj, t) {
// FIXME. What we want is
//
Expand Down
21 changes: 8 additions & 13 deletions builtins/Function.es
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,14 @@
* just fine.
*/

use namespace __ES4__;
use namespace ECMAScript4_Internal;

public dynamic class Function
{
// IMPLEMENTATION ARTIFACT: A getter because Function is loaded before int.
static function get length() { return 1 }

/* E262-3 15.3.1: The Function Constructor Called as a Function */
static meta function invoke(...args)
magic::construct(Function, args);
helper::construct(Function, args);

/* The following is for the benefit of the specification, don't remove it.
Expand All @@ -72,7 +69,7 @@
parameters = args.join(",");
}
body = string(body);
magic::initializeFunction(this, __ES4__::global, parameters, body);
helper::initializeFunction(this, __ES4__::global, parameters, body);
}
*/
Expand All @@ -93,11 +90,9 @@
throw new Error("Implementation error");
}

/* XXX: The prototype object behaves like a function (and
system magic makes its classname be "Function", though it's
not an instance of the Function class). So here we install
some things in the prototype that ensures that the object
behaves like a function in some trivial ways.
/* XXX: The prototype object behaves like a function. So here
we install some things in the prototype that ensures that
the object behaves like a function in some trivial ways.
*/
public prototype meta function invoke(...args)
undefined;
Expand Down Expand Up @@ -133,7 +128,7 @@
thisArg = global;
if (argArray === null)
argArray = [];
return magic::apply(fn, thisArg, argArray);
return helper::apply(fn, thisArg, argArray);
}

/* E262-3 15.3.4.4: Function.prototype.call.
Expand Down Expand Up @@ -184,7 +179,7 @@
throw new TypeError("[[HasInstance]]: prototype is not object");

while (true) {
V = magic::getPrototype(V);
V = helper::getPrototype(V);
if (V === null)
return false;
if (O == V)
Expand All @@ -203,7 +198,7 @@
// This is a getter because 'double' is not defined by the time we
// start constructing Functions.
public function get length()
magic::fnLength(this);
helper::fnLength(this);

// 'length' is logically a read-only property, so setting it should fail silently
public function set length(x) {
Expand Down
10 changes: 5 additions & 5 deletions builtins/GenericFunction.es
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
(2) The RI has no real meta-object functionality at this point, so
this code uses some primitives that have been hacked into the
system as magic hooks. These hooks will eventually be useful
system as helper hooks. These hooks will eventually be useful
for the meta-objects system anyhow.
(3) Using arrays like I do here is nuts, we should switch to
Expand Down Expand Up @@ -441,7 +441,7 @@
switch type (v) {
case (v:undefined) { return UndefinedType }
case (v:null) { return NullType }
case (v:*) { return magic::getClassOfObject(v) }
case (v:*) { return helper::getClassOfObject(v) }
}
}

Expand Down Expand Up @@ -487,19 +487,19 @@
let supers = [];
switch type (clsOrInterface) {
case (cls:Class) {
let probe = magic::getSuperClass(cls);
let probe = helper::getSuperClass(cls);
if (probe !== null)
supers.push(probe);
for ( let i=0 ; ; i++ ) {
let probe = magic::getImplementedInterface(cls, toUint(i));
let probe = helper::getImplementedInterface(cls, toUint(i));
if (probe === null)
break;
supers.push(probe);
}
}
case (iface:Interface) {
for ( let i=0 ; ; i++ ) {
let probe = magic::getSuperInterface(iface, toUint(i));
let probe = helper::getSuperInterface(iface, toUint(i));
if (probe === null)
break;
supers.push(probe);
Expand Down
24 changes: 11 additions & 13 deletions builtins/Global.es
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
* Status: not reviewed against specs.
*/

use namespace ECMAScript4_Internal;

// 15.1.1.1 NaN
// 15.1.1.2 Infinity
// 15.1.1.3 undefined
Expand Down Expand Up @@ -80,7 +78,7 @@
{
initial_obj = (v is Object) ? v : null;
current_obj = initial_obj;
current_ids = magic::getEnumerableIds(initial_obj);
current_ids = helper::getEnumerableIds(initial_obj);
}

// FIXME: why no ResultFun, boolean args?
Expand All @@ -101,24 +99,24 @@
throw iterator::StopIteration;

// No more properties in current_obj: try walking up the prototype chain.
current_obj = magic::getPrototype(current_obj);
current_obj = helper::getPrototype(current_obj);
if (current_obj === null)
throw iterator::StopIteration;

current_ids = magic::getEnumerableIds(current_obj);
current_ids = helper::getEnumerableIds(current_obj);
current_index = 0;
}

let id : EnumerableId = current_ids[current_index++];

// Check for a shadowing property from initial_obj to current_obj on the prototype chain.
for (let obj : Object = initial_obj; obj !== current_obj; obj = magic::getPrototype(obj)) {
if (magic::hasOwnProperty(obj, id))
for (let obj : Object = initial_obj; obj !== current_obj; obj = helper::getPrototype(obj)) {
if (helper::hasOwnProperty(obj, id))
continue loop;
}

// Check whether name is still bound in order to skip deleted properties.
if (magic::hasOwnProperty(current_obj, id))
if (helper::hasOwnProperty(current_obj, id))
return result_fun(id, initial_obj);
}
}
Expand Down Expand Up @@ -166,23 +164,23 @@
this.send(undefined)

public function send(i)
magic::genSend(this, i)
helper::genSend(this, i)

public function throw_(e)
magic::genThrow(this, e)
helper::genThrow(this, e)

public function close() : void
magic::genClose(this)
helper::genClose(this)

// FIXME: this gets trumped by Mach.magicToUstring
// FIXME: this gets trumped by Mach.primitiveToUstring
//public function toString()
// "[object Generator]"
}

// 15.1.2.1 eval (x)
//
// FIXME: This should probably be an intrinsic::eval that looks
// like public::eval below but which delegates to magic::eval,
// like public::eval below but which delegates to helper::eval,
// passing "this function" as the object from which to extract the
// scope chain.

Expand Down
Loading

0 comments on commit 4997d30

Please sign in to comment.