polycomp 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/lowering.rs CHANGED
@@ -11,7 +11,7 @@ struct LoopTargets {
11
11
 
12
12
  struct Lowerer<'a> {
13
13
  module_id: usize,
14
- fn_id: FnId,
14
+ _fn_id: FnId,
15
15
  bindings: &'a ImportBindings,
16
16
  local_fn_names: &'a FxHashMap<String, usize>,
17
17
  call_sites: &'a mut Vec<CallSite>,
@@ -21,6 +21,7 @@ struct Lowerer<'a> {
21
21
  current_block: usize,
22
22
  scopes: Vec<FxHashMap<String, Register>>,
23
23
  loop_stack: Vec<LoopTargets>,
24
+ defer_stack: Vec<Expr>,
24
25
  }
25
26
 
26
27
  impl<'a> Lowerer<'a> {
@@ -33,7 +34,7 @@ impl<'a> Lowerer<'a> {
33
34
  ) -> Self {
34
35
  Self {
35
36
  module_id,
36
- fn_id,
37
+ _fn_id: fn_id,
37
38
  bindings,
38
39
  local_fn_names,
39
40
  call_sites,
@@ -46,6 +47,7 @@ impl<'a> Lowerer<'a> {
46
47
  current_block: 0,
47
48
  scopes: vec![FxHashMap::default()],
48
49
  loop_stack: Vec::new(),
50
+ defer_stack: Vec::new(),
49
51
  }
50
52
  }
51
53
 
@@ -79,6 +81,7 @@ impl<'a> Lowerer<'a> {
79
81
  IrInstruction::Return(_)
80
82
  | IrInstruction::Jump(_)
81
83
  | IrInstruction::BranchIf(_, _, _)
84
+ | IrInstruction::Throw(_)
82
85
  )
83
86
  })
84
87
  }
@@ -127,6 +130,14 @@ impl<'a> Lowerer<'a> {
127
130
  id
128
131
  }
129
132
 
133
+ fn emit_defers(&mut self) -> Result<(), PolyError> {
134
+ let defers = self.defer_stack.clone();
135
+ for expr in defers.into_iter().rev() {
136
+ let _ = self.lower_expr(&expr)?;
137
+ }
138
+ Ok(())
139
+ }
140
+
130
141
  fn lower_stmts(&mut self, stmts: &[Stmt]) -> Result<(), PolyError> {
131
142
  for stmt in stmts {
132
143
  self.lower_stmt(stmt)?;
@@ -170,8 +181,27 @@ impl<'a> Lowerer<'a> {
170
181
  }
171
182
  }
172
183
 
184
+ Stmt::MultiVarDecl {
185
+ names,
186
+ init,
187
+ is_function_scoped,
188
+ ..
189
+ } => {
190
+ let init_reg = self.lower_expr(init)?;
191
+ for (idx, name) in names.iter().enumerate() {
192
+ let dst = self.alloc_reg(IrType::Dynamic);
193
+ self.bind_var(name.clone(), dst, *is_function_scoped);
194
+ let idx_reg = self.alloc_reg(IrType::I64);
195
+ self.emit(IrInstruction::LoadConst(idx_reg, Constant::Int(idx as i64)));
196
+ self.emit(IrInstruction::GetIndex(dst, init_reg, idx_reg));
197
+ }
198
+ }
199
+
173
200
  Stmt::Assign {
174
- target, op, value, span
201
+ target,
202
+ op,
203
+ value,
204
+ span,
175
205
  } => {
176
206
  let rhs = self.lower_expr(value)?;
177
207
  match target {
@@ -219,15 +249,32 @@ impl<'a> Lowerer<'a> {
219
249
  self.emit(IrInstruction::SetIndex(obj_reg, idx_reg, rhs));
220
250
  }
221
251
  }
252
+ AssignTarget::Tuple(names) => {
253
+ for (idx, name) in names.iter().enumerate() {
254
+ if let Some(var_reg) = self.lookup_var(name) {
255
+ let idx_reg = self.alloc_reg(IrType::I64);
256
+ self.emit(IrInstruction::LoadConst(
257
+ idx_reg,
258
+ Constant::Int(idx as i64),
259
+ ));
260
+ self.emit(IrInstruction::GetIndex(var_reg, rhs, idx_reg));
261
+ }
262
+ }
263
+ }
222
264
  }
223
265
  }
