Skip to content

Commit 2861ef7

Browse files
committed
refactor(codegen): extract schema/field-access helpers into schema.rs
Move 44 schema/type-layout methods into src/codegen/schema.rs (~1,503 extracted lines), covering: - Schema bounds and size checks (emit_loaded_schema_bounds_check, emit_loaded_schema_exact_size_check) - Molecule table field helpers (emit_molecule_table_field_bounds_to_t5, emit_molecule_table_field_span_to_t5_t6) - Cell metadata/field hash equality (emit_cell_metadata_equality, emit_cell_field_hash_equality) - Fixed-field pointer loading (emit_loaded_fixed_field_pointer_to_stack, emit_dynamic_fixed_field_pointer_to_stack) - Dynamic table field helpers (emit_dynamic_table_field_equality_check, emit_dynamic_table_field_span_to_stack, emit_dynamic_table_fixed_field_pointer_to_stack) - Loaded field comparison (emit_loaded_field_equals_expected, emit_loaded_fixed_bytes_against_source, emit_loaded_field_bytes_equals_expected) - Fixed-byte source/comparison (emit_fixed_byte_source_byte_to, emit_fixed_byte_comparison, expected_fixed_byte_source, emit_generic_fixed_byte_comparison, emit_store_fixed_byte_const_to_scratch) - u128 and prelude value resolution (operand_is_u128, emit_u128_add_sub_with_u64, emit_prelude_u64_value_source_to_t1, emit_schema_field_source_to_t1, emit_expected_operand_to_t1) - Schema field source preparation (emit_prepare_schema_field_source, emit_schema_field_source_pointer_to) - Field access dispatch (emit_schema_field_access, emit_dynamic_schema_field_access, emit_aggregate_field_access, emit_tuple_call_return_field_access, emit_generic_field_access) Also includes cargo fmt pass across existing submodules. Visibility changes in mod.rs: - Extracted methods: fn -> pub(crate) fn - Types: SchemaFieldLayout, ExpectedFixedByteSource, SchemaFieldValueSource, PreludeU64ValueSource, PreludeU64OperandSource, SourcePointer -> pub(crate) - Constants: CKB_SOURCE_INPUT, CKB_SOURCE_OUTPUT, CKB_CELL_FIELD_{CAPACITY,LOCK_HASH,TYPE_HASH}, RUNTIME_SCRATCH_BUFFER_SIZE, RUNTIME_EXPR_TEMP_SLOTS -> pub(crate) - Free function: fixed_byte_const_bytes -> pub(crate) File sizes: - mod.rs: 8,671 -> 7,168 lines (1,503 removed) - schema.rs: 1,525 lines (new) - assembler/runtime/abi/collections: fmt-only changes All green: cargo check 0 warnings, 686/686 tests, clippy clean, 5/5 assembly snapshots unchanged.
1 parent da59d95 commit 2861ef7

6 files changed

Lines changed: 1616 additions & 1580 deletions

File tree

‎src/codegen/abi.rs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::ir::*;
1313
use crate::ENTRY_WITNESS_ABI_MAGIC;
1414

1515
use super::{
16-
fixed_aggregate_pointer_param_width, fixed_byte_pointer_param_width, fixed_register_width,
17-
named_type_name, type_static_length, CellScriptRuntimeError, CodeGenerator,
16+
fixed_aggregate_pointer_param_width, fixed_byte_pointer_param_width, fixed_register_width, named_type_name, type_static_length,
17+
CellScriptRuntimeError, CodeGenerator,
1818
};
1919
pub(crate) const ENTRY_WITNESS_LABEL: &str = "_cellscript_entry";
2020
pub(crate) const ENTRY_WITNESS_MAGIC: &[u8; 8] = ENTRY_WITNESS_ABI_MAGIC;
@@ -89,7 +89,10 @@ pub(crate) fn call_param_abi_arg_count(param: &IrParam, needs_type_hash: bool) -
8989
}
9090
1
9191
}
92-
pub(crate) fn entry_witness_payload_layout(params: &[IrParam], runtime_bound_param_indices: &BTreeSet<usize>) -> Vec<EntryWitnessPayloadArg> {
92+
pub(crate) fn entry_witness_payload_layout(
93+
params: &[IrParam],
94+
runtime_bound_param_indices: &BTreeSet<usize>,
95+
) -> Vec<EntryWitnessPayloadArg> {
9396
params
9497
.iter()
9598
.enumerate()

‎src/codegen/assembler.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,13 @@ impl ParsedAssembly {
658658
})
659659
}
660660

661-
pub(crate) fn encode_section(&self, section: SectionKind, out: &mut Vec<u8>, layout: &SectionLayout, base_bias: usize) -> Result<()> {
661+
pub(crate) fn encode_section(
662+
&self,
663+
section: SectionKind,
664+
out: &mut Vec<u8>,
665+
layout: &SectionLayout,
666+
base_bias: usize,
667+
) -> Result<()> {
662668
let ops = match section {
663669
SectionKind::Text => &self.text_ops,
664670
SectionKind::Rodata => &self.rodata_ops,
@@ -1895,4 +1901,3 @@ fn pad_to_alignment(out: &mut Vec<u8>, align: usize) {
18951901
let pad = padding_for(out.len(), align);
18961902
out.resize(out.len() + pad, 0);
18971903
}
1898-

‎src/codegen/collections.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use crate::error::Result;
88
use crate::ir::*;
99

1010
use super::{
11-
const_usize_operand, fixed_scalar_operand_width, fixed_scalar_width,
12-
molecule_vector_element_fixed_width, operand_fixed_byte_width, type_static_length,
13-
CellScriptRuntimeError, CodeGenerator, RUNTIME_COLLECTION_BUFFER_SIZE, RUNTIME_EXPR_TEMP_SLOTS,
11+
const_usize_operand, fixed_scalar_operand_width, fixed_scalar_width, molecule_vector_element_fixed_width,
12+
operand_fixed_byte_width, type_static_length, CellScriptRuntimeError, CodeGenerator, RUNTIME_COLLECTION_BUFFER_SIZE,
13+
RUNTIME_EXPR_TEMP_SLOTS,
1414
};
1515

1616
impl CodeGenerator {

0 commit comments

Comments
 (0)