@@ -123,7 +123,7 @@ class PyScriptTag extends Plugin {
123123 document . dispatchEvent ( pyScriptRegistered ) ;
124124 }
125125 }
126- // Register it (thUs extracting the code from the page).
126+ // Register it (thus extracting the code from the page).
127127 customElements . define ( 'py-script' , PyScript ) ;
128128 }
129129}
@@ -173,11 +173,27 @@ class MicroPythonRuntime extends Runtime {
173173 }
174174}
175175
176+
177+ class CPythonRuntime extends Runtime {
178+ /*
179+ The standard CPython version of Python compiled to WASM. For more
180+ information, see:
181+
182+ https://github.com/python/cpython/blob/main/Tools/wasm/README.md
183+
184+ TODO: Finish this.
185+ */
186+
187+ static get url ( ) {
188+ return "pybuild/python.js" ;
189+ }
190+ }
191+
176192/******************************************************************************
177193The core PyScript app definition.
178194******************************************************************************/
179195
180- function main ( ) {
196+ const main = function ( ) {
181197 // Really simple logging. Emoji 🐍 highlights PyScript app logs. ;-)
182198 const logger = function ( ) {
183199 return Function . prototype . bind . call ( console . log , console , "🐍 " , ...arguments ) ;
@@ -197,10 +213,10 @@ function main() {
197213 const pendingScripts = [ ] ;
198214 // Details of runtimes.
199215 // Key: lowercase runtime name.
200- // Value: path to load runtime.
216+ // Value: the class wrapping that version of the runtime.
201217 const runtimes = {
202218 "micropython" : MicroPythonRuntime ,
203- "cpython" : "pybuild/python.js"
219+ "cpython" : CPythonRuntime
204220 }
205221 // Default to smallest/fastest runtime.
206222 runtimes [ "default" ] = runtimes [ "micropython" ]
@@ -356,7 +372,6 @@ function main() {
356372 evaluate each script in turn with the runtime.
357373 */
358374 logger ( "Evaluating code. 🤖\n" + script . code ) ;
359- debugger ;
360375 runtime . eval ( script . code ) ;
361376 } ,
362377 }
@@ -366,14 +381,8 @@ function main() {
366381 // steps.
367382 //
368383 // These functions are defined in the order they're roughly expected to
369- // be called through the life-cycle of the page.
370-
371- app [ "run" ] = function ( ) {
372- /*
373- Start everthing running.
374- */
375- app . loadConfig ( ) ;
376- }
384+ // be called through the life-cycle of the page, although this cannot be
385+ // guaranteed for some of the functions.
377386
378387 function onPyConfigured ( e ) {
379388 /*
@@ -432,11 +441,19 @@ function main() {
432441 }
433442 document . addEventListener ( "py-eval-script" , onEvalScript ) ;
434443
435- return app ;
436- }
444+ // Finally, return a function to start PyScript.
445+
446+ return function ( ) {
447+ /*
448+ Start PyScript.
449+ */
450+ // TODO: check test/debug flag.
451+ app . loadConfig ( ) ;
452+ return app ;
453+ }
454+ } ( ) ;
437455
438456/******************************************************************************
439457Start PyScript.
440458******************************************************************************/
441- const _pyscriptApp = main ( ) ;
442- _pyscriptApp . run ( ) ;
459+ main ( ) ;
0 commit comments