Last active
August 26, 2022 20:26
-
-
Save rlkelly/706e6a85a6b00f4d3c5c1a9eddd76a13 to your computer and use it in GitHub Desktop.
Revisions
-
rlkelly revised this gist
Aug 26, 2022 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,8 +13,7 @@ func add_vals{output_ptr: felt*}(x, y) -> (output_len, sum : felt*): return (1, z) end func bunch_of_vals{output_ptr: felt*}(x, y) -> (output_len, output_arr : felt*): let (z: felt*) = alloc() assert z[0] = x @@ -25,13 +24,14 @@ func bunch_of_vals{output_ptr: felt*}(x, y) -> (output_len, sum : felt*): end func invoke_func{output_ptr: felt*}(func_ptr : codeoffset, foo_args_len : felt, foo_args : felt*) -> (arr_len, arr: felt*): let (func_pc) = get_label_location(func_ptr) invoke(func_pc, foo_args_len, foo_args) let (ap_val) = get_ap() let result_arr : felt* = cast([ap_val - 1], felt*) let result_arr_len = [ap_val - 2] return (result_arr_len, result_arr) end func main{output_ptr : felt*}(): @@ -42,9 +42,10 @@ func main{output_ptr : felt*}(): assert array[0] = 10 assert array[1] = 99 let (arr_len, res_arr) = invoke_func(bunch_of_vals, 2, array) serialize_word(res_arr[0]) serialize_word(res_arr[1]) serialize_word(res_arr[2]) return () end -
rlkelly revised this gist
Aug 26, 2022 . 1 changed file with 16 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,12 +13,24 @@ func add_vals{output_ptr: felt*}(x, y) -> (output_len, sum : felt*): return (1, z) end func bunch_of_vals{output_ptr: felt*}(x, y) -> (output_len, sum : felt*): let (z: felt*) = alloc() assert z[0] = x assert z[1] = y assert z[2] = x + y return (3, z) end func invoke_func{output_ptr: felt*}(func_ptr : codeoffset, foo_args_len : felt, foo_args : felt*, output_len: felt) -> (arr_len, arr: felt*): let (func_pc) = get_label_location(func_ptr) invoke(func_pc, foo_args_len, foo_args) let (ap_val) = get_ap() let result_arr : felt* = cast([ap_val - 1], felt*) return (output_len, result_arr) end @@ -30,7 +42,9 @@ func main{output_ptr : felt*}(): assert array[0] = 10 assert array[1] = 99 let (arr_len, res_arr) = invoke_func(bunch_of_vals, 2, array, 3) serialize_word(res_arr[0]) serialize_word(res_arr[1]) serialize_word(res_arr[2]) return () end -
rlkelly created this gist
Aug 26, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ %builtins output from starkware.cairo.common.serialize import serialize_word from starkware.cairo.common.registers import get_ap from starkware.cairo.common.alloc import alloc from starkware.cairo.common.invoke import invoke from starkware.cairo.common.registers import get_label_location func add_vals{output_ptr: felt*}(x, y) -> (output_len, sum : felt*): let (z: felt*) = alloc() assert z[0] = x + y return (1, z) end func invoke_func{output_ptr: felt*}(func_ptr : codeoffset, foo_args_len : felt, foo_args : felt*, output_len: felt) -> (arr_len, arr: felt*): let (func_pc) = get_label_location(func_ptr) invoke(func_pc, foo_args_len, foo_args) let (ap_val) = get_ap() let result_arr : felt* = cast([ap_val - output_len], felt*) return (output_len, result_arr) end func main{output_ptr : felt*}(): alloc_locals let (local array : felt*) = alloc() assert array[0] = 10 assert array[1] = 99 let (arr_len, res_arr) = invoke_func(add_vals, 2, array, 1) serialize_word(res_arr[0]) return () end