-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
187 lines (160 loc) · 5.44 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1" name="viewport" />
<title>Featherweight Generics Go implementation in Scala</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://unpkg.com/vue-prism-editor"></script>
<script src="https://unpkg.com/prismjs"></script>
<script src="https://unpkg.com/prismjs/components/prism-go"></script>
<script type="text/javascript" src="./js/target/scala-2.13/featherweightgo-fastopt.js"></script>
<link rel="stylesheet" href="https://unpkg.com/vue-prism-editor/dist/prismeditor.min.css">
<link rel="stylesheet" href="https://unpkg.com/prismjs/themes/prism-tomorrow.css" />
<style>
.col {
padding: 8px;
}
.container {
display: flex;
flex-flow: row wrap;
padding: 8px;
}
.col {
flex: 1 1 48%;
}
@media (max-width: 896px) {
.col {
flex: 1 1 100%;
}
}
#editor-col {
text-align: center;
padding-bottom: 100px;
}
#result pre {
font-size: large;
white-space: pre-wrap;
word-wrap: break-word;
word-break: break-all;
padding-left: 20px;
}
.forkme {
vertical-align: top;
}
h1 {
text-align: center;
display: inline-block;
margin-right: auto;
margin-left: auto;
width: 90%;
}
h2 {
border-bottom: 1px solid gray;
}
h3 {
font-family: serif;
font-size: x-large;
}
.error {
color: orangered;
}
</style>
</head>
<body>
<div>
<a class="forkme" href="https://github.com/y-yu/featherweight_go" target="_blank"><img width="5%" src="https://github.blog/wp-content/uploads/2008/12/forkme_left_darkblue_121621.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1"></a>
<h1>Featherweight <em>Generics</em> Go implementation in Scala</h1>
</div>
<div id="app" class="container">
<div id="editor-col" class="col">
<label>
<input type="checkbox" v-model="lineNumbers"/>
LineNumbers
</label>
<prism-editor v-model="code" language="go" :highlight="highlighter" :line-numbers="lineNumbers"></prism-editor>
</div>
<div id="result" class="col">
<h2>Results</h2>
<p>
<h3>Return type of <code>main</code></h3>
<pre v-html="type" v-bind:class="isTypeCheckSuccess"></pre>
</p>
<p>
<h3>Return value of <code>main</code></h3>
<pre v-html="result" v-bind:class="isEvaluationSuccess"></pre>
</p>
<p>
<h3>AST</h3>
<details>
<summary>Click to show all the AST</summary>
<pre v-html="ast"></pre>
</details>
</p>
</div>
</div>
<h2>References</h2>
<ul>
<li>The JavaScript of <a href="https://arxiv.org/abs/2005.11710">Featherweight Generics Go</a> implementation is generated by <a href="https://www.scala-js.org/">Scala.js</a>.</li>
<li>The editor is created by <a href="https://github.com/koca/vue-prism-editor">Vue Prism Editor</a>.</li>
<li>Thanks to help me make this site: <a href="https://github.com/nanashiki">@nanashiki</a>, <a href="https://github.com/kazuma1989">@kazuma1989</a> and <a href="https://github.com/nobuoka">@nobuoka</a>.</li>
</ul>
<script>
Vue.component('vue-prism-editor', PrismEditor);
new Vue({
el: '#app',
data : {
code: FeatherweightGoMain.exampleSourceCode,
lineNumbers: true,
store: { },
isTypeCheckSuccess: {
error: false
},
isEvaluationSuccess: {
error: false
}
},
methods: {
highlighter(code) {
return Prism.highlight(code, Prism.languages.go, "go");
}
},
computed: {
ast: function() {
try {
const ast = FeatherweightGoMain.parse(this.code);
const [isTypeCheckSuccess, type] = FeatherweightGoMain.typeCheck(this.code);
const [isEvaluationSuccess, result] = FeatherweightGoMain.eval(this.code);
this.store = {
ast: ast,
result: result,
type: type
};
this.isEvaluationSuccess = {
error: !isEvaluationSuccess
};
this.isTypeCheckSuccess = {
error: !isTypeCheckSuccess
};
return ast;
} catch(error) {
this.isEvaluationSuccess = {
error: true
};
this.isTypeCheckSuccess = {
error: true
};
return error.message;
}
},
result: function () {
return this.store.result;
},
type: function () {
return this.store.type;
}
}
})
</script>
</body>
</html>