2025-09-11 23:58:10 +09:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
use inkwell::AddressSpace;
|
|
|
|
|
use inkwell::values::BasicValueEnum as BVE;
|
|
|
|
|
|
|
|
|
|
use crate::backend::llvm::context::CodegenContext;
|
🏗️ Refactor: Major LLVM codegen modularization + Phase 15 docs cleanup + Phase 21 DDD concept
## LLVM Codegen Refactoring (by ChatGPT5)
- Split massive boxcall.rs into focused submodules:
- strings.rs: String method optimizations (concat, length)
- arrays.rs: Array operations (get, set, push, length)
- maps.rs: Map operations (get, set, has, size)
- fields.rs: getField/setField handling
- invoke.rs: Tagged invoke implementation
- marshal.rs: Helper functions for marshaling
- Improved code organization and maintainability
- No functional changes, pure refactoring
## Phase 15 Documentation Cleanup
- Restructured phase-15 folder:
- implementation/: Technical implementation docs
- planning/: Planning and sequence docs
- archive/: Redundant/old content
- Removed duplicate content (80k→20k line reduction mentioned 5 times)
- Converted all .txt files to .md for consistency
- Fixed broken links in README.md
- Removed redundant INDEX.md
## Phase 21: Database-Driven Development (New)
- Revolutionary concept: Source code in SQLite instead of files
- Instant refactoring with SQL transactions
- Structured management of boxes, methods, dependencies
- Technical design with security considerations
- Vision: World's first DB-driven programming language
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 00:35:11 +09:00
|
|
|
mod fields;
|
|
|
|
|
mod invoke;
|
|
|
|
|
mod marshal;
|
2025-09-11 23:58:10 +09:00
|
|
|
use crate::mir::{function::MirFunction, ValueId};
|
|
|
|
|
|
|
|
|
|
// BoxCall lowering (large): mirrors existing logic; kept in one function for now
|
|
|
|
|
pub(in super::super) fn lower_boxcall<'ctx>(
|
|
|
|
|
codegen: &CodegenContext<'ctx>,
|
|
|
|
|
func: &MirFunction,
|
|
|
|
|
vmap: &mut HashMap<ValueId, inkwell::values::BasicValueEnum<'ctx>>,
|
|
|
|
|
dst: &Option<ValueId>,
|
|
|
|
|
box_val: &ValueId,
|
|
|
|
|
method: &str,
|
|
|
|
|
method_id: &Option<u16>,
|
|
|
|
|
args: &[ValueId],
|
|
|
|
|
box_type_ids: &HashMap<String, i64>,
|
|
|
|
|
entry_builder: &inkwell::builder::Builder<'ctx>,
|
|
|
|
|
) -> Result<(), String> {
|
|
|
|
|
use crate::backend::llvm::compiler::helpers::{as_float, as_int};
|
|
|
|
|
use super::super::types::classify_tag;
|
|
|
|
|
let i64t = codegen.context.i64_type();
|
|
|
|
|
let recv_v = *vmap.get(box_val).ok_or("box receiver missing")?;
|
|
|
|
|
let recv_p = match recv_v {
|
|
|
|
|
BVE::PointerValue(pv) => pv,
|
|
|
|
|
BVE::IntValue(iv) => {
|
|
|
|
|
let pty = codegen.context.ptr_type(AddressSpace::from(0));
|
|
|
|
|
codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_int_to_ptr(iv, pty, "recv_i2p")
|
|
|
|
|
.map_err(|e| e.to_string())?
|
|
|
|
|
}
|
|
|
|
|
_ => return Err("box receiver must be pointer or i64 handle".to_string()),
|
|
|
|
|
};
|
|
|
|
|
let recv_h = codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_ptr_to_int(recv_p, i64t, "recv_p2i")
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
|
|
|
|
|
// Resolve type_id
|
|
|
|
|
let type_id: i64 = if let Some(crate::mir::MirType::Box(bname)) = func.metadata.value_types.get(box_val) {
|
|
|
|
|
*box_type_ids.get(bname).unwrap_or(&0)
|
|
|
|
|
} else if let Some(crate::mir::MirType::String) = func.metadata.value_types.get(box_val) {
|
|
|
|
|
*box_type_ids.get("StringBox").unwrap_or(&0)
|
|
|
|
|
} else {
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
🏗️ Refactor: Major LLVM codegen modularization + Phase 15 docs cleanup + Phase 21 DDD concept
## LLVM Codegen Refactoring (by ChatGPT5)
- Split massive boxcall.rs into focused submodules:
- strings.rs: String method optimizations (concat, length)
- arrays.rs: Array operations (get, set, push, length)
- maps.rs: Map operations (get, set, has, size)
- fields.rs: getField/setField handling
- invoke.rs: Tagged invoke implementation
- marshal.rs: Helper functions for marshaling
- Improved code organization and maintainability
- No functional changes, pure refactoring
## Phase 15 Documentation Cleanup
- Restructured phase-15 folder:
- implementation/: Technical implementation docs
- planning/: Planning and sequence docs
- archive/: Redundant/old content
- Removed duplicate content (80k→20k line reduction mentioned 5 times)
- Converted all .txt files to .md for consistency
- Fixed broken links in README.md
- Removed redundant INDEX.md
## Phase 21: Database-Driven Development (New)
- Revolutionary concept: Source code in SQLite instead of files
- Instant refactoring with SQL transactions
- Structured management of boxes, methods, dependencies
- Technical design with security considerations
- Vision: World's first DB-driven programming language
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 00:35:11 +09:00
|
|
|
// Delegate String methods
|
|
|
|
|
if super::strings::try_handle_string_method(codegen, func, vmap, dst, box_val, method, args, recv_v)? {
|
|
|
|
|
return Ok(());
|
2025-09-11 23:58:10 +09:00
|
|
|
}
|
|
|
|
|
|
🏗️ Refactor: Major LLVM codegen modularization + Phase 15 docs cleanup + Phase 21 DDD concept
## LLVM Codegen Refactoring (by ChatGPT5)
- Split massive boxcall.rs into focused submodules:
- strings.rs: String method optimizations (concat, length)
- arrays.rs: Array operations (get, set, push, length)
- maps.rs: Map operations (get, set, has, size)
- fields.rs: getField/setField handling
- invoke.rs: Tagged invoke implementation
- marshal.rs: Helper functions for marshaling
- Improved code organization and maintainability
- No functional changes, pure refactoring
## Phase 15 Documentation Cleanup
- Restructured phase-15 folder:
- implementation/: Technical implementation docs
- planning/: Planning and sequence docs
- archive/: Redundant/old content
- Removed duplicate content (80k→20k line reduction mentioned 5 times)
- Converted all .txt files to .md for consistency
- Fixed broken links in README.md
- Removed redundant INDEX.md
## Phase 21: Database-Driven Development (New)
- Revolutionary concept: Source code in SQLite instead of files
- Instant refactoring with SQL transactions
- Structured management of boxes, methods, dependencies
- Technical design with security considerations
- Vision: World's first DB-driven programming language
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 00:35:11 +09:00
|
|
|
// Delegate Array methods
|
|
|
|
|
if super::arrays::try_handle_array_method(codegen, func, vmap, dst, box_val, method, args, recv_h)? {
|
|
|
|
|
return Ok(());
|
2025-09-11 23:58:10 +09:00
|
|
|
}
|
|
|
|
|
|
🏗️ Refactor: Major LLVM codegen modularization + Phase 15 docs cleanup + Phase 21 DDD concept
## LLVM Codegen Refactoring (by ChatGPT5)
- Split massive boxcall.rs into focused submodules:
- strings.rs: String method optimizations (concat, length)
- arrays.rs: Array operations (get, set, push, length)
- maps.rs: Map operations (get, set, has, size)
- fields.rs: getField/setField handling
- invoke.rs: Tagged invoke implementation
- marshal.rs: Helper functions for marshaling
- Improved code organization and maintainability
- No functional changes, pure refactoring
## Phase 15 Documentation Cleanup
- Restructured phase-15 folder:
- implementation/: Technical implementation docs
- planning/: Planning and sequence docs
- archive/: Redundant/old content
- Removed duplicate content (80k→20k line reduction mentioned 5 times)
- Converted all .txt files to .md for consistency
- Fixed broken links in README.md
- Removed redundant INDEX.md
## Phase 21: Database-Driven Development (New)
- Revolutionary concept: Source code in SQLite instead of files
- Instant refactoring with SQL transactions
- Structured management of boxes, methods, dependencies
- Technical design with security considerations
- Vision: World's first DB-driven programming language
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 00:35:11 +09:00
|
|
|
// Delegate Map methods
|
|
|
|
|
if super::maps::try_handle_map_method(codegen, func, vmap, dst, box_val, method, args, recv_h)? {
|
|
|
|
|
return Ok(());
|
2025-09-11 23:58:10 +09:00
|
|
|
}
|
|
|
|
|
|
🏗️ Refactor: Major LLVM codegen modularization + Phase 15 docs cleanup + Phase 21 DDD concept
## LLVM Codegen Refactoring (by ChatGPT5)
- Split massive boxcall.rs into focused submodules:
- strings.rs: String method optimizations (concat, length)
- arrays.rs: Array operations (get, set, push, length)
- maps.rs: Map operations (get, set, has, size)
- fields.rs: getField/setField handling
- invoke.rs: Tagged invoke implementation
- marshal.rs: Helper functions for marshaling
- Improved code organization and maintainability
- No functional changes, pure refactoring
## Phase 15 Documentation Cleanup
- Restructured phase-15 folder:
- implementation/: Technical implementation docs
- planning/: Planning and sequence docs
- archive/: Redundant/old content
- Removed duplicate content (80k→20k line reduction mentioned 5 times)
- Converted all .txt files to .md for consistency
- Fixed broken links in README.md
- Removed redundant INDEX.md
## Phase 21: Database-Driven Development (New)
- Revolutionary concept: Source code in SQLite instead of files
- Instant refactoring with SQL transactions
- Structured management of boxes, methods, dependencies
- Technical design with security considerations
- Vision: World's first DB-driven programming language
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 00:35:11 +09:00
|
|
|
// getField/setField
|
|
|
|
|
if fields::try_handle_field_method(codegen, vmap, dst, method, args, recv_h)? {
|
|
|
|
|
return Ok(());
|
2025-09-11 23:58:10 +09:00
|
|
|
}
|
|
|
|
|
|
2025-09-12 04:54:09 +09:00
|
|
|
// Minimal untyped fallback: Array.length with missing annotations
|
|
|
|
|
if method == "length" && args.is_empty() {
|
|
|
|
|
let fnty = i64t.fn_type(&[i64t.into()], false);
|
|
|
|
|
let callee = codegen
|
|
|
|
|
.module
|
|
|
|
|
.get_function("nyash_array_length_h")
|
|
|
|
|
.unwrap_or_else(|| codegen.module.add_function("nyash_array_length_h", fnty, None));
|
|
|
|
|
let call = codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_call(callee, &[recv_h.into()], "alen_fallback")
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
if let Some(d) = dst {
|
|
|
|
|
let rv = call
|
|
|
|
|
.try_as_basic_value()
|
|
|
|
|
.left()
|
|
|
|
|
.ok_or("array_length_h returned void".to_string())?;
|
|
|
|
|
vmap.insert(*d, rv);
|
|
|
|
|
}
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-11 23:58:10 +09:00
|
|
|
if let Some(mid) = method_id {
|
🏗️ Refactor: Major LLVM codegen modularization + Phase 15 docs cleanup + Phase 21 DDD concept
## LLVM Codegen Refactoring (by ChatGPT5)
- Split massive boxcall.rs into focused submodules:
- strings.rs: String method optimizations (concat, length)
- arrays.rs: Array operations (get, set, push, length)
- maps.rs: Map operations (get, set, has, size)
- fields.rs: getField/setField handling
- invoke.rs: Tagged invoke implementation
- marshal.rs: Helper functions for marshaling
- Improved code organization and maintainability
- No functional changes, pure refactoring
## Phase 15 Documentation Cleanup
- Restructured phase-15 folder:
- implementation/: Technical implementation docs
- planning/: Planning and sequence docs
- archive/: Redundant/old content
- Removed duplicate content (80k→20k line reduction mentioned 5 times)
- Converted all .txt files to .md for consistency
- Fixed broken links in README.md
- Removed redundant INDEX.md
## Phase 21: Database-Driven Development (New)
- Revolutionary concept: Source code in SQLite instead of files
- Instant refactoring with SQL transactions
- Structured management of boxes, methods, dependencies
- Technical design with security considerations
- Vision: World's first DB-driven programming language
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-12 00:35:11 +09:00
|
|
|
invoke::try_handle_tagged_invoke(
|
|
|
|
|
codegen,
|
|
|
|
|
func,
|
|
|
|
|
vmap,
|
|
|
|
|
dst,
|
|
|
|
|
*mid,
|
|
|
|
|
type_id,
|
|
|
|
|
recv_h,
|
|
|
|
|
args,
|
|
|
|
|
entry_builder,
|
|
|
|
|
)?;
|
2025-09-11 23:58:10 +09:00
|
|
|
return Ok(());
|
|
|
|
|
} else {
|
|
|
|
|
Err(format!("BoxCall requires method_id for method '{}'. The method_id should be automatically injected during MIR compilation.", method))
|
|
|
|
|
}
|
|
|
|
|
}
|