Skip to content

sondernextdoor/VMCompiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VM Compiler

WIP compiler written in C#. The compiler translates a small custom language into instructions for a simple virtual machine. The code is a work in progress and was created around the same time as the author's virtual machine project (2021/2022).

Language overview

The language resembles a very small imperative language with C-like syntax. Supported features include:

  • Data types: byte, word, dword, qword, string, bool, and determine.
  • Variables: declared using [type] [name] = [value];.
  • Functions: function name([param list]) returns [type] { body }.
  • Function calls with parameters.
  • Control flow: while(condition){ ... } and if(condition){ ... } with comparison operators such as ==, !=, >=, <=, <, >.
  • Built‑ins: print(string) and add(qword,qword) are predefined.

Comments start with //* and continue to the end of the line.

Example program

print("Hello, world!");

The corresponding output generated by the compiler is stored in samples/hello.asm and looks like:

entry strout "Hello, world!" ret

Building and running

A C# compiler (such as mcs from Mono or the .NET SDK) is required. To build the project using mcs:

mcs -out:Compiler.exe Compiler.cs

Running the resulting executable will assemble and execute main.vmc located next to the binary:

mono Compiler.exe

Replace mono with dotnet if you build using the .NET SDK. Since the codebase is incomplete, compilation may require additional dependencies or modifications.

See the samples directory for a minimal example.

About

A compiler and programming language for my virtual machine project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages