Skip to content
Open
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@
[submodule "vendor/grammars/hoon-grammar"]
path = vendor/grammars/hoon-grammar
url = https://github.com/pkova/hoon-grammar.git
[submodule "vendor/grammars/huff-ghlang"]
path = vendor/grammars/huff-ghlang
url = https://github.com/sambacha/huff-ghlang.git
[submodule "vendor/grammars/idl.tmbundle"]
path = vendor/grammars/idl.tmbundle
url = https://github.com/mgalloy/idl.tmbundle
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ vendor/grammars/holyc.tmbundle:
- source.hc
vendor/grammars/hoon-grammar:
- source.hoon
vendor/grammars/huff-ghlang:
- source.huff
vendor/grammars/idl.tmbundle:
- source.idl
- source.idl-dlm
Expand Down
15 changes: 12 additions & 3 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2638,8 +2638,8 @@ HOCON:
extensions:
- ".hocon"
filenames:
- .scalafix.conf
- .scalafmt.conf
- ".scalafix.conf"
- ".scalafmt.conf"
tm_scope: source.hocon
ace_mode: text
language_id: 679725279
Expand Down Expand Up @@ -2850,6 +2850,15 @@ Hosts File:
tm_scope: source.hosts
ace_mode: text
language_id: 231021894
Huff:
type: programming
color: "#707598"
extensions:
- ".hf"
- ".huff"
tm_scope: source.huff
ace_mode: text
language_id: 405540950
Hy:
type: programming
ace_mode: text
Expand Down Expand Up @@ -6819,7 +6828,7 @@ TI Program:
TL-Verilog:
type: programming
extensions:
- ".tlv"
- ".tlv"
tm_scope: source.tlverilog
ace_mode: verilog
color: "#C40023"
Expand Down
158 changes: 158 additions & 0 deletions samples/huff/errors.huff
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/// @title Errors
/// @notice SPDX-License-Identifier: MIT
/// @author jtriley.eth
/// @author clabby <https://github.com/clabby>
/// @notice Custom error utilities.

// https://docs.soliditylang.org/en/latest/control-structures.html?highlight=panic#panic-via-assert-and-error-via-require

// Errors
#define error Error(string)
#define error Panic(uint256)

// Constants
// Solidity Panic Codes
#define constant COMPILER_PANIC = 0x00
#define constant ASSERT_FALSE = 0x01
#define constant ARITHMETIC_OVERFLOW = 0x11
#define constant DIVIDE_BY_ZERO = 0x12
#define constant INVALID_ENUM_VALUE = 0x21
#define constant INVALID_STORAGE_BYTE_ARRAY = 0x22
#define constant EMPTY_ARRAY_POP = 0x31
#define constant ARRAY_OUT_OF_BOUNDS = 0x32
#define constant MEMORY_TOO_LARGE = 0x41
#define constant UNINITIALIZED_FUNCTION_POINTER = 0x51

/*

Solidity Require. Error `string` MUST be no greater than 32 bytes.

MEMORY LAYOUT WHEN THROWN
| sig || message offset || message length || message "revert" |
0x08c379a 0000000000000000000000000000000000000000000000000000000000000020 0000000000000000000000000000000000000000000000000000000000000006 7265766572740000000000000000000000000000000000000000000000000000

*/
#define macro REQUIRE() = takes (3) returns (0) {
// takes: // [condition, message_length, message]
do_not_throw // [do_not_throw_jumpdest, condition, message_length, message]
jumpi // [message_length, message]
__ERROR(Error) // [error_sig, , message_length, message]
0x00 // [mem_ptr, error_sig, message_length, message]
mstore // [message_length, message]
0x20 // [message_offset, message_length, message]
0x04 // [message_offset_ptr, message_offset, message_length, message]
mstore // [message_length, message]
0x24 // [message_length_ptr, message_length, message]
mstore // [message]
0x44 // [message_ptr, message]
mstore // []
0x80 // [size]
0x00 // [offset, size]
revert // []
do_not_throw: // [message_length, message]
pop // [message]
pop // []
}

