Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Fib using array + panic + some u32 #63

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
fix(core): add debug info for u32
  • Loading branch information
0xLucqs committed Mar 6, 2023
commit 737af575a81f061597a5515684ac9858dea05fed
1 change: 0 additions & 1 deletion core/src/sierra/process/types.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ impl<'a, 'ctx> Compiler<'a, 'ctx> {
self.debug.next_line();
// All those types are known in advance. A struct is a combination of multiple "primitive" types
let type_name = type_declaration.long_id.generic_id.0.as_str();
println!("{:}", type_declaration);
match type_name {
// Regular felt
"felt" => self.felt(type_declaration),
12 changes: 9 additions & 3 deletions core/src/sierra/types/array.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ impl<'a, 'ctx> Compiler<'a, 'ctx> {
let val_type = self.types_by_id.get(id).unwrap().into_int_type();
// Get the arrya value type name.
let debug_name = debug_name.clone().expect(DEBUG_NAME_EXPECTED).to_string();
let array_debug_name = format!("Array<{:#}>", debug_name);
// Array capacity and len are felts for now. The reason for that is that there is no specific
// reason.
let felt_type = *self.types_by_name.get("felt").unwrap();
@@ -22,13 +23,18 @@ impl<'a, 'ctx> Compiler<'a, 'ctx> {
// Create debug type for the array pointer.
let ptr_debug = self.debug.create_type(9090909009, "arr_ptr", 64);
// Save Array<T> in the types map.
self.types_by_name.insert(format!("Array<{:#}>", debug_name), ty.as_basic_type_enum());
self.types_by_name.insert(array_debug_name.clone(), ty.as_basic_type_enum());
// Save the type by its id.
self.types_by_id.insert(*id, ty.as_basic_type_enum());
self.types_by_id.insert(type_declaration.id.id, ty.as_basic_type_enum());
// Get the felt debug type.
let felt_debug = *self.debug.types_by_name.get("felt").unwrap();
// Create debug struct type for array.
self.debug.create_struct(*id, debug_name.as_str(), &ty, &[ptr_debug, felt_debug, felt_debug])
self.debug.create_struct(
type_declaration.id.id,
&array_debug_name,
&ty,
&[ptr_debug, felt_debug, felt_debug],
)
}
GenericArg::UserType(_) => todo!(),
_ => {
5 changes: 2 additions & 3 deletions core/src/sierra/types/sierra_struct.rs
Original file line number Diff line number Diff line change
@@ -16,15 +16,14 @@ impl<'a, 'ctx> Compiler<'a, 'ctx> {

for generic_arg in type_declaration.long_id.generic_args.iter() {
match generic_arg {
GenericArg::Type(ConcreteTypeId { id, debug_name }) => {
GenericArg::Type(ConcreteTypeId { id, debug_name: _debug_name }) => {
args.push(
self.types_by_id
.get(id)
.expect("Type should have been defined before struct")
.as_basic_type_enum(),
);
println!("struct {id:?}, {debug_name:?}, \n {:?}", self.types_by_name);
debug_args.push(*self.debug.types_by_name.get(&debug_name.clone().unwrap().to_string()).unwrap());
debug_args.push(*self.debug.types_by_id.get(id).unwrap());
}
// Ignore the user type as it is not a struct field.
GenericArg::UserType(_) => continue,
1 change: 1 addition & 0 deletions core/src/sierra/types/sierra_u32.rs
Original file line number Diff line number Diff line change
@@ -8,5 +8,6 @@ impl<'a, 'ctx> Compiler<'a, 'ctx> {
let ty = self.context.custom_width_int_type(32).as_basic_type_enum();
self.types_by_name.insert("u32".to_owned(), ty);
self.types_by_id.insert(type_declaration.id.id, ty);
self.debug.create_type(type_declaration.id.id, "u32", 32);
}
}