NEWTON
Asked
1 year ago
42
views
0
I am going through the official Cairo language tutorial. When I get to the build_dict
function for the 15-puzzle, I am a bit confused so would like to print out some things to see.
struct Location:
member row : felt
member col : felt
end
...
func finalize_state(dict : DictAccess*, idx) -> (
dict : DictAccess*):
if idx == 0:
return (dict=dict)
end
assert dict.key = idx
assert dict.prev_value = idx - 1
assert dict.new_value = idx - 1
return finalize_state(
dict=dict + DictAccess.SIZE, idx=idx - 1)
end
##### I added the {} along with context in it for output #####
func main{output_ptr : felt*}():
alloc_locals
local loc_tuple : (Location, Location, Location, Location, Location) = (
Location(row=0, col=2),
Location(row=1, col=2),
Location(row=1, col=3),
Location(row=2, col=3),
Location(row=3, col=3),
)
# Get the value of the frame pointer register (fp) so that
# we can use the address of loc_tuple.
let (__fp__, _) = get_fp_and_pc()
# Since the tuple elements are next to each other we can use the
# address of loc_tuple as a pointer to the 5 locations.
verify_location_list(
loc_list=cast(&loc_tuple, Location*), n_steps=4)
##### Here is what I added #####
local locs : Location* = cast(&loc_tuple, Location*)
tempvar loc = [locs]
tempvar row = loc.row
serialize_word(row)
################################
return ()
end
I added the lines for printing the first row in loc_tuple
. However, the Cairo compiler is giving me the following errors:
Traceback (most recent call last):
File "/Users/yijiachen/cairo_venv/bin/cairo-compile", line 10, in <module>
sys.exit(main())
File "/Users/yijiachen/cairo_venv/lib/python3.8/site-packages/starkware/cairo/lang/compiler/cairo_compile.py", line 397, in main
cairo_compile_common(
File "/Users/yijiachen/cairo_venv/lib/python3.8/site-packages/starkware/cairo/lang/compiler/cairo_compile.py", line 121, in cairo_compile_common
assembled_program = assemble_func(
File "/Users/yijiachen/cairo_venv/lib/python3.8/site-packages/starkware/cairo/lang/compiler/cairo_compile.py", line 367, in
cairo_assemble_program
check_main_args(program)
File "/Users/yijiachen/cairo_venv/lib/python3.8/site-packages/starkware/cairo/lang/compiler/cairo_compile.py", line 296, in check_main_args
assert main_args == expected_builtin_ptrs, (
AssertionError: Expected main to contain the following arguments (in this order): []. Found: ['output_ptr'].
I have tried with various serialize_word
statements and none seem to work. This issue never arose before with other serialize_word
statements, including in earlier parts of the tutorial.
ㅤ This question was originally posted on Stack Overflow
0
Declare %builtins output
at the top of your code so that the compiler will know that you use an implicit argument (output_ptr) in your main function and expect it.
The Cairo compiler is able to process implicit arguments only if you declare that you are going to use them. See here.
ㅤ This answer was originally posted on Stack Overflow
answered
1 year ago
0
Declare %builtins output
at the top of your code so that the compiler will know that you use an implicit argument (output_ptr) in your main function and expect it.
The Cairo compiler is able to process implicit arguments only if you declare that you are going to use them. See here.
ㅤ This answer was originally posted on Stack Overflow
answered
5 months ago
How to use get_fp_and_pc in Cairo Lang?
Cairo Lang / StarkNet: What are Revoked references? What is alloc_locals?
How to install Cairo v0.10.0 on my device?
How to divide felt in Cairo Lang using unsigned_div_rem?
StarkNet error while deploying: IndexError: list assignment index out of range. Can anyone help?
What is the difference between tempvar/let in Cairo Lang? How to use allow_locals and local?
How to make recursive function in Cairo Lang?
How do I move my Pathfinder node to another server / disk?
How to make math operation with Field Elements (felts) in Cairo lang?
Which is this extension that shows you errors before compilation ser?
开始学习Cairo
signing a message using account.signMessage(data) | starknet.js
How to use Hints in Cairo Lang?
Error compiling Pathfinder (rust)