Compiles one `CASE` guard and returns the register and source position of its boolean result.
(
ctx: &mut Context,
symtable: &mut TempSymtable<'_, '_>,
test_reg: Register,
test_type: ExprType,
guard: CaseGuardSpan,
)
| 317 | |
| 318 | /// Compiles one `CASE` guard and returns the register and source position of its boolean result. |
| 319 | fn compile_case_guard( |
| 320 | ctx: &mut Context, |
| 321 | symtable: &mut TempSymtable<'_, '_>, |
| 322 | test_reg: Register, |
| 323 | test_type: ExprType, |
| 324 | guard: CaseGuardSpan, |
| 325 | ) -> Result<(Register, LineCol)> { |
| 326 | match guard { |
| 327 | CaseGuardSpan::Is(relop, expr) => { |
| 328 | let pos = expr.start_pos(); |
| 329 | |
| 330 | let mut scope = symtable.temp_scope(); |
| 331 | let lhs_reg = scope.alloc().map_err(|e| Error::from_syms(e, pos))?; |
| 332 | let rhs_reg = scope.alloc().map_err(|e| Error::from_syms(e, pos))?; |
| 333 | let cond_reg = scope.alloc().map_err(|e| Error::from_syms(e, pos))?; |
| 334 | |
| 335 | ctx.codegen.emit(bytecode::make_move(lhs_reg, test_reg), pos); |
| 336 | let rhs_type = compile_expr(&mut ctx.codegen, symtable, rhs_reg, expr)?; |
| 337 | compile_case_relop( |
| 338 | ctx, |
| 339 | pos, |
| 340 | (lhs_reg, test_type), |
| 341 | (rhs_reg, rhs_type), |
| 342 | relop, |
| 343 | cond_reg, |
| 344 | )?; |
| 345 | |
| 346 | Ok((cond_reg, pos)) |
| 347 | } |
| 348 | |
| 349 | CaseGuardSpan::To(from_expr, to_expr) => { |
| 350 | let pos = from_expr.start_pos(); |
| 351 | |
| 352 | let mut scope = symtable.temp_scope(); |
| 353 | let lhs_from_reg = scope.alloc().map_err(|e| Error::from_syms(e, pos))?; |
| 354 | let rhs_from_reg = scope.alloc().map_err(|e| Error::from_syms(e, pos))?; |
| 355 | let cond_from_reg = scope.alloc().map_err(|e| Error::from_syms(e, pos))?; |
| 356 | |
| 357 | let lhs_to_reg = scope.alloc().map_err(|e| Error::from_syms(e, pos))?; |
| 358 | let rhs_to_reg = scope.alloc().map_err(|e| Error::from_syms(e, pos))?; |
| 359 | let cond_to_reg = scope.alloc().map_err(|e| Error::from_syms(e, pos))?; |
| 360 | |
| 361 | let cond_reg = scope.alloc().map_err(|e| Error::from_syms(e, pos))?; |
| 362 | |
| 363 | ctx.codegen.emit(bytecode::make_move(lhs_from_reg, test_reg), pos); |
| 364 | let rhs_from_type = compile_expr(&mut ctx.codegen, symtable, rhs_from_reg, from_expr)?; |
| 365 | compile_case_relop( |
| 366 | ctx, |
| 367 | pos, |
| 368 | (lhs_from_reg, test_type), |
| 369 | (rhs_from_reg, rhs_from_type), |
| 370 | CaseRelOp::GreaterEqual, |
| 371 | cond_from_reg, |
| 372 | )?; |
| 373 | |
| 374 | ctx.codegen.emit(bytecode::make_move(lhs_to_reg, test_reg), pos); |
| 375 | let rhs_to_type = compile_expr(&mut ctx.codegen, symtable, rhs_to_reg, to_expr)?; |
| 376 | compile_case_relop( |
no test coverage detected