-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·116 lines (108 loc) · 3.69 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Solidity to LIGO compiler</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="nav">
<a href="https://vird.github.io/eth2tez_online/" class="nav_selected" >Ligo</a>
<a href="https://vird.github.io/eth2tez_online/smartpy.html">SmartPy</a>
<div class="example_selector">
<span id="load_msg">
Need some time to load. Loading...
</span>
<select id="src_select">
</select>
</div>
</div>
<div class="contents">
<div class="code">
<div id="solidity_src_wrap">
<textarea id="solidity_src" spellcheck="false">pragma solidity ^0.5.11;
contract Ifer {
uint public value;
function ifer() public returns (uint) {
uint x = 6;
if (x == 5) {
x += 1;
}
else {
x -= 1;
}
return x;
}
}</textarea>
</div>
<div id="ligo_dst_wrap">
<pre id="ligo_dst"></pre>
</div>
<div class="minibutton" id="compile_btn">Compiling...</div>
</div>
</div>
<script src="common/soljson.js"></script>
<script src="common/sol_wrapper.js"></script>
<script src="common/fy.js"></script>
<script src="common/codegen.js"></script>
<script src="eth2tez/config.js"></script>
<script src="common/type.js"></script>
<script src="eth2tez/ast4gen.js"></script>
<script src="eth2tez/ast.js"></script>
<script src="eth2tez/solidity_to_ast4gen.js"></script>
<script src="eth2tez/translate.js"></script>
<script src="eth2tez/type_inference.js"></script>
<script src="example_list.js"></script>
<script>
document.querySelector('#solidity_src').focus();
document.querySelector('#load_msg').innerText = "Very experimental. Use it at your own RISK.";
function compile() {
document.querySelector('#compile_btn').style.display = '';
document.querySelector('#compile_btn').innerHTML = "Compiling..."
document.querySelector('#compile_btn').style.background = ""
var next = function() {
try {
var code = document.querySelector('#solidity_src').value;
var solidity_ast = ast_gen(code);
var ast = solidity_to_ast4gen(solidity_ast);
var ast = type_inference.gen(ast);
var res = translate.gen(ast);
document.querySelector('#ligo_dst').innerHTML = res;
document.querySelector('#compile_btn').style.display = 'none';
} catch (e) {
console.log(e);
document.querySelector('#compile_btn').innerHTML = "ERROR"
document.querySelector('#compile_btn').style.background = "#faa"
}
};
setTimeout(next, 10);
}
compile();
var timeout = null;
function onchange() {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(function(){
timeout = null;
compile();
}, 100);
};
document.querySelector('#solidity_src').onchange = onchange;
document.querySelector('#solidity_src').onkeyup = onchange;
var $src_select = document.querySelector('#src_select')
var jl_list = example_list.map(function(example){
return "<option>"+example.title+"</option>";
})
$src_select.onchange = function(t) {
example_list.map(function(t){
if (t.title == $src_select.value) {
document.querySelector('#solidity_src').value = t.code;
compile();
}
});
}
$src_select.innerHTML = jl_list.join('');
</script>
</body>
</html>