2025-09-12 01:45:00 +09:00
|
|
|
mod console;
|
|
|
|
|
mod env;
|
|
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
use crate::backend::llvm::context::CodegenContext;
|
2025-09-12 19:23:16 +09:00
|
|
|
use crate::mir::{function::MirFunction, BasicBlockId, ValueId};
|
2025-09-12 01:45:00 +09:00
|
|
|
use inkwell::values::BasicValueEnum as BVE;
|
2025-09-12 19:23:16 +09:00
|
|
|
use crate::backend::llvm::compiler::codegen::instructions::builder_cursor::BuilderCursor;
|
2025-09-12 01:45:00 +09:00
|
|
|
|
|
|
|
|
/// Full ExternCall lowering dispatcher (console/debug/env.*)
|
2025-09-12 19:23:16 +09:00
|
|
|
pub(in super::super) fn lower_externcall<'ctx, 'b>(
|
2025-09-12 01:45:00 +09:00
|
|
|
codegen: &CodegenContext<'ctx>,
|
2025-09-12 19:23:16 +09:00
|
|
|
cursor: &mut BuilderCursor<'ctx, 'b>,
|
2025-09-12 20:06:48 +09:00
|
|
|
resolver: &mut super::Resolver<'ctx>,
|
2025-09-12 19:23:16 +09:00
|
|
|
cur_bid: BasicBlockId,
|
2025-09-12 01:45:00 +09:00
|
|
|
func: &MirFunction,
|
|
|
|
|
vmap: &mut HashMap<ValueId, BVE<'ctx>>,
|
|
|
|
|
dst: &Option<ValueId>,
|
|
|
|
|
iface_name: &str,
|
|
|
|
|
method_name: &str,
|
|
|
|
|
args: &[ValueId],
|
2025-09-12 20:06:48 +09:00
|
|
|
bb_map: &std::collections::HashMap<crate::mir::BasicBlockId, inkwell::basic_block::BasicBlock<'ctx>>,
|
|
|
|
|
preds: &std::collections::HashMap<crate::mir::BasicBlockId, Vec<crate::mir::BasicBlockId>>,
|
|
|
|
|
block_end_values: &std::collections::HashMap<crate::mir::BasicBlockId, std::collections::HashMap<ValueId, BVE<'ctx>>>,
|
2025-09-12 01:45:00 +09:00
|
|
|
) -> Result<(), String> {
|
|
|
|
|
// console/debug
|
|
|
|
|
if (iface_name == "env.console"
|
|
|
|
|
&& matches!(method_name, "log" | "warn" | "error"))
|
|
|
|
|
|| (iface_name == "env.debug" && method_name == "trace")
|
|
|
|
|
{
|
2025-09-12 20:06:48 +09:00
|
|
|
return console::lower_log_or_trace(codegen, cursor, resolver, cur_bid, vmap, dst, iface_name, method_name, args, bb_map, preds, block_end_values);
|
2025-09-12 01:45:00 +09:00
|
|
|
}
|
|
|
|
|
if iface_name == "env.console" && method_name == "readLine" {
|
2025-09-12 19:23:16 +09:00
|
|
|
return console::lower_readline(codegen, cursor, cur_bid, vmap, dst, args);
|
2025-09-12 01:45:00 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// env.*
|
|
|
|
|
if iface_name == "env.future" && method_name == "spawn_instance" {
|
2025-09-12 20:06:48 +09:00
|
|
|
return env::lower_future_spawn_instance(codegen, cursor, resolver, cur_bid, vmap, dst, args, bb_map, preds, block_end_values);
|
2025-09-12 01:45:00 +09:00
|
|
|
}
|
|
|
|
|
if iface_name == "env.local" && method_name == "get" {
|
2025-09-12 20:06:48 +09:00
|
|
|
return env::lower_local_get(codegen, cursor, resolver, cur_bid, func, vmap, dst, args, bb_map, preds, block_end_values);
|
2025-09-12 01:45:00 +09:00
|
|
|
}
|
|
|
|
|
if iface_name == "env.box" && method_name == "new" {
|
2025-09-12 22:36:20 +09:00
|
|
|
return env::lower_box_new(codegen, cursor, resolver, cur_bid, func, vmap, dst, args, bb_map, preds, block_end_values);
|
2025-09-12 01:45:00 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Err(format!(
|
|
|
|
|
"ExternCall lowering unsupported: {}.{} (add a NyRT shim for this interface method)",
|
|
|
|
|
iface_name, method_name
|
|
|
|
|
))
|
|
|
|
|
}
|