Skip to content

Separate semantic source frontend from legacy x64 emission - #17

Draft
Papishushi wants to merge 1 commit into
feat/portable-x64-cli-v0from
feat/semantic-source-frontend-v0
Draft

Papishushi wants to merge 1 commit into
feat/portable-x64-cli-v0from
feat/semantic-source-frontend-v0

Conversation

@Papishushi

@Papishushi Papishushi commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Removes the final hidden source-to-x64 computation from the portable pipeline, stacked on #16.

Semantic frontend

Adds SourceCompiler.CompileSemantic(...), which performs source-level work without invoking a native backend:

  • canonical source/grammar normalization
  • import/export contract parsing and validation
  • lexical analysis and high-level parsing
  • semantic identity normalization
  • process-vs-library contract rules
  • module-call / host-I/O reserved-name validation
  • portable contract construction
  • architecture-neutral callable/frame/stack validation

It returns SourceSemanticCompilation(Module, PortableContracts). The result deliberately exposes no Assembly, native entry label, host adapter, or other native artifact surface.

Shared architecture-neutral validation

A first version that merely skipped module.Compile(...) would have silently lost semantic checks historically buried inside the legacy emitter. This PR therefore extracts reusable validation from FunctionEmitter:

  • frame/cell type validation and duplicate binding rejection
  • argument/local/body-VAR frame construction
  • evaluation-stack underflow and return-path validation
  • local/import call stack requirements through the existing semantic scope graph
  • initializer validation
  • explicit RETURN type checks
  • named LOAD/STORE symbol resolution
  • rejection of STORE to readonly/const frame bindings
  • recursive validation of nested functions/actions

FunctionEmitter.Validate(...) performs those checks without emitting NASM. FunctionEmitter.Compile(...) reuses the same frame and validation helpers before entering native optimization/code generation, preventing the semantic and legacy paths from drifting.

Legacy backend retained explicitly

SourceCompiler.Compile(...) keeps its existing public signature and behavior. It now reuses the same parsed semantic state before entering a dedicated legacy-native emission phase, so compatibility remains intact while the backend boundary becomes explicit.

Portable pipeline

PortableSourceX64Pipeline now consumes CompileSemantic(...) directly:

source
  -> semantic frontend
  -> indexed UBCM
  -> independent verifier
  -> typed decoder
  -> x64 backend

There is no legacy NASM artifact to compute or discard anymore.

The semantic frontend also receives the real processImage mode, rather than pretending every portable compilation is a library merely to suppress the legacy _start emitter. Process/library contract validation is therefore independent from native code generation.

Tests

  • proves semantic and legacy frontend paths produce identical canonical indexed UBCM for the same library/contracts
  • proves SourceSemanticCompilation exposes only Module and PortableContracts
  • proves semantic compilation can complete where only the legacy native _start emitter rejects the source, demonstrating that no native emitter was invoked
  • proves semantic compilation still rejects evaluation-stack underflow
  • proves semantic compilation still rejects STORE to a readonly frame binding
  • proves portable process images enforce process contract rules while the same exported source remains valid as a library
  • existing portable and legacy regression suites remain green

Validation

Head 5f7cc720 passed Windows and Ubuntu .NET, including the complete Linux native regression corpus, plus CodeQL, Codacy and DocFX while temporarily targeted at main.

The first Isolation attempt hit a pre-existing race in prototypes/isolation/run_program.py: /proc/<pid>/stat disappeared between path construction and read_text(), raising ProcessLookupError. Re-running the identical job on the identical SHA passed the previously failing Calls originating in Ubytec modules step and the complete Isolation suite. No compiler change was required.

The PR is restored to its proper stacked base #16. Its focused diff is four files: semantic frontend, shared callable validation, portable pipeline wiring, and dedicated tests.

Next boundary

The independent raw UBCM verifier still validates wire structure, indices and operand contracts but does not yet independently simulate evaluation-stack depth or enforce readonly frame writes. Those properties are representable in indexed UBCM, so the next milestone is to move equivalent guarantees to the binary trust boundary before making the portable path the normal/default CLI route.

@Papishushi
Papishushi changed the base branch from feat/portable-x64-cli-v0 to main October 14, 2026 12:10
@codacy-production

codacy-production Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 29 complexity · 2 duplication

Metric Results
Complexity 29
Duplication 2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Comment thread Ubytec/CommandLineDriver.cs Fixed
Comment thread Ubytec/CommandLineDriver.cs Fixed
Comment thread Ubytec/CommandLineDriver.cs Fixed
Comment thread Ubytec/CommandLineDriver.cs Fixed
@Papishushi
Papishushi changed the base branch from main to feat/portable-x64-cli-v0 October 14, 2026 12:27
@Papishushi
Papishushi added this pull request to stack #13 October 14, 2026 14:40
@Papishushi
Papishushi force-pushed the feat/semantic-source-frontend-v0 branch from 62dc976 to 3b134fc Compare October 15, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants