https://github.com/vardan2009/kitelang
hobby programming language compiler written in C++
https://github.com/vardan2009/kitelang
assembly cmake compiler compilers cpp lowlevel programming-language x86 x86-64
Last synced: 6 months ago
JSON representation
hobby programming language compiler written in C++
- Host: GitHub
- URL: https://github.com/vardan2009/kitelang
- Owner: Vardan2009
- Created: 2024-09-01T12:21:01.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-24T20:14:55.000Z (over 1 year ago)
- Last Synced: 2024-10-24T21:31:31.188Z (over 1 year ago)
- Topics: assembly, cmake, compiler, compilers, cpp, lowlevel, programming-language, x86, x86-64
- Language: C++
- Homepage:
- Size: 143 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Kite Programming Language
Kite is a very simple low-level programming language.\
It provides direct access to memory and hardware with pointers and registers, allowing for system-level programming with minimal abstraction.\
This repository contains a simple compiler for it written in C++ that generates 64bit x86 ELF assembly (tested with NASM 2.15.05 on Linux x86_64)
## Showcase
- Hello World!
```
#include
global _start
fn _start() : byte {
print("Hello, World!")
return 0
}
```
- Variables (and basic arithmetic)
```
#include
global _start
fn _start() : byte {
let x : byte = 9
let y : byte = 10
print("x: ")
printi(x)
printc('\n')
print("y: ")
printi(y)
printc('\n')
print("x + y: ")
printi(x + y)
printc('\n')
return 0
}
```
- Functions
```
#include
global _start
fn _start() : byte {
printi(factor(10, 5))
return 0
}
fn factor(a : int64, b : int64) : int64 {
return a * b
}
```
- Pointers
```
#include
global _start
fn _start() : byte {
let value : byte = 20
let vptr : ptr8 = &value
print("The Value: ")
printi(value)
printc('\n')
print("The Address: ")
printi(vptr)
printc('\n')
print("Dereferenced Pointer Value: ")
printi(*vptr)
printc('\n')
return 0
}
```
- User Input
```
#include
global _start
fn _start() : byte {
; allocate space for input reading
let buf : char[512]
; read line into buffer
readln(buf, 512)
return 0
}
```
- File Operations
```
#include
#include
global _start
fn _start() : byte {
; Open file and get file descriptor
let fd : int64 = fopen("/test.txt")
; if file descriptor is invalid
if fd < 0 {
print("Failed to open file!\n")
return 1
}
; allocate space for file reading
let buf : char[2048]
; read into buffer
readfd(fd, buf, 2048)
; print the buffer
print(buf)
; close the file
fclose(fd)
return 0
}
```