upgrading the test harness

This commit is contained in:
Jeremy Ashkenas 2010-02-09 08:15:11 -05:00
parent c6a6788694
commit a451e90374
3 changed files with 35 additions and 93 deletions

View File

@ -10,193 +10,139 @@
// and cloned throughout, containing messages from higher in the AST,
// information about the current scope, and indentation level.
exports.Expressions = function Expressions() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return Expressions === this.constructor ? this : __a;
return this.values = arguments;
};
exports.LiteralNode = function LiteralNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return LiteralNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.ReturnNode = function ReturnNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return ReturnNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.CommentNode = function CommentNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return CommentNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.CallNode = function CallNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return CallNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.ExtendsNode = function ExtendsNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return ExtendsNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.ValueNode = function ValueNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return ValueNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.AccessorNode = function AccessorNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return AccessorNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.IndexNode = function IndexNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return IndexNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.RangeNode = function RangeNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return RangeNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.SliceNode = function SliceNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return SliceNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.ThisNode = function ThisNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return ThisNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.AssignNode = function AssignNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return AssignNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.OpNode = function OpNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return OpNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.CodeNode = function CodeNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return CodeNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.SplatNode = function SplatNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return SplatNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.ObjectNode = function ObjectNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return ObjectNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.ArrayNode = function ArrayNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return ArrayNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.PushNode = function PushNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return PushNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.ClosureNode = function ClosureNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return ClosureNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.WhileNode = function WhileNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return WhileNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.ForNode = function ForNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return ForNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.TryNode = function TryNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return TryNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.ThrowNode = function ThrowNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return ThrowNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.ExistenceNode = function ExistenceNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return ExistenceNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.ParentheticalNode = function ParentheticalNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return ParentheticalNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.IfNode = function IfNode() {
var __a;
var arguments = Array.prototype.slice.call(arguments, 0);
this.name = this.constructor.name;
__a = this.values = arguments;
return IfNode === this.constructor ? this : __a;
return this.values = arguments;
};
exports.Expressions.wrap = function wrap(values) {
return this.values = values;
@ -425,6 +371,8 @@
return node === this.expressions[l - this.last_index];
},
compile: function compile(o) {
o = o || {
};
return o.scope ? compile.__superClass__.constructor.call(this, o) : this.compile_root(o);
},
// Compile each expression in the Expressions body.
@ -470,7 +418,7 @@
},
// Compiles a single expression within the expressions body.
compile_expression: function compile_expression(node, o) {
var returns, stmt, temp;
var returns, stmt;
this.indent = o.indent;
stmt = node.is_statement();
// We need to return the result if this is the last node in the expressions body.
@ -487,13 +435,8 @@
returns: true
}));
}
// If it's not part of a constructor, we can just return the value of the expression.
if (!((o.scope.method == undefined ? undefined : o.scope.method.is_constructor()))) {
return this.idt() + 'return ' + node.compile(o);
}
// It's the last line of a constructor, add a safety check.
temp = o.scope.free_variable();
return this.idt() + temp + ' = ' + node.compile(o) + ";\n" + this.idt() + "return " + o.scope.method.name + ' === this.constructor ? this : ' + temp + ';';
// Otherwise, we can just return the value of the expression.
return this.idt() + 'return ' + node.compile(o);
}
}));
// Wrap up a node as an Expressions, unless it already is one.

View File

@ -9,15 +9,13 @@
// as well as the Expressions body where it should declare its variables,
// and the function that it wraps.
Scope = (exports.Scope = function Scope(parent, expressions, method) {
var __a;
this.parent = parent;
this.expressions = expressions;
this.method = method;
this.variables = {
};
this.temp_variable = this.parent ? this.parent.temp_variable : '__a';
__a = this;
return Scope === this.constructor ? this : __a;
return this;
});
// Look up a variable in lexical scope, or declare it if not found.
Scope.prototype.find = function find(name, remote) {

View File

@ -116,7 +116,7 @@ Node: exports.Node: ->
# the top level of a block (which would be unnecessary), and we haven't
# already been asked to return the result.
Node::compile: (o) ->
@options: dup(o || {})
@options: dup(o or {})
@indent: o.indent
top: if @top_sensitive() then o.top else del o, 'top'
closure: @is_statement() and not @is_statement_only() and not top and
@ -185,6 +185,7 @@ Expressions: exports.Expressions: inherit Node, {
node is @expressions[l - @last_index]
compile: (o) ->
o ||= {}
if o.scope then super(o) else @compile_root(o)
# Compile each expression in the Expressions body.