sway-core 0.1.2

Sway core language.
Documentation
use crate::{
    asm_generation::{convert_expression_to_asm, AsmNamespace, RegisterSequencer},
    asm_lang::Op,
    error::*,
    semantic_analysis::ast_node::TypedConstantDeclaration,
};

/// Provisions a register to put a value in, and then adds the assembly used to initialize the
/// value to the end of the buffer.
pub(crate) fn convert_constant_decl_to_asm<'sc>(
    const_decl: &TypedConstantDeclaration<'sc>,
    namespace: &mut AsmNamespace<'sc>,
    register_sequencer: &mut RegisterSequencer,
) -> CompileResult<'sc, Vec<Op<'sc>>> {
    let val_register = register_sequencer.next();
    let initialization = convert_expression_to_asm(
        &const_decl.value,
        namespace,
        &val_register,
        register_sequencer,
    );
    namespace.insert_variable(const_decl.name.clone(), val_register);
    initialization
}