From 93adde5a3d7f921bf53df5ad368d0d246df13b82 Mon Sep 17 00:00:00 2001 From: agra Date: Wed, 20 May 2026 10:32:56 +0300 Subject: [PATCH] ffi 2.16a xfail: `#jni_env(env) { body }` block-form intrinsic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `#jni_env(synth_env) { ... }` should parse as a block-scoped env intrinsic, today the lexer doesn't know the directive and the parser errors at the `#` token in expression position. The make-green follow-up adds the `hash_jni_env` lexer token, parser arm in parsePrimary, AST node, and sema acceptance — body runs as a normal block, env captured for later. TL push/pop semantics + optional env in `#jni_call` land in 2.16b. --- examples/ffi-jni-env-01-block.sx | 21 +++++++++++++++++++++ tests/expected/ffi-jni-env-01-block.exit | 1 + tests/expected/ffi-jni-env-01-block.txt | 1 + 3 files changed, 23 insertions(+) create mode 100644 examples/ffi-jni-env-01-block.sx create mode 100644 tests/expected/ffi-jni-env-01-block.exit create mode 100644 tests/expected/ffi-jni-env-01-block.txt diff --git a/examples/ffi-jni-env-01-block.sx b/examples/ffi-jni-env-01-block.sx new file mode 100644 index 0000000..a8c9aa0 --- /dev/null +++ b/examples/ffi-jni-env-01-block.sx @@ -0,0 +1,21 @@ +// Phase 2 step 2.16a (PLAN-FFI.md): xfail then green for the +// `#jni_env(env) { body }` block-form intrinsic. +// +// Scopes a JNIEnv* over a lexical block. Step 2.16a lands parser + +// AST + sema acceptance — the body runs as a normal block, the env +// arg is captured but not yet used at lowering. The TL push/pop +// semantics (step 2.16b) and lexical-direct resolution in `#jni_call` +// (step 2.16c) follow. +// +// Today the lexer doesn't recognise `#jni_env` and the parser errors +// at the unknown directive token. + +#import "modules/std.sx"; + +main :: () -> s32 { + synth_env : *void = null; + #jni_env(synth_env) { + print("inside #jni_env scope\n"); + } + 0; +} diff --git a/tests/expected/ffi-jni-env-01-block.exit b/tests/expected/ffi-jni-env-01-block.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/expected/ffi-jni-env-01-block.exit @@ -0,0 +1 @@ +1 diff --git a/tests/expected/ffi-jni-env-01-block.txt b/tests/expected/ffi-jni-env-01-block.txt new file mode 100644 index 0000000..3a3c7e4 --- /dev/null +++ b/tests/expected/ffi-jni-env-01-block.txt @@ -0,0 +1 @@ +/Users/agra/projects/sx/examples/ffi-jni-env-01-block.sx:17:5: error: unexpected token in expression