Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# rain.sol.codegen

Solidity native tooling to generate Solidity code.

Notably builds a valid Solidity file (pragma, etc.) that passes foundry
formatting cleanly, that can build the constant caches needed for prebuilt
function pointer tables to ensure runtime gas efficiency.

Includes interfaces for the interpreter and sub parsers/externs for Rain
contracts to implement and be compatible with the code generation functions here.
Comment on lines +9 to +10
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Hyphenate compound modifier “sub-parsers”.

Use “sub-parsers” as a compound adjective for correctness and consistency.

✏️ Proposed fix
-Includes interfaces for the interpreter and sub parsers/externs for Rain
+Includes interfaces for the interpreter and sub-parsers/externs for Rain
🧰 Tools
🪛 LanguageTool

[grammar] ~9-~9: Use a hyphen to join words.
Context: ...s interfaces for the interpreter and sub parsers/externs for Rain contracts to im...

(QB_NEW_EN_HYPHEN)

🤖 Prompt for AI Agents
In `@README.md` around lines 9 - 10, Update the README sentence to hyphenate the
compound adjective by changing "sub parsers/externs" to "sub-parsers/externs"
(the phrase appearing in the line describing interfaces for the interpreter and
sub-parsers/externs for Rain contracts) so the compound modifier is consistently
and correctly presented.


`script/BuildPointers.sol` includes an example implementation and
`.github/workflows/git-clean.yaml` an example CI action to show how to build
pointers cleanly and ensure that the source code does not become out of sync with
the built artifacts when merging new code.

Generated code is intended to be imported downstream into contracts that may
themselves expose pointers to be included in the generated code. This circular
dependency means the pointers may need to be built several times until they
produce a stable output where the pointers do not move, and therefore do not
break the codehash over the contract that includes the pointers.
59 changes: 38 additions & 21 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions foundry.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"lib/forge-std": {
"rev": "b8f065fda83b8cd94a6b2fec8fcd911dc3b444fd"
"rev": "1801b0541f4fda118a10798fd3486bb7051c5dd6"
},
"lib/rain.math.binary": {
"rev": "f44f846a43928ba0a7ed4a7bb810a8933e23cce1"
"rev": "122a490bb1869c7533f108cb8b371d75de9db60f"
}
}
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 57 files
+14 −31 .github/workflows/ci.yml
+1 −1 .github/workflows/sync.yml
+2 −2 CONTRIBUTING.md
+11 −9 README.md
+3 −12 foundry.toml
+2 −2 package.json
+2 −12 scripts/vm.py
+2 −2 src/Base.sol
+1 −1 src/Config.sol
+2 −2 src/LibVariable.sol
+2 −2 src/Script.sol
+28 −13 src/StdAssertions.sol
+8 −5 src/StdChains.sol
+9 −13 src/StdCheats.sol
+24 −4 src/StdConfig.sol
+2 −2 src/StdConstants.sol
+2 −2 src/StdError.sol
+2 −4 src/StdInvariant.sol
+4 −12 src/StdJson.sol
+2 −2 src/StdMath.sol
+11 −9 src/StdStorage.sol
+2 −2 src/StdStyle.sol
+4 −12 src/StdToml.sol
+5 −13 src/StdUtils.sol
+2 −4 src/Test.sol
+26 −41 src/Vm.sol
+10 −19 src/console.sol
+2 −2 src/console2.sol
+2 −2 src/interfaces/IERC1155.sol
+2 −2 src/interfaces/IERC165.sol
+2 −2 src/interfaces/IERC20.sol
+2 −2 src/interfaces/IERC4626.sol
+2 −2 src/interfaces/IERC6909.sol
+2 −2 src/interfaces/IERC721.sol
+4 −10 src/interfaces/IERC7540.sol
+2 −2 src/interfaces/IERC7575.sol
+3 −8 src/interfaces/IMulticall3.sol
+691 −1,380 src/safeconsole.sol
+2 −2 test/CommonBase.t.sol
+34 −5 test/Config.t.sol
+19 −1 test/LibVariable.t.sol
+2 −2 test/StdAssertions.t.sol
+24 −24 test/StdChains.t.sol
+19 −20 test/StdCheats.t.sol
+2 −2 test/StdConstants.t.sol
+3 −4 test/StdError.t.sol
+2 −2 test/StdJson.t.sol
+6 −6 test/StdMath.t.sol
+24 −27 test/StdStorage.t.sol
+2 −2 test/StdStyle.t.sol
+2 −2 test/StdToml.t.sol
+13 −13 test/StdUtils.t.sol
+3 −3 test/Vm.t.sol
+2 −4 test/compilation/CompilationScript.sol
+2 −4 test/compilation/CompilationScriptBase.sol
+2 −4 test/compilation/CompilationTest.sol
+2 −4 test/compilation/CompilationTestBase.sol
20 changes: 14 additions & 6 deletions script/BuildPointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import {LibFs} from "../src/lib/LibFs.sol";
import {LibCodeGen} from "../src/lib/LibCodeGen.sol";
import {CodeGennable} from "../test/concrete/CodeGennable.sol";

