-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
129 lines (123 loc) · 3.55 KB
/
index.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<link href="https://pvinis.github.io/iosevka-webfont/3.4.1/iosevka.css" rel="stylesheet" />
<title>Franca</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#wasmForm {
background-color: #ffffff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 500px;
box-sizing: border-box;
}
textarea {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-family: 'Courier New', monospace;
resize: vertical;
height: 150px;
margin-bottom: 15px;
font-family: "Iosevka Web";
}
button {
background-color: #007BFF;
color: #ffffff;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
}
pre {
font-family: "Iosevka Web";
background-color: #e8e8e8;
padding: 10px;
border-radius: 4px;
margin-top: 15px;
font-size: 14px;
white-space: pre-wrap; /* Since CSS 2.1 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
#stats {
font-family: "Iosevka Web";
margin-top: 10px;
color: #333;
}
</style>
</head>
<body>
<form id="wasmForm">
<textarea id="inputVal" placeholder="Write rust code here">
pub fn eval(&mut self, s: String) {
let mut st = &mut vec![];
let mut b = &mut 0;
let mut a = &mut self.a;
let mut p = &mut self.p;
let mut ip = &mut self.ip;
let by = s.as_bytes();
while *ip < by.len() {
let c = by[*ip];
match c as char {
']' => {
if a[*p] != 0 {
*ip = st.pop().unwrap();
}
*b = *ip;
}
'[' => {
if a[*p] == 0 {
*ip = *b;
}
st.push(*ip);
}
'+' => a[*p] += 1,
'-' => a[*p] -= 1,
'>' => *p += 1,
'<' => *p -= 1,
'.' => self.b.push(a[*p]),
',' => {},
_ => unreachable!(),
};
*ip += 1;
}
}
</textarea>
<button type="submit">Enter</button>
<pre><div id="output"></div></pre>
<div id="stats"></div>
</form>
<script type="module">
import init, { mkterse } from "./pkg/libfranca.js";
init();
document.getElementById('wasmForm').addEventListener('submit', function(e) {
e.preventDefault();
const inputValue = document.getElementById('inputVal').value;
const result = mkterse(inputValue);
document.getElementById('output').textContent = result;
const inputBytes = new TextEncoder().encode(inputValue).length;
const outputBytes = new TextEncoder().encode(result).length;
document.getElementById('stats').innerHTML = `
Input: ${inputValue.length} chars, ${inputBytes} bytes<br>
Output: ${result.length} chars, ${outputBytes} bytes
`;
});
</script>
</body>
</html>