Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d941d38

Browse files
committed
Add a disasm function
1 parent 8561199 commit d941d38

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/createRuby.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,28 @@ export default async function createRuby() {
7373
`);
7474

7575
return {
76+
// A function that disassembles the YARV instructions for the given source.
77+
disasm(source: string) {
78+
const jsonSource = JSON.stringify(JSON.stringify(source));
79+
const rubySource = `RubyVM::InstructionSequence.compile(JSON.parse(${jsonSource})).disasm`;
80+
81+
return ruby.eval(rubySource).toString();
82+
},
7683
// A function that calls through to the SyntaxTree.format function to get
7784
// the pretty-printed version of the source.
7885
format(source: string) {
79-
const rubySource = `
80-
SyntaxTree.format(JSON.parse(${JSON.stringify(JSON.stringify(source))}))
81-
`;
86+
const jsonSource = JSON.stringify(JSON.stringify(source));
87+
const rubySource = `SyntaxTree.format(JSON.parse(${jsonSource}))`;
8288

8389
return ruby.eval(rubySource).toString();
8490
},
8591
// A function that calls through to PP to get the pretty-printed version of
8692
// the syntax tree.
8793
prettyPrint(source: string) {
94+
const jsonSource = JSON.stringify(JSON.stringify(source));
8895
const rubySource = `
8996
PP.format([], 80) do |q|
90-
source = JSON.parse(${JSON.stringify(JSON.stringify(source))})
97+
source = JSON.parse(${jsonSource})
9198
SyntaxTree.parse(source).pretty_print(q)
9299
end.join
93100
`;

src/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ nav h1, nav a, nav span {
3838

3939
textarea {
4040
font-size: 0.9em;
41+
overflow-wrap: normal;
42+
overflow-x: scroll;
43+
resize: none;
44+
white-space: pre;
4145
}
4246

4347
.CodeMirror {

0 commit comments

Comments
 (0)