🏗️ 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
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
use inkwell::{values::BasicValueEnum as BVE, AddressSpace};
|
|
|
|
|
|
2025-09-17 02:50:39 +09:00
|
|
|
use super::super::ctx::{BlockCtx, LowerFnCtx};
|
🏗️ 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
|
|
|
use crate::backend::llvm::context::CodegenContext;
|
|
|
|
|
use crate::mir::{function::MirFunction, ValueId};
|
|
|
|
|
|
2025-09-12 20:40:48 +09:00
|
|
|
// use super::marshal::{get_i64, get_tag_const};
|
🏗️ 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
|
|
|
|
|
|
|
|
/// Handle method_id-tagged plugin invoke path; returns Ok(()) if handled.
|
2025-09-12 22:36:20 +09:00
|
|
|
pub(super) fn try_handle_tagged_invoke<'ctx, 'b>(
|
🏗️ 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
|
|
|
codegen: &CodegenContext<'ctx>,
|
|
|
|
|
func: &MirFunction,
|
2025-09-12 22:36:20 +09:00
|
|
|
cursor: &mut crate::backend::llvm::compiler::codegen::instructions::builder_cursor::BuilderCursor<'ctx, 'b>,
|
|
|
|
|
resolver: &mut super::super::Resolver<'ctx>,
|
🏗️ 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
|
|
|
vmap: &mut HashMap<ValueId, inkwell::values::BasicValueEnum<'ctx>>,
|
|
|
|
|
dst: &Option<ValueId>,
|
|
|
|
|
mid: u16,
|
|
|
|
|
type_id: i64,
|
|
|
|
|
recv_h: inkwell::values::IntValue<'ctx>,
|
|
|
|
|
args: &[ValueId],
|
|
|
|
|
entry_builder: &inkwell::builder::Builder<'ctx>,
|
2025-09-12 22:36:20 +09:00
|
|
|
cur_bid: crate::mir::BasicBlockId,
|
2025-09-17 02:50:39 +09:00
|
|
|
bb_map: &std::collections::HashMap<
|
|
|
|
|
crate::mir::BasicBlockId,
|
|
|
|
|
inkwell::basic_block::BasicBlock<'ctx>,
|
|
|
|
|
>,
|
2025-09-12 22:36:20 +09:00
|
|
|
preds: &std::collections::HashMap<crate::mir::BasicBlockId, Vec<crate::mir::BasicBlockId>>,
|
2025-09-17 02:50:39 +09:00
|
|
|
block_end_values: &std::collections::HashMap<
|
|
|
|
|
crate::mir::BasicBlockId,
|
|
|
|
|
std::collections::HashMap<ValueId, inkwell::values::BasicValueEnum<'ctx>>,
|
|
|
|
|
>,
|
🏗️ 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
|
|
|
) -> Result<(), String> {
|
|
|
|
|
let i64t = codegen.context.i64_type();
|
|
|
|
|
let argc_val = i64t.const_int(args.len() as u64, false);
|
|
|
|
|
|
|
|
|
|
// Fast path: <= 4 fixed args
|
|
|
|
|
if args.len() <= 4 {
|
|
|
|
|
let mut a = [i64t.const_zero(); 4];
|
|
|
|
|
for (i, vid) in args.iter().enumerate() {
|
2025-09-12 22:36:20 +09:00
|
|
|
let iv = match func.metadata.value_types.get(vid) {
|
|
|
|
|
Some(crate::mir::MirType::Float) => {
|
2025-09-17 02:50:39 +09:00
|
|
|
let fv = resolver.resolve_f64(
|
|
|
|
|
codegen,
|
|
|
|
|
cursor,
|
|
|
|
|
cur_bid,
|
|
|
|
|
*vid,
|
|
|
|
|
bb_map,
|
|
|
|
|
preds,
|
|
|
|
|
block_end_values,
|
|
|
|
|
vmap,
|
|
|
|
|
)?;
|
2025-09-12 20:40:48 +09:00
|
|
|
let fnty = i64t.fn_type(&[codegen.context.f64_type().into()], false);
|
2025-09-17 02:50:39 +09:00
|
|
|
let callee = codegen
|
|
|
|
|
.module
|
|
|
|
|
.get_function("nyash.box.from_f64")
|
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
|
codegen
|
|
|
|
|
.module
|
|
|
|
|
.add_function("nyash.box.from_f64", fnty, None)
|
|
|
|
|
});
|
|
|
|
|
let call = codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_call(callee, &[fv.into()], "arg_f2h")
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
call.try_as_basic_value()
|
|
|
|
|
.left()
|
|
|
|
|
.ok_or("from_f64 returned void".to_string())?
|
|
|
|
|
.into_int_value()
|
2025-09-12 20:40:48 +09:00
|
|
|
}
|
2025-09-17 02:50:39 +09:00
|
|
|
_ => resolver.resolve_i64(
|
|
|
|
|
codegen,
|
|
|
|
|
cursor,
|
|
|
|
|
cur_bid,
|
|
|
|
|
*vid,
|
|
|
|
|
bb_map,
|
|
|
|
|
preds,
|
|
|
|
|
block_end_values,
|
|
|
|
|
vmap,
|
|
|
|
|
)?,
|
2025-09-12 20:40:48 +09:00
|
|
|
};
|
|
|
|
|
a[i] = iv;
|
🏗️ 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
|
|
|
}
|
|
|
|
|
let mut tags = [i64t.const_int(3, false); 4];
|
|
|
|
|
for (i, vid) in args.iter().enumerate() {
|
2025-09-12 20:40:48 +09:00
|
|
|
let tag = match func.metadata.value_types.get(vid) {
|
|
|
|
|
Some(crate::mir::MirType::Float) => 5,
|
2025-09-17 02:50:39 +09:00
|
|
|
Some(crate::mir::MirType::String)
|
|
|
|
|
| Some(crate::mir::MirType::Box(_))
|
|
|
|
|
| Some(crate::mir::MirType::Array(_))
|
|
|
|
|
| Some(crate::mir::MirType::Future(_))
|
|
|
|
|
| Some(crate::mir::MirType::Unknown) => 8,
|
2025-09-12 20:40:48 +09:00
|
|
|
_ => 3,
|
|
|
|
|
};
|
|
|
|
|
tags[i] = i64t.const_int(tag as u64, false);
|
🏗️ 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
|
|
|
}
|
|
|
|
|
let fnty = i64t.fn_type(
|
|
|
|
|
&[
|
2025-09-17 02:50:39 +09:00
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
🏗️ 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
|
|
|
],
|
|
|
|
|
false,
|
|
|
|
|
);
|
|
|
|
|
let callee = codegen
|
|
|
|
|
.module
|
|
|
|
|
.get_function("nyash_plugin_invoke3_tagged_i64")
|
2025-09-17 02:50:39 +09:00
|
|
|
.unwrap_or_else(|| {
|
|
|
|
|
codegen
|
|
|
|
|
.module
|
|
|
|
|
.add_function("nyash_plugin_invoke3_tagged_i64", fnty, None)
|
|
|
|
|
});
|
🏗️ 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
|
|
|
let tid = i64t.const_int(type_id as u64, true);
|
|
|
|
|
let midv = i64t.const_int(mid as u64, false);
|
|
|
|
|
let call = codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_call(
|
|
|
|
|
callee,
|
|
|
|
|
&[
|
2025-09-17 02:50:39 +09:00
|
|
|
tid.into(),
|
|
|
|
|
midv.into(),
|
|
|
|
|
argc_val.into(),
|
|
|
|
|
recv_h.into(),
|
|
|
|
|
a[0].into(),
|
|
|
|
|
tags[0].into(),
|
|
|
|
|
a[1].into(),
|
|
|
|
|
tags[1].into(),
|
|
|
|
|
a[2].into(),
|
|
|
|
|
tags[2].into(),
|
|
|
|
|
a[3].into(),
|
|
|
|
|
tags[3].into(),
|
🏗️ 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
|
|
|
],
|
|
|
|
|
"pinvoke_tagged",
|
|
|
|
|
)
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
if let Some(d) = dst {
|
|
|
|
|
let rv = call
|
|
|
|
|
.try_as_basic_value()
|
|
|
|
|
.left()
|
|
|
|
|
.ok_or("invoke3_i64 returned void".to_string())?;
|
|
|
|
|
store_invoke_return(codegen, func, vmap, *d, rv)?;
|
|
|
|
|
}
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Variable length path: build i64 arrays for vals and tags
|
|
|
|
|
let n = args.len() as u32;
|
|
|
|
|
let arr_ty = i64t.array_type(n);
|
|
|
|
|
let vals_arr = entry_builder
|
|
|
|
|
.build_alloca(arr_ty, "vals_arr")
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
let tags_arr = entry_builder
|
|
|
|
|
.build_alloca(arr_ty, "tags_arr")
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
for (i, vid) in args.iter().enumerate() {
|
|
|
|
|
let idx = [
|
|
|
|
|
codegen.context.i32_type().const_zero(),
|
|
|
|
|
codegen.context.i32_type().const_int(i as u64, false),
|
|
|
|
|
];
|
|
|
|
|
let gep_v = unsafe {
|
|
|
|
|
codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_in_bounds_gep(arr_ty, vals_arr, &idx, &format!("v_gep_{}", i))
|
|
|
|
|
.map_err(|e| e.to_string())?
|
|
|
|
|
};
|
|
|
|
|
let gep_t = unsafe {
|
|
|
|
|
codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_in_bounds_gep(arr_ty, tags_arr, &idx, &format!("t_gep_{}", i))
|
|
|
|
|
.map_err(|e| e.to_string())?
|
|
|
|
|
};
|
2025-09-12 22:36:20 +09:00
|
|
|
let vi = match func.metadata.value_types.get(vid) {
|
|
|
|
|
Some(crate::mir::MirType::Float) => {
|
2025-09-17 02:50:39 +09:00
|
|
|
let fv = resolver.resolve_f64(
|
|
|
|
|
codegen,
|
|
|
|
|
cursor,
|
|
|
|
|
cur_bid,
|
|
|
|
|
*vid,
|
|
|
|
|
bb_map,
|
|
|
|
|
preds,
|
|
|
|
|
block_end_values,
|
|
|
|
|
vmap,
|
|
|
|
|
)?;
|
2025-09-12 20:40:48 +09:00
|
|
|
let fnty = i64t.fn_type(&[codegen.context.f64_type().into()], false);
|
2025-09-17 02:50:39 +09:00
|
|
|
let callee = codegen
|
|
|
|
|
.module
|
|
|
|
|
.get_function("nyash.box.from_f64")
|
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
|
codegen
|
|
|
|
|
.module
|
|
|
|
|
.add_function("nyash.box.from_f64", fnty, None)
|
|
|
|
|
});
|
|
|
|
|
let call = codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_call(callee, &[fv.into()], "arg_f2h")
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
call.try_as_basic_value()
|
|
|
|
|
.left()
|
|
|
|
|
.ok_or("from_f64 returned void".to_string())?
|
|
|
|
|
.into_int_value()
|
2025-09-12 20:40:48 +09:00
|
|
|
}
|
2025-09-17 02:50:39 +09:00
|
|
|
_ => resolver.resolve_i64(
|
|
|
|
|
codegen,
|
|
|
|
|
cursor,
|
|
|
|
|
cur_bid,
|
|
|
|
|
*vid,
|
|
|
|
|
bb_map,
|
|
|
|
|
preds,
|
|
|
|
|
block_end_values,
|
|
|
|
|
vmap,
|
|
|
|
|
)?,
|
2025-09-12 20:40:48 +09:00
|
|
|
};
|
|
|
|
|
let ti = match func.metadata.value_types.get(vid) {
|
|
|
|
|
Some(crate::mir::MirType::Float) => i64t.const_int(5, false),
|
2025-09-17 02:50:39 +09:00
|
|
|
Some(crate::mir::MirType::String)
|
|
|
|
|
| Some(crate::mir::MirType::Box(_))
|
|
|
|
|
| Some(crate::mir::MirType::Array(_))
|
|
|
|
|
| Some(crate::mir::MirType::Future(_))
|
|
|
|
|
| Some(crate::mir::MirType::Unknown) => i64t.const_int(8, false),
|
2025-09-12 20:40:48 +09:00
|
|
|
_ => i64t.const_int(3, false),
|
|
|
|
|
};
|
2025-09-17 02:50:39 +09:00
|
|
|
codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_store(gep_v, vi)
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_store(gep_t, ti)
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
🏗️ 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
|
|
|
}
|
|
|
|
|
let vals_ptr = codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_pointer_cast(
|
|
|
|
|
vals_arr,
|
|
|
|
|
codegen.context.ptr_type(AddressSpace::from(0)),
|
|
|
|
|
"vals_arr_i8p",
|
|
|
|
|
)
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
let tags_ptr = codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_pointer_cast(
|
|
|
|
|
tags_arr,
|
|
|
|
|
codegen.context.ptr_type(AddressSpace::from(0)),
|
|
|
|
|
"tags_arr_i8p",
|
|
|
|
|
)
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
let fnty = i64t.fn_type(
|
|
|
|
|
&[
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
i64t.into(),
|
|
|
|
|
codegen.context.ptr_type(AddressSpace::from(0)).into(),
|
|
|
|
|
codegen.context.ptr_type(AddressSpace::from(0)).into(),
|
|
|
|
|
],
|
|
|
|
|
false,
|
|
|
|
|
);
|
|
|
|
|
let callee = codegen
|
|
|
|
|
.module
|
|
|
|
|
.get_function("nyash.plugin.invoke_tagged_v_i64")
|
2025-09-17 02:50:39 +09:00
|
|
|
.unwrap_or_else(|| {
|
|
|
|
|
codegen
|
|
|
|
|
.module
|
|
|
|
|
.add_function("nyash.plugin.invoke_tagged_v_i64", fnty, None)
|
|
|
|
|
});
|
🏗️ 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
|
|
|
let tid = i64t.const_int(type_id as u64, true);
|
|
|
|
|
let midv = i64t.const_int(mid as u64, false);
|
|
|
|
|
let call = codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_call(
|
|
|
|
|
callee,
|
2025-09-17 02:50:39 +09:00
|
|
|
&[
|
|
|
|
|
tid.into(),
|
|
|
|
|
midv.into(),
|
|
|
|
|
argc_val.into(),
|
|
|
|
|
recv_h.into(),
|
|
|
|
|
vals_ptr.into(),
|
|
|
|
|
tags_ptr.into(),
|
|
|
|
|
],
|
🏗️ 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
|
|
|
"pinvoke_tagged_v",
|
|
|
|
|
)
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
if let Some(d) = dst {
|
|
|
|
|
let rv = call
|
|
|
|
|
.try_as_basic_value()
|
|
|
|
|
.left()
|
|
|
|
|
.ok_or("invoke_v returned void".to_string())?;
|
|
|
|
|
store_invoke_return(codegen, func, vmap, *d, rv)?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn store_invoke_return<'ctx>(
|
|
|
|
|
codegen: &CodegenContext<'ctx>,
|
|
|
|
|
func: &MirFunction,
|
|
|
|
|
vmap: &mut HashMap<ValueId, inkwell::values::BasicValueEnum<'ctx>>,
|
|
|
|
|
dst: ValueId,
|
|
|
|
|
rv: inkwell::values::BasicValueEnum<'ctx>,
|
|
|
|
|
) -> Result<(), String> {
|
|
|
|
|
if let Some(mt) = func.metadata.value_types.get(&dst) {
|
|
|
|
|
match mt {
|
2025-09-12 05:48:59 +09:00
|
|
|
crate::mir::MirType::Integer => {
|
🏗️ 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
|
|
|
vmap.insert(dst, rv);
|
|
|
|
|
}
|
2025-09-12 05:48:59 +09:00
|
|
|
crate::mir::MirType::Bool => {
|
|
|
|
|
// Normalize i64 bool (0/1) to i1
|
|
|
|
|
if let BVE::IntValue(iv) = rv {
|
|
|
|
|
let i64t = codegen.context.i64_type();
|
|
|
|
|
let zero = i64t.const_zero();
|
|
|
|
|
let b1 = codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_int_compare(inkwell::IntPredicate::NE, iv, zero, "bool_i64_to_i1")
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
vmap.insert(dst, b1.into());
|
|
|
|
|
} else {
|
|
|
|
|
vmap.insert(dst, rv);
|
|
|
|
|
}
|
|
|
|
|
}
|
🏗️ 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
|
|
|
crate::mir::MirType::String => {
|
2025-09-12 22:36:20 +09:00
|
|
|
// Keep as i64 handle across blocks (pointer is produced on demand via Resolver)
|
2025-09-17 02:50:39 +09:00
|
|
|
if let BVE::IntValue(iv) = rv {
|
|
|
|
|
vmap.insert(dst, iv.into());
|
|
|
|
|
} else {
|
|
|
|
|
return Err("invoke ret expected i64 for String".to_string());
|
|
|
|
|
}
|
🏗️ 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
|
|
|
}
|
|
|
|
|
crate::mir::MirType::Box(_)
|
|
|
|
|
| crate::mir::MirType::Array(_)
|
|
|
|
|
| crate::mir::MirType::Future(_)
|
|
|
|
|
| crate::mir::MirType::Unknown => {
|
|
|
|
|
let h = if let BVE::IntValue(iv) = rv {
|
|
|
|
|
iv
|
|
|
|
|
} else {
|
|
|
|
|
return Err("invoke ret expected i64".to_string());
|
|
|
|
|
};
|
|
|
|
|
let pty = codegen.context.ptr_type(AddressSpace::from(0));
|
|
|
|
|
let ptr = codegen
|
|
|
|
|
.builder
|
|
|
|
|
.build_int_to_ptr(h, pty, "ret_handle_to_ptr")
|
|
|
|
|
.map_err(|e| e.to_string())?;
|
|
|
|
|
vmap.insert(dst, ptr.into());
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
|
|
|
|
vmap.insert(dst, rv);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
vmap.insert(dst, rv);
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2025-09-13 00:07:38 +09:00
|
|
|
|
|
|
|
|
// Boxed wrapper delegating to the existing implementation
|
|
|
|
|
pub(super) fn try_handle_tagged_invoke_boxed<'ctx, 'b>(
|
|
|
|
|
ctx: &mut LowerFnCtx<'ctx, 'b>,
|
|
|
|
|
blk: &BlockCtx<'ctx>,
|
|
|
|
|
dst: &Option<ValueId>,
|
|
|
|
|
mid: u16,
|
|
|
|
|
type_id: i64,
|
|
|
|
|
recv_h: inkwell::values::IntValue<'ctx>,
|
|
|
|
|
args: &[ValueId],
|
|
|
|
|
entry_builder: &inkwell::builder::Builder<'ctx>,
|
|
|
|
|
) -> Result<(), String> {
|
|
|
|
|
try_handle_tagged_invoke(
|
|
|
|
|
ctx.codegen,
|
|
|
|
|
ctx.func,
|
|
|
|
|
ctx.cursor,
|
|
|
|
|
ctx.resolver,
|
|
|
|
|
ctx.vmap,
|
|
|
|
|
dst,
|
|
|
|
|
mid,
|
|
|
|
|
type_id,
|
|
|
|
|
recv_h,
|
|
|
|
|
args,
|
|
|
|
|
entry_builder,
|
|
|
|
|
blk.cur_bid,
|
|
|
|
|
ctx.bb_map,
|
|
|
|
|
ctx.preds,
|
|
|
|
|
ctx.block_end_values,
|
|
|
|
|
)
|
|
|
|
|
}
|