HAMID hamri
HAMID hamri

Reputation: 1

How JavaScript language is been executed under the hood in Google V8 engine

Hello Guys I have a question, so i study computer science at university , we have built a simple language called NewJava , its syntax is similar to Java, we built the interpreter with c++ , we have done everything lexical thing , grammar , we create token , parse it to create The abstract syntax tree , then for example when we see variable declaration in NewJava such as : ‘’ dec number = 10’’ we store the variable with its value in a hashMap using c++ to keep track with the value, and same thing with other functionalities such as creating obj, array, linkedList , everything we create in NewJava is just converted into c++ w pushed into a hash-table. Our teacher said that this is how programming languages are created, it looked weird to me , because when i read the V8 engine for example i saw that the AST compiled and machine code generated , and not like i study, i want to know if javaScript for example works the same way we created NewJava or not? , thank you!

I have searched on google about that and i saw that the code of AST is compiled into bytecode!

Upvotes: -1

Views: 141

Answers (1)

jmrk
jmrk

Reputation: 40641

It sounds like your "NewJava" is a simplification of how production-quality virtual machines often work, which of course is totally appropriate for a university course where you implement it yourself. In particular, it's based on an AST interpreter, not a JIT compiler. So your teacher is right that this is the general principle, and you're right that it's not exactly the same.

Note that different virtual machines employ different implementation techniques, they're not all the same (and they also change over time as long as they're under active development), so there is no one single right answer to "how programming languages are created".

To read more about V8, see v8.dev/blog.

Upvotes: 0

Related Questions