-
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.
Merge pull request #95 from ethdebug/cleanup-docs
Organize pointers implementation guide a bit
- Loading branch information
Showing
14 changed files
with
236 additions
and
201 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
packages/web/docs/implementation-guides/implementation-guides.mdx
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,57 @@ | ||
--- | ||
sidebar_position: 4 | ||
pagination_prev: null | ||
pagination_next: null | ||
--- | ||
|
||
# Implementation guides | ||
|
||
This section of these docs serves to provide resources that guide readers who | ||
are looking to implement one or more components of **ethdebug/format**. | ||
Because of the distinct concerns involved in implementing this format on the | ||
compilation side vs. the concerns involved on the debugging side, this page | ||
lists and categorizes the available guides into the appropriate heading. | ||
|
||
|
||
## For debuggers | ||
|
||
<dl> | ||
<dt>**Guide: [Dereferencing pointers](/docs/implementation-guides/pointers)**</dt> | ||
<dd> | ||
This guide provides readers with a tour of the **@ethdebug/pointers** | ||
TypeScript reference implementation, showing example concrete logic for how a | ||
debugger might process **ethdebug/format** pointers. | ||
|
||
For an introduction to **ethdebug/format** pointers, please see | ||
the Pointer specification's [Overview](/spec/pointer/overview) and | ||
[Key concepts](/spec/pointer/concepts) pages. | ||
</dd> | ||
|
||
<dt>**Other guides**</dt> | ||
<dd> | ||
_Guides for other aspects of debugger-side **ethdebug/format** implementation | ||
are planned and still need to be written._ | ||
</dd> | ||
|
||
</dl> | ||
|
||
## For compilers | ||
|
||
<dl> | ||
<dt>**No availble guides yet**</dt> | ||
<dd> | ||
_Guides for implementing **ethdebug/format** support inside a compiler are | ||
planned and still need to be written._ | ||
</dd> | ||
</dl> | ||
|
||
:::tip[Work in progress] | ||
|
||
Sadly, things are looking a little scarce right now. Please stay tuned as work | ||
on this effort progresses. | ||
|
||
**Interested in helping out?** If you'd like to help with writing initial | ||
reference implementations for one or more schemas, please reach out in our | ||
[Matrix.chat](https://matrix.to/#/#ethdebug:matrix.org). | ||
|
||
::: |
8 changes: 0 additions & 8 deletions
8
packages/web/docs/implementation-guides/pointers/_category_.json
This file was deleted.
Oops, something went wrong.
120 changes: 108 additions & 12 deletions
120
...web/docs/implementation-guides/pointers/dereference-logic/dereference-logic.mdx
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 |
---|---|---|
@@ -1,20 +1,116 @@ | ||
--- | ||
sidebar_position: 5 | ||
sidebar_label: The dereference function | ||
--- | ||
|
||
# The dereference function | ||
import CodeListing from "@site/src/components/CodeListing"; | ||
|
||
These next few pages cover how the components described thus far are combined | ||
to create the final `dereference(pointer: Pointer)` function. | ||
# The `dereference()` function | ||
|
||
- The [Summary](/docs/implementation-guides/pointers/dereference-logic/summary) | ||
page broadly describes the control flow structure behind this function | ||
implementation. | ||
## Summary | ||
|
||
- [Generating regions on the fly](/docs/implementation-guides/pointers/dereference-logic/generating-regions) | ||
describes the process of recursively processing a pointer and reducing it to | ||
a concrete list of fully-evaluated `Cursor.Region` objects. | ||
The pages in this section cover the internals of the `dereference()` function | ||
in the **@ethdebug/pointers** reference implementation. | ||
|
||
- [Making regions concrete](/docs/implementation-guides/pointers/dereference-logic/making-regions-concrete) | ||
describes the process for converting a single `Pointer.Region` object into | ||
its fully-evaluated `Cursor.Region` equivalent at runtime. | ||
The full signature of this function is as follows: | ||
|
||
<CodeListing | ||
packageName="@ethdebug/pointers" | ||
sourcePath="src/dereference/index.ts" | ||
extract={ | ||
(sourceFile, project) => { | ||
const definition = sourceFile.getFunction("dereference"); | ||
const tempSourceFile = project.createSourceFile( | ||
"dereference-summary.ts", | ||
"", | ||
{ overwrite: true } | ||
); | ||
|
||
for (const importDeclaration of sourceFile.getImportDeclarations()) { | ||
tempSourceFile.addImportDeclaration(importDeclaration.getStructure()); | ||
} | ||
|
||
const commentText = definition.getLeadingCommentRanges() | ||
.map(range => | ||
sourceFile.getFullText() | ||
.substring(range.getPos(), range.getEnd())) | ||
.join("\n"); | ||
|
||
const declaration = tempSourceFile.addFunction({ | ||
name: definition.getName(), | ||
parameters: definition.getParameters() | ||
.map((param, index, array) => ({ | ||
name: param.getName(), | ||
type: param.getType().getText(param), | ||
hasQuestionToken: param.hasQuestionToken() || param.hasInitializer(), | ||
leadingTrivia: "\n", | ||
trailingTrivia: index < array.length - 1 ? undefined : "\n" | ||
})), | ||
returnType: definition.getReturnType().getText(definition), | ||
hasDeclareKeyword: true, | ||
isAsync: true, | ||
leadingTrivia: `${commentText}\n` | ||
}); | ||
|
||
|
||
return tempSourceFile.getFunction("dereference"); | ||
} | ||
} /> | ||
|
||
:::tip | ||
|
||
Remember from the | ||
[Cursors](/docs/implementation-guides/pointers/types/cursors) section that a `Cursor` | ||
provides a `view(state: Machine.State)` method, which returns an ordered | ||
collection of concrete `Cursor.Region` objects. | ||
|
||
::: | ||
|
||
### `DereferenceOptions` | ||
|
||
Note the optional `options: DereferenceOptions` argument. This argument | ||
allows for specifying additional information upfront that is necessary for | ||
viewing the cursor later. Currently, this is needed only for pointers that | ||
compose stack-located regions. | ||
|
||
<CodeListing | ||
packageName="@ethdebug/pointers" | ||
sourcePath="src/dereference/index.ts" | ||
extract={sourceFile => sourceFile.getInterface("DereferenceOptions")} | ||
/> | ||
|
||
## Control flow architecture | ||
|
||
The `dereference()` function itself performs two tasks: | ||
1. Create a "simple cursor": a function that takes a machine state and | ||
produces an asynchronous list of `Cursor.Region`s. | ||
2. Adapt this simple cursor to conform to the full `Cursor` interface | ||
|
||
Within the process of creating this simple cursor it gets more interesting: | ||
by leveraging JavaScript's | ||
[AsyncIterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator)s, | ||
the implementation can compute regions on the fly by recursively breaking down | ||
pointers into their nested child pointers. | ||
|
||
Since the desired end-result of `dereference()` is an object that can turn | ||
a pointer into its composite ordered list of concrete regions at a particular | ||
machine state, this implementation separates the concerns of generating this | ||
list from converting this list into the promised return interface. | ||
|
||
To generate this list asynchronously on the fly, the implementation uses a | ||
_stack of processing requests_ (which it calls "memos"), initially populated | ||
with a request to dereference the root pointer. Each memo represents a state | ||
or context change in some form: either a request to dereference a pointer or | ||
sub-pointer, a request to save a set of regions by their names, or a request | ||
to save the computed values of a set of variables by their identifiers. | ||
|
||
The other pages in this section proceed to go into more detail. | ||
|
||
<details> | ||
<summary>See the full `src/dereference/index.ts` module</summary> | ||
|
||
<CodeListing | ||
packageName="@ethdebug/pointers" | ||
sourcePath="src/dereference/index.ts" | ||
/> | ||
</details> |
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
108 changes: 0 additions & 108 deletions
108
packages/web/docs/implementation-guides/pointers/dereference-logic/summary.mdx
This file was deleted.
Oops, something went wrong.
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.