-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
220 additions
and
37 deletions.
There are no files selected for viewing
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
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
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
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,19 +1,44 @@ | ||
import { VmInput, getAssembly, runVm } from "./api-generic"; | ||
import { decodeProgram } from "./program"; | ||
import { decodeProgram, decodeSpi, liftBytes } from "./program"; | ||
|
||
export * from "./api"; | ||
export { runVm } from "./api-generic"; | ||
|
||
export function exampleGetAssembly(program: u8[]): string { | ||
const p = decodeProgram(program); | ||
return getAssembly(p); | ||
export enum InputKind { | ||
Generic = 0, | ||
SPI = 1, | ||
} | ||
|
||
export function exampleRun(program: u8[]): void { | ||
const input = new VmInput(); | ||
input.registers[7] = 9; | ||
input.gas = 10_000; | ||
input.program = program; | ||
const output = runVm(input, true); | ||
console.log(`Finished with status: ${output.status}`); | ||
export function disassemble(input: u8[], kind: InputKind): string { | ||
const program = liftBytes(input); | ||
if (kind === InputKind.Generic) { | ||
const p = decodeProgram(program); | ||
return getAssembly(p); | ||
} | ||
|
||
if (kind === InputKind.SPI) { | ||
const p = decodeSpi(program); | ||
return getAssembly(p); | ||
} | ||
|
||
return `Unknown kind: ${kind}`; | ||
} | ||
|
||
export function run(input: u8[], kind: InputKind): void { | ||
if (kind === InputKind.Generic) { | ||
const vmInput = new VmInput(); | ||
vmInput.registers[7] = 9; | ||
vmInput.gas = 10_000; | ||
vmInput.program = input; | ||
|
||
const output = runVm(vmInput, true); | ||
console.log(`Finished with status: ${output.status}`); | ||
return; | ||
} | ||
|
||
if (kind === InputKind.SPI) { | ||
throw new Error("SPI running not supported yet"); | ||
} | ||
|
||
throw new Error(`Unknown kind: ${kind}`); | ||
} |
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
Large diffs are not rendered by default.
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
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