Data Segment in Compiler Construction

200 Views Asked by At

i am developing a compiler for my own defined language , i have generated 3 address code and now i am going to develop a virtual machine which can run that 3 address code. but for that i need Data Segment (where i can store all of my variables values) .i have two data types in my language (int and char) .
please give me a hint that how can i construct a data segment where i can store all of my variables (int and char both) values
thanks reading my problem

1

There are 1 best solutions below

0
On

I strongly recommend to read C.Queinnec's book Lisp In Small Pieces; it explains very well a lot of things related to your questions.

While C.Queinnec's book focus apparently on Lisp-like languages, it teach you concepts which you can apply to a lot of other languages, including your own. In particular, you'll want to formalize more the denotational semantics or operational semantics of your language.

You could also at least study some VM, including Ocaml virtual machine, JVM, Parrot VM, NekoVM, LUA VM...

And you may later want to use just in time compilation techniques, notably with LLVM or libjit etc...

See also http://lambda-the-ultimate.org/

BTW, you may find much more convenient to have your language implementation reuse some existing VM.

I don't grasp why is a data segment such an issue. Your VM usually starts with some heap image, which contain both data and bytecode. A lot of languages have (at least implicitly) closures - or at least objects - mixing code and data.