|
| 1 | +# Compiler front end |
| 2 | + |
| 3 | +The development checkout provides JavaScript.compiler.parse_source(source, |
| 4 | +filename=...) for the adopted python-browser/1 profile. It parses, binds and |
| 5 | +validates source without running target code, then returns an immutable ModuleIR. |
| 6 | +It does not emit or execute JavaScript yet; EMIT-01 owns that next step. |
| 7 | + |
| 8 | +The API uses only the declared Python runtime and standard library. A ModuleIR |
| 9 | +records profile/schema identity, SHA-256 of UTF-8 input, stable lexical binding |
| 10 | +IDs and typed nodes with original source spans. to_dict returns an independent |
| 11 | +JSON-serializable snapshot; integer constants are decimal strings tagged as |
| 12 | +python-int so an IR consumer cannot lose precision through JSON numbers. |
| 13 | + |
| 14 | +Bindings distinguish module constants/functions, function parameters/locals, |
| 15 | +builtin APIs and explicit JavaScript registry aliases. Alias resolution follows |
| 16 | +binding identity: a parameter named len or Array is not rewritten to a builtin |
| 17 | +or imported intrinsic. Branch and loop value types merge conservatively; source |
| 18 | +order, guards, defaults and errors remain represented for the emitter. |
| 19 | + |
| 20 | +CompileError exposes a Diagnostic with code, phase, message and SourceSpan. |
| 21 | +Locations use one-based character columns, converting Python AST's UTF-8 byte |
| 22 | +offsets. PJS100 covers syntax/features, PJS110 binding/import boundaries and |
| 23 | +PJS120 unsupported operations/calls. Unknown syntax/imports are refused before |
| 24 | +any output publication or target execution. Syntax, binding and validation |
| 25 | +phases remain distinct. |
| 26 | + |
| 27 | +Use the adopted language contract for supported forms. Initial module bindings |
| 28 | +are unconditional immutable literals; for loops are function-local with simple |
| 29 | +targets and no else clause. Source is UTF-8 and limited to 1 MiB. This front end |
| 30 | +does not load Python application imports, provide browser APIs or certify that |
| 31 | +arbitrary dependencies can be translated. |
0 commit comments