Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix semiautovivification with slices #849

Merged
merged 1 commit into from
Feb 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/ast.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/ast.ls
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,6 @@ class exports.Chain extends Node
@head.called = true
else if not @tails.1 and it.key?name is \prototype
@head.sproto = true
else if delete it.vivify
@head = Assign Chain(@head, @tails.splice 0, 9e9), that!, \= \||
else if it instanceof Call and @tails.length is 1
and bi and bi.op in logics = <[ && || xor ]>
call = it
Expand Down Expand Up @@ -759,6 +757,7 @@ class exports.Chain extends Node
.add Call [context, Arr [this; Arr partial.args; Arr partial.partialized]]), post).compile o
@carp 'invalid callee' if tails.0 instanceof Call and not head.is-callable!
@expand-slice o
@expand-vivify!
@expand-bind o
@expand-splat o
@expand-star o
Expand Down Expand Up @@ -837,6 +836,13 @@ class exports.Chain extends Node
i = 0
call <<< method: \.apply, args: [ctx or Literal \null; JS args]

expand-vivify: !->
{tails} = this
i = 0
while i < tails.length when delete tails[i++]vivify
@head = Assign Chain(@head, tails.splice 0, i), that!, \= \||
i = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just i--?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tails can contain multiple things in a row that aren't vivifications. The when guard makes i keep incrementing until it finds a vivification, at which point the loop body splices out everything in tails up to that vivification into the Assign. i needs to be reset back to 0 at that point because i elements have been removed from tails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, duh. I use splice so much I can't even remember its arguments.. Sorry :/.


expand-bind: !(o) ->
{tails} = this
i = -1
Expand Down
5 changes: 5 additions & 0 deletions test/chaining.ls
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ eq '0,1' ''+o.a.b
eq '2,3' ''+o.a.c.d
eq 5 o.a.b.e.f.4

a = []
eq 2 a{}[0, 1].length
eq \object typeof a.0
eq \object typeof a.1

# Bang Call
eq '' String!
(-> ok true)!
Expand Down