Using the Compiler

To compile your source files first save your code as a text file (Or any thing else really). Make sure you save were you installed the Diamond SDK. Then goto the directory were you installed the Diamond SDK. There you should find a program called 'diamond_c.exe'. This is the Diamond compiler , you can either drag your source file into the compiler or , open up the command prompt and change your working directory (using the cd command) to your installation directory. Now just type 'diamond_c <source file name>' (Make sure you replace <source_file_name> with the name of the file you want to compile). Next after we compile our code there should be a .RDYCMP file somewere. Just click on the file and it will assemble its self. The file that ends with .GEX is your program , just double click on it to run it.

Using the Assembler

The Diamond compiler just generates Intermediate Language code , An Intermediate Language is an assembly language used by a Virtual Machine. The program called gxbcc (Or VASM if you are using newer versions) is the program that assembles the Intermediate Language code and compiles it into Bytecode. Bytecode is binary data that is run by the Virtual Machine. You can write programs in the Intermediate Language just like Diamond. So if you want to write a program in the IL language just save your source file then drag it into the gxbcc.exe (Or VASM.exe) and there you go , you have a progam!


Diamond is a easy language to learn and is designed to be easy. A Hello world Program would look like this


Hello world

import diamond.core

module Application

   void main()
      PrintLine("Hello World!")


The line that says "import diamond.core" imports all the functions from the diamond library. (This has all the basic functions like PrintLine) Then we need to make a module. A module is a static class. This means that it is not an object. The virtual machine now needs to find a function to execute. This is called an entrypoint. The first function that is called by the Virtual machine (The beginning of our code) always needs to be called main. Also it needs to begin with a void and end with a () to specify that it is a function. A void means that our function will not return a value. You need to end modules , classes , and functions with end.

A simple Name program

Alright now for a more advanced program. Lets make a program that will ask the user for his/her name then say hi to the user using there name. Alright so we need to import a diamond.core library so we can use the basic functions. Now lets make a module called Program. Ok now we have define our main function and write our code. Lets declare a variable called a string. A string is a list of characters. Strings are in enclosed by double quotes. We need to type string then a name. Our name can be anything we want but lets call ours name. But before we give it a value lets tell the user to type there name. So lets use the Print function to write a message. So type Print("What is your name"). Now on our next line lets give the string name a value. We are going to assign it to the return value of a function called wait. Wait lets the user type stuff and stops the program until they hit Enter. So lets type name = wait(). Ok now that we got the users name lets say hi to him. So lets use the PrintLine function to tell the user his/her name. So type PrintLine("Your name is: " + name). This add "Your name is: " and the value of name together then print them out. If you missed anything here is all the code.


import diamond.core

module Program

   void main()
      string name
      Print("What is your name:")
      name = wait()
      PrintLine("Your name is: " + name)


The IF Statement

The IF Statment

Last edited Aug 7, 2011 at 12:00 AM by Grunt, version 9


No comments yet.