Add some comments

This commit is contained in:
Brian Carroll 2021-12-13 23:05:05 +00:00
parent cd91be678f
commit 3adaacc66e
2 changed files with 15 additions and 14 deletions

View file

@ -351,8 +351,7 @@ pub fn decode_low_level<'a>(
match storage.get(&args[0]) { match storage.get(&args[0]) {
VirtualMachineStack { value_type, .. } | Local { value_type, .. } => { VirtualMachineStack { value_type, .. } | Local { value_type, .. } => {
match value_type { match value_type {
I32 => code_builder.i32_const(1), I32 | I64 => code_builder.i32_const(1), // always true for integers
I64 => code_builder.i32_const(1),
F32 => { F32 => {
code_builder.i32_reinterpret_f32(); code_builder.i32_reinterpret_f32();
code_builder.i32_const(0x7f80_0000); code_builder.i32_const(0x7f80_0000);
@ -591,7 +590,7 @@ pub fn decode_low_level<'a>(
And => code_builder.i32_and(), And => code_builder.i32_and(),
Or => code_builder.i32_or(), Or => code_builder.i32_or(),
Not => code_builder.i32_eqz(), Not => code_builder.i32_eqz(),
Hash => return NotImplemented, Hash => return NotImplemented, // TODO: generated helpers
ExpectTrue => return NotImplemented, ExpectTrue => return NotImplemented,
RefCountGetPtr => { RefCountGetPtr => {
code_builder.i32_const(4); code_builder.i32_const(4);

View file

@ -52,21 +52,23 @@ impl From<&ModifyRc> for RefcountOp {
} }
} }
/// Generate mono IR to help with code gen /// Generate specialized helper procs for code gen
/// -------------------------------------- /// ----------------------------------------------
/// ///
/// Some operations, such as refcounting and equality comparison, need /// Some low level operations need specialized helper procs to traverse data structures at runtime.
/// specialized helper procs to traverse data structures at runtime. /// This includes refcounting, hashing, and equality checks.
/// ///
/// For example, when checking List equality, we need to visit each element /// For example, when checking List equality, we need to visit each element and compare them.
/// and compare them recursively. Similarly, when incrementing a List refcount, /// Depending on the type of the list elements, we may need to recurse deeper into each element.
/// we also increment the elements recursively. /// For tag unions, we may need branches for different tag IDs, etc.
/// This logic is the same for all targets, so we implement it once using mono IR. ///
/// This module creates specialized helper procs for all such operations and types used in the program.
/// ///
/// The backend drives the process, in two steps: /// The backend drives the process, in two steps:
/// 1) When it sees the relevant node, it calls MonoCodeGen to get the replacement IR. /// 1) When it sees the relevant node, it calls CodeGenHelp to get the replacement IR.
/// MonoCodeGen generates a call to the helper proc, and remembers it for step 2. /// CodeGenHelp returns IR for a call to the helper proc, and remembers the specialization.
/// 2) After the backend has generated all user procs, it generates the helper procs too. /// 2) After the backend has generated code for all user procs, it takes the IR for all of the
/// specialized helpers procs, and generates target code for them too.
/// ///
pub struct CodeGenHelp<'a> { pub struct CodeGenHelp<'a> {
arena: &'a Bump, arena: &'a Bump,