From a530c8c1e943e08263b5fd77f9c9e738343b59fa Mon Sep 17 00:00:00 2001 From: Philippe Dumonet Date: Tue, 9 Aug 2022 23:42:41 +0200 Subject: [PATCH] Improve table docs section Explain that `__tablestart` and `__tablesize` also work for code tables. Furthermore expand the code table example to make its usage in the context clearer --- src/get-started/huff-by-example/README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/get-started/huff-by-example/README.md b/src/get-started/huff-by-example/README.md index 94b3f5b..28e5ba6 100644 --- a/src/get-started/huff-by-example/README.md +++ b/src/get-started/huff-by-example/README.md @@ -412,7 +412,7 @@ packed jumptables are cheaper to copy into memory, but they are more expensive to pull a PC out of due to the bitshifting required. The opposite is true for Regular Jump Tables. -There are two builtin functions related to jumptables. +There are two builtin functions related to tables, they work on both jump and code tables. #### `__tablestart(TABLE)` Pushes the program counter (PC) of the start of the table passed to the stack. @@ -491,4 +491,15 @@ somewhere within the contract. #define table CODE_TABLE { 0x604260005260206000F3 } + +#define macro MAIN() = takes (0) returns (0) { + __tablesize(CODE_TABLE) // [size] + // copy table to memory + dup1 // [size, size] + __tablestart(CODE_TABLE) // [start, size, size] + returndatasize // [0, start, size, size] + mstore // [size] + returndatasize // [0, size] + return +} ```