Converting Nand compiler to C Compiler or something else

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Converting Nand compiler to C Compiler or something else

The_Larks
Would this be a trivial exercise? Say, to convert the final compiler you've created into one that can write executable ANSI C assembly? You would just have to change the grammar a bit and obviously the target of the assembly... no?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Converting Nand compiler to C Compiler or something else

cadet1620
Administrator
The_Larks wrote
Would this be a trivial exercise? Say, to convert the final compiler you've created into one that can write executable ANSI C assembly? You would just have to change the grammar a bit and obviously the target of the assembly... no?
Compiling to assembly language is going to depend on the computer you intend to run on and the assembler that you intend to use.

I think it would be a moderate amount of work to compile from Jack to C++ (C would be more difficult since it doesn't support objects).

You would need to do multiple passes. The first pass would gather type information for all functions and variables so that it could write appropriate casts on all assignments and function arguments.

Next pass could generate .h files containing class definitions from each Jack file.  Final pass would generate the .cpp files.

--Mark

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Converting Nand compiler to C Compiler or something else

The_Larks
I do have one very important question. I didn’t encapsulate any of my project 8 assembly writers in any classes or functions. It’s all one big series of controls statements. It made it easier to debug and edit each implementation while not having to worry about breaking any others. 

When we use our VMWriter for projects 10 and 11, we aren’t making any external calls to functions inside of said VMWriter, correct? All that’s happening in 10 and 11 is that we are generating the code that is fed *into* our VMWriter, and then the VMWriter does the rest… So once it’s fully functional in Project 8, I don’t have to touch it. Is this correct?


On Nov 17, 2016, at 1:14 PM, cadet1620 [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:

The_Larks wrote
Would this be a trivial exercise? Say, to convert the final compiler you've created into one that can write executable ANSI C assembly? You would just have to change the grammar a bit and obviously the target of the assembly... no?
Compiling to assembly language is going to depend on the computer you intend to run on and the assembler that you intend to use.

I think it would be a moderate amount of work to compile from Jack to C++ (C would be more difficult since it doesn't support objects).

You would need to do multiple passes. The first pass would gather type information for all functions and variables so that it could write appropriate casts on all assignments and function arguments.

Next pass could generate .h files containing class definitions from each Jack file.  Final pass would generate the .cpp files.

--Mark




To unsubscribe from Converting Nand compiler to C Compiler or something else, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Converting Nand compiler to C Compiler or something else

cadet1620
Administrator
The_Larks wrote
I do have one very important question. I didn’t encapsulate any of my project 8 assembly writers in any classes or functions. It’s all one big series of controls statements. It made it easier to debug and edit each implementation while not having to worry about breaking any others.

When we use our VMWriter for projects 10 and 11, we aren’t making any external calls to functions inside of said VMWriter, correct? All that’s happening in 10 and 11 is that we are generating the code that is fed *into* our VMWriter, and then the VMWriter does the rest… So once it’s fully functional in Project 8, I don’t have to touch it. Is this correct?
You are correct. The compiler you will write in projects 10 and 11 will generate .vm files. You can test your compiler by running the generated .vm files in the VMEmulator.

Running the .vm files through your translator and being able to run them in the CPUEmulator is a bonus. One thing that you may find when you try that is that your VM translator generates code that is too big to load into ROM. After you complete the book, you might want to search the forum for info on generating smaller VM code.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Converting Nand compiler to C Compiler or something else

The_Larks
A bonus in what way? It is a requirement that our VMWriter should correctly emit assembly translated from the .vm files our compiler creates, yes? 
On Nov 17, 2016, at 1:38 PM, cadet1620 [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:

The_Larks wrote
I do have one very important question. I didn’t encapsulate any of my project 8 assembly writers in any classes or functions. It’s all one big series of controls statements. It made it easier to debug and edit each implementation while not having to worry about breaking any others.

When we use our VMWriter for projects 10 and 11, we aren’t making any external calls to functions inside of said VMWriter, correct? All that’s happening in 10 and 11 is that we are generating the code that is fed *into* our VMWriter, and then the VMWriter does the rest… So once it’s fully functional in Project 8, I don’t have to touch it. Is this correct?
You are correct. The compiler you will write in projects 10 and 11 will generate .vm files. You can test your compiler by running the generated .vm files in the VMEmulator.

Running the .vm files through your translator and being able to run them in the CPUEmulator is a bonus. Ont thing that you may find when you try that is that your VM translator generates code that is too big to load into ROM. After you complete the book, you might want to search the forum for info on generating smaller VM code.

--Mark



To unsubscribe from Converting Nand compiler to C Compiler or something else, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Converting Nand compiler to C Compiler or something else

cadet1620
Administrator
The_Larks wrote
A bonus in what way? It is a requirement that our VMWriter should correctly emit assembly translated from the .vm files our compiler creates, yes?
It's not a requirement of the normal course. Some instructors could add it as a requirement, but I have not heard of any who have.

It is an amazing feeling when you can translate your game using your tools and your OS and see it running (albeit slowly) on the CPUEmulator!

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Converting Nand compiler to C Compiler or something else

cadet1620
Administrator
In reply to this post by The_Larks
Here's a link to a forum article about generating Windows executable code from VM:
  VM translator generate x86 windows assembly
This is more inline with the concept of the two-tier compiler described in the book.  Changing the output language of the VM translator retargets the compiler without requiring any changes to the compiler itself.

--Mark
Loading...