Question

For fun and practice, I want to build a very simple programming language and compiler (using Java). I will describe my design idea, and then ask a number of questions about it. Will appreciate your help :)

The design:

The programs written with this language would run on a (simple of course) Virtual Machine I will create.

The steps for writing and running a program:

1 - The programmer writes the code in the compiler (a kind of IDE). Compilation happens as follows:

  • The compiler scans the code, and converts each line to op-code. For example, if the line of code is: print ("hello"), the compiler will convert it to something like p"hello" - this would be the op-code.

  • After scanning the entire code, we'll have a Bytecode file, composed of all the op-codes generated.

    This Bytecode type will be created by me for my VM. This won't be Bytecode in the tehnical definition, in the sense that it's op-codes won't be one byte each. Instead, each op-code will be an instruction combining letters and numbers. (Like in my example: the op-code p"hello" tells the VM to print "Hello" to the screen). It is Bytecode in the sense that it is the result of compiling programming-language code, and it is code be executed by the VM (correct?).

2 - Running the program (executing the Bytecode) is done as follows:

  • The program runs inside the Virtual Machine program. This program will scan the Bytecode loaded into it, and convert each op-code to some Java operation (since the VM program will be written in Java). For example, the VM will read the op-code p"hello", and in reaction execute: System.out.println("hello");.

My questions

  • Is this VM program considered a VM?

  • Is this Bytecode considered Bytecode? (Even though it's not written in the professional way, where each op-code is one byte)?

No correct solution

OTHER TIPS

Yes to both questions (off-topic on stackoverflow):

Is this VM program considered a VM?

Yes, a (process) virtual machine is something interpreting some low-level representation like a bytecode

Is this Bytecode considered Bytecode?

Yes, byte-codes are not always one byte each.

I strongly recommend reading Queinnec's Lisp in small pieces

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top