Skip to content

Instantly share code, notes, and snippets.

@iafonov
Created January 17, 2011 18:26
Show Gist options
  • Save iafonov/783201 to your computer and use it in GitHub Desktop.
Save iafonov/783201 to your computer and use it in GitHub Desktop.
V8 AST
function test(x) {
return x === 1;
}
if (test(2)) {
print("no")
}
/* AST
["FunctionLiteral",
{"name":""},
["Declaration",
{"mode":"VAR"},
["VariableProxy",
{"name":"test",
"mode":"DYNAMIC_GLOBAL"
}
],
["FunctionLiteral",
{"name":"test"},
["ReturnStatement",
["CompareOperation",
{"op":"EQ_STRICT"},
["Slot",
{"type":"PARAMETER",
"index":0
}
],
["Literal",
{"handle":1}
]
]
]
]
],
["IfStatement",
["Call",
["VariableProxy",
{"name":"test",
"mode":"DYNAMIC_GLOBAL"
}
],
["Literal",
{"handle":2}
]
],
["Block",
["ExpressionStatement",
["Assignment",
{"op":"ASSIGN"},
["Slot",
{"type":"LOCAL",
"index":0
}
],
["Call",
["VariableProxy",
{"name":"print",
"mode":"DYNAMIC_GLOBAL"
}
],
["Literal",
{"handle":"no"}
]
]
]
]
],
["EmptyStatement"]
],
["ReturnStatement",
["Slot",
{"type":"LOCAL",
"index":0
}
]
]
]
["FunctionLiteral",
{"name":"test"},
["ReturnStatement",
["CompareOperation",
{"op":"EQ_STRICT"},
["Slot",
{"type":"PARAMETER",
"index":0
}
],
["Literal",
{"handle":1}
]
]
]
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment