Giter VIP home page Giter VIP logo

virtual-machine-translator's Introduction

Virtual Machine Translator

Background

Java (or C#) compilers generate code written in an intermediate language called bytecode (or IL). This code is designed to run on a virtual machine architecture like the JVM (or CLR). One way to implement such VM programs is to translate them further into lower-level programs written in the machine language of some concrete (rather than virtual) host computer. I have built such a VM translator, designed to translate programs written in the VM language into programs written in the Hack assembly language.

Implementation

We propose implementing in two stages. This will allow us to unit-test our implementation incrementally, using test programs . In what follows, when we say "the VM translator should implement some VM command" we mean "the VM translator should translate the given VM command into a sequence of Hack assembly commands that accomplish the same task".

Stage I: Handling stack arithmetic commands: The first version of the basic VM translator should implement the nine arithmetic / logical commands (add, sub , neg ,eq , gt , lt, and , or , not) of the VM language as well as the VM command push constant x.

The latter command is the generic push command for which the first argument is constant and the second argument is some non-negative integer x. This command comes handy at this early stage, since it helps provide values for testing the implementation of the arithmetic / logical VM commands. For example, in order to test how the VM translator handles the VM add command, we can test how it handles the VM code push constant 3, push constant 5, add. The other arithmetic and logical commands are tested similarly.

Stage II: Handling memory access commands: The next version of the basic VM translator should include a full implementation of the VM language's push and pop commands, handling the eight memory segments described as follows constant ,local, argument, this, that, pointer, temp, static segments . and also includes the Branching commands (label ,if-goto , goto) and Function commands (function which declares a function , call which used to call a function ,return which used to return from a function )

Push and Pop commands


Branching commands


Function commands

Call command


Function excution & Return commands


Memory recycle after return command


Working Stack during excution


Preparing the code to work

After we Translate the code we need add Bootstrap code to initailize the Virtual machine memory before starting the code


The big picture

At the end the overall Translator work is to produce code that work efficiently and smoothly on the paltform the will excute the code by handling complex not only naive oprations such as

  • defining and creating variables .

  • Loops , conditional and unconditional branches.

  • Classes , Objects , Member variables and Methods .

  • Functions creation , calls and returns .

  • Recursion issues .

  • Static and Global variables .

  • Including different Classes(Liberaries) .

  • ... etc.


Usage

  VMTranslator.exe [Filename(s)/path or directory name/path]

Notes

These are some sympols and rules that the translator uses/follows to perform it's job .


At docs/Examples folder some examples for VM files translated to asm .

Badges

C++

MIT License

virtual-machine-translator's People

Contributors

abdulrahman9901 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.