Skip to content

Commit b9b8967

Browse files
committed
Define polymorphic value schema for numbers
1 parent b1a6130 commit b9b8967

File tree

7 files changed

+40
-16
lines changed

7 files changed

+40
-16
lines changed

packages/web/spec/data/overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ These schemas (like all schemas in this format) are specified as
2626
Please refer to the following resources in this section, or see the navigation
2727
bar for complete contents.
2828

29+
- [Non-negative numeric values](/spec/data/value)
2930
- [Hexadecimal strings](/spec/data/hex)
3031
- [Unsigned integer](/spec/data/unsigned)

packages/web/spec/data/value.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
import SchemaViewer from "@site/src/components/SchemaViewer";
6+
7+
# Non-negative numeric values
8+
9+
<SchemaViewer
10+
schema={{ id: "schema:ethdebug/format/data/value" }}
11+
/>

packages/web/src/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const pointerSchemaIndex: SchemaIndex = {
163163
})).reduce((a, b) => ({ ...a, ...b }), {}),
164164
};
165165

166-
const dataSchemaIndex: SchemaIndex = ["hex", "unsigned"].map(name => ({
166+
const dataSchemaIndex: SchemaIndex = ["value", "hex", "unsigned"].map(name => ({
167167
[`schema:ethdebug/format/data/${name}`]: {
168168
href: `/spec/data/${name}`
169169
}

schemas/data/value.schema.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$schema: "https://json-schema.org/draft/2020-12/schema"
2+
$id: "schema:ethdebug/format/data/value"
3+
4+
title: ethdebug/format/data/value
5+
description: |
6+
A non-negative integer value, expressed either as a native JSON number or as
7+
a `0x`-prefixed hexadecimal string.
8+
9+
oneOf:
10+
- description: A non-negative integer literal
11+
$ref: "schema:ethdebug/format/data/unsigned"
12+
13+
- description: |
14+
A `0x`-prefixed hexadecimal string representing literal bytes or a number
15+
commonly displayed in base 16 (e.g. bytecode instruction offsets).
16+
$ref: "schema:ethdebug/format/data/hex"
17+
18+
examples:
19+
- "0x0000"
20+
- 2

schemas/materials/source-range.schema.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ properties:
3535
offset:
3636
description: |
3737
Byte offset at beginning of range.
38-
$ref: "schema:ethdebug/format/data/unsigned"
38+
$ref: "schema:ethdebug/format/data/value"
3939

4040
length:
4141
description: Number of bytes contained in range
42-
$ref: "schema:ethdebug/format/data/unsigned"
42+
$ref: "schema:ethdebug/format/data/value"
4343

4444
unevaluatedProperties: false
4545

schemas/pointer/expression.schema.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ $defs:
2121
description: |
2222
An unsigned number or a `0x`-prefixed string of hexadecimal digits
2323
24-
oneOf:
25-
- description: A non-negative integer literal
26-
$ref: "schema:ethdebug/format/data/unsigned"
27-
28-
- description: |
29-
A `0x`-prefixed hexadecimal string representing literal bytes
30-
$ref: "schema:ethdebug/format/data/hex"
24+
$ref: "schema:ethdebug/format/data/value"
3125

3226
examples:
3327
- 5

schemas/program/instruction.schema.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ properties:
1818
instruction's program counter. For EOF bytecode, this value **must** be
1919
the offset from the start of the container, not the start of a particular
2020
code section within that container.
21-
oneOf:
22-
- $ref: "schema:ethdebug/format/data/unsigned"
23-
- $ref: "schema:ethdebug/format/data/hex"
21+
$ref: "schema:ethdebug/format/data/value"
2422

2523
operation:
2624
title: Machine operation information
@@ -36,9 +34,9 @@ properties:
3634
minItems: 1
3735
items:
3836
description: |
39-
An immediate value, specified as a `0x`-prefixed hexadecimal string.
40-
type: string
41-
pattern: "^0x[0-9a-fA-F]{1,}$"
37+
An immediate value specified as argument to the opcode
38+
$ref: "schema:ethdebug/format/data/value"
39+
4240
required:
4341
- mnemonic
4442

0 commit comments

Comments
 (0)