Skip to content

Commit e469502

Browse files
committed
Add gather context operator
1 parent fc976ed commit e469502

File tree

6 files changed

+89
-1
lines changed

6 files changed

+89
-1
lines changed

packages/format/src/types/program/context.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ testSchemaGuards("ethdebug/format/program/context", [
2222
schema: "schema:ethdebug/format/program/context/pick",
2323
guard: Context.isPick
2424
},
25+
{
26+
schema: "schema:ethdebug/format/program/context/gather",
27+
guard: Context.isGather
28+
},
2529
{
2630
schema: "schema:ethdebug/format/program/context/frame",
2731
guard: Context.isFrame

packages/format/src/types/program/context.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type Context =
77
| Context.Variables
88
| Context.Remark
99
| Context.Pick
10+
| Context.Gather
1011
| Context.Frame;
1112

1213
export const isContext = (value: unknown): value is Context => [
@@ -15,6 +16,7 @@ export const isContext = (value: unknown): value is Context => [
1516
Context.isRemark,
1617
Context.isPick,
1718
Context.isFrame,
19+
Context.isGather,
1820
].some(guard => guard(value));
1921

2022
export namespace Context {
@@ -90,6 +92,15 @@ export namespace Context {
9092
"pick" in value && value.pick instanceof Array &&
9193
value.pick.every(isContext);
9294

95+
export interface Gather {
96+
gather: Context[];
97+
}
98+
99+
export const isGather = (value: unknown): value is Pick =>
100+
typeof value === "object" && !!value &&
101+
"gather" in value && value.gather instanceof Array &&
102+
value.gather.every(isContext);
103+
93104
export interface Frame {
94105
frame: string;
95106
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
sidebar_position: 7
3+
---
4+
5+
import SchemaViewer from "@site/src/components/SchemaViewer";
6+
7+
# Gather multiple contexts
8+
9+
<SchemaViewer
10+
schema={{ id: "schema:ethdebug/format/program/context/gather" }}
11+
/>

packages/web/src/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ const programSchemaIndex: SchemaIndex = {
215215
},
216216

217217
...(
218-
["code", "variables", "remark", "pick", "frame"].map(name => ({
218+
["code", "variables", "remark", "pick", "gather", "frame"].map(name => ({
219219
[`schema:ethdebug/format/program/context/${name}`]: {
220220
href: `/spec/program/context/${name}`
221221
}

schemas/program/context.schema.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ allOf:
3838
required: ["pick"]
3939
then:
4040
$ref: "schema:ethdebug/format/program/context/pick"
41+
- if:
42+
required: ["gather"]
43+
then:
44+
$ref: "schema:ethdebug/format/program/context/gather"
4145
- if:
4246
required: ["frame"]
4347
then:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
$schema: "https://json-schema.org/draft/2020-12/schema"
2+
$id: "schema:ethdebug/format/program/context/gather"
3+
4+
title: ethdebug/format/program/context/gather
5+
description: |
6+
A context specifying the `"gather"` property with a list of contexts
7+
indicates that all specified contexts apply simultaneously.
8+
9+
type: object
10+
properties:
11+
gather:
12+
title: Contexts to gather
13+
type: array
14+
items:
15+
$ref: "schema:ethdebug/format/program/context"
16+
minItems: 2
17+
additionalItems: false
18+
required:
19+
- gather
20+
21+
examples:
22+
- gather:
23+
- frame: "ir"
24+
code:
25+
source:
26+
id: 0
27+
range:
28+
offset: 8
29+
length: 11
30+
- frame: "source"
31+
code:
32+
source:
33+
id: 3
34+
range:
35+
offset: 113
36+
length: 19
37+
- gather:
38+
- variables:
39+
- identifier: x
40+
declaration:
41+
source:
42+
id: 5
43+
range:
44+
offset: 10
45+
length: 56
46+
type:
47+
kind: string
48+
- variables:
49+
- identifier: x
50+
declaration:
51+
source:
52+
id: 5
53+
range:
54+
offset: 10
55+
length: 56
56+
pointer:
57+
location: storage
58+
slot: 0

0 commit comments

Comments
 (0)