A compiler front-end and back-end built from scratch in 1 month.
Note
Please bear in mind Glory is a proof-of-concept, rather than a language that is intended to be used. There are no intentions of updating Glory at the moment.
Glory currently only supports NASM output for Windows 10. This means an external assembler and linker need to be installed onto your system to use Glory:
-
Install MinGW to
C:\MinGW
. -
In MinGW installation manager, install
mingw-32-base
bin.
- Hit
Apply Changes
-
Install NASM to
C:\MinGW\bin
. -
Go to
Advanced System Settings
on Windows. -
Click on
Environmental Variables
.
-
Select
Path
underUser Variables
and click theEdit
button. -
Click on
New
then writeC:\MinGW\bin
. -
Check if it works by opening cmd and running
nasm --version
andgcc --version
.
- Create a file called helloworld.asm.
global _main
extern _printf
segment .data
message: db 'Hello world', 10, 0
section .text
_main:
push message
call _printf
add esp, 4
ret
-
Cd to where you saved the asm file.
-
Assemble using
nasm -f win32 helloworld.asm
- Link with
gcc helloworld.obj -o helloworld.exe
- Run the exe from command prompt and check if it works.
Once the assembler and linker is setup on your system, you can install Glory from the Releases
section of the repository.
It is recommended to add glorycompiler.exe
as an environment variable, as this allows you to run the compiler from any directory.
- Create a new file ending with a
.glr
file extension.
- Run the compiler using:
glorycompiler [path to glr file]
- Run the compiled EXE through the command prompt.
- Multidimensional arrays
- Function call indexing
- Dead code elimination
- Recursion
- Order of operations (
1 + 2 * 3
is treated as1 + (2 * 3)
) - While loops
- No floats, strings or other data types/structures
- No exponentiation operator
- No bound checking for arrays
- No array literals
- Only able to print integers using
printInt()
int factorial(int n)
{
int answer = 1;
while n > 0
{
answer *= n;
n -=1 ;
}
return answer;
}
printInt(factorial(6));
Output: 720
int factorial(int n)
{
if n == 0
{
return 1;
}
else
{
return n * factorial(n-1);
}
}
printInt(factorial(5));
Output: 120
int[8] sort(int[8] arr)
{
int i = 0;
while i < 8
{
int j = 0;
while j < 8 - i - 1
{
if arr[j] > arr[j + 1]
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
j += 1;
}
i += 1;
}
return arr;
}
int[8] myArr; # = [10,2,5,3,0,10,120,25];
# The pain of having no array literals
myArr[0] = 10; myArr[1] = 2; myArr[2] = 5; myArr[3] = 3;
myArr[4] = 0; myArr[5] = 10; myArr[6] = 120; myArr[7] = 25;
int[8] sorted = sort(myArr);
int i = 0;
while(i < 8)
{
printInt(sorted[i]);
i+= 1;
}
Output: 0235101025120