Skip to content

Commit 19d9536

Browse files
authored
feat(PARSE-02): add binding-aware compiler front end (#29)
1 parent ff1128e commit 19d9536

6 files changed

Lines changed: 527 additions & 1 deletion

File tree

‎IMPLEMENTATION_PLAN.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ Date, RegExp, Map/Set or prototype/descriptor expansion first.
370370
first syntax/semantic decisions and reference corpus. It does not claim that
371371
translation is implemented yet.
372372

373+
[The compiler front-end API](docs/compiler-front-end.md) implements parsing,
374+
lexical binding, validation and immutable typed IR in the development checkout;
375+
JavaScript emission remains a separate milestone.
376+
373377
## Compiler contracts and artifacts
374378

375379
Preserve ordinary supported Python truthiness, integers, Unicode, evaluation

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ globals and other unlisted APIs remain future work. Development is tracked in
8888
the [issues](https://github.com/outside-labs/Python-JavaScript/issues) and
8989
[Project](https://github.com/orgs/outside-labs/projects/11).
9090

91+
The development checkout now includes a [binding-aware compiler front end](docs/compiler-front-end.md)
92+
that validates source and produces typed IR. JavaScript emission and browser
93+
execution remain subsequent milestones.
94+
9195
## Development
9296

9397
```sh

‎docs/compiler-front-end.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.

‎docs/compiler-language.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ and arbitrary user objects are outside the first profile.
2020
| Scalars | None, bool, arbitrary-precision int and Unicode str literals; tuples of supported values. Floats/bytes/complex wait for separate numeric/binary contracts. |
2121
| Bindings | Simple names, immutable module constants, ordinary local assignments and top-level plain functions. Preserve lexical binding identity and evaluation order. |
2222
| Functions | Positional arguments and immutable literal defaults; return, direct calls and recursion. Keyword/variadic calls, nested closures, decorators, annotations and async functions are deferred. |
23-
| Control flow | if/elif/else, for over approved strings/tuples, break/continue, ordinary return and expression statements. while/comprehensions/generators are deferred initially. |
23+
| Control flow | if/elif/else, function-local for over approved strings/tuples, break/continue, ordinary return and expression statements; loop-else is deferred. while/comprehensions/generators are deferred initially. |
2424
| Operations | Supported scalar arithmetic/comparisons, Python and/or/not, identity on supported values, string membership and supported indexing. Mixed or unknown operand forms need helpers or a source-located rejection. |
2525
| Builtins/errors | len on adopted strings/tuples, print of adopted values, approved isinstance checks and explicit builtin TypeError raising needed by the fixture. No eval/exec, reflection or undeclared I/O. |
2626
| JavaScript API | Resolve explicit imports/aliases through a versioned symbol/method registry. Start with Array.of and length as a binding fixture; other exports/methods need adopted signatures and parity cases before lowering. |
@@ -66,6 +66,8 @@ source-located diagnostics, not an interpreter/server fallback.
6666

6767
## Front end and diagnostics
6868

69+
Source input is UTF-8 with an explicit 1 MiB front-end limit.
70+
6971
Use ast -> bind -> validate -> typed IR -> lower -> emit. Never import or execute
7072
application/dependency modules to compile them. Carry original file/line/column
7173
spans and stable binding identities through every pass. Validate imports,

0 commit comments

Comments
 (0)