Skip to content

Commit 6c5f39e

Browse files
wthollidayclaude
andcommitted
Add lyte_compiler_check to the C FFI
Exposes a fast parse + type-check + safety-check pass without specialization or backend codegen, for editor-side validation in non-Rust hosts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 57b511f commit 6c5f39e

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

Sources/CLyte/include/lyte.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ bool lyte_compiler_add_source(LyteCompiler* compiler, const char* source, const
5050
/// Call before lyte_compiler_add_source. Returns true on success.
5151
bool lyte_compiler_add_prelude(LyteCompiler* compiler, const char* source);
5252

53+
/// Parse and type-check (including safety checks) all added source,
54+
/// without specializing or invoking any backend. Useful for fast
55+
/// validation in editors. Returns true on success; on failure, the
56+
/// error message is available via lyte_compiler_get_error.
57+
bool lyte_compiler_check(LyteCompiler* compiler);
58+
5359
/// Parse, type-check, specialize, and compile all added source into
5460
/// a LyteProgram (auto-selects JIT or VM backend).
5561
/// Returns NULL on error. Caller must free with lyte_program_free.

src/ffi.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,25 @@ pub unsafe extern "C" fn lyte_compiler_add_prelude(
206206
})
207207
}
208208

209+
/// Parse and type-check (including safety checks) all added source,
210+
/// without specializing or invoking any backend.
211+
/// Returns true if the program is well-typed and safe; false otherwise.
212+
/// On failure, the error message is available via lyte_compiler_get_error.
213+
#[no_mangle]
214+
pub unsafe extern "C" fn lyte_compiler_check(ptr: *mut LyteCompiler) -> bool {
215+
if ptr.is_null() {
216+
return false;
217+
}
218+
catch_panic(ptr, |c| {
219+
c.last_error = None;
220+
if !c.compiler.check() {
221+
c.set_error(&c.compiler.last_errors.join("\n"));
222+
return false;
223+
}
224+
true
225+
})
226+
}
227+
209228
// ============ Program API ============
210229

211230
// On LLVM builds: JIT backend with function pointers.

0 commit comments

Comments
 (0)