llvm/codegen: extract wrapper/object emission into object.rs; dedupe mod.rs. runner/json_v0_bridge: introduce BridgeEnv + VarScope to unify lowering paths (lower_expr/args) and cache env flags; thread env through stmt lowering; minor HashMap type cleanups. Build + PyVM stage-2 smokes passed.

This commit is contained in:
Selfhosting Dev
2025-09-17 02:50:39 +09:00
parent f2ffa30645
commit 4bd49884ca
32 changed files with 3348 additions and 2304 deletions

View File

@ -12,11 +12,7 @@ pub(in super::super) fn lower_const<'ctx>(
value: &ConstValue,
) -> Result<(), String> {
let bval = match value {
ConstValue::Integer(i) => codegen
.context
.i64_type()
.const_int(*i as u64, true)
.into(),
ConstValue::Integer(i) => codegen.context.i64_type().const_int(*i as u64, true).into(),
ConstValue::Float(f) => codegen.context.f64_type().const_float(*f).into(),
ConstValue::Bool(b) => codegen
.context
@ -28,10 +24,7 @@ pub(in super::super) fn lower_const<'ctx>(
.builder
.build_global_string_ptr(s, "str")
.map_err(|e| e.to_string())?;
let len = codegen
.context
.i32_type()
.const_int(s.len() as u64, false);
let len = codegen.context.i32_type().const_int(s.len() as u64, false);
// declare i8* @nyash_string_new(i8*, i32)
let rt = codegen.context.ptr_type(inkwell::AddressSpace::from(0));
let fn_ty = rt.fn_type(
@ -50,7 +43,11 @@ pub(in super::super) fn lower_const<'ctx>(
.unwrap_or_else(|| codegen.module.add_function("nyash_string_new", fn_ty, None));
let call = codegen
.builder
.build_call(callee, &[gv.as_pointer_value().into(), len.into()], "strnew")
.build_call(
callee,
&[gv.as_pointer_value().into(), len.into()],
"strnew",
)
.map_err(|e| e.to_string())?;
call.try_as_basic_value()
.left()