self-compiling pattern matching correctly

This commit is contained in:
Jeremy Ashkenas
2010-02-11 20:11:11 -05:00
parent 98f15d001f
commit 38d1381c02
2 changed files with 18 additions and 7 deletions

View File

@@ -600,6 +600,7 @@ AssignNode: exports.AssignNode: inherit Node, {
if obj instanceof SplatNode
val: new LiteralNode(obj.compile_value(o, val_var, @variable.base.objects.indexOf(obj)))
else
idx: new LiteralNode(idx) unless typeof idx is 'object'
val: new ValueNode(new LiteralNode(val_var), [new access_class(idx)])
assigns.push(new AssignNode(obj, val).compile(o))
assigns.join("\n")
@@ -664,11 +665,12 @@ SplatNode: exports.SplatNode: inherit Node, {
if @index then @compile_param(o) else @name.compile(o)
compile_param: (o) ->
o.scope.find @name
@name + ' = Array.prototype.slice.call(arguments, ' + @index + ')'
name: @name.compile(o)
o.scope.find name
name + ' = Array.prototype.slice.call(arguments, ' + @index + ')'
compile_value: (o, name, index) ->
"Array.prototype.slice.call(" + @name + ', ' + @index + ')'
"Array.prototype.slice.call(" + name + ', ' + index + ')'
}