Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
491bbf8
Merge pull request #3 from Jacco/master
Jacco May 22, 2015
b1800cf
Merge pull request #4 from skulpt/decorators
Jacco May 22, 2015
c6d9af7
First decorator and descriptor implementation
Jacco May 22, 2015
a55f728
Merge pull request #426 from Jacco/decorators
bnmnetp May 23, 2015
8f278d3
Calling a descriptor: for staticmethod/class method decorator
Jacco May 23, 2015
36b044e
Merge pull request #429 from Jacco/decorators
bnmnetp May 23, 2015
9c03b80
Adds KeyboardInterrupt Exception
ebertmi Aug 19, 2015
078d8a9
Merge remote-tracking branch 'upstream/master'
ebertmi Aug 19, 2015
108c2ce
Merge remote-tracking branch 'upstream/master'
ebertmi Sep 30, 2015
0fc79c3
Add basic locals support and module __str__
ebertmi Oct 5, 2015
25e6729
Fixes couple of math.log edges adds unit test
ebertmi Oct 11, 2015
870dfcb
Deactivates some tests for complex, have been wrong
ebertmi Oct 14, 2015
44e9b1e
Merge remote-tracking branch 'upstream/master' into pr_log2
ebertmi Oct 15, 2015
ec647e8
Merge remote-tracking branch 'upstream/master' into pr_locals
ebertmi Oct 18, 2015
4c2ba6d
Disables one failing test, we need to implement frexp
ebertmi Oct 19, 2015
9a317c4
Merge branch 'pr_abs_impr' into epy_build
ebertmi Oct 19, 2015
7994395
Merge branch 'pr_locals' into epy_build
ebertmi Oct 19, 2015
c64c8e9
Merge branch 'pr_fromlistimport' into epy_build
ebertmi Oct 19, 2015
6fe5ef1
Refactor module.__str__ for google clousure
ebertmi Oct 19, 2015
3388232
Merge branch 'pr_locals' into epy_build
ebertmi Oct 19, 2015
ad541ba
Fixes c-style print for py3
ebertmi Oct 20, 2015
877b563
Fixes various skulpt python3 issues
ebertmi Apr 28, 2016
7579c3a
Merge remote-tracking branch 'upstream/master' into epy_build
ebertmi Apr 28, 2016
2669f18
Merge fixes
ebertmi Apr 28, 2016
04e2b0e
Merge remote-tracking branch 'upstream/decorators' into epy_build
ebertmi May 13, 2016
649ea49
Merge remote-tracking branch 'upstream/master' into epy_build
ebertmi Jul 12, 2016
2d18224
File writing and reading improvements
ebertmi Jul 12, 2016
75309aa
Merge remote-tracking branch 'skulpt/master' into epy_build
ebertmi Jul 21, 2016
d3f354e
[SenseHat] Adds Killable While and Killable For :fireworks:
ebertmi Jul 18, 2016
ab57ed3
Fixes Sk.killableWhile performance issues
ebertmi Jul 20, 2016
0d35167
Fix for relative imports in console/repl mode.
brianpmarks Jul 18, 2016
6b6f5b9
Performance improvement and tries to fix choked events
ebertmi Jul 25, 2016
d41863d
Prevents Exception on Firefox 47 (Windows 10) for failing regex
ebertmi Jul 25, 2016
d74cb64
Fixes time module timezoneName bug in FF47 on Win 10
ebertmi Jul 26, 2016
61d92f8
Guards window object access in time.js
ebertmi Jul 27, 2016
c97afea
implemetation of copy and types module
robyntorregrosa Aug 1, 2016
62c45bf
Use a Javascript object instead of a Python dictionary for performance.
rixner Aug 2, 2016
fdbdb12
capitalized CPython, got rid of __dict__() in testing code
robyntorregrosa Aug 2, 2016
9653fc0
Merge remote-tracking branch 'upstream/master' into epy_build
ebertmi Aug 3, 2016
b3a9dc8
Fixes killableWhile and math.isinf
ebertmi Aug 3, 2016
c77b84a
add pure python staticmethod and tests
bnmnetp Aug 3, 2016
c0e86e4
commented out tests for classmethod
bnmnetp Aug 3, 2016
2703562
Merge pull request #613 from rixner/copy-module-pr
albertjan Aug 3, 2016
d04eda9
update license
bnmnetp Aug 4, 2016
388b65f
Merge pull request #614 from skulpt/staticmethod
albertjan Aug 4, 2016
180dfdb
hasattr now checks for __getattr__, added in testing
robyntorregrosa Aug 2, 2016
644df13
implemented builtin delattr, cleaned up setattr (can no longer set at…
robyntorregrosa Aug 4, 2016
69fee5f
Try to add classmethod
bnmnetp Aug 4, 2016
8475a70
Merge branch 'master' into classmethod
bnmnetp Aug 4, 2016
91a92a0
check # args before check for builtins in setattr, delattr
robyntorregrosa Aug 4, 2016
4e863c3
temporary fix
Aug 5, 2016
116245c
Fixes uncaught errors inside suspensions regression
ebertmi Aug 5, 2016
9965a0d
Merge remote-tracking branch 'upstream/master' into epy_build
ebertmi Aug 5, 2016
87b7063
non-temporary-fix
Aug 12, 2016
fa55a6c
re assign $free because its assigned the first of the varargs
Aug 12, 2016
1993fc2
clean up varargs and free solution
Aug 16, 2016
e3b68d1
callSimOrSuspend in the other branch as well
Aug 16, 2016
54645b5
Merge pull request #616 from skulpt/staticmethod
bnmnetp Aug 18, 2016
6b7b908
Merge pull request #615 from skulpt/licenseupdate
bnmnetp Aug 18, 2016
5fca812
handle suspendable functions without a canSuspend arg
Aug 19, 2016
168908b
fix left shift
Aug 19, 2016
c9ab155
make sure all @OPiMedia tests pass
Aug 19, 2016
ecceecd
Merge pull request #622 from albertjan/leftshift-fix
bnmnetp Aug 21, 2016
70b4379
Merge pull request #618 from rixner/delattr-pr
bnmnetp Aug 21, 2016
20d27cc
make it possible to have an input fun that takes a prompt
Aug 22, 2016
96b11cd
Merge pull request #624 from albertjan/input-fun-prompt
bnmnetp Aug 22, 2016
4a16f24
sleepy-len now works, the canSuspendIdx should have been 1
Aug 28, 2016
ecfc84b
add regression test
Aug 28, 2016
ad58b6e
Add dummy 'root' substitution for run_template.html
meredydd Aug 31, 2016
c6de20b
Merge pull request #630 from meredydd/brun-pr
albertjan Aug 31, 2016
93d0dc6
Merge pull request #619 from albertjan/len-sleep
eah13 Sep 6, 2016
da1a5e9
return .instance from ensureAnonymous
Sep 8, 2016
5735fe3
Merge pull request #632 from albertjan/fix-anonymous-turtle
bnmnetp Sep 16, 2016
7b6f8ce
Merge remote-tracking branch 'upstream/master' into epy_build
ebertmi Sep 19, 2016
c90d67b
Fixes file opening
ebertmi Jan 18, 2017
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
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2009-2010 Scott Graham
Copyright (c) 2009-2016 Scott Graham and contributors to the Skulpt Project

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -25,7 +25,7 @@ Portions of the code were written with the benefit of viewing code that's in
the official "CPython" and "pypy" distribution and/or translated from code that's in the
official "CPython" and "pypy" distribution. As such, they are:

Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Python Software
Copyright (c) 2001 -- 2016 Python Software
Foundation; All Rights Reserved"

per:
Expand Down
15 changes: 12 additions & 3 deletions skulpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def bowerProperty(name):
('support/closure-library/closure/goog/debug/error.js', FILE_TYPE_DIST),
('support/closure-library/closure/goog/asserts/asserts.js', FILE_TYPE_DIST),
('support/es6-promise-polyfill/promise-1.0.0.hacked.js', FILE_TYPE_DIST),
'support/setImmediate/setImmediate.js',
'src/env.js',
'src/type.js',
'src/abstract.js',
Expand Down Expand Up @@ -729,11 +730,19 @@ def dist(options):
builtinfn = os.path.join(DIST_DIR, OUTFILE_LIB)
debuggerfn = os.path.join(DIST_DIR, OUTFILE_DEBUGGER)

ret = test()

# Run tests on uncompressed.
if options.verbose:
print ". Running tests on uncompressed..."
print ". Re-Running tests on uncompressed... with debug mode on to find suspension errors."

ret = test()
# turn the tests in debug mode off because they take too long
# # Run tests on uncompressed.
# if options.verbose:
# print ". Re-Running tests on uncompressed... with debug mode on to find suspension errors."
#
#
# ret = test(debug_mode=True)

# turn the tests in debug mode off because they take too long
# # Run tests on uncompressed.
Expand Down Expand Up @@ -881,7 +890,7 @@ def run_in_browser(fn, options, debug_mode=False):

with open('support/run_template.html') as tpfile:
page = tpfile.read()
page = page % dict(code=prog,scripts=scripts,debug_mode=str(debug_mode).lower())
page = page % dict(code=prog,scripts=scripts,debug_mode=str(debug_mode).lower(),root="")

with open("{0}/run.html".format(RUN_DIR),"w") as htmlfile:
htmlfile.write(page)
Expand Down
124 changes: 102 additions & 22 deletions src/builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ Sk.builtin.len = function len (item) {
var int_ = function(i) { return new Sk.builtin.int_(i); };

if (item.sq$length) {
return Sk.misceval.chain(item.sq$length(), int_);
return Sk.misceval.chain(item.sq$length(true), int_);
}

if (item.mp$length) {
Expand Down Expand Up @@ -559,7 +559,8 @@ Sk.builtin.dir = function dir (x) {
var internal = [
"__bases__", "__mro__", "__class__", "__name__", "GenericGetAttr",
"GenericSetAttr", "GenericPythonGetAttr", "GenericPythonSetAttr",
"pythonFunctions", "HashNotImplemented", "constructor"];
"pythonFunctions", "HashNotImplemented", "constructor", "__dict__"
];
if (internal.indexOf(k) !== -1) {
return null;
}
Expand Down Expand Up @@ -670,10 +671,13 @@ Sk.builtin.repr = function repr (x) {
Sk.builtin.open = function open (filename, mode, bufsize) {
Sk.builtin.pyCheckArgs("open", arguments, 1, 3);
if (mode === undefined) {
mode = new Sk.builtin.str("r");
mode = new Sk.builtin.str("r");
}

return new Sk.builtin.file(filename, mode, bufsize);

/*if (mode.v !== "r" && mode.v !== "b" && !Sk.nonreadopen) {
throw new Sk.builtin.ValueError("Hinweis: Bitte verwenden Sie PyCharm für dieses Beispiel. Das Schreiben von Dateien wird derzeit nicht online unterstützt.");
}*/
};

Sk.builtin.isinstance = function isinstance (obj, type) {
Expand Down Expand Up @@ -754,11 +758,11 @@ Sk.builtin.hash = function hash (value) {
value.$savedHash_ = value.tp$hash();
return value.$savedHash_;
} else {
if (value.__id === undefined) {
if (value.__hash === undefined) {
Sk.builtin.hashCount += 1;
value.__id = Sk.builtin.hashCount;
value.__hash = Sk.builtin.hashCount;
}
return new Sk.builtin.int_(value.__id);
return new Sk.builtin.int_(value.__hash);
}
} else if (typeof value === "number" || value === null ||
value === true || value === false) {
Expand Down Expand Up @@ -788,24 +792,31 @@ Sk.builtin.getattr = function getattr (obj, name, default_) {
};

Sk.builtin.setattr = function setattr (obj, name, value) {

Sk.builtin.pyCheckArgs("setattr", arguments, 3, 3);
if (!Sk.builtin.checkString(name)) {
throw new Sk.builtin.TypeError("attribute name must be string");
}
if (obj.tp$setattr) {
obj.tp$setattr(Sk.ffi.remapToJs(name), value);
} else {
throw new Sk.builtin.AttributeError("object has no attribute " + Sk.ffi.remapToJs(name));
// cannot set or del attr from builtin type
if (obj === undefined || obj["$r"] === undefined || obj["$r"]().v.slice(1,5) !== "type") {
if (!Sk.builtin.checkString(name)) {
throw new Sk.builtin.TypeError("attribute name must be string");
}
if (obj.tp$setattr) {
obj.tp$setattr(Sk.ffi.remapToJs(name), value);
} else {
throw new Sk.builtin.AttributeError("object has no attribute " + Sk.ffi.remapToJs(name));
}
return Sk.builtin.none.none$;
}

return Sk.builtin.none.none$;
throw new Sk.builtin.TypeError("can't set attributes of built-in/extension type '" + obj.tp$name + "'");
};

Sk.builtin.raw_input = function (prompt) {
var sys = Sk.importModule("sys");
var lprompt = prompt ? prompt : "";

if (Sk.inputfunTakesPrompt) {
return Sk.misceval.callsimOrSuspend(Sk.builtin.file.$readline, sys["$d"]["stdin"], null, lprompt);
}

return Sk.misceval.chain(undefined, function () {
return Sk.misceval.callsimOrSuspend(sys["$d"]["stdout"]["write"], sys["$d"]["stdout"], new Sk.builtin.str(prompt));
}, function () {
Expand Down Expand Up @@ -994,6 +1005,7 @@ Sk.builtin.filter = function filter (fun, iterable) {

Sk.builtin.hasattr = function hasattr (obj, attr) {
Sk.builtin.pyCheckArgs("hasattr", arguments, 2, 2);
var special, ret;
if (!Sk.builtin.checkString(attr)) {
throw new Sk.builtin.TypeError("hasattr(): attribute name must be string");
}
Expand All @@ -1002,14 +1014,32 @@ Sk.builtin.hasattr = function hasattr (obj, attr) {
if (obj.tp$getattr(attr.v)) {
return Sk.builtin.bool.true$;
} else {
return Sk.builtin.bool.false$;
special = Sk.abstr.lookupSpecial(obj, "__getattr__");
if (special) {
ret = Sk.misceval.tryCatch(function () {
var val = Sk.misceval.callsim(special, obj, attr);
if (val) {
return Sk.builtin.bool.true$;
} else {
return Sk.builtin.bool.false$;
}
}, function(e) {
if (e instanceof Sk.builtin.AttributeError) {
return Sk.builtin.bool.false$;
} else {
throw e;
}
});
return ret;
} else {
return Sk.builtin.bool.false$;
}
}
} else {
throw new Sk.builtin.AttributeError("Object has no tp$getattr method");
}
};


Sk.builtin.pow = function pow (a, b, c) {
var ret;
var res;
Expand Down Expand Up @@ -1207,6 +1237,17 @@ Sk.builtin.reversed = function reversed (seq) {
}
};

Sk.builtin.id = function (obj) {
Sk.builtin.pyCheckArgs("id", arguments, 1, 1);

if (obj.__id === undefined) {
Sk.builtin.idCount += 1;
obj.__id = Sk.builtin.idCount;
}

return new Sk.builtin.int_(obj.__id);
};

Sk.builtin.bytearray = function bytearray () {
throw new Sk.builtin.NotImplementedError("bytearray is not yet implemented");
};
Expand All @@ -1221,9 +1262,37 @@ Sk.builtin.callable = function callable (obj) {
return Sk.builtin.bool.false$;
};

Sk.builtin.delattr = function delattr () {
throw new Sk.builtin.NotImplementedError("delattr is not yet implemented");
Sk.builtin.delattr = function delattr (obj, attr) {
Sk.builtin.pyCheckArgs("delattr", arguments, 2, 2);
if (obj["$d"][attr.v] !== undefined) {
var ret = Sk.misceval.tryCatch(function() {
var try1 = Sk.builtin.setattr(obj, attr, undefined);
return try1;
}, function(e) {
Sk.misceval.tryCatch(function() {
var try2 = Sk.builtin.setattr(obj["$d"], attr, undefined);

return try2;
}, function(e) {
if (e instanceof Sk.builtin.AttributeError) {
throw new Sk.builtin.AttributeError(Sk.abstr.typeName(obj) + " instance has no attribute '"+ attr.v+ "'");
} else {
throw e;
}
});
});
return ret;
} // cannot set or del attr from builtin type
if (obj["$r"]().v.slice(1,5) !== "type") {
if (obj.ob$type === Sk.builtin.type && obj[attr.v] !== undefined) {
obj[attr.v] = undefined;
return Sk.builtin.none.none$;
}
throw new Sk.builtin.AttributeError(Sk.abstr.typeName(obj) + " instance has no attribute '"+ attr.v+ "'");
}
throw new Sk.builtin.TypeError("can't set attributes of built-in/extension type '" + obj.tp$name + "'");
};

Sk.builtin.execfile = function execfile () {
throw new Sk.builtin.NotImplementedError("execfile is not yet implemented");
};
Expand Down Expand Up @@ -1255,7 +1324,19 @@ Sk.builtin.iter = function iter (obj, sentinel) {
};

Sk.builtin.locals = function locals () {
throw new Sk.builtin.NotImplementedError("locals is not yet implemented");
/*global Sk.locals */
if (Sk["locals"] != null) {
var localsDict = [];
for (var prop in Sk["locals"]) {
if (Sk["locals"].hasOwnProperty(prop)) {
localsDict.push(new Sk.builtin.str(prop));
localsDict.push(Sk["locals"][prop]);
}
}
return new Sk.builtin.dict(localsDict);
} else {
throw new Sk.builtin.NotImplementedError("locals is not yet implemented");
}
};
Sk.builtin.memoryview = function memoryview () {
throw new Sk.builtin.NotImplementedError("memoryview is not yet implemented");
Expand Down Expand Up @@ -1298,7 +1379,6 @@ Sk.builtin.intern = function intern () {
throw new Sk.builtin.NotImplementedError("intern is not yet implemented");
};


/*
Sk.builtinFiles = {};
Sk.builtin.read = function read(x) {
Expand Down
19 changes: 19 additions & 0 deletions src/builtin/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ var $builtinmodule = function (name) {
return Sk.builtin.none.none$;
});

sys.exit = new Sk.builtin.func(function(arg) {
Sk.builtin.pyCheckArgs("exit", arguments, 0, 1);
var exit_status;
if (arg == null || Sk.builtin.checkNone(arg)) {
exit_status = 0
} else if (Sk.builtin.checkInt(arg)){
exit_status = Sk.ffi.remapToJs(arg);
} else {
exit_status = 1;
}

if (Sk.builtin.checkString(arg)) {
// print arg to console
Sk.output(Sk.ffi.remapToJs(arg))
}

throw new Sk.builtin.SystemExit(exit_status);
});

sys.__stdout__ = new Sk.builtin.file(new Sk.builtin.str("/dev/stdout"), "w");
sys.__stdin__ = new Sk.builtin.file(new Sk.builtin.str("/dev/stdin"), "r");

Expand Down
1 change: 1 addition & 0 deletions src/builtindict.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Sk.builtins = {
"float_$rw$": Sk.builtin.float_,
"int_$rw$" : Sk.builtin.int_,
"hasattr" : Sk.builtin.hasattr,
"id" : Sk.builtin.id,

"map" : Sk.builtin.map,
"filter": Sk.builtin.filter,
Expand Down
12 changes: 12 additions & 0 deletions src/classmethod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class classmethod(object):
"Emulate PyClassMethod_Type() in Objects/funcobject.c"

def __init__(self, f):
self.f = f

def __get__(self, obj, klass=None):
if klass is None:
klass = type(obj)
def newfunc(*args):
return self.f(klass, *args)
return newfunc
Loading