Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into pr_conjugate
Browse files Browse the repository at this point in the history
  • Loading branch information
ebertmi committed Sep 28, 2015
2 parents d206d50 + c1a86ed commit f738353
Show file tree
Hide file tree
Showing 19 changed files with 333 additions and 9 deletions.
1 change: 0 additions & 1 deletion m

This file was deleted.

2 changes: 2 additions & 0 deletions m
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
PATH=$(npm bin):$PATH ./skulpt.py "$@"
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dependencies": {
"jshint": "~2.5.2",
"jscs": "~1.11"
"jscs": "~1.12",
"jsdoc": "~3.3.2"
}
}
1 change: 1 addition & 0 deletions src/builtin/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var $builtinmodule = function (name) {

sys.debug = new Sk.builtin.func(function () {
debugger;
return Sk.builtin.none.none$;
});

return sys;
Expand Down
24 changes: 18 additions & 6 deletions src/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1769,13 +1769,21 @@ Compiler.prototype.cgenexpgen = function (generators, genIndex, elt) {
this._jump(start);
this.setBlock(start);

this.annotateSource(elt);

// load targets
nexti = this._gr("next", "Sk.abstr.iternext(", iter, ")");
out ("$ret = Sk.abstr.iternext(", iter,(this.u.canSuspend?", true":", false"),");");

this._checkSuspension(elt);

nexti = this._gr("next", "$ret");
this._jumpundef(nexti, end); // todo; this should be handled by StopIteration
target = this.vexpr(ge.target, nexti);

n = ge.ifs.length;
for (i = 0; i < n; ++i) {
this.annotateSource(ge.ifs[i]);

ifres = this.vexpr(ge.ifs[i]);
this._jumpfalse(ifres, start);
}
Expand All @@ -1785,6 +1793,8 @@ Compiler.prototype.cgenexpgen = function (generators, genIndex, elt) {
}

if (genIndex >= generators.length) {
this.annotateSource(elt);

velt = this.vexpr(elt);
out("return [", skip, "/*resume*/,", velt, "/*ret*/];");
this.setBlock(skip);
Expand Down Expand Up @@ -1834,23 +1844,25 @@ Compiler.prototype.cclass = function (s) {
entryBlock = this.newBlock("class entry");

this.u.prefixCode = "var " + scopename + "=(function $" + s.name.v + "$class_outer($globals,$locals,$rest){var $gbl=$globals,$loc=$locals;";
this.u.switchCode += "return(function $" + s.name.v + "$_closure(){";
this.u.switchCode += "(function $" + s.name.v + "$_closure(){";
this.u.switchCode += "var $blk=" + entryBlock + ",$exc=[],$ret=undefined,currLineNo=undefined,currColNo=undefined;"
if (Sk.execLimit !== null) {
this.u.switchCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = Date.now()}";
}
if (Sk.yieldLimit !== null && this.u.canSuspend) {
this.u.switchCode += "if (typeof Sk.lastYield === 'undefined') {Sk.lastYield = Date.now()}";
}
this.u.switchCode += "while(true){";

this.u.switchCode += "while(true){try{";
this.u.switchCode += this.outputInterruptTest();
this.u.switchCode += "switch($blk){";
this.u.suffixCode = "}break;}}).apply(null,$rest);});";
this.u.suffixCode = "}}catch(err){ if (!(err instanceof Sk.builtin.BaseException)) { err = new Sk.builtin.ExternalError(err); } err.traceback.push({lineno: currLineNo, colno: currColNo, filename: '"+this.filename+"'}); if ($exc.length>0) { $err = err; $blk=$exc.pop(); continue; } else { throw err; }}}"
this.u.suffixCode += "}).apply(null,$rest);});";

this.u.private_ = s.name;

this.cbody(s.body);
out("break;");
out("return;");

// build class

Expand Down Expand Up @@ -2235,7 +2247,7 @@ Compiler.prototype.cmod = function (mod) {

var entryBlock = this.newBlock("module entry");
this.u.prefixCode = "var " + modf + "=(function($modname){";
this.u.varDeclsCode = "var $gbl = {}, $blk=" + entryBlock + ",$exc=[],$loc=$gbl,$err=undefined;$gbl.__name__=$modname,$ret=undefined,currLineNo=undefined,currColNo=undefined;";
this.u.varDeclsCode = "var $gbl = {}, $blk=" + entryBlock + ",$exc=[],$loc=$gbl,$err=undefined;$gbl.__name__=$modname;var $ret=undefined,currLineNo=undefined,currColNo=undefined;";
if (Sk.execLimit !== null) {
this.u.varDeclsCode += "if (typeof Sk.execStart === 'undefined') {Sk.execStart = Date.now()}";
}
Expand Down
2 changes: 1 addition & 1 deletion src/dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Sk.builtin.dict.prototype.tp$iter = function () {
for (k in this) {
if (this.hasOwnProperty(k)) {
bucket = this[k];
if (bucket && bucket.$hash !== undefined) {
if (bucket && bucket.$hash !== undefined && bucket.items !== undefined) {
// skip internal stuff. todo; merge pyobj and this
for (i = 0; i < bucket.items.length; i++) {
allkeys.push(bucket.items[i].lhs);
Expand Down
36 changes: 36 additions & 0 deletions src/lib/turtle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,42 @@ function generateTurtleModule(_target) {
};
proto.$getscreen.isSk = true;

proto.$clone = function() {

var newTurtleInstance = Sk.misceval.callsimOrSuspend(_module.Turtle);

// All the properties that are in getState()
newTurtleInstance.instance._x = this._x;
newTurtleInstance.instance._y = this._y;
newTurtleInstance.instance._angle = this._angle;
newTurtleInstance.instance._radians = this._radians;
newTurtleInstance.instance._shape = this._shape;
newTurtleInstance.instance._color = this._color;
newTurtleInstance.instance._fill = this._fill;
newTurtleInstance.instance._filling = this._filling;
newTurtleInstance.instance._size = this._size;
newTurtleInstance.instance._computed_speed = this._computed_speed;
newTurtleInstance.instance._down = this._down;
newTurtleInstance.instance._shown = this._shown;

// Other properties to copy
newTurtleInstance.instance._isRadians = this._isRadians;
newTurtleInstance.instance._fullCircle = this._fullCircle;
newTurtleInstance.instance._bufferSize = this._bufferSize;
console.log(this._undoBuffer);
newTurtleInstance.instance._undoBuffer = this._undoBuffer;
console.log(newTurtleInstance.instance._undoBuffer);


newTurtleInstance._clonedFrom = this;

return newTurtleInstance;
};
proto.$clone.returnType = function(value) {
// When I return the instance here, I'm not sure if it ends up with the right "Turtle" python type.
return value
};

proto.$getturtle = proto.$getpen = function() {
return this.skInstance;
};
Expand Down
11 changes: 11 additions & 0 deletions test/run/t555.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from time import sleep

def sleeping_generator():
for i in range(5):
sleep(0.01)
yield i

x = (i for i in sleeping_generator())

print list(x)

1 change: 1 addition & 0 deletions test/run/t555.py.real
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0, 1, 2, 3, 4]
100 changes: 100 additions & 0 deletions test/run/t555.py.symtab
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Sym_type: module
Sym_name: top
Sym_lineno: 0
Sym_nested: False
Sym_haschildren: True
-- Identifiers --
name: list
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: sleep
is_referenced: False
is_imported: True
is_parameter: False
is_global: False
is_declared_global: False
is_local: True
is_free: False
is_assigned: False
is_namespace: False
namespaces: [
]
name: sleeping_generator
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: True
namespaces: [
Sym_type: function
Sym_name: sleeping_generator
Sym_lineno: 3
Sym_nested: False
Sym_haschildren: False
Func_params: []
Func_locals: ['i']
Func_globals: ['range', 'sleep']
Func_frees: []
-- Identifiers --
name: i
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: [
]
name: range
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: sleep
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: x
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: [
]
49 changes: 49 additions & 0 deletions test/run/t555.trans
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Module(body=[ImportFrom(module='time',
names=[alias(name='sleep',
asname=None)],
level=0),
FunctionDef(name='sleeping_generator',
args=arguments(args=[],
vararg=None,
kwarg=None,
defaults=[]),
body=[For(target=Name(id='i',
ctx=Store()),
iter=Call(func=Name(id='range',
ctx=Load()),
args=[Num(n=5)],
keywords=[],
starargs=None,
kwargs=None),
body=[Expr(value=Call(func=Name(id='sleep',
ctx=Load()),
args=[Num(n=0.01)],
keywords=[],
starargs=None,
kwargs=None)),
Expr(value=Yield(value=Name(id='i',
ctx=Load())))],
orelse=[])],
decorator_list=[]),
Assign(targets=[Name(id='x',
ctx=Store())],
value=GeneratorExp(elt=Name(id='i',
ctx=Load()),
generators=[comprehension(target=Name(id='i',
ctx=Store()),
iter=Call(func=Name(id='sleeping_generator',
ctx=Load()),
args=[],
keywords=[],
starargs=None,
kwargs=None),
ifs=[])])),
Print(dest=None,
values=[Call(func=Name(id='list',
ctx=Load()),
args=[Name(id='x',
ctx=Load())],
keywords=[],
starargs=None,
kwargs=None)],
nl=True)])
5 changes: 5 additions & 0 deletions test/run/t556.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class C:
try:
raise Exception("Oops")
except:
print "Caught"
1 change: 1 addition & 0 deletions test/run/t556.py.real
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Caught
37 changes: 37 additions & 0 deletions test/run/t556.py.symtab
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Sym_type: module
Sym_name: top
Sym_lineno: 0
Sym_nested: False
Sym_haschildren: True
-- Identifiers --
name: C
is_referenced: False
is_imported: False
is_parameter: False
is_global: False
is_declared_global: False
is_local: True
is_free: False
is_assigned: True
is_namespace: True
namespaces: [
Sym_type: class
Sym_name: C
Sym_lineno: 1
Sym_nested: False
Sym_haschildren: False
Class_methods: []
-- Identifiers --
name: Exception
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: [
]
]
17 changes: 17 additions & 0 deletions test/run/t556.trans
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Module(body=[ClassDef(name='C',
bases=[],
body=[TryExcept(body=[Raise(type=Call(func=Name(id='Exception',
ctx=Load()),
args=[Str(s='Oops')],
keywords=[],
starargs=None,
kwargs=None),
inst=None,
tback=None)],
handlers=[ExceptHandler(type=None,
name=None,
body=[Print(dest=None,
values=[Str(s='Caught')],
nl=True)])],
orelse=[])],
decorator_list=[])])
2 changes: 2 additions & 0 deletions test/run/t557.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class C:
raise Exception("Oops")
1 change: 1 addition & 0 deletions test/run/t557.py.real
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXCEPTION: Exception: Oops on line 2
1 change: 1 addition & 0 deletions test/run/t557.py.real.force
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXCEPTION: Exception: Oops on line 2
Loading

0 comments on commit f738353

Please sign in to comment.