builder/vm: stabilize json_lint_vm under unified calls
- Fix condition_fn resolution: Value call path + dev safety + stub injection - VM bridge: handle Method::birth via BoxCall; ArrayBox push/get/length/set direct bridge - Receiver safety: pin receiver in method_call_handlers to avoid undefined use across blocks - Local vars: materialize on declaration (use init ValueId; void for uninit) - Prefer legacy BoxCall for Array/Map/String/user boxes in emit_box_or_plugin_call (stability-first) - Test runner: update LLVM hint to llvmlite harness (remove LLVM_SYS_180_PREFIX guidance) - Docs/roadmap: update CURRENT_TASK with unified default-ON + guards Note: NYASH_DEV_BIRTH_INJECT_BUILTINS=1 can re-enable builtin birth() injection during migration.
This commit is contained in:
@ -55,5 +55,131 @@ pub(super) fn apply_cli_directives_from_source(
|
||||
}
|
||||
|
||||
// Lint: enforce fields at top-of-box (delegated)
|
||||
super::pipeline::lint_fields_top(code, strict_fields, verbose)
|
||||
super::pipeline::lint_fields_top(code, strict_fields, verbose)?;
|
||||
|
||||
// Dev-only guards (strict but opt-in via env)
|
||||
// 1) ASI strict: disallow binary operator at end-of-line (line continuation)
|
||||
if std::env::var("NYASH_ASI_STRICT").ok().as_deref() == Some("1") {
|
||||
// operators to check (suffixes)
|
||||
const OP2: [&str; 6] = ["==", "!=", "<=", ">=", "&&", "||"];
|
||||
const OP1: [&str; 7] = ["+", "-", "*", "/", "%", "<", ">"];
|
||||
for (i, line) in code.lines().enumerate() {
|
||||
let l = line.trim_end();
|
||||
if l.is_empty() { continue; }
|
||||
let mut bad = false;
|
||||
for op in OP2.iter() { if l.ends_with(op) { bad = true; break; } }
|
||||
if !bad { for op in OP1.iter() { if l.ends_with(op) { bad = true; break; } } }
|
||||
if bad {
|
||||
return Err(format!("Parse error: Strict ASI violation — line {} ends with operator", i + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2) '+' mixed types (String and Number) error (opt-in)
|
||||
if std::env::var("NYASH_PLUS_MIX_ERROR").ok().as_deref() == Some("1") {
|
||||
for (i, line) in code.lines().enumerate() {
|
||||
if let Some((ltok, rtok)) = find_plus_operands(line) {
|
||||
let left_is_num = is_number_literal(ltok);
|
||||
let right_is_str = is_string_literal(rtok);
|
||||
let left_is_str = is_string_literal(ltok);
|
||||
let right_is_num = is_number_literal(rtok);
|
||||
if (left_is_num && right_is_str) || (left_is_str && right_is_num) {
|
||||
return Err(format!("Type error: '+' mixed String and Number at line {} (use str()/explicit conversion)", i + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3) '==' on likely Box variables: emit guidance to use equals() (opt-in)
|
||||
if std::env::var("NYASH_BOX_EQ_GUIDE_ERROR").ok().as_deref() == Some("1") {
|
||||
for (i, line) in code.lines().enumerate() {
|
||||
let l = line;
|
||||
let mut idx = 0usize;
|
||||
while let Some(pos) = l[idx..].find("==") {
|
||||
let at = idx + pos;
|
||||
// find left token end and right token start
|
||||
let (left_ok, right_ok) = (peek_ident_left(l, at), peek_ident_right(l, at + 2));
|
||||
if left_ok && right_ok {
|
||||
return Err(format!("Type error: '==' on boxes — use equals() (line {})", i + 1));
|
||||
}
|
||||
idx = at + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// ---- Helpers (very small, no external deps) ----
|
||||
fn is_number_literal(s: &str) -> bool {
|
||||
let t = s.trim();
|
||||
!t.is_empty() && t.chars().all(|c| c.is_ascii_digit())
|
||||
}
|
||||
fn is_string_literal(s: &str) -> bool {
|
||||
let t = s.trim();
|
||||
t.starts_with('"')
|
||||
}
|
||||
|
||||
fn find_plus_operands(line: &str) -> Option<(&str, &str)> {
|
||||
let bytes = line.as_bytes();
|
||||
let mut i = 0usize;
|
||||
while i < bytes.len() {
|
||||
if bytes[i] as char == '+' {
|
||||
// extract left token
|
||||
let mut l = i;
|
||||
while l > 0 && bytes[l - 1].is_ascii_whitespace() { l -= 1; }
|
||||
let mut lstart = l;
|
||||
while lstart > 0 {
|
||||
let c = bytes[lstart - 1] as char;
|
||||
if c.is_ascii_alphanumeric() || c == '_' || c == '"' { lstart -= 1; } else { break; }
|
||||
}
|
||||
let left = &line[lstart..l];
|
||||
// extract right token
|
||||
let mut r = i + 1;
|
||||
while r < bytes.len() && bytes[r].is_ascii_whitespace() { r += 1; }
|
||||
let mut rend = r;
|
||||
while rend < bytes.len() {
|
||||
let c = bytes[rend] as char;
|
||||
if c.is_ascii_alphanumeric() || c == '_' || c == '"' { rend += 1; } else { break; }
|
||||
}
|
||||
if r <= rend { let right = &line[r..rend]; return Some((left, right)); }
|
||||
return None;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn peek_ident_left(s: &str, pos: usize) -> bool {
|
||||
// scan left for first non-space token end, then back to token start
|
||||
let bytes = s.as_bytes();
|
||||
if pos == 0 { return false; }
|
||||
let mut i = pos;
|
||||
// skip spaces
|
||||
while i > 0 && bytes[i - 1].is_ascii_whitespace() { i -= 1; }
|
||||
if i == 0 { return false; }
|
||||
// now consume identifier chars backwards
|
||||
let mut j = i;
|
||||
while j > 0 {
|
||||
let c = bytes[j - 1] as char;
|
||||
if c.is_ascii_alphanumeric() || c == '_' { j -= 1; } else { break; }
|
||||
}
|
||||
if j == i { return false; }
|
||||
// ensure not starting with digit only (avoid numeric literal)
|
||||
let tok = &s[j..i];
|
||||
!tok.chars().next().map(|c| c.is_ascii_digit()).unwrap_or(false)
|
||||
}
|
||||
fn peek_ident_right(s: &str, pos: usize) -> bool {
|
||||
let bytes = s.as_bytes();
|
||||
let mut i = pos;
|
||||
while i < bytes.len() && bytes[i].is_ascii_whitespace() { i += 1; }
|
||||
if i >= bytes.len() { return false; }
|
||||
let mut j = i;
|
||||
while j < bytes.len() {
|
||||
let c = bytes[j] as char;
|
||||
if c.is_ascii_alphanumeric() || c == '_' { j += 1; } else { break; }
|
||||
}
|
||||
if j == i { return false; }
|
||||
let tok = &s[i..j];
|
||||
!tok.chars().next().map(|c| c.is_ascii_digit()).unwrap_or(false)
|
||||
}
|
||||
|
||||
@ -310,7 +310,10 @@ pub fn emit_mir_json_for_harness(
|
||||
dst, func, callee, args, effects, ..
|
||||
} => {
|
||||
// Phase 15.5: Unified Call support with environment variable control
|
||||
let use_unified = std::env::var("NYASH_MIR_UNIFIED_CALL").unwrap_or_default() == "1";
|
||||
let use_unified = match std::env::var("NYASH_MIR_UNIFIED_CALL").ok().as_deref().map(|s| s.to_ascii_lowercase()) {
|
||||
Some(s) if s == "0" || s == "false" || s == "off" => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
if use_unified && callee.is_some() {
|
||||
// v1: Unified mir_call format
|
||||
@ -435,7 +438,10 @@ pub fn emit_mir_json_for_harness(
|
||||
|
||||
// Phase 15.5: JSON v1 schema with environment variable control
|
||||
let use_v1_schema = std::env::var("NYASH_JSON_SCHEMA_V1").unwrap_or_default() == "1"
|
||||
|| std::env::var("NYASH_MIR_UNIFIED_CALL").unwrap_or_default() == "1";
|
||||
|| match std::env::var("NYASH_MIR_UNIFIED_CALL").ok().as_deref().map(|s| s.to_ascii_lowercase()) {
|
||||
Some(s) if s == "0" || s == "false" || s == "off" => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
let root = if use_v1_schema {
|
||||
create_json_v1_root(json!(funs))
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#![cfg(feature = "interpreter-legacy")]
|
||||
|
||||
use super::super::NyashRunner;
|
||||
use nyash_rust::{
|
||||
backend::VM, interpreter::NyashInterpreter, mir::MirCompiler, parser::NyashParser,
|
||||
};
|
||||
use nyash_rust::{backend::VM, interpreter::NyashInterpreter, mir::MirCompiler, parser::NyashParser};
|
||||
|
||||
impl NyashRunner {
|
||||
/// Execute benchmark mode (split)
|
||||
@ -241,4 +241,3 @@ impl NyashRunner {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#![cfg(feature = "vm-legacy")]
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
use super::super::NyashRunner;
|
||||
use crate::runner::json_v0_bridge;
|
||||
#[cfg(feature = "interpreter-legacy")]
|
||||
use nyash_rust::{interpreter::NyashInterpreter, parser::NyashParser};
|
||||
#[cfg(not(feature = "interpreter-legacy"))]
|
||||
use nyash_rust::parser::NyashParser;
|
||||
// Use the library crate's plugin init module rather than the bin crate root
|
||||
use crate::cli_v;
|
||||
use crate::runner::pipeline::{resolve_using_target, suggest_in_base};
|
||||
@ -13,6 +16,7 @@ use std::{fs, process};
|
||||
|
||||
// (moved) suggest_in_base is now in runner/pipeline.rs
|
||||
|
||||
#[cfg(feature = "interpreter-legacy")]
|
||||
impl NyashRunner {
|
||||
// legacy run_file_legacy removed (was commented out)
|
||||
|
||||
@ -289,3 +293,12 @@ impl NyashRunner {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "interpreter-legacy"))]
|
||||
impl NyashRunner {
|
||||
/// Interpreter backend is disabled in default builds. Use `--backend vm` or `--backend llvm`.
|
||||
pub(crate) fn execute_nyash_file(&self, _filename: &str) {
|
||||
eprintln!("❌ Interpreter backend (AST) is disabled. Build with --features interpreter-legacy to enable, or use --backend vm/llvm.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +103,8 @@ pub fn ny_llvmc_emit_exe_lib(
|
||||
.arg("exe")
|
||||
.arg("--out")
|
||||
.arg(exe_out);
|
||||
if let Some(dir) = nyrt_dir { cmd.arg("--nyrt").arg(dir); } else { cmd.arg("--nyrt").arg("target/release"); }
|
||||
let default_nyrt = std::env::var("NYASH_EMIT_EXE_NYRT") .ok() .or_else(|| std::env::var("NYASH_ROOT").ok().map(|r| format!("{}/target/release", r))) .unwrap_or_else(|| "target/release".to_string());
|
||||
if let Some(dir) = nyrt_dir { cmd.arg("--nyrt").arg(dir); } else { cmd.arg("--nyrt").arg(default_nyrt); }
|
||||
if let Some(flags) = extra_libs { if !flags.trim().is_empty() { cmd.arg("--libs").arg(flags); } }
|
||||
let status = cmd.status().map_err(|e| {
|
||||
let prog_path = std::path::Path::new(cmd.get_program());
|
||||
@ -146,7 +147,8 @@ pub fn ny_llvmc_emit_exe_bin(
|
||||
.arg("exe")
|
||||
.arg("--out")
|
||||
.arg(exe_out);
|
||||
if let Some(dir) = nyrt_dir { cmd.arg("--nyrt").arg(dir); } else { cmd.arg("--nyrt").arg("target/release"); }
|
||||
let default_nyrt = std::env::var("NYASH_EMIT_EXE_NYRT") .ok() .or_else(|| std::env::var("NYASH_ROOT").ok().map(|r| format!("{}/target/release", r))) .unwrap_or_else(|| "target/release".to_string());
|
||||
if let Some(dir) = nyrt_dir { cmd.arg("--nyrt").arg(dir); } else { cmd.arg("--nyrt").arg(default_nyrt); }
|
||||
if let Some(flags) = extra_libs { if !flags.trim().is_empty() { cmd.arg("--libs").arg(flags); } }
|
||||
let status = cmd.status().map_err(|e| {
|
||||
let prog_path = std::path::Path::new(cmd.get_program());
|
||||
|
||||
Reference in New Issue
Block a user