-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
711dc99
commit 8ef7271
Showing
5 changed files
with
549 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const config = @import("config"); | ||
const Instruction = @import("definition.zig").Instruction; | ||
|
||
pub const enabled = config.enable_metering; | ||
|
||
pub const Meter = if (enabled) usize else void; | ||
|
||
pub const initial_meter = if (enabled) 0 else {}; | ||
|
||
pub const MeteringTrapError = if (enabled) error{TrapMeterExceeded} else error{}; | ||
|
||
pub fn reduce(fuel: Meter, instruction: Instruction) Meter { | ||
if (fuel == 0) { | ||
return fuel; | ||
} | ||
return switch (instruction.opcode) { | ||
.Invalid, .Unreachable, .DebugTrap, .Noop, .Block, .Loop, .If, .IfNoElse, .Else, .End, .Branch, .Branch_If, .Branch_Table, .Drop => fuel, | ||
else => fuel - 1, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.