-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make a relatively cursed generic router for lowering instructions
- Loading branch information
Showing
6 changed files
with
271 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
shin-asm/src/compile/hir/lower/instruction/instr_lowerer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use shin_core::format::scenario::instructions::Instruction; | ||
|
||
use super::from_instr_args::FromInstrArgs; | ||
use crate::compile::hir::lower::from_hir::{FromHirBlockCtx, FromHirCollectors}; | ||
|
||
pub trait InstrLowerFn<Dummy, Args: FromInstrArgs> { | ||
fn lower_instr( | ||
&self, | ||
collectors: &mut FromHirCollectors, | ||
ctx: &FromHirBlockCtx, | ||
instr_name: &str, | ||
args: Args, | ||
) -> Option<Instruction>; | ||
} | ||
|
||
// TODO: refine the selection of the InstrLowerFn shapes | ||
|
||
impl< | ||
Args: FromInstrArgs, | ||
F: Fn(&mut FromHirCollectors, &FromHirBlockCtx, &str, Args) -> Option<Instruction>, | ||
> InstrLowerFn<((), (), (), ()), Args> for F | ||
{ | ||
fn lower_instr( | ||
&self, | ||
collectors: &mut FromHirCollectors, | ||
ctx: &FromHirBlockCtx, | ||
instr_name: &str, | ||
args: Args, | ||
) -> Option<Instruction> { | ||
self(collectors, ctx, instr_name, args) | ||
} | ||
} | ||
|
||
impl< | ||
Args: FromInstrArgs, | ||
F: Fn(&mut FromHirCollectors, &FromHirBlockCtx, Args) -> Option<Instruction>, | ||
> InstrLowerFn<((), (), ()), Args> for F | ||
{ | ||
fn lower_instr( | ||
&self, | ||
collectors: &mut FromHirCollectors, | ||
ctx: &FromHirBlockCtx, | ||
_instr_name: &str, | ||
args: Args, | ||
) -> Option<Instruction> { | ||
self(collectors, ctx, args) | ||
} | ||
} | ||
|
||
impl<Args: FromInstrArgs, F: Fn(&str, Args) -> Option<Instruction>> InstrLowerFn<((), ()), Args> | ||
for F | ||
{ | ||
fn lower_instr( | ||
&self, | ||
_collectors: &mut FromHirCollectors, | ||
_ctx: &FromHirBlockCtx, | ||
instr_name: &str, | ||
args: Args, | ||
) -> Option<Instruction> { | ||
self(instr_name, args) | ||
} | ||
} | ||
|
||
impl<Args: FromInstrArgs, F: Fn(Args) -> Option<Instruction>> InstrLowerFn<((),), Args> for F { | ||
fn lower_instr( | ||
&self, | ||
_collectors: &mut FromHirCollectors, | ||
_ctx: &FromHirBlockCtx, | ||
_instr_name: &str, | ||
args: Args, | ||
) -> Option<Instruction> { | ||
self(args) | ||
} | ||
} | ||
|
||
impl<F: Fn() -> Option<Instruction>> InstrLowerFn<(), ()> for F { | ||
fn lower_instr( | ||
&self, | ||
_collectors: &mut FromHirCollectors, | ||
_ctx: &FromHirBlockCtx, | ||
_instr_name: &str, | ||
_args: (), | ||
) -> Option<Instruction> { | ||
self() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.