/// @title BuildPointers
/// @notice Script to build the pointers file for the CodeGennable contract.
/// @dev This shows an example of how to use the bytes constant generation
/// utility in LibCodeGen.
contract BuildPointers is Script {
/// Builds the pointers file for the CodeGennable contract to show an example
/// of how to use the bytes constant generation utility.
function run() external {
CodeGennable codeGennable = new CodeGennable();

Expand All @@ -16,13 +22,15 @@ contract BuildPointers is Script {
address(codeGennable),
"CodeGennable",
string.concat(
LibCodeGen.bytesConstantString(vm, "/// @dev Some bytes comment.", "SOME_BYTES_CONSTANT", hex"12345678"),
LibCodeGen.bytesConstantString(
vm,
"/// @dev Longer constant.",
"LONGER_BYTES_CONSTANT",
hex"e2bafcba65b2c99d33f5096307bc57c2e7f195d2a178f56e45d720bb64344998e2bafcba65b2c99d33f5096307bc57c2e7f195d2a178f56e45d720bb64344998"
)
vm, "/// @dev Some bytes comment.", "SOME_BYTES_CONSTANT", hex"12345678"
),
LibCodeGen.bytesConstantString(
vm,
"/// @dev Longer constant.",
"LONGER_BYTES_CONSTANT",
hex"e2bafcba65b2c99d33f5096307bc57c2e7f195d2a178f56e45d720bb64344998e2bafcba65b2c99d33f5096307bc57c2e7f195d2a178f56e45d720bb64344998"
)
)
);
}
Expand Down
13 changes: 13 additions & 0 deletions src/interface/IIntegrityToolingV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

/// @title IIntegrityToolingV1
/// Implemented by any contract that exposes integrity check functions for the
/// Rain interpreter. Ostensibly this is for the interpreter itself and also
/// extension points such as externs. These integrity checks are for the opcodes
/// tooled by IOpcodeToolingV1 implementations.
interface IIntegrityToolingV1 {
/// Builds integrity function pointers.
/// This is intended for use by the Rain interpreter to run integrity checks
/// over rainlang code before it is used/deployed/executed. The expectation
/// is that the pointers will be built ahead of time and cached in a constant
/// for efficiency. As the process is deterministic for a given source and
/// compiler configuration, the output can be tested against the used value
/// in CI and the translation from source to pointers can also be tested in
/// CI. See .github/workflows/git-clean.yaml for an example of such a test.
function buildIntegrityFunctionPointers() external view returns (bytes memory);
}
12 changes: 12 additions & 0 deletions src/interface/IOpcodeToolingV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

/// @title IOpcodeToolingV1
/// Implemented by any contract that exposes opcode functions (new words) for the
/// Rain interpreter. Ostensibly this is for the interpreter itself and also
/// extension points such as externs.
interface IOpcodeToolingV1 {
/// Builds opcode function pointers.
/// This is intended for use by the Rain interpreter to run opcodes
/// implementing rainlang execution logic. The expectation is that the
/// pointers will be built ahead of time and cached in a constant for
/// efficiency. As the process is deterministic for a given source and
/// compiler configuration, the output can be tested against the used value
/// in CI and the translation from source to pointers can also be tested in
/// CI. See .github/workflows/git-clean.yaml for an example of such a test.
function buildOpcodeFunctionPointers() external view returns (bytes memory);
}
20 changes: 20 additions & 0 deletions src/interface/IParserToolingV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

/// @title IParserToolingV1
/// Implemented by any contract that exposes parser tooling functions for the
/// Rain interpreter. Ostensibly this is for the interpreter itself while sub
/// parsers have a separate interface.
interface IParserToolingV1 {
/// Builds operand handler function pointers.
/// This is intended for use by the Rain interpreter to run operand handling
/// logic when parsing rainlang code. The expectation is that the pointers
/// will be built ahead of time and cached in a constant for efficiency. As
/// the process is deterministic for a given source and compiler
/// configuration, the output can be tested against the used value in CI and
/// the translation from source to pointers can also be tested in CI. See
/// .github/workflows/git-clean.yaml for an example of such a test.
function buildOperandHandlerFunctionPointers() external pure returns (bytes memory);

/// Builds literal parser function pointers.
/// This is intended for use by the Rain interpreter to run literal parsing
/// logic when parsing rainlang code. The expectation is that the pointers
/// will be built ahead of time and cached in a constant for efficiency. As
/// the process is deterministic for a given source and compiler
/// configuration, the output can be tested against the used value in CI and
/// the translation from source to pointers can also be tested in CI. See
/// .github/workflows/git-clean.yaml for an example of such a test.
function buildLiteralParserFunctionPointers() external pure returns (bytes memory);
}
11 changes: 11 additions & 0 deletions src/interface/ISubParserToolingV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

/// @title ISubParserToolingV1
/// Implemented by any contract that exposes sub parser tooling functions for the
/// Rain interpreter.
interface ISubParserToolingV1 {
/// Builds sub parser word parsers.
/// This is intended for use by the Rain interpreter to run sub parser word
/// parsing logic when parsing rainlang code. The expectation is that the
/// parsers will be built ahead of time and cached in a constant for
/// efficiency. As the process is deterministic for a given source and
/// compiler configuration, the output can be tested against the used value
/// in CI and the translation from source to parsers can also be tested in
/// CI. See .github/workflows/git-clean.yaml for an example of such a test.
function buildSubParserWordParsers() external pure returns (bytes memory);
}
Loading