You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+49
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,52 @@
1
+
# Modified version of Skulpt for FranceIOI
2
+
3
+
The file *src/internalpython.js* should be created automatically when building the sources. If that's not the case, you should create it with the following content :
4
+
5
+
Sk.internalPy={"files":{"src/classmethod.py":"class classmethod(object):\n \"Emulate PyClassMethod_Type() in Objects/funcobject.c\"\n\n def __init__(self, f):\n self.f = f\n\n def __get__(self, obj, klass=None):\n if klass is None:\n klass = type(obj)\n def newfunc(*args):\n return self.f(klass, *args)\n return newfunc\n","src/property.py":"class property(object):\n \"Emulate PyProperty_Type() in Objects/descrobject.c\"\n\n def __init__(self, fget=None, fset=None, fdel=None, doc=None):\n self.fget = fget\n self.fset = fset\n self.fdel = fdel\n if doc is None and fget is not None:\n if hasattr(fget, '__doc__'):\n doc = fget.__doc__\n else:\n doc = None\n self.__doc__ = doc\n\n def __get__(self, obj, objtype=None):\n if obj is None:\n return self\n if self.fget is None:\n raise AttributeError(\"unreadable attribute\")\n return self.fget(obj)\n\n def __set__(self, obj, value):\n if self.fset is None:\n raise AttributeError(\"can't set attribute\")\n self.fset(obj, value)\n\n def __delete__(self, obj):\n if self.fdel is None:\n raise AttributeError(\"can't delete attribute\")\n self.fdel(obj)\n\n def getter(self, fget):\n return type(self)(fget, self.fset, self.fdel, self.__doc__)\n\n def setter(self, fset):\n return type(self)(self.fget, fset, self.fdel, self.__doc__)\n\n def deleter(self, fdel):\n return type(self)(self.fget, self.fset, fdel, self.__doc__)\n","src/staticmethod.py":"class staticmethod(object):\n \"Emulate PyStaticMethod_Type() in Objects/funcobject.c\"\n\n def __init__(self, f):\n self.f = f\n\n def __get__(self, obj, objtype=None):\n return self.f\n"}}
6
+
7
+
In this modified version, each modification of a variable
8
+
9
+
v = X
10
+
11
+
is transformed to
12
+
13
+
v = window.currentPythonRunner.reportValue(X, 'v');
14
+
15
+
Objects, lists and dicts contains a unique *__uuid* field. Every time an object method is called, a list is modified, a dict is modified, a new reference is created with the same *__uuid*. These objects also contain a *_parents* which contains the _uuid of the parents. This allows to create a new reference for the parent objects. For example :
16
+
17
+
a = [1, 2, 3]
18
+
b = [..., a, ...] # A list containing a
19
+
c = { ..., 'element': a , ... } # A dict containing a
20
+
21
+
*a._parents* will contain the _uuid of *b* and *c*. This allows to create a new reference for *b* and *c* whenever *a* changes.
22
+
23
+
Note : An object has an internal variable *$d* (dollar sign + d) that is a dict and that contains all the object's variable memebers.
24
+
25
+
The code related to the references update is in *src/persistent.js*.
26
+
27
+
Most of the modifications are in *src/compile.js* and their aim is to call the rights functions of *src/persistent.js* within the javascript code generated from the python one.
28
+
29
+
The generated javascript code is visible in Codecast's console when you hit "Compile". It is also possible to add a "debugger;" instruction within the generated code if you add
30
+
31
+
out("debugger;");
32
+
33
+
at the place you want in *src/compile.js*/
34
+
35
+
36
+
# Development
37
+
38
+
npm run watch
39
+
40
+
It updates dist/skulpt.js every time there is a modification in the source.
41
+
42
+
43
+
# Build
44
+
45
+
npm run dist
46
+
47
+
You can then get the file *dist/skulpt.min.js* and replace Codecast's skulpt file.
48
+
49
+
1
50
# Welcome to Skulpt
2
51
3
52
[](https://gitter.im/skulpt/skulpt?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
0 commit comments