/*

Solidity Panic.

MEMORY LAYOUT WHEN THROWN
| sig || panic code |
0x4e487b71 0000000000000000000000000000000000000000000000000000000000000001

*/
#define macro PANIC() = takes (1) returns (0) {
// takes: // [panic_code]
__ERROR(Panic) // [panic_sig, panic_code]
0x00 // [panic_sig_offset, panic_sig, panic_code]
mstore // [panic_code]
0x04 // [panic_code_offset, panic_code]
mstore // []
0x24 // [revert_size]
0x00 // [revert_offset, revert_size]
revert // []
}

/*
Solidity Assert.

MEMORY LAYOUT WHEN THROWN
| sig || assert failed panic code |
0x4e487b71 0000000000000000000000000000000000000000000000000000000000000001

*/
#define macro ASSERT() = takes (1) returns (0) {
// takes: // [condition]
do_not_panic // [do_not_panic_jumpdest, condition]
jumpi // []
[ASSERT_FALSE] // [assert_false]
PANIC() // []
do_not_panic: // []
}

// Assert that two stack elements are equal
#define macro ASSERT_EQ() = {
// takes: [a, b]
eq // [a == b]
ASSERT() // []
}

// Assert that two stack elements are not equal
#define macro ASSERT_NOT_EQ() = {
// takes: [a, b]
eq iszero // [a != b]
ASSERT() // []
}

// Assert that two memory offsets contain equal words
#define macro ASSERT_MEM_EQ(ptr_a, ptr_b) = {
// takes: []
<ptr_b> mload // [b]
<ptr_a> mload // [a, b]
eq // [a == b]
ASSERT() // []
}

// Assert that two memory offsets do not contain equal words
#define macro ASSERT_MEM_NOT_EQ(ptr_a, ptr_b) = {
// takes: []
<ptr_b> mload // [b]
<ptr_a> mload // [a, b]
eq iszero // [a != b]
ASSERT() // []
}

// Assert that two storage slots contain equal words
#define macro ASSERT_STORAGE_EQ(slot_a, slot_b) = {
// takes: []
<slot_b> sload // [b]
<slot_a> sload // [a, b]
eq // [a == b]
ASSERT() // []
}

// Assert that two storage slots do not contain equal words
#define macro ASSERT_STORAGE_NOT_EQ(slot_a, slot_b) = {
// takes: []
<slot_b> sload // [b]
<slot_a> sload // [a, b]
eq iszero // [a != b]
ASSERT() // []
}

/* Bubbles up revert data if call failed. Call directly after `call`, `staticcall`, `delegatecall`. */
#define macro BUBBLE_UP_IF_FAILED() = takes (1) returns (0) {
// takes: // [call_succeeded]
call_succeeded // [call_succeeded_jumpdest, call_succeeded]
jumpi // []
returndatasize // [returndatasize]
0x00 // [memory_offset, returndatasize]
returndatasize // [returndatasize, memory_offset, returndatasize]
dup2 // [returndata_offset, returndatasize, memory_offset, returndatasize]
dup3 // [memory_offset, returndata_offset, returndatasize, memory_offset, returndatasize]
returndatacopy // [memory_offset, returndatasize]
revert // []
call_succeeded:
}
1 change: 1 addition & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **HiveQL:** [adidonato/language-hql](https://github.com/adidonato/language-hql)
- **HolyC:** [codingdandy/holyc.tmbundle](https://github.com/codingdandy/holyc.tmbundle)
- **Hosts File:** [Alhadis/language-etc](https://github.com/Alhadis/language-etc)
- **Huff:** [sambacha/huff-ghlang](https://github.com/sambacha/huff-ghlang)
- **Hy:** [tshakalekholoane/vscode-hy](https://github.com/tshakalekholoane/vscode-hy)
- **IDL:** [mgalloy/idl.tmbundle](https://github.com/mgalloy/idl.tmbundle)
- **IGOR Pro:** [byte-physics/language-igor](https://github.com/byte-physics/language-igor)
Expand Down
1 change: 1 addition & 0 deletions vendor/grammars/huff-ghlang
Submodule huff-ghlang added at b56c9a
19 changes: 19 additions & 0 deletions vendor/licenses/git_submodule/huff-ghlang.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: huff-ghlang
version: b56c9ad8dd512fc4cf09c116c07d5cf14d95a3a4
type: git_submodule
homepage: https://github.com/sambacha/huff-ghlang.git
license: mit
licenses:
- sources: LICENSE.txt
text: |+
Copyright 2022 Huff-Language

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

notices: []
...