Skip to content

Commit

Permalink
Merge f3df004 into d102972
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed Jun 7, 2024
2 parents d102972 + f3df004 commit 8147e89
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 87 deletions.
25 changes: 15 additions & 10 deletions sway-core/src/semantic_analysis/ast_node/declaration/auto_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,18 +624,22 @@ where
};

let method_name = decl.name.as_str();
code.push_str(&format!("if _method_name == \"{method_name}\" {{"));

if args_types == "()" {
code.push_str(&format!("if _method_name == \"{method_name}\" {{
let result_{method_name}: raw_slice = encode::<{return_type}>(__contract_entry_{method_name}());
__contract_ret(result_{method_name}.ptr(), result_{method_name}.len::<u8>());
}}\n"));
if args_types != "()" {
code.push_str(&format!(
"let args: {args_types} = _buffer.decode::<{args_types}>();"
));
}

code.push_str(&format!(
"let _result: {return_type} = __contract_entry_{method_name}({expanded_args});\n"
));

if return_type == "()" {
code.push_str("__contract_ret(asm() { zero: raw_ptr }, 0);\n}\n");
} else {
code.push_str(&format!("if _method_name == \"{method_name}\" {{
let args: {args_types} = decode_second_param::<{args_types}>();
let result_{method_name}: raw_slice = encode::<{return_type}>(__contract_entry_{method_name}({expanded_args}));
__contract_ret(result_{method_name}.ptr(), result_{method_name}.len::<u8>());
}}\n"));
code.push_str("let _result = encode(_result); __contract_ret(_result.ptr(), _result.len::<u8>());\n}\n");
}
}

Expand Down Expand Up @@ -674,6 +678,7 @@ where

let code = format!(
"{att} pub fn __entry() {{
let mut _buffer = BufferReader::from_second_parameter();
let _method_name = decode_first_param::<str>();
{code}
{fallback}
Expand Down
2 changes: 1 addition & 1 deletion sway-lib-core/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ generate_tuple_encode() {
CODE="$CODE $element: AbiEncode, "
done

CODE="$CODE{ fn abi_encode(self, buffer: Buffer) -> Buffer { "
CODE="$CODE{ #[inline(always)] fn abi_encode(self, buffer: Buffer) -> Buffer { "

i=0
for element in ${elements[@]}
Expand Down
Loading

0 comments on commit 8147e89

Please sign in to comment.