Update README

This commit is contained in:
Krzosa Karol
2022-10-10 22:23:20 +02:00
parent 38ee15bb44
commit 7df42bf79b

View File

@@ -1,75 +1,39 @@
# The Core Language
A compiled language that assumes C as base reality but it also has lots of ideas taken from Jai, Go like type system, order indepent declarations using Ion algorithm. Syntax currently is whitespace significant. Made to practice language development. It has lot's of ideas from modern programming languages that you would not find in any compiler book. It supports **modules** combined with **ordered independent declarations** and **lazy typechecking**. Also **runtime reflection**, **slices** and other standard features you would find in C.
A statically typed systems programming language that **you shouldn't use**, I'm NOT joking.
The basic premise of the language is simplicity and debuggability,
reinforcing already useful ideas from C,C++,Go,Odin,Jai and shaving off round edges. In the future it might become
a single/two file, easily embeddable library language with optional fixed-size allocation scheme.
The language is currently **very debuggable**. It can produce readable C code with line directives. This allows you to debug the programs with Visual Studio with full source mapping, exactly like you would debug C programs.
## Using Windows API example
More examples can be found in /examples and /modules:
## Simple drawing to window example
``` odin
#import "KERNEL32.core"
#import "Base.core"
#import "Multimedia.core"
PAGE_SIZE :: 4096
Memory :: struct
commit : SizeU
reserve: SizeU
data : *U8
Reserve :: (size: SizeU): Memory
// C like compound expressions with named arguments
result := Memory{reserve=AlignUp(size, PAGE_SIZE)}
// Named arguments to function calls
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 := AlignUp(size, PAGE_SIZE)
total_commit := m.commit + commit_size
clamped_commit := ClampTopSizeU(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,
)
Assert(result != 0)
m.commit += adjusted_commit
return true
return false
Release :: (m: *Memory)
result := VirtualFree(m.data->*void, 0, MEM_RELEASE)
if result != 0
m.data = 0
m.commit = 0
m.reserve = 0
main :: (): int
StartMultimedia(title = "Hello people!")
for UpdateMultimedia()
if Mu.key[Key.Escape].down
Mu.quit = true
for y := 0, y < Mu.window.y, y+=1
for x := 0, x < Mu.window.x, x+=1
Mu.screen[x + y*Mu.window.x] = 0xFFFFFF00
```
## Simple math library example (operator overloading!)
## Features
``` odin
Vec3 :: struct ;; x: F32; y: F32; z: F32
Length :: (a: Vec3): F32 ;; return sqrtf(a.x*a.x + a.y*a.y + a.z*a.z)
Negate :: (a: Vec3): Vec3 ;; return {-a.x, -a.y, -a.z}
Dot :: (a: Vec3, b: Vec3): F32 ;; return a.x*b.x + a.y*b.y + a.z*b.z
"*" :: (a: Vec3, b: Vec3): Vec3 ;; return {a.x*b.x, a.y*b.y, a.z*b.z}
"*" :: (a: Vec3, b: F32) : Vec3 ;; return {a.x*b, a.y*b, a.z*b}
"+" :: (a: Vec3, b: Vec3): Vec3 ;; return {a.x+b.x, a.y+b.y, a.z+b.z}
"/" :: (a: Vec3, b: Vec3): Vec3 ;; return {a.x/b.x, a.y/b.y, a.z/b.z}
"/" :: (a: Vec3, b: F32) : Vec3 ;; return {a.x/b, a.y/b, a.z/b}
"-" :: (a: Vec3, b: Vec3): Vec3 ;; return {a.x-b.x, a.y-b.y, a.z-b.z}
```
* Debuggers(Visual Studio, Remedybg) fully work with the language, you can step through the program
* Compiles to C code, in the future it will also compile to bytecode and hopefully a raw x64 executable
* Very strict Go like type system with untyped literals
* Order independent declarations
* Module system, user namespaces the library, only the used library code gets compiled
* Windows and Linux(only tested on Ubuntu) support
* Runtime type reflection
* Typesafe variadic arguments
* Operator overloading
* Slices
* Multiple return values
## What's missing ?