Last active
August 29, 2015 13:57
-
-
Save obscuren/9887744 to your computer and use it in GitHub Desktop.
much nerd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### Script | |
a = 100000 | |
b = a | |
if a == b { | |
b = 10000 | |
if b == a { | |
c = 10 | |
} | |
} | |
store[0] = 10 | |
a = store[0] | |
store[a] = 300 | |
e = store[a] | |
##### Syntax tree (e.g. AST), generated by the parser | |
Statement list | |
"" | |
| Statement list | |
| "" | |
| | Statement list | |
| | "" | |
| | | Statement list | |
| | | "" | |
| | | | Statement list | |
| | | | "" | |
| | | | | Statement list | |
| | | | | "" | |
| | | | | | Statement list | |
| | | | | | "" | |
| | | | | | | Empty | |
| | | | | | | "" | |
| | | | | | | Assignment | |
| | | | | | | "" | |
| | | | | | | | Constant | |
| | | | | | | | "100000" | |
| | | | | | | | Set local | |
| | | | | | | | "a" | |
| | | | | | Assignment | |
| | | | | | "" | |
| | | | | | | Identifier | |
| | | | | | | "a" | |
| | | | | | | Set local | |
| | | | | | | "b" | |
| | | | | If then | |
| | | | | "" | |
| | | | | | Equal | |
| | | | | | "" | |
| | | | | | | Identifier | |
| | | | | | | "a" | |
| | | | | | | Identifier | |
| | | | | | | "b" | |
| | | | | | Statement list | |
| | | | | | "" | |
| | | | | | | Statement list | |
| | | | | | | "" | |
| | | | | | | | Empty | |
| | | | | | | | "" | |
| | | | | | | | Assignment | |
| | | | | | | | "" | |
| | | | | | | | | Constant | |
| | | | | | | | | "10000" | |
| | | | | | | | | Set local | |
| | | | | | | | | "b" | |
| | | | | | | If then | |
| | | | | | | "" | |
| | | | | | | | Equal | |
| | | | | | | | "" | |
| | | | | | | | | Identifier | |
| | | | | | | | | "b" | |
| | | | | | | | | Identifier | |
| | | | | | | | | "a" | |
| | | | | | | | Statement list | |
| | | | | | | | "" | |
| | | | | | | | | Empty | |
| | | | | | | | | "" | |
| | | | | | | | | Assignment | |
| | | | | | | | | "" | |
| | | | | | | | | | Constant | |
| | | | | | | | | | "10" | |
| | | | | | | | | | Set local | |
| | | | | | | | | | "c" | |
| | | | Assignment | |
| | | | "" | |
| | | | | Constant | |
| | | | | "10" | |
| | | | | Set store | |
| | | | | "" | |
| | | | | | Constant | |
| | | | | | "0" | |
| | | Assignment | |
| | | "" | |
| | | | Store | |
| | | | "" | |
| | | | | Constant | |
| | | | | "0" | |
| | | | Set local | |
| | | | "a" | |
| | Assignment | |
| | "" | |
| | | Constant | |
| | | "300" | |
| | | Set store | |
| | | "" | |
| | | | Identifier | |
| | | | "a" | |
| Assignment | |
| "" | |
| | Store | |
| | "" | |
| | | Identifier | |
| | | "a" | |
| | Set local | |
| | "e" | |
############ Intermediate code, uses the above syntax tree | |
1 push : | |
2 const : 100000 | |
3 push : | |
4 const : 0 | |
5 mstore : | |
6 push : | |
7 const : 0 | |
8 mload : | |
9 push : | |
10 const : 32 | |
11 mstore : | |
12 push : | |
13 const : 0 | |
14 mload : | |
15 push : | |
16 const : 32 | |
17 mload : | |
18 equal : | |
19 not : | |
20 jmpi : | |
21 push : | |
22 const : 10000 | |
23 push : | |
24 const : 32 | |
25 mstore : | |
26 push : | |
27 const : 32 | |
28 mload : | |
29 push : | |
30 const : 0 | |
31 mload : | |
32 equal : | |
33 not : | |
34 jmpi : | |
35 push : | |
36 const : 10 | |
37 push : | |
38 const : 64 | |
39 mstore : | |
39 target : | |
39 target : | |
40 push : | |
41 const : 10 | |
42 push : | |
43 const : 0 | |
44 sstore : | |
45 push : | |
46 const : 0 | |
47 sload : | |
48 push : | |
49 const : 0 | |
50 mstore : | |
51 push : | |
52 const : 300 | |
53 push : | |
54 const : 0 | |
55 mload : | |
56 sstore : | |
57 push : | |
58 const : 0 | |
59 mload : | |
60 sload : | |
61 push : | |
62 const : 96 | |
63 mstore : | |
############### ASM Produces by the compiler | |
[PUSH 100000 PUSH 0 MSTORE PUSH 0 MLOAD PUSH 32 MSTORE PUSH 0 MLOAD PUSH 32 MLOAD EQ NOT PUSH 40 JUMPI PUSH 10000 PUSH 32 MSTORE PUSH 32 MLOAD PUSH 0 MLOAD EQ NOT PUSH 40 JUMPI PUSH 10 PUSH 64 MSTORE PUSH 10 PUSH 0 SSTORE PUSH 0 SLOAD PUSH 0 MSTORE PUSH 300 PUSH 0 MLOAD SSTORE PUSH 0 MLOAD SLOAD PUSH 96 MSTORE] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment