P1SCode — Architecture (language & SDK)¶
This page describes how the P1SCode stack is put together: which components exist, what they own, and how data flows from .p1s to binaries. It pairs with P1SCode — Modules, imports, and the std story, P1SCode — Language reference (concise), and P1SCode Toolchain Workflow.
1. Design intent¶
Goal |
Today’s approach |
|---|---|
One parse/lex contract |
Shared crate |
Shippable programs |
Host Python driver |
Fast feedback on image |
|
Truth in tests |
|
Code generation is intentionally not duplicated in Rust for M1: the transpiler remains the single emitter for production ELF.
2. Layer diagram¶
flowchart TB
subgraph sources["Sources"]
P1S[".p1s files"]
end
subgraph merge["Import expansion"]
PY_MERGE["p1sc.py resolve_imports"]
RS_MERGE["p1sc_syntax::import_resolve"]
end
subgraph lexparse["Lex + parse"]
LEX["lexer"]
PARSE["parser → AST"]
end
subgraph host_only["Host only"]
TOK_PY["p1sc_lexer_unified / tokenize"]
TRANS["transpile → Rust source"]
CARGO["Cargo → ELF"]
end
subgraph device["On device"]
P1SC_ELF["p1sc.elf check"]
end
P1S --> PY_MERGE
P1S --> RS_MERGE
PY_MERGE --> TOK_PY
TOK_PY --> TRANS
TRANS --> CARGO
RS_MERGE --> LEX
LEX --> PARSE
PARSE --> P1SC_ELF
Important: Merge is implemented twice (Python and Rust) with intentionally aligned behavior; it is verified by fixture lex parity, parse_program_with_imports tests, and import_resolve unit tests—not by calling Rust from Python in the driver.
3. Component inventory¶
Component |
Path |
Responsibility |
|---|---|---|
Profile / keywords |
|
Keyword set shared with |
Python driver |
|
CLI, diagnostics JSON shape, merge, tokenize, transpile, build orchestration. |
Unified lexer (Python) |
|
Rust-aligned tokens for transpile. |
Rust syntax crate |
|
Lexer, parser, AST, import_resolve, |
Native checker |
|
|
Diagnostics bridge |
|
Wraps |
Fixture harness |
|
Python success/error/bridge cases + |
App template |
|
Starting layout, |
4. Data shapes (contract summary)¶
Merged source (UTF-8 text): result of import graph expansion; file-import lines removed; virtual imports stripped (see P1SCode — Modules, imports, and the std story).
Token stream (Python): tuples
(KIND, lexeme)withSTRING,KEYWORD,IDENTIFIER,SYMBOL.Rust tokens: richer
TokenType;dump_tokenscan emit JSON comparable to Python for parity.Diagnostics (host + native check): JSON array of
{ code, message, file, line, column }— see P1SCode Toolchain Workflow.
5. Evolution directions (architecture)¶
These are roadmap items, not promises:
Single merge implementation on host: e.g. subprocess or extension to
dump_tokens/ smallp1sc_frontcrate—reduces drift risk.Transpile from AST (Rust or Python): today transpile is token-driven; moving to AST → Rust would tighten parser/transpiler coupling.
Typed IR or MIR: later layer for optimization and native codegen without Cargo on device.
Versioned language / std: tie
p1scode_profile.jsonand module namespaces to a semver or edition flag.
For M1-style milestones and ramdisk layout, see newdocs/p1scode-m1.md.
See also¶
P1SCode — Modules, imports, and the std story — imports, virtual
os//std//p1/P1SCode — Language reference (concise) — condensed syntax reference
P1SCode Language Guide — tutorial-style introduction
P1SCode Status And Scope — supported vs preview