bridge(v1): add minimal mir_call(Global) support for print-family (print|nyash.console.log|env.console.{log,warn,error}); stageb_print_vm now strict-PASS under v1 downconvert. tests: suppress noise via quiet env in stageb_print_vm.

This commit is contained in:
nyash-codex
2025-11-02 07:30:46 +09:00
parent 289dd0d5ab
commit 91f3d82deb
2 changed files with 66 additions and 5 deletions

View File

@ -253,6 +253,71 @@ pub fn try_parse_v1_to_module(json: &str) -> Result<Option<MirModule>, String> {
signature.return_type = MirType::Void; signature.return_type = MirType::Void;
} }
} }
"mir_call" => {
// Minimal v1 mir_call support (Global only; print-family)
// dst: optional
let dst_opt = inst.get("dst").and_then(|d| d.as_u64()).map(|v| ValueId::new(v as u32));
// args: array of value ids
let mut argv: Vec<ValueId> = Vec::new();
if let Some(arr) = inst.get("args").and_then(|a| a.as_array()) {
for a in arr {
let id = a.as_u64().ok_or_else(|| format!(
"mir_call arg must be integer value id in function '{}'",
func_name
))? as u32;
argv.push(ValueId::new(id));
}
}
// callee: only Global(name) supported here
let callee_obj = inst.get("callee").ok_or_else(|| {
format!("mir_call missing callee in function '{}'", func_name)
})?;
let ctype = callee_obj
.get("type")
.and_then(Value::as_str)
.ok_or_else(|| format!("mir_call callee.type missing in function '{}'", func_name))?;
match ctype {
"Global" => {
let raw_name = callee_obj
.get("name")
.and_then(Value::as_str)
.ok_or_else(|| format!(
"mir_call callee Global missing name in function '{}'",
func_name
))?;
// Map known console aliases to interpreter-accepted names
let mapped = match raw_name {
"print" => "print".to_string(),
"nyash.builtin.print" => "nyash.builtin.print".to_string(),
"nyash.console.log" => "nyash.console.log".to_string(),
// Accept env.console.* as nyash.console.log (numeric only)
"env.console.log" | "env.console.warn" | "env.console.error" => {
"nyash.console.log".to_string()
}
other => {
return Err(format!(
"unsupported Global callee '{}' in mir_call (Gate-C v1 bridge)",
other
));
}
};
block_ref.add_instruction(MirInstruction::Call {
dst: dst_opt,
func: ValueId::new(0),
callee: Some(crate::mir::definitions::Callee::Global(mapped)),
args: argv,
effects: EffectMask::PURE,
});
if let Some(d) = dst_opt { max_value_id = max_value_id.max(d.as_u32() + 1); }
}
other => {
return Err(format!(
"unsupported callee type '{}' in mir_call (Gate-C v1 bridge)",
other
));
}
}
}
other => { other => {
return Err(format!( return Err(format!(
"unsupported instruction '{}' in function '{}' (Gate-C v1 bridge)", "unsupported instruction '{}' in function '{}' (Gate-C v1 bridge)",

View File

@ -27,15 +27,11 @@ if ! stageb_json_nonempty "$json"; then
exit 1 exit 1
fi fi
set +e set +e
output=$(NYASH_NYVM_V1_DOWNCONVERT=1 "$NYASH_BIN" --json-file "$json") output=$(NYASH_NYVM_V1_DOWNCONVERT=1 NYASH_QUIET=1 HAKO_QUIET=1 NYASH_CLI_VERBOSE=0 NYASH_DISABLE_PLUGINS=1 "$NYASH_BIN" --json-file "$json")
rc=$? rc=$?
set -e set -e
rm -f "$json" rm -f "$json"
if [ $rc -ne 0 ]; then
echo "[SKIP] stageb_print_vm (v1 downconvert not yet supporting call/extern)" >&2
exit 0
fi
if [ "$output" = "3" ] && [ $rc -eq 0 ]; then if [ "$output" = "3" ] && [ $rc -eq 0 ]; then
echo "[PASS] stageb_print_vm" echo "[PASS] stageb_print_vm"
exit 0 exit 0