-
Notifications
You must be signed in to change notification settings - Fork 9
/
Types.sol
75 lines (60 loc) · 1.83 KB
/
Types.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "./BokkyPooBahsRedBlackTreeLibrary.sol";
import "forge-std/console.sol";
bool constant DEBUG = true;
uint256 constant INS_SIZE = 32 * 6;
struct Instruction {
uint256 opcode;
uint256 p1;
uint256 p2;
uint256 p3;
uint256 p4;
uint256 p5;
}
struct Cursor {
uint256 tbl;
uint256 ptr;
}
struct ExecEngine {
uint256 pc;
uint256 opcode;
uint256 p1;
uint256 p2;
uint256 p3;
uint256 p4;
uint256 p5;
Cursor[4] cursors;
uint256[10] mem;
}
library SqliteExecutor {
using SqliteExecutor for ExecEngine;
using BokkyPooBahsRedBlackTreeLibrary for Tree;
function parseNext(ExecEngine memory e, bytes calldata bytecode) internal pure {
(e.opcode, e.p1, e.p2, e.p3, e.p4, e.p5) = abi.decode(
bytecode[e.pc * INS_SIZE:(e.pc + 1) * INS_SIZE],
(uint256, uint256, uint256, uint256, uint256, uint256)
);
}
// function _set_pc(ExecEngine memory e, uint256 e.pc) internal {
// e.e.pc = e.pc;
// }
function getCursor(ExecEngine memory e) internal pure returns (Cursor memory) {
// TODO: currently cursors are used as-is, but maybe
// sqlite does some memory ops and move it around,
// in which case accessing through mem will be necessary
return e.cursors[e.p1];
}
function tbl(ExecEngine memory e) internal pure returns (uint256) {
return e.cursors[e.p1].tbl;
}
function ptr(ExecEngine memory e) internal pure returns (uint256) {
return e.cursors[e.p1].ptr;
}
function ptr(ExecEngine memory e, uint256 val) internal pure {
e.cursors[e.p1].ptr = val;
}
// function _op_table(ExecEngine memory e, Tree storage table) internal view {
// // TODO: implement wrapper
// }
}