224
266
 
225
267
  Stmt::If {
268
+ init,
226
269
  cond,
227
270
  then_body,
228
271
  else_body,
229
272
  ..
230
273
  } => {
274
+ self.push_scope();
275
+ if let Some(init_stmt) = init {
276
+ self.lower_stmt(init_stmt)?;
277
+ }
231
278
  let cond_reg = self.lower_expr(cond)?;
232
279
  let then_bb = self.new_block();
233
280
  let else_bb = self.new_block();
@@ -247,6 +294,7 @@ impl<'a> Lowerer<'a> {
247
294
  self.pop_scope();
248
295
  self.emit(IrInstruction::Jump(merge_bb));
249
296
 
297
+ self.pop_scope();
250
298
  self.switch_to(merge_bb);
251
299
  }
252
300
 
@@ -333,7 +381,11 @@ impl<'a> Lowerer<'a> {
333
381
  }
334
382
 
335
383
  Stmt::ForIn {
336
- var, iter, body, ..
384
+ index_var,
385
+ var,
386
+ iter,
387
+ body,
388
+ ..
337
389
  } => {
338
390
  let arr_reg = self.lower_expr(iter)?;
339
391
  let len_reg = self.alloc_reg(IrType::I64);
@@ -348,6 +400,9 @@ impl<'a> Lowerer<'a> {
348
400
  self.emit(IrInstruction::LoadConst(one_reg, Constant::Int(1)));
349
401
 
350
402
  self.push_scope();
403
+ if let Some(iv) = index_var {
404
+ self.bind_var(iv.clone(), idx_reg, false);
405
+ }
351
406
  let elem_reg = self.alloc_reg(IrType::Dynamic);
352
407
  self.bind_var(var.clone(), elem_reg, false);
353
408
 
@@ -390,11 +445,115 @@ impl<'a> Lowerer<'a> {
390
445
  self.switch_to(exit_bb);
391
446
  }
392
447
 
448
+ Stmt::Switch {
449
+ expr,
450
+ cases,
451
+ default,
452
+ ..
453
+ } => {
454
+ let target_val = if let Some(e) = expr {
455
+ Some(self.lower_expr(e)?)
456
+ } else {
457
+ None
458
+ };
459
+ let exit_bb = self.new_block();
460
+ self.loop_stack.push(LoopTargets {
461
+ break_bb: exit_bb,
462
+ continue_bb: exit_bb,
463
+ });
464
+
465
+ let mut next_case_bb = self.new_block();
466
+ for (vals, body) in cases {
467
+ self.switch_to(next_case_bb);
468
+ next_case_bb = self.new_block();
469
+ let case_body_bb = self.new_block();
470
+
471
+ if let Some(tv) = target_val {
472
+ for val_expr in vals {
473
+ let vr = self.lower_expr(val_expr)?;
474
+ let cmp_r = self.alloc_reg(IrType::Bool);
475
+ self.emit(IrInstruction::BinOp(IrBinOp::Eq, cmp_r, tv, vr));
476
+ let try_next_val = self.new_block();
477
+ self.emit(IrInstruction::BranchIf(cmp_r, case_body_bb, try_next_val));
478
+ self.switch_to(try_next_val);
479
+ }
480
+ self.emit(IrInstruction::Jump(next_case_bb));
481
+ } else {
482
+ // Go switch without expr (boolean conditions)
483
+ for val_expr in vals {
484
+ let cond_r = self.lower_expr(val_expr)?;
485
+ let try_next_val = self.new_block();
486
+ self.emit(IrInstruction::BranchIf(cond_r, case_body_bb, try_next_val));
487
+ self.switch_to(try_next_val);
488
+ }
489
+ self.emit(IrInstruction::Jump(next_case_bb));
490
+ }
491
+
492
+ self.switch_to(case_body_bb);
493
+ self.push_scope();
494
+ self.lower_stmts(body)?;
495
+ self.pop_scope();
496
+ self.emit(IrInstruction::Jump(exit_bb));
497
+ }
498
+
499
+ self.switch_to(next_case_bb);
500
+ self.push_scope();
501
+ self.lower_stmts(default)?;
502
+ self.pop_scope();
503
+ self.emit(IrInstruction::Jump(exit_bb));
504
+
505
+ self.loop_stack.pop();
506
+ self.switch_to(exit_bb);
507
+ }
508
+
509
+ Stmt::TryCatch {
510
+ try_body,
511
+ catch_var,
512
+ catch_body,
513
+ finally_body,
514
+ ..
515
+ } => {
516
+ let catch_bb = self.new_block();
517
+ let finally_bb = self.new_block();
518
+ let err_reg = self.alloc_reg(IrType::Dynamic);
519
+
520
+ self.emit(IrInstruction::TryBegin(catch_bb, err_reg));
521
+ self.push_scope();
522
+ self.lower_stmts(try_body)?;
523
+ self.pop_scope();
524
+ self.emit(IrInstruction::TryEnd);
525
+ self.emit(IrInstruction::Jump(finally_bb));
526
+
527
+ self.switch_to(catch_bb);
528
+ self.push_scope();
529
+ if let Some(cv) = catch_var {
530
+ self.bind_var(cv.clone(), err_reg, false);
531
+ }
532
+ self.lower_stmts(catch_body)?;
533
+ self.pop_scope();
534
+ self.emit(IrInstruction::Jump(finally_bb));
535
+
536
+ self.switch_to(finally_bb);
537
+ self.push_scope();
538
+ self.lower_stmts(finally_body)?;
539
+ self.pop_scope();
540
+ }
541
+
542
+ Stmt::Throw(expr, _) => {
543
+ let r = self.lower_expr(expr)?;
544
+ self.emit(IrInstruction::Throw(r));
545
+ }
546
+
547
+ Stmt::Defer(expr, _) => {
548
+ self.defer_stack.push(expr.clone());
549
+ }
550
+
393
551
  Stmt::Return(expr, _) => {
394
552
  let reg = match expr {
395
553
  Some(e) => Some(self.lower_expr(e)?),
396
554
  None => None,
397
555
  };
556
+ self.emit_defers()?;
398
557
  self.emit(IrInstruction::Return(reg));
399
558
  }
400
559
 
@@ -456,6 +615,76 @@ impl<'a> Lowerer<'a> {
456
615
  self.emit(IrInstruction::LoadConst(r, Constant::String(s.clone())));
457
616
  Ok(r)
458
617
  }
618
+ Expr::Regex { pattern, flags, .. } => {
619
+ let r = self.alloc_reg(IrType::Dynamic);
620
+ self.emit(IrInstruction::LoadConst(
621
+ r,
622
+ Constant::Regex {
623
+ pattern: pattern.clone(),
624
+ flags: flags.clone(),
625
+ },
626
+ ));
627
+ Ok(r)
628
+ }
629
+ Expr::TemplateStr { parts, .. } => {
630
+ if parts.is_empty() {
631
+ let r = self.alloc_reg(IrType::Str);
632
+ self.emit(IrInstruction::LoadConst(r, Constant::String(String::new())));
633
+ return Ok(r);
634
+ }
635
+ let mut current_reg: Option<Register> = None;
636
+ for p in parts {
637
+ let part_reg = match p {
638
+ TemplatePart::Literal(s) => {
639
+ let r = self.alloc_reg(IrType::Str);
640
+ self.emit(IrInstruction::LoadConst(r, Constant::String(s.clone())));
641
+ r
642
+ }
643
+ TemplatePart::Expr { expr, format_spec } => {
644
+ let raw_r = self.lower_expr(expr)?;
645
+ if let Some(spec) = format_spec {
646
+ let spec_r = self.alloc_reg(IrType::Str);
647
+ self.emit(IrInstruction::LoadConst(
648
+ spec_r,
649
+ Constant::String(format!("%{spec}")),
650
+ ));
651
+ let res_r = self.alloc_reg(IrType::Str);
652
+ self.emit(IrInstruction::CallBuiltin(
653
+ res_r,
654
+ BuiltinId::Sprintf,
655
+ vec![spec_r, raw_r],
656
+ ));
657
+ res_r
658
+ } else {
659
+ let res_r = self.alloc_reg(IrType::Str);
660
+ self.emit(IrInstruction::CallBuiltin(
661
+ res_r,
662
+ BuiltinId::Str,
663
+ vec![raw_r],
664
+ ));
665
+ res_r
666
+ }
667
+ }
668
+ };
669
+ if let Some(acc) = current_reg {
670
+ let next_acc = self.alloc_reg(IrType::Str);
671
+ self.emit(IrInstruction::BinOp(
672
+ IrBinOp::Add,
673
+ next_acc,
674
+ acc,
675
+ part_reg,
676
+ ));
677
+ current_reg = Some(next_acc);
678
+ } else {
679
+ current_reg = Some(part_reg);
680
+ }
681
+ }
682
+ Ok(current_reg.unwrap_or_else(|| {
683
+ let r = self.alloc_reg(IrType::Str);
684
+ self.emit(IrInstruction::LoadConst(r, Constant::String(String::new())));
685
+ r
686
+ }))
687
+ }
459
688
  Expr::Var(name, span) => {
460
689
  if let Some(r) = self.lookup_var(name) {
461
690
  return Ok(r);
@@ -481,7 +710,7 @@ impl<'a> Lowerer<'a> {
481
710
  *span,
482
711
  ))
483
712
  }
484
- Expr::Array(items, _) => {
713
+ Expr::Array(items, _) | Expr::Tuple(items, _) => {
485
714
  let mut regs = Vec::with_capacity(items.len());
486
715
  for item in items {
487
716
  regs.push(self.lower_expr(item)?);
@@ -500,6 +729,13 @@ impl<'a> Lowerer<'a> {
500
729
  }
501
730
  Ok(obj)
502
731
  }
732
+ Expr::Cast { ty, expr, .. } => {
733
+ let src = self.lower_expr(expr)?;
734
+ let ir_ty = hint_to_ir_type(*ty);
735
+ let dst = self.alloc_reg(ir_ty);
736
+ self.emit(IrInstruction::Cast(dst, ir_ty, src));
737
+ Ok(dst)
738
+ }
503
739
  Expr::Unary(op, inner, _) => {
504
740
  let src = self.lower_expr(inner)?;
505
741
  let dst = self.alloc_reg(IrType::Dynamic);
@@ -512,7 +748,6 @@ impl<'a> Lowerer<'a> {
512
748
  Ok(dst)
513
749
  }
514
750
  Expr::Binary(op, l, r, _) => {
515
- // Short-circuit `&&` / `||` / `and` / `or`
516
751
  if matches!(op, BinOp::And | BinOp::Or) {
517
752
  let l_reg = self.lower_expr(l)?;
518
753
  let res = self.alloc_reg(IrType::Bool);
@@ -542,6 +777,33 @@ impl<'a> Lowerer<'a> {
542
777
  return Ok(res);
543
778
  }
544
779
 
780
+ if *op == BinOp::NullCoal {
781
+ let l_reg = self.lower_expr(l)?;
782
+ let res = self.alloc_reg(IrType::Dynamic);
783
+ let nil_reg = self.alloc_reg(IrType::Dynamic);
784
+ self.emit(IrInstruction::LoadConst(nil_reg, Constant::Nil));
785
+ let is_nil = self.alloc_reg(IrType::Bool);
786
+ self.emit(IrInstruction::BinOp(IrBinOp::Eq, is_nil, l_reg, nil_reg));
787
+
788
+ let rhs_bb = self.new_block();
789
+ let short_bb = self.new_block();
790
+ let merge_bb = self.new_block();
791
+
792
+ self.emit(IrInstruction::BranchIf(is_nil, rhs_bb, short_bb));
793
+
794
+ self.switch_to(short_bb);
795
+ self.emit(IrInstruction::Move(res, l_reg));
796
+ self.emit(IrInstruction::Jump(merge_bb));
797
+
798
+ self.switch_to(rhs_bb);
799
+ let r_reg = self.lower_expr(r)?;
800
+ self.emit(IrInstruction::Move(res, r_reg));
801
+ self.emit(IrInstruction::Jump(merge_bb));
802
+
803
+ self.switch_to(merge_bb);
804
+ return Ok(res);
805
+ }
806
+
545
807
  let lr = self.lower_expr(l)?;
546
808
  let rr = self.lower_expr(r)?;
547
809
  let dst = self.alloc_reg(IrType::Dynamic);
@@ -587,9 +849,7 @@ impl<'a> Lowerer<'a> {
587
849
  self.emit(IrInstruction::CallBuiltin(dst, builtin, arg_regs));
588
850
  return Ok(dst);
589
851
  }
590
- if let Some(&idx) = self.local_fn_names.get(name) {
591
- // If calling self directly, emit fast CallFn!
592
- let _ = idx;
852
+ if self.local_fn_names.contains_key(name) {
593
853
  let site = self.alloc_call_site(
594
854
  LazyTarget::SelfModule {
595
855
  module_id: self.module_id,
@@ -610,24 +870,58 @@ impl<'a> Lowerer<'a> {
610
870
  self.emit(IrInstruction::CallLazy(dst, site, arg_regs));
611
871
  Ok(dst)
612
872
  }
613
- Expr::Member { object, field, .. } => {
873
+ Expr::Member {
874
+ object,
875
+ field,
876
+ optional,
877
+ ..
878
+ } => {
614
879
  if let Expr::Var(ns, _) = &**object {
615
- if ns == "console" && field == "log" {
616
- self.emit(IrInstruction::CallBuiltin(
617
- dst,
618
- BuiltinId::Println,
619
- arg_regs,
620
- ));
880
+ if (ns == "console" || ns == "Console")
881
+ && (field == "log" || field == "WriteLine" || field == "Write")
882
+ {
883
+ let b = if field == "Write" {
884
+ BuiltinId::Print
885
+ } else {
886
+ BuiltinId::Println
887
+ };
888
+ self.emit(IrInstruction::CallBuiltin(dst, b, arg_regs));
621
889
  return Ok(dst);
622
890
  }
623
- if ns == "Math"
891
+ if (ns == "Math" || ns == "math")
624
892
  && let Some(b) = BuiltinId::from_name(field)
625
893
  {
626
894
  self.emit(IrInstruction::CallBuiltin(dst, b, arg_regs));
627
895
  return Ok(dst);
628
896
  }
629
- if self.bindings.namespaces.contains_key(ns) && self.lookup_var(ns).is_none()
630
- {
897
+ if (ns == "fmt" || ns == "std") && (field == "Println" || field == "Print" || field == "Printf" || field == "Sprintf") {
898
+ let b = match field.as_str() {
899
+ "Println" => BuiltinId::Println,
900
+ "Print" => BuiltinId::Print,
901
+ "Printf" => BuiltinId::Printf,
902
+ _ => BuiltinId::Sprintf,
903
+ };
904
+ self.emit(IrInstruction::CallBuiltin(dst, b, arg_regs));
905
+ return Ok(dst);
906
+ }
907
+ if ns == "strings" || ns == "re" || ns == "regexp" || ns == "Regex" {
908
+ let b_opt = match field.as_str() {
909
+ "Contains" | "contains" => Some(BuiltinId::StrContains),
910
+ "Split" | "split" => Some(BuiltinId::StrSplit),
911
+ "TrimSpace" | "Trim" | "trim" => Some(BuiltinId::StrTrim),
912
+ "ToUpper" | "toUpperCase" | "upper" => Some(BuiltinId::StrUpper),
913
+ "ToLower" | "toLowerCase" | "lower" => Some(BuiltinId::StrLower),
914
+ "ReplaceAll" | "Replace" | "replace" => Some(BuiltinId::StrReplace),
915
+ "MatchString" | "match" | "IsMatch" | "test" => Some(BuiltinId::RegexTest),
916
+ "FindAllString" | "findAll" => Some(BuiltinId::RegexFindAll),
917
+ _ => None,
918
+ };
919
+ if let Some(b) = b_opt {
920
+ self.emit(IrInstruction::CallBuiltin(dst, b, arg_regs));
921
+ return Ok(dst);
922
+ }
923
+ }
924
+ if self.bindings.namespaces.contains_key(ns) && self.lookup_var(ns).is_none() {
631
925
  let site = self.alloc_call_site(
632
926
  LazyTarget::Direct {
633
927
  from_module: self.module_id,
@@ -639,34 +933,41 @@ impl<'a> Lowerer<'a> {
639
933
  return Ok(dst);
640
934
  }
641
935
  }
936
+
642
937
  let obj_reg = self.lower_expr(object)?;
643
- if field == "push" || field == "append" {
644
- let mut b_args = vec![obj_reg];
645
- b_args.extend(arg_regs);
646
- self.emit(IrInstruction::CallBuiltin(dst, BuiltinId::Push, b_args));
647
- return Ok(dst);
648
- }
649
- if field == "pop" && arg_regs.is_empty() {
650
- self.emit(IrInstruction::CallBuiltin(
651
- dst,
652
- BuiltinId::Pop,
653
- vec![obj_reg],
654
- ));
655
- return Ok(dst);
656
- }
657
- if field == "len" && arg_regs.is_empty() {
658
- self.emit(IrInstruction::CallBuiltin(
938
+ if *optional {
939
+ let nil_r = self.alloc_reg(IrType::Dynamic);
940
+ self.emit(IrInstruction::LoadConst(nil_r, Constant::Nil));
941
+ let is_nil = self.alloc_reg(IrType::Bool);
942
+ self.emit(IrInstruction::BinOp(IrBinOp::Eq, is_nil, obj_reg, nil_r));
943
+ let call_bb = self.new_block();
944
+ let skip_bb = self.new_block();
945
+ let merge_bb = self.new_block();
946
+ self.emit(IrInstruction::BranchIf(is_nil, skip_bb, call_bb));
947
+
948
+ self.switch_to(skip_bb);
949
+ self.emit(IrInstruction::Move(dst, nil_r));
950
+ self.emit(IrInstruction::Jump(merge_bb));
951
+
952
+ self.switch_to(call_bb);
953
+ self.emit(IrInstruction::CallMethod(
659
954
  dst,
660
- BuiltinId::Len,
661
- vec![obj_reg],
955
+ obj_reg,
956
+ field.clone(),
957
+ arg_regs,
662
958
  ));
959
+ self.emit(IrInstruction::Jump(merge_bb));
960
+
961
+ self.switch_to(merge_bb);
663
962
  return Ok(dst);
664
963
  }
665
- let fn_reg = self.alloc_reg(IrType::Dynamic);
666
- self.emit(IrInstruction::GetField(fn_reg, obj_reg, field.clone()));
667
- let mut m_args = vec![obj_reg];
668
- m_args.extend(arg_regs);
669
- self.emit(IrInstruction::CallIndirect(dst, fn_reg, m_args));
964
+
965
+ self.emit(IrInstruction::CallMethod(
966
+ dst,
967
+ obj_reg,
968
+ field.clone(),
969
+ arg_regs,
970
+ ));
670
971
  Ok(dst)
671
972
  }
672
973
  other => {
@@ -676,10 +977,38 @@ impl<'a> Lowerer<'a> {
676
977
  }
677
978
  }
678
979
  }
679
- Expr::Member { object, field, .. } => {
980
+ Expr::Member {
981
+ object,
982
+ field,
983
+ optional,
984
+ ..
985
+ } => {
680
986
  let obj_reg = self.lower_expr(object)?;
681
987
  let dst = self.alloc_reg(IrType::Dynamic);
682
- if field == "length" {
988
+
989
+ if *optional {
990
+ let nil_r = self.alloc_reg(IrType::Dynamic);
991
+ self.emit(IrInstruction::LoadConst(nil_r, Constant::Nil));
992
+ let is_nil = self.alloc_reg(IrType::Bool);
993
+ self.emit(IrInstruction::BinOp(IrBinOp::Eq, is_nil, obj_reg, nil_r));
994
+ let get_bb = self.new_block();
995
+ let skip_bb = self.new_block();
996
+ let merge_bb = self.new_block();
997
+ self.emit(IrInstruction::BranchIf(is_nil, skip_bb, get_bb));
998
+
999
+ self.switch_to(skip_bb);
1000
+ self.emit(IrInstruction::Move(dst, nil_r));
1001
+ self.emit(IrInstruction::Jump(merge_bb));
1002
+
1003
+ self.switch_to(get_bb);
1004
+ self.emit(IrInstruction::GetField(dst, obj_reg, field.clone()));
1005
+ self.emit(IrInstruction::Jump(merge_bb));
1006
+
1007
+ self.switch_to(merge_bb);
1008
+ return Ok(dst);
1009
+ }
1010
+
1011
+ if field == "length" || field == "Count" {
683
1012
  self.emit(IrInstruction::CallBuiltin(
684
1013
  dst,
685
1014
  BuiltinId::Len,
@@ -729,7 +1058,7 @@ impl<'a> Lowerer<'a> {
729
1058
 
730
1059
  fn hint_to_ir_type(hint: TypeHint) -> IrType {
731
1060
  match hint {
732
- TypeHint::Unknown => IrType::Dynamic,
1061
+ TypeHint::Unknown | TypeHint::Array | TypeHint::Object | TypeHint::Regex => IrType::Dynamic,
733
1062
  TypeHint::Void => IrType::Void,
734
1063
  TypeHint::Bool => IrType::Bool,
735
1064
  TypeHint::Int => IrType::I64,
@@ -746,6 +1075,7 @@ fn map_binop(op: BinOp) -> IrBinOp {
746
1075
  BinOp::Div => IrBinOp::Div,
747
1076
  BinOp::FloorDiv => IrBinOp::FloorDiv,
748
1077
  BinOp::Mod => IrBinOp::Mod,
1078
+ BinOp::Pow => IrBinOp::Pow,
749
1079
  BinOp::Eq => IrBinOp::Eq,
750
1080
  BinOp::Ne => IrBinOp::Ne,
751
1081
  BinOp::Lt => IrBinOp::Lt,
@@ -754,6 +1084,7 @@ fn map_binop(op: BinOp) -> IrBinOp {
754
1084
  BinOp::Ge => IrBinOp::Ge,
755
1085
  BinOp::And => IrBinOp::And,
756
1086
  BinOp::Or => IrBinOp::Or,
1087
+ BinOp::NullCoal => IrBinOp::Or,
757
1088
  BinOp::BitAnd => IrBinOp::BitAnd,
758
1089
  BinOp::BitOr => IrBinOp::BitOr,
759
1090
  BinOp::BitXor => IrBinOp::BitXor,
@@ -782,10 +1113,10 @@ pub fn lower_function(
782
1113
 
783
1114
  lowerer.lower_stmts(&decl.body)?;
784
1115
  if !lowerer.current_terminated() {
1116
+ lowerer.emit_defers()?;
785
1117
  lowerer.emit(IrInstruction::Return(None));
786
1118
  }
787
1119
 
788
- let _ = lowerer.fn_id;
789
1120
  Ok(IrFunction {
790
1121
  id: fn_id,
791
1122
  module_id,