Skip to content

Commit

Permalink
Remove internal flag, integrate internal vars into subslice operand
Browse files Browse the repository at this point in the history
  • Loading branch information
hacker-volodya committed Feb 26, 2024
1 parent e0f7a0c commit 726a5b4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 156 deletions.
46 changes: 14 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ However, nothing can stop you from just copying `cp0.json` (and `schema.json` if
| bytecode.operands[i].name | Operand variable name. Allowed chars are `a-zA-Z0-9_`, must not begin with digit or underscore and must not end with underscore. Required.
| bytecode.operands[i].loader | Loader function for operand. Must be one of `int`, `uint`, `ref`, `pushint_long`, `subslice`. Loaders are described below. Required.
| bytecode.operands[i].loader_args | Arguments for loader function, specified below. Optional, no arguments in case of absence.
| bytecode.operands[i].internal | Internal flag. If true, this operand is used as a subslice length variable, should be used only for serialization/deserialization, humans and implementations do not need them. Optional, default is false.
| value_flow | Information related to usage of stack and registers by instruction. Optional.
| value_flow.doc_stack | Free-form description of stack inputs and outputs. Usually the form is `[inputs] - [outputs]` where `[inputs]` are consumed stack values and `outputs` are produced stack values (top of stack is the last value). Optional.
| value_flow.inputs | Incoming values constraints. Input is unconstrained if absent.
Expand Down Expand Up @@ -207,44 +206,27 @@ Loads a single reference from bytecode. Unlike `subslice` with `refs_add = 1`, s
Special loader which currently is used only in `PUSHINT_LONG` instruction. Loads 5-bit uint `size` and then loads and returns integer of bit size `8 * size + 19`. No arguments are required.
#### subslice
```json
[
{
"name": "r",
"loader": "uint",
"loader_args": {
"size": 2
},
"internal": true
},
{
"name": "x",
"loader": "uint",
"loader_args": {
"size": 5
},
"internal": true
},
{
"name": "slice",
"loader": "subslice",
"loader_args": {
"bits_length_var": "x",
"bits_padding": 1,
"refs_length_var": "r",
"refs_add": 1,
"completion_tag": true
}
{
"name": "slice",
"loader": "subslice",
"loader_args": {
"bits_length_var_size": 5,
"bits_padding": 1,
"refs_length_var_size": 2,
"refs_add": 1,
"completion_tag": true
}
]
}
```
_TLB notation: `r:(## 2) xx:(## 5) c:((r + 1) * ^Cell) ssss:((8 * xx + 1) * Bit)`_

Loads subslice of bit length `{bits_length_var} * 8 + bits_padding` and ref count `{refs_length_var} + refs_add`. If `completion_tag` argument with value `true` is passed, remove completion tag from bitstring (trailing `'1' + '0' * x`). Length variables are usually `"internal": true` because they should not be showed to user or provided to an implementation.
Loads `r` uint of size `refs_length_var_size` (if present), `x` uint of size `bits_length_var_size` (if present). Then loads subslice of bit length `x * 8 + bits_padding` and ref count `r + refs_add`. If `completion_tag` argument with value `true` is passed, remove completion tag from bitstring (trailing `'1' + '0' * x`).

| Argument | Description
| -------- | -----------
| bits_length_var | Name of (previously parsed) operand which contains bit length to load. Optional, assuming this part of bit length is 0 if absent.
| bits_length_var_size | Size of bit length operand. Optional, assuming this part of bit length is 0 if absent.
| bits_padding | Constant integer value to add to length of bitstring to load. Optional, assuming 0 if absent.
| refs_length_var | Name of (previously parsed) operand which contains ref count to load. Optional, assuming this part of ref count is 0 if absent.
| refs_length_var_size | Size of ref count operand. Optional, assuming this part of ref count is 0 if absent.
| refs_add | Constant integer value to add to ref count. Optional, assuming 1 if absent.
| completion_tag | Boolean flag, tells to remove trailing `'1' + '0' * x` from bitstring if true. Optional, assuming false if absent.

Expand Down
132 changes: 14 additions & 118 deletions cp0.json
Original file line number Diff line number Diff line change
Expand Up @@ -3300,19 +3300,11 @@
"tlb": "#8B x:(## 4) sss:((8 * x + 4) * Bit)",
"prefix": "8B",
"operands": [
{
"name": "x",
"loader": "uint",
"loader_args": {
"size": 4
},
"internal": true
},
{
"name": "s",
"loader": "subslice",
"loader_args": {
"bits_length_var": "x",
"bits_length_var_size": 4,
"bits_padding": 4,
"completion_tag": true
}
Expand Down Expand Up @@ -3348,29 +3340,13 @@
"tlb": "#8C r:(## 2) xx:(## 5) c:((r + 1) * ^Cell) ssss:((8 * xx + 1) * Bit)",
"prefix": "8C",
"operands": [
{
"name": "r",
"loader": "uint",
"loader_args": {
"size": 2
},
"internal": true
},
{
"name": "x",
"loader": "uint",
"loader_args": {
"size": 5
},
"internal": true
},
{
"name": "slice",
"loader": "subslice",
"loader_args": {
"bits_length_var": "x",
"bits_length_var_size": 5,
"bits_padding": 1,
"refs_length_var": "r",
"refs_length_var_size": 2,
"refs_add": 1,
"completion_tag": true
}
Expand Down Expand Up @@ -3421,29 +3397,13 @@
"to": 4
},
"operands": [
{
"name": "r",
"loader": "uint",
"loader_args": {
"size": 3
},
"internal": true
},
{
"name": "x",
"loader": "uint",
"loader_args": {
"size": 7
},
"internal": true
},
{
"name": "slice",
"loader": "subslice",
"loader_args": {
"bits_length_var": "x",
"bits_length_var_size": 7,
"bits_padding": 6,
"refs_length_var": "r",
"refs_length_var_size": 3,
"completion_tag": true
}
}
Expand Down Expand Up @@ -3478,29 +3438,13 @@
"tlb": "#8F_ r:(## 2) xx:(## 7) c:(r * ^Cell) ssss:((8 * xx) * Bit)",
"prefix": "8F_",
"operands": [
{
"name": "r",
"loader": "uint",
"loader_args": {
"size": 2
},
"internal": true
},
{
"name": "x",
"loader": "uint",
"loader_args": {
"size": 7
},
"internal": true
},
{
"name": "s",
"loader": "subslice",
"loader_args": {
"bits_length_var": "x",
"bits_length_var_size": 7,
"bits_padding": 0,
"refs_length_var": "r"
"refs_length_var_size": 2
}
}
]
Expand Down Expand Up @@ -3540,19 +3484,11 @@
"tlb": "#9 x:(## 4) ssss:((8 * x) * Bit)",
"prefix": "9",
"operands": [
{
"name": "x",
"loader": "uint",
"loader_args": {
"size": 4
},
"internal": true
},
{
"name": "s",
"loader": "subslice",
"loader_args": {
"bits_length_var": "x",
"bits_length_var_size": 4,
"bits_padding": 0
}
}
Expand Down Expand Up @@ -19077,28 +19013,12 @@
"prefix": "CFC0_",
"operands": [
{
"name": "x",
"loader": "uint",
"loader_args": {
"size": 2
},
"internal": true
},
{
"name": "y",
"loader": "uint",
"loader_args": {
"size": 3
},
"internal": true
},
{
"name": "sss",
"name": "s",
"loader": "subslice",
"loader_args": {
"bits_length_var": "y",
"bits_length_var_size": 3,
"bits_padding": 2,
"refs_length_var": "x",
"refs_length_var_size": 2,
"completion_tag": true
}
}
Expand Down Expand Up @@ -21157,19 +21077,11 @@
"tlb": "#D72A_ x:(## 7) sss:((8 * x + 3) * Bit)",
"prefix": "D72A_",
"operands": [
{
"name": "x",
"loader": "uint",
"loader_args": {
"size": 7
},
"internal": true
},
{
"name": "s",
"loader": "subslice",
"loader_args": {
"bits_length_var": "x",
"bits_length_var_size": 7,
"bits_padding": 3,
"completion_tag": true
}
Expand Down Expand Up @@ -21211,19 +21123,11 @@
"tlb": "#D72E_ x:(## 7) sss:((8 * x + 3) * Bit)",
"prefix": "D72E_",
"operands": [
{
"name": "x",
"loader": "uint",
"loader_args": {
"size": 7
},
"internal": true
},
{
"name": "s",
"loader": "subslice",
"loader_args": {
"bits_length_var": "x",
"bits_length_var_size": 7,
"bits_padding": 3,
"completion_tag": true
}
Expand Down Expand Up @@ -43109,19 +43013,11 @@
"tlb": "#FEF n:(## 4) ssss:((n * 8 + 8) * Bit)",
"prefix": "FEF",
"operands": [
{
"name": "n",
"loader": "uint",
"loader_args": {
"size": 4
},
"internal": true
},
{
"name": "s",
"loader": "subslice",
"loader_args": {
"bits_length_var": "n",
"bits_length_var_size": 4,
"bits_padding": 8
}
}
Expand Down
6 changes: 0 additions & 6 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,6 @@
"type": "object",
"title": "Arguments for loader function. Optional, no arguments in case of absence.",
"default": {}
},
"internal": {
"type": "boolean",
"title": "Internal flag",
"description": "If true, this operand is used as a subslice length variable, should be used only for serialization/deserialization, humans and implementations do not need them.",
"default": false
}
},
"required": [
Expand Down

0 comments on commit 726a5b4

Please sign in to comment.