Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Improve table docs section #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/get-started/huff-by-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this works as intended- maybe something like this?

#define macro MAIN() = {
    __tablesize(CODE_TABLE)  // [table_size]
    __tablestart(CODE_TABLE) // [table_start, table_size]
    returndatasize           // [0x00, table_start, table_size]
    codecopy                 // []
    msize returndatasize     // [0x00, 0x20]
    return                   // []
}

Also wondering if we should use tricks like returndatasize here- idea is to have easily readable (er, as easily readible as we can manage) code here.

Copy link
Author

@Philogy Philogy Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my bad, replace mstore with codecopy in my example and it'll work (compiled and tested this time), your example would pad the return with 0-bytes but it works too.

When it comes to tricks like returndatasize I feel like they should at least be in the docs somewhere but I agree that this might not be the best place. My thought was that if someone sees that and actually thinks to question it they'll learn as they research / ask about it.

```