Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
feat eval script
Browse files Browse the repository at this point in the history
  • Loading branch information
Ljzn committed Sep 28, 2020
1 parent f686291 commit ba60128
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 26 deletions.
66 changes: 53 additions & 13 deletions j/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,38 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>miniForth playGround</title>
</head>
<style>
*{
box-sizing: border-box;
padding: 0;
margin: 0;
}

<body>
<textarea id='miniForth'>
.parent {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
grid-column-gap: 0px;
grid-row-gap: 0px;
width: 100vw;
height: 100vh;
}

</textarea>
#miniForth {
min-width: 50vw;
grid-area: 1 / 1 / 3 / 2;
}
#asm { grid-area: 1 / 2 / 2 / 3; }
#result { grid-area: 2 / 2 / 3 / 3; }
</style>
</head>

<div id='asm'></div>
<body>
<div class="parent">
<textarea id='miniForth'></textarea>
<div id='asm'></div>
<div id='result'></div>
</div>
</body>

<!-- <footer>
Expand Down Expand Up @@ -1923,13 +1947,13 @@
\ Embeded loop is unsupported yet.
`

// window size
W = window.innerWidth;
H = window.innerHeight;
M.style.height = H / 2 - 25 + 'px';
M.style.width = W - 20 + 'px';
A.style.height = H / 2 - 25 + 'px';
A.style.width = W - 20 + 'px';
// // window size
// W = window.innerWidth;
// H = window.innerHeight;
// M.style.height = H / 2 - 25 + 'px';
// M.style.width = W - 20 + 'px';
// A.style.height = H / 2 - 25 + 'px';
// A.style.width = W - 20 + 'px';

var i0;
var i1;
Expand All @@ -1953,15 +1977,31 @@
i0 = i1;
}, 1000)

var r = document.getElementById('result')

function evalScript(opcodes) {
console.log(opcodes)
let s = bsvjs.Script.fromAsmString(opcodes);
let i = new bsvjs.Interp();
// i.flags = bsvjs.Script.Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES | bsv.Script.Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES;
i.script = s;
i.verify();
console.log(i)
i = i.toJSON()

console.log(i)
r.innerText = 'stack: '
+ JSON.stringify(fixDouble(i.stack))
+ '\naltstack: '
+ JSON.stringify(fixDouble(i.altStack))
+ (i.errStr != '' ? `\nerror: ${i.errStr}` : '')
}

console.log(i);
// function lineLimit(str) {
// return str.match(/.{1,30}/g).join('\n')
// }
function fixDouble(str) {
return str.slice(str.length/2)
}

</script>
Expand Down
66 changes: 53 additions & 13 deletions j/source.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,38 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>miniForth playGround</title>
</head>
<style>
*{
box-sizing: border-box;
padding: 0;
margin: 0;
}

<body>
<textarea id='miniForth'>
.parent {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
grid-column-gap: 0px;
grid-row-gap: 0px;
width: 100vw;
height: 100vh;
}

</textarea>
#miniForth {
min-width: 50vw;
grid-area: 1 / 1 / 3 / 2;
}
#asm { grid-area: 1 / 2 / 2 / 3; }
#result { grid-area: 2 / 2 / 3 / 3; }
</style>
</head>

<div id='asm'></div>
<body>
<div class="parent">
<textarea id='miniForth'></textarea>
<div id='asm'></div>
<div id='result'></div>
</div>
</body>

<!-- <footer>
Expand Down Expand Up @@ -60,13 +84,13 @@

M.value = String.raw`XXXREADMEXXX`

// window size
W = window.innerWidth;
H = window.innerHeight;
M.style.height = H / 2 - 25 + 'px';
M.style.width = W - 20 + 'px';
A.style.height = H / 2 - 25 + 'px';
A.style.width = W - 20 + 'px';
// // window size
// W = window.innerWidth;
// H = window.innerHeight;
// M.style.height = H / 2 - 25 + 'px';
// M.style.width = W - 20 + 'px';
// A.style.height = H / 2 - 25 + 'px';
// A.style.width = W - 20 + 'px';

var i0;
var i1;
Expand All @@ -90,15 +114,31 @@
i0 = i1;
}, 1000)

var r = document.getElementById('result')

function evalScript(opcodes) {
console.log(opcodes)
let s = bsvjs.Script.fromAsmString(opcodes);
let i = new bsvjs.Interp();
// i.flags = bsvjs.Script.Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES | bsv.Script.Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES;
i.script = s;
i.verify();
console.log(i)
i = i.toJSON()

console.log(i)
r.innerText = 'stack: '
+ JSON.stringify(fixDouble(i.stack))
+ '\naltstack: '
+ JSON.stringify(fixDouble(i.altStack))
+ (i.errStr != '' ? `\nerror: ${i.errStr}` : '')
}

console.log(i);
// function lineLimit(str) {
// return str.match(/.{1,30}/g).join('\n')
// }
function fixDouble(str) {
return str.slice(str.length/2)
}

</script>
Expand Down

1 comment on commit ba60128

@vercel
Copy link

@vercel vercel bot commented on ba60128 Sep 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.