Files
corelang/README.md
Krzosa Karol 1f9a5fe81d Add README
2022-07-28 14:26:14 +02:00

44 lines
1.3 KiB
Markdown

# The Core Language
A compiled language with Go like type system, Jai like syntax, order indepent declarations using Ion algorithm. Made to practice language development. It has lot's of ideas from modern programming languages that you would not find in any compiler book.
## Language example code
``` C
#import "Windows.kl"
#import "base.kl"
PAGE_SIZE :: 4096
Memory :: struct
commit : SizeU
reserve: SizeU
data : *U8
reserve :: (size: SizeU): Memory
result := Memory{reserve=align_up(size, PAGE_SIZE)}
result.data = VirtualAlloc(
flProtect = PAGE_READWRITE,
dwSize = result.reserve,
flAllocationType = MEM_RESERVE,
lpAddress = 0)->*U8
return result
commit :: (m: *Memory, size: SizeU): Bool
commit_size := align_up(size, PAGE_SIZE)
total_commit := m.commit + commit_size
clamped_commit := clamp_top_sizeu(total_commit, m.reserve)
adjusted_commit := clamped_commit - m.commit
if adjusted_commit != 0
result := VirtualAlloc(
lpAddress = (m.data + m.commit)->*void,
dwSize = adjusted_commit,
flAllocationType = MEM_COMMIT,
flProtect = PAGE_READWRITE,
)
m.commit += adjusted_commit
return true
return false
```
Actual examples with comments explaining language features **can be found in /examples**