forked from skulpt/skulpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 43 make sort(reverse=True) work
There were two possible approaches to making key=value parameters work and I took what I saw as the safe impact with the most limited impact. I also tried code in function.js that automatically added the co_varnames to all functions defined using Sk.builtin.func as follows: if ( code ) { funStr = code.toString(); parms= funStr.slice(funStr.indexOf('(')+1, funStr.indexOf(')')).match(/([^\s,]+)/g); if ( parms.length > 0 ) { this.func_code['co_varnames']=parms; } } This code worked for sort(reverse=True), but lots of code started to fail in the unit tests having to do with parameter passing and Python defined functions. It would be good in the above code to only trigger on native JS library functions.
- Loading branch information
Showing
6 changed files
with
101 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
l = [9,8,1,2,3,45,5] | ||
l.sort() | ||
print l | ||
print "---------------- DEFAULT" | ||
l.sort(reverse=True) | ||
print l | ||
print "---------------- REVERSE" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[1, 2, 3, 5, 8, 9, 45] | ||
---------------- DEFAULT | ||
[45, 9, 8, 5, 3, 2, 1] | ||
---------------- REVERSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Sym_type: module | ||
Sym_name: top | ||
Sym_lineno: 0 | ||
Sym_nested: False | ||
Sym_haschildren: False | ||
-- Identifiers -- | ||
name: True | ||
is_referenced: True | ||
is_imported: False | ||
is_parameter: False | ||
is_global: True | ||
is_declared_global: False | ||
is_local: False | ||
is_free: False | ||
is_assigned: False | ||
is_namespace: False | ||
namespaces: [ | ||
] | ||
name: l | ||
is_referenced: True | ||
is_imported: False | ||
is_parameter: False | ||
is_global: False | ||
is_declared_global: False | ||
is_local: True | ||
is_free: False | ||
is_assigned: True | ||
is_namespace: False | ||
namespaces: [ | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Module(body=[Assign(targets=[Name(id='l', | ||
ctx=Store())], | ||
value=List(elts=[Num(n=9), | ||
Num(n=8), | ||
Num(n=1), | ||
Num(n=2), | ||
Num(n=3), | ||
Num(n=45), | ||
Num(n=5)], | ||
ctx=Load())), | ||
Expr(value=Call(func=Attribute(value=Name(id='l', | ||
ctx=Load()), | ||
attr='sort', | ||
ctx=Load()), | ||
args=[], | ||
keywords=[], | ||
starargs=None, | ||
kwargs=None)), | ||
Print(dest=None, | ||
values=[Name(id='l', | ||
ctx=Load())], | ||
nl=True), | ||
Print(dest=None, | ||
values=[Str(s='---------------- DEFAULT')], | ||
nl=True), | ||
Expr(value=Call(func=Attribute(value=Name(id='l', | ||
ctx=Load()), | ||
attr='sort', | ||
ctx=Load()), | ||
args=[], | ||
keywords=[keyword(arg='reverse', | ||
value=Name(id='True', | ||
ctx=Load()))], | ||
starargs=None, | ||
kwargs=None)), | ||
Print(dest=None, | ||
values=[Name(id='l', | ||
ctx=Load())], | ||
nl=True), | ||
Print(dest=None, | ||
values=[Str(s='---------------- REVERSE')], | ||
nl=True)]) |