@@ -937,6 +937,20 @@ let rec lower_expression ctx (expr : Ast.expr) =
937937 emit_instruction ctx alloc_instr;
938938
939939 result_val
940+
941+ | Ast. NewWithFlag (typ , flag_expr ) ->
942+ (* Object allocation with GFP flag - only valid in kernel context *)
943+ let ir_type = ast_type_to_ir_type typ in
944+ let result_reg = allocate_register ctx in
945+ let result_val = make_ir_value (IRRegister result_reg) (IRPointer (ir_type, make_bounds_info () )) expr.expr_pos in
946+
947+ (* Lower the flag expression *)
948+ let flag_val = lower_expression ctx flag_expr in
949+
950+ let alloc_instr = make_ir_instruction (IRObjectNewWithFlag (result_val, ir_type, flag_val)) expr.expr_pos in
951+ emit_instruction ctx alloc_instr;
952+
953+ result_val
940954
941955(* * Helper function to handle register() builtin function calls *)
942956and handle_register_builtin_call ctx args expr_pos ?target_register ?target_type () =
@@ -1335,7 +1349,7 @@ and lower_statement ctx stmt =
13351349
13361350 (* Handle function call and new expression declarations elegantly by proper instruction ordering *)
13371351 (match expr_opt with
1338- | Some expr when (match expr.expr_desc with Ast. Call _ | Ast. New _ -> true | _ -> false ) ->
1352+ | Some expr when (match expr.expr_desc with Ast. Call _ | Ast. New _ | Ast. NewWithFlag _ -> true | _ -> false ) ->
13391353 (* For function calls and new expressions: emit declaration first, then operation with assignment *)
13401354 let target_type = match typ_opt with
13411355 | Some ast_type -> resolve_type_alias ctx reg ast_type
@@ -1348,6 +1362,9 @@ and lower_statement ctx stmt =
13481362 | Ast. New typ ->
13491363 let ir_type = ast_type_to_ir_type typ in
13501364 IRPointer (ir_type, make_bounds_info () )
1365+ | Ast. NewWithFlag (typ , _ ) ->
1366+ let ir_type = ast_type_to_ir_type typ in
1367+ IRPointer (ir_type, make_bounds_info () )
13511368 | _ -> IRU32 ))
13521369 in
13531370
@@ -1385,6 +1402,13 @@ and lower_statement ctx stmt =
13851402 let result_val = make_ir_value (IRRegister reg) target_type expr.Ast. expr_pos in
13861403 let alloc_instr = make_ir_instruction (IRObjectNew (result_val, ir_type)) expr.Ast. expr_pos in
13871404 emit_instruction ctx alloc_instr
1405+ | Ast. NewWithFlag (typ , flag_expr ) ->
1406+ (* Handle new expression with flag: emit allocation instruction with flag *)
1407+ let ir_type = ast_type_to_ir_type typ in
1408+ let result_val = make_ir_value (IRRegister reg) target_type expr.Ast. expr_pos in
1409+ let flag_val = lower_expression ctx flag_expr in
1410+ let alloc_instr = make_ir_instruction (IRObjectNewWithFlag (result_val, ir_type, flag_val)) expr.Ast. expr_pos in
1411+ emit_instruction ctx alloc_instr
13881412 | _ -> () ) (* Shouldn't happen due to our guard *)
13891413 | _ ->
13901414 (* Non-function call declarations: use existing logic *)
0 commit comments