Intent Phase 4 follow-up: make :foreign python executable in codegen

t-735·WorkTask·
·
·
Created3 weeks ago·Updated3 weeks ago·pipeline runs →

Dependencies

Description

Edit

Implement executable FFI for :foreign python declarations.

Current state:

  • Parser stores declForeign.
  • Emitter ignores declForeign and emits spec-only stubs unless λ exists.

Required behavior: 1. Emit.emitDecl must generate runnable Python from declForeign when target is python. 2. Define precedence/validation when both λ and :foreign are present:

  • either reject with clear diagnostic, OR
  • define deterministic precedence and document it.

3. Unsupported foreign target languages must produce clear compile/check diagnostics (not silent stubs). 4. Keep existing non-FFI behavior unchanged.

Suggested implementation notes:

  • Add explicit handling in emit path for declForeign = Just ("python", code).
  • If embedding raw code, ensure function signature params (_in, _in1, etc.) are accessible.
  • Prefer explicit generated function body over opaque eval where possible.

Tests:

  • Parsing + emit + execution for a simple FFI declaration (e.g. uppercase transformation).
  • Mixed cases: spec-only, lambda-only, foreign-only, lambda+foreign (according to chosen rule).
  • Unsupported foreign language error test.

Acceptance:

  • FFI declaration that currently emits NotImplementedError now emits runnable Python and behaves as expected.

Timeline (1)