feat: 配列/Mapリテラル糖衣構文の実装とネームスペース解決の改善計画

- ArrayLiteral/MapLiteralのAST定義追加
- パーサーで[...]と{...}構文をサポート
- MIR Builderでnew Box() + push/setへのdesugaring実装
- テストケースとスモークスクリプト追加
- CURRENT_TASK.mdにネームスペース解決Phase-1計画を追記
- 3段階解決順序(ローカル→エイリアス→プラグイン)の設計合意
This commit is contained in:
Selfhosting Dev
2025-09-16 06:13:44 +09:00
parent 18bc386bc5
commit 6ca56b0652
27 changed files with 446 additions and 50 deletions

View File

@ -114,6 +114,28 @@ impl super::MirBuilder {
ASTNode::New { class, arguments, .. } =>
self.build_new_expression(class.clone(), arguments.clone()),
ASTNode::ArrayLiteral { elements, .. } => {
let arr_id = self.value_gen.next();
self.emit_instruction(MirInstruction::NewBox { dst: arr_id, box_type: "ArrayBox".to_string(), args: vec![] })?;
for e in elements {
let v = self.build_expression_impl(e)?;
self.emit_instruction(MirInstruction::BoxCall { dst: None, box_val: arr_id, method: "push".to_string(), method_id: None, args: vec![v], effects: super::EffectMask::MUT })?;
}
Ok(arr_id)
}
ASTNode::MapLiteral { entries, .. } => {
let map_id = self.value_gen.next();
self.emit_instruction(MirInstruction::NewBox { dst: map_id, box_type: "MapBox".to_string(), args: vec![] })?;
for (k, expr) in entries {
// const string key
let k_id = self.value_gen.next();
self.emit_instruction(MirInstruction::Const { dst: k_id, value: ConstValue::String(k) })?;
let v_id = self.build_expression_impl(expr)?;
self.emit_instruction(MirInstruction::BoxCall { dst: None, box_val: map_id, method: "set".to_string(), method_id: None, args: vec![k_id, v_id], effects: super::EffectMask::MUT })?;
}
Ok(map_id)
}
ASTNode::Nowait { variable, expression, .. } =>
self.build_nowait_statement(variable.clone(), *expression.clone()),