breaking changes
python 2 incorrectness:
long- when adding two long objects the result is likely to be an
int
- when adding two long objects the result is likely to be an
method- unbound methods are no longer supported
- The
baseclass for all type objects will beobjecteven if the base class is not specified
skulpt api
Sk.builtin.object.prototype.genericGetAttr->Sk.generic.getAttrSk.builtin.object.prototype.genericSetAttr->Sk.generic.setAttrSk.builtin.typeLookupremovedbiginter.jsreplaced by the jsbi librarySk.abstr.inheritsremoved - inheritance exclusively dealt with bySk.abstr.setUpInheritanceSk.misceval.objectReprreturns a js string (previouslySk.builtin.str)Sk.__future__.python3becomes the default. Those wishing to usepython2must define this in theSk.configureobject.Sk.abstr.binary_op_,Sk.abstr.binary_iop_,Sk.abstr.unary_op_removed - useSk.abstr.numberBinOp,Sk.abstr.numberInplaceBinOp,Sk.abstr.numberUnaryOpinstead.
slot changes only relevant for those developers and those writing slotfunctions directly - hopefully very few users
mp$lengthreplaced bysq$lengthin the codebasesq$ass_item/sq$ass_slicereplaced withmp$ass_subscriptnb$nonzeroreplaced withnb$booland switch version takes care of mapping the appropriate dunder method.mp$del_subscriptreplaced bymp$ass_subscript(as per Cpython)- deleting vs setting an item is based on the call signature
mp$ass_subscript(key, value)-> set itemmp$ass_subscript(key)-> delete item
- If a dunder func is defined on a user defined class then the slot function is guaranteed.
- e.g.
__len__defined guaranteessq$length. - A slot function defined by skulpt in this way throws the appropriate errors and converts the return value to the appropriate object.
sq$length:__len__is called usingSk.misceval.callsim(OrSuspend)Array.- The result is checked to be an
intand then converted tonumbersincesq$lengthexpects anumber.
- e.g.
tp$strremoved from some builtins as per Python 3.8 changes- If
tp$richcompareis defined - wrapper functionsob$eqetc are created during - this waySk.misceval.richCompareBoolneed only check for the existance of anob$*slot.- in fact - the existance of these slots is guaranteed since they are inherited from
Sk.builtin.object
- in fact - the existance of these slots is guaranteed since they are inherited from
tp$mro/tp$basesare Js Arrays rather thanSk.builtin.tupletp$strand$rfor errors were changed as per Cpython.nb$int_->nb$intnb$lng->nb$longnb$float_->nb$float- return values for certain slot functions have changed
tp$hash- should return a javascript number less thanNumber.MAX_SAFE_INTEGERcan be postive or negativenb$index- should return a javascript number or BigInt (older browsers should be a JSBI BigInt)tp$richcompare/ob$*- should return a javascript boolean
tp$namewas removed from instances ofSk.builtin.funcandSk.buitin.methodin favour of$namesince it'stp$nameshould be thetype name
flags
sk$acceptable_as_base_classused for some type objectssk$objectevery skulpt object will have this flag. An easy way to determine if you have a skulpt object or a javascript objecthp$typeall instance ofsk$klasstypessk$prototypicaldo we need to walk up the MRO or can we just check theprototypesk$builtinBasethe most derived base which is a native skulpt classsk$baseClassbuiltin classes that are direct childs ofobject
other internal changes
- the use of
numPromoteFuncwas removed for performance improvements in the implementation ofSk.asbtr.numberBinOp- It was performance beneficial to leave the promoting to the respective
nb$slots intbinop slots only deal with instance ofintfloatbinop slots deal with instances offloatandintcomplexbinop slots deal with instances ofcomplex,floatandint
- It was performance beneficial to leave the promoting to the respective
- since
longwas effectively removed when a number is larger thanNumber.MAX_SAFE_INTEGERit's.vvalue is aBigInt. ifBigIntis not available in the browser then theJSBIlibrary is used to replicateBigIntfunctionality. setandfrozensetnow share much of their implementationcollectionsmodule rewritten using new apiitertoolsmodule rewritten using new api - these are now type objects rather than instances ofgeneratoroperatormodule rewritten using new apimathmodule adapted to the new apidictandsetthrow errors if the objects change size during iteration as per Cpython.- fully tested
Sk.builtin.check*moved tosrc/check.jsnumber.jsremovednumtype.jsremovedseqtype.jsremovedSk.builtin.check*moved tosrc/check.jsmp$subscriptshould not be called by a js object (see changes inrandom.js)quick$lookupadded todict.prototypewhich is a fast way to lookup upstrkeysdict.prototype.entriesrather than has values that arearraysof key value pairsobject.prototype.tp$hashwill no longer add$savedHash_to the object - instead it uses a javascript map and assigns objects to a random number less thanNumber.MAX_SAFE_INTEGERrather than incrementing the hash value each time.float.prototype.tp$hashfor integers this will be the same value asSk.builtin.int.prototype.tp$hashfor non integers this will be a random number less thanNumber.MAX_SAFE_INTEGER. Previously this was the number rounded down - but this creates a lot of collisions.
call signatures of builtins
newis required for (almost) all builtin types- 3 exceptions -
Sk.builtin.bool,Sk.builtin.none,Sk.builtin.NotImplemented - These 3 will always return their respective constant(s) and are thus not required to be used as constructors.
- 3 exceptions -
- Restricted parameters for directly accessing a constructor of an
Sk.builtintype - assertion failures raised in dev mode if
newis not used
| type | params | notes |
|---|---|---|
Sk.builtin.int_ |
`{number | JSBI (bigint) |
Sk.builtin.float_ |
`{number | undefined}` |
Sk.builtin.complex |
{number, number} |
|
Sk.builtin.list |
{Array=} |
Array of py objects or can be called with a python iterable |
Sk.builtin.tuple |
{Array=} |
Array of py objects can be called with a python iterable |
Sk.builtin.set |
{Array=} |
Array of py objects or can be called with a python iterable |
Sk.builtin.dict |
{Array=} |
key/value pairs - only python objects |
Sk.builtin.str |
{*} |
|
Sk.builtin.bool |
{*} |
Major changes
- All type objects are now callable using their respective
tp$callmethods inherited fromSk.builtin.type - All native type objects will require a
tp$newandtp$initmethod (maybe inherited bySk.builtin.object) - All type objects are javascript instances of
Sk.builtin.type - All single inherited objects follow javascript inheritance
- All native type objects now have the following and replaces the use of
Sk.builtin.funcfor all dunder function/methods.wrapper_descriptorsakaslot_wrappersmethod_descriptorsclassmethod_descriptorsgetset_descriptorsakaattributes/member_descriptors
Sk.builtin.sk_methodis an alternative toSk.builtin.funcand is used by the abovedescriptortypes- mangled names are never passed to the user but instead are an attribute on
Sk.builtin.strinstances as$mangled mappingproxyadded$dremoved on all type objects.attributesof a type object now only appear on theprototype. Previously these appeared on both thetypeobject and theprototype
Additions
dict,set,tupleare suspendablemap,filter,zip,reversed,enumerateare suspendableclassmethod,property,staticmethodhave native skulpt implementationssupercan now be unbound see this explanationSk.builtin.funcobjects gain aqualnamein compile code- API for building native types
Sk.abstr.buildNativeClass
range_iteratorclass addedreverseiterators added forlist,dict_views,range|operator valid fordict,dict_keys,dict_itemsCouterhas number slots added
Sk.abstr.
objectHashbuildNativeClassbuildIteratorClasssetUpBuiltinMrosetUpMethodssetUpGetSetssetUpSlotssetUpClassMethodsetUpBaseInheritancesetUpModuleMethodcheckNoKwargscheckNoArgscheckOneArgcheckArgsLencopyKeywordsToNamedArgs
Sk.generic.
getAttrsetAttrselfIternewnewMethodDefiterNextWithArrayiterNextWithArrayCheckSizeiterLengthHintWithArrayMethodDefiterReverseLengthHintMethodDefgetSetDict
Sk.misceval.
asIndex- will return the internal representation of the integer - or undefined if tho indexable - could be a number or a bigint (JSBI) only usedasIndexOrThrow- doesasIndexbut throws an error if the number is not indexable - with an optional message parameter.asIndexSized- throws an error if the object is not indexable, returns a Number always, Option to throw an error if the index is larger thanNumber.MAX_SAFE_INTEGER. This is the goto method for most buitins now.Iterator- a python class that easily wraps an iteratorarrayFromIterable- optional canSuspend implementation that returns an array from a python iterator
slotdefs.js
- contains all the information about mapping slots to dunders and vice versa.