This repository has been archived by the owner on Jul 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsource.html
106 lines (84 loc) · 2.47 KB
/
source.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>miniForth playGround</title>
</head>
<body>
<textarea id='miniForth'>
</textarea>
<div id='asm'></div>
</body>
<!-- <footer>
<a href="./fulfill.html"><button>Fulfill the predicate</button></a>
</footer> -->
<script type="text/javascript">
var myInput = document.getElementById("miniForth");
if(myInput.addEventListener ) {
myInput.addEventListener('keydown',this.keyHandler,false);
} else if(myInput.attachEvent ) {
myInput.attachEvent('onkeydown',this.keyHandler); /* damn IE hack */
}
function keyHandler(e) {
var TABKEY = 9;
if(e.keyCode == TABKEY) {
var start = myInput.selectionStart;
var end = myInput.selectionEnd;
var sel = myInput.value.substring(start, end);
var finText = myInput.value.substring(0, start) + ' ' + myInput.value.substring(end);
myInput.value = finText;
myInput.focus();
myInput.selectionEnd= end + 4;
if(e.preventDefault) {
e.preventDefault();
}
return false;
}
}
</script>
<script src="./modules/bsv.bundle.js"></script>
<script>
XXXPARSERXXX
var W;
var H;
var M = document.getElementById('miniForth');
var A = document.getElementById('asm')
A.style.backgroundColor = '#F1F1F1';
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';
var i0;
var i1;
var o;
window.setInterval(() => {
// parse result
i1 = M.value;
if(i1 != i0) {
try {
o = peg$parse(i1)
evalScript(o)
} catch (err) {
o = err
}
// console.log(o)
A.innerText = o;
}
i0 = i1;
}, 1000)
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);
}
</script>
</html>