forked from Shando/game_engine_for_esp8266_with_compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
84 lines (77 loc) · 1.89 KB
/
test.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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<title>test</title>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="theme-color" content="#7CCD7C">
</head>
<style type='text/css'>
#testOut{
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="testOut"></div>
<script type="text/javascript" src="asm.js"></script>
<script type="text/javascript" src="cpu.js"></script>
<script type="text/javascript" src="compiler.js"></script>
<script type="text/javascript">
var language = 'rus';
var chars = [];
var globalJKey = 0;
var globalKey = 0;
var debugVar = [];
var numberDebugString = [];
var d = document.getElementById("testOut");
var err = '';
function test(src, out){
err = '';
var t = tokenize(src);
var c = compile(t);
asmSource = c.join('\n');
asm(asmSource);
chars = [];
for(var i=0;i<100000;i++)
cpu.step();
d.innerHTML += "<br><b>" + out + "</b> - <b>" + chars + "</b> - ";
if(out == chars)
d.innerHTML += "true";
else
d.innerHTML += "false " + err;
}
function info(s){
console.log(s);
err += s;
}
function Display() {
function init() {}
function reset() {}
function char(c,x,y,color,bgcolor){
chars += c;
}
function updatePixel(x,y) {}
function drawPixel(color, x, y) {}
function plot(color, x, y) {}
return {
init: init,
reset: reset,
char:char,
updatePixel: updatePixel,
drawPixel: drawPixel,
plot:plot
};
}
var display = new Display();
d.innerHTML = "";
test('putn(42);','42');
test('putn(41+3-2);','42');
test('printf("%d",41+3-2);','42');
test('printf("%d%d",2+2*(4-1)-4,2);','42');
test('printf("HELLO %s","WORLD");','HELLO WORLD');
test('int x=1;int y=1;int i;int n=15;void main(){for(i=1;i<n;i++){x=x+y;y=x-y;}putn(y);}','610');
</script>
</body>
</html>