From 496be276316648fde9ecd9dc01ef13d8fdf6eba6 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Mon, 15 Apr 2024 07:40:18 +0200 Subject: [PATCH] gitignore fix --- cairo/.gitignore | 4 +++- cairo/lang/compiler/lib/__init__.py | 0 cairo/lang/compiler/lib/registers.cairo | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 cairo/lang/compiler/lib/__init__.py create mode 100644 cairo/lang/compiler/lib/registers.cairo diff --git a/cairo/.gitignore b/cairo/.gitignore index 6769e21..03d56cb 100644 --- a/cairo/.gitignore +++ b/cairo/.gitignore @@ -157,4 +157,6 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +#.idea/ + +!/lang/compiler/lib/ \ No newline at end of file diff --git a/cairo/lang/compiler/lib/__init__.py b/cairo/lang/compiler/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cairo/lang/compiler/lib/registers.cairo b/cairo/lang/compiler/lib/registers.cairo new file mode 100644 index 0000000..7f18f9d --- /dev/null +++ b/cairo/lang/compiler/lib/registers.cairo @@ -0,0 +1,18 @@ +// Returns the contents of the fp and pc registers of the calling function. +// The pc register's value is the address of the instruction that follows directly after the +// invocation of get_fp_and_pc(). +func get_fp_and_pc() -> (fp_val: felt*, pc_val: felt*) { + // The call instruction itself already places the old fp and the return pc at + // [ap - 2], [ap - 1]. + return (fp_val=cast([ap - 2], felt*), pc_val=cast([ap - 1], felt*)); +} + +// Returns the content of the ap register just before this function was invoked. +@known_ap_change +func get_ap() -> (ap_val: felt*) { + // Once get_ap() is invoked, fp points to ap + 2 (since the call instruction placed the old fp + // and pc in memory, advancing ap accordingly). + // Hence, the desired ap value is fp - 2. + let (fp_val, pc_val) = get_fp_and_pc(); + return (ap_val=fp_val - 2); +} \ No newline at end of file