@@ -123,7 +123,7 @@ class PyScriptTag extends Plugin {
123
123
document . dispatchEvent ( pyScriptRegistered ) ;
124
124
}
125
125
}
126
- // Register it (thUs extracting the code from the page).
126
+ // Register it (thus extracting the code from the page).
127
127
customElements . define ( 'py-script' , PyScript ) ;
128
128
}
129
129
}
@@ -173,11 +173,27 @@ class MicroPythonRuntime extends Runtime {
173
173
}
174
174
}
175
175
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
+
176
192
/******************************************************************************
177
193
The core PyScript app definition.
178
194
******************************************************************************/
179
195
180
- function main ( ) {
196
+ const main = function ( ) {
181
197
// Really simple logging. Emoji 🐍 highlights PyScript app logs. ;-)
182
198
const logger = function ( ) {
183
199
return Function . prototype . bind . call ( console . log , console , "🐍 " , ...arguments ) ;
@@ -197,10 +213,10 @@ function main() {
197
213
const pendingScripts = [ ] ;
198
214
// Details of runtimes.
199
215
// Key: lowercase runtime name.
200
- // Value: path to load runtime.
216
+ // Value: the class wrapping that version of the runtime.
201
217
const runtimes = {
202
218
"micropython" : MicroPythonRuntime ,
203
- "cpython" : "pybuild/python.js"
219
+ "cpython" : CPythonRuntime
204
220
}
205
221
// Default to smallest/fastest runtime.
206
222
runtimes [ "default" ] = runtimes [ "micropython" ]
@@ -356,7 +372,6 @@ function main() {
356
372
evaluate each script in turn with the runtime.
357
373
*/
358
374
logger ( "Evaluating code. 🤖\n" + script . code ) ;
359
- debugger ;
360
375
runtime . eval ( script . code ) ;
361
376
} ,
362
377
}
@@ -366,14 +381,8 @@ function main() {
366
381
// steps.
367
382
//
368
383
// 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.
377
386
378
387
function onPyConfigured ( e ) {
379
388
/*
@@ -432,11 +441,19 @@ function main() {
432
441
}
433
442
document . addEventListener ( "py-eval-script" , onEvalScript ) ;
434
443
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
+ } ( ) ;
437
455
438
456
/******************************************************************************
439
457
Start PyScript.
440
458
******************************************************************************/
441
- const _pyscriptApp = main ( ) ;
442
- _pyscriptApp . run ( ) ;
459
+ main ( ) ;
0 commit comments