feat(phase33): mir_call.hako Stages 2-4 complete - 全段階実装完了 🎉
Stage 2: CallEmitBox拡張 (+12 lines) - make_mir_call_closure(params, captures, me_capture, dst) - make_mir_call_value(func_vid, arg_ids, dst) Stage 3: mir_call.hako簡略化 (208→164 lines, -21.2%) - CallEmitBox完全活用により手動JSON生成を削除 - 74.4%削減達成 (Python 641→Hakorune 164 lines) Stage 4: Smoke Tests追加 (+102 lines) - closure_simple.hako: Closure callee typeテスト - value_simple.hako: Value callee typeテスト Phase 33 Final Achievement: ✅ 10/10 instructions 完全実装 (100%) - Phase v0: const, binop, compare, ret (4/4) - Phase v1: branch, jump, copy (3/3) - Phase v2-A: phi (1/1) - Phase v2-B: loopform (1/1) - Phase v2-C: mir_call (1/1) ← NEW! Test Coverage: - Unit tests: 288 lines (6 tests, all callee types) - Smoke tests: 147 lines (3 tests) - Total: 435 lines test coverage 🚀 Python → Hakorune Script 移行 100% 完了!
This commit is contained in:
@ -41,6 +41,19 @@ static box CallEmitBox {
|
||||
return {op: "mir_call", dst: dst, callee: callee, args: arg_ids}
|
||||
}
|
||||
|
||||
make_mir_call_closure(params, captures, me_capture, dst) {
|
||||
local callee = {type: "Closure", params: params, captures: captures}
|
||||
if me_capture != null {
|
||||
callee.me_capture = me_capture
|
||||
}
|
||||
return {op: "mir_call", dst: dst, callee: callee, args: []}
|
||||
}
|
||||
|
||||
make_mir_call_value(func_vid, arg_ids, dst) {
|
||||
local callee = {type: "Value", value: func_vid}
|
||||
return {op: "mir_call", dst: dst, callee: callee, args: arg_ids}
|
||||
}
|
||||
|
||||
_canonical_module_name(name, arity) {
|
||||
if name == null { return "" }
|
||||
if name.indexOf("/") >= 0 { return name }
|
||||
|
||||
@ -114,71 +114,33 @@ static box LLVMMirCallInstructionBox {
|
||||
}
|
||||
|
||||
// Stage 4: Closure creation
|
||||
// TODO: CallEmitBox に make_mir_call_closure を追加する必要あり
|
||||
// CallEmitBox.make_mir_call_closure を活用
|
||||
_lower_closure(self, callee, args, dst) {
|
||||
// Placeholder: 将来実装
|
||||
local params = callee.get("params")
|
||||
local captures = callee.get("captures")
|
||||
local me_capture = callee.get("me_capture")
|
||||
|
||||
local json = "{"
|
||||
json = json + "\"op\":\"mir_call\""
|
||||
json = json + ",\"dst\":" + dst.toString()
|
||||
json = json + ",\"callee\":{\"type\":\"Closure\""
|
||||
|
||||
// params 配列
|
||||
if params != null {
|
||||
json = json + ",\"params\":" + me._array_to_json(self, params)
|
||||
if params == null {
|
||||
params = new ArrayBox()
|
||||
}
|
||||
if captures == null {
|
||||
captures = new ArrayBox()
|
||||
}
|
||||
|
||||
// captures 配列
|
||||
if captures != null {
|
||||
json = json + ",\"captures\":" + me._array_to_json(self, captures)
|
||||
}
|
||||
|
||||
json = json + "}"
|
||||
json = json + ",\"args\":" + me._array_to_json(self, args)
|
||||
json = json + "}"
|
||||
|
||||
return json
|
||||
local json_obj = CallEmitBox.make_mir_call_closure(params, captures, me_capture, dst)
|
||||
return JsonEmitBox.to_json_instruction(json_obj)
|
||||
}
|
||||
|
||||
// Stage 4: Value call (dynamic function value)
|
||||
// TODO: CallEmitBox に make_mir_call_value を追加する必要あり
|
||||
// CallEmitBox.make_mir_call_value を活用
|
||||
_lower_value(self, callee, args, dst) {
|
||||
// Placeholder: 将来実装
|
||||
local func_vid = callee.get("value")
|
||||
if func_vid == null {
|
||||
return me._mir_call_error_fallback(self, "Value: value is null")
|
||||
}
|
||||
|
||||
local json = "{"
|
||||
json = json + "\"op\":\"mir_call\""
|
||||
json = json + ",\"dst\":" + dst.toString()
|
||||
json = json + ",\"callee\":{\"type\":\"Value\",\"value\":" + func_vid.toString() + "}"
|
||||
json = json + ",\"args\":" + me._array_to_json(self, args)
|
||||
json = json + "}"
|
||||
|
||||
return json
|
||||
}
|
||||
|
||||
// Helper: ArrayBox を JSON 配列に変換
|
||||
_array_to_json(self, arr) {
|
||||
if arr == null {
|
||||
return "[]"
|
||||
}
|
||||
local json = "["
|
||||
local size = arr.size()
|
||||
local i = 0
|
||||
loop(i < size) {
|
||||
if i > 0 {
|
||||
json = json + ","
|
||||
}
|
||||
local val = arr.get(i)
|
||||
json = json + val.toString()
|
||||
i = i + 1
|
||||
}
|
||||
json = json + "]"
|
||||
return json
|
||||
local json_obj = CallEmitBox.make_mir_call_value(func_vid, args, dst)
|
||||
return JsonEmitBox.to_json_instruction(json_obj)
|
||||
}
|
||||
|
||||
// エラーフォールバック: 空の MIR Call を返す
|
||||
|
||||
Reference in New Issue
Block a user