From 0d2a95ab89a208b8c01e16d71c0ab0cafa20393e Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Fri, 30 Sep 2022 16:43:11 +0200 Subject: [PATCH] Update README --- README.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f0d838c..897bdc6 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,11 @@ A compiled language that assumes C as base reality but it also has lots of ideas 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. -## Language examples +## Using Windows API example * More examples can be found in /examples and /modules -``` C -// -// Virtual memory abstraction using Windows API -// - +``` #import "KERNEL32.core" #import "Base.core" @@ -29,7 +25,10 @@ Allocate :: (size: U64): *void return HeapAlloc(ProcessHeap, 0, size) 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, @@ -63,10 +62,53 @@ Release :: (m: *Memory) ``` +## Operator overload example + +``` +"-" :: (a: Vec3, b: Vec3): Vec3 ;; return {a.x-b.x, a.y-b.y, a.z-b.z} +"-" :: (a: Vec3): Vec3 ;; return {-a.x, -a.y, -a.z } +``` + +## Unicode conversion example + +``` +Utf8ToUtf32 :: (c: *U8, max_advance: S64): U32, S64 + out_str: U32 + advance: S64 + if (c[0] & 0b10000000) == 0 + if max_advance >= 1 + c0 := c[0]->U32 + out_str = c0 + advance = 1 + + elif (c[0] & 0b11100000) == 0b11000000 + if (c[1] & 0b11000000) == 0b10000000 // Continuation byte required + if max_advance >= 2 + c0 := c[0]->U32; c1 := c[1]->U32 + out_str = (c0 & 0b00011111) << 6 | (c1 & 0b00111111) + advance = 2 + + elif (c[0] & 0b11110000) == 0b11100000 + if (c[1] & 0b11000000) == 0b10000000 && (c[2] & 0b11000000) == 0b10000000 // Two continuation bytes required + if max_advance >= 3 + c0 := c[0]->U32; c1 := c[1]->U32; c2 := c[2]->U32 + out_str = (c0 & 0b00001111) << 12 | (c1 & 0b00111111) << 6 | (c2 & 0b00111111) + advance = 3 + + elif (c[0] & 0b11111000) == 0b11110000 + if (c[1] & 0b11000000) == 0b10000000 && (c[2] & 0b11000000) == 0b10000000 && (c[3] & 0b11000000) == 0b10000000 // Three continuation bytes required + if max_advance >= 4 + c0 := c[0]->U32; c1 := c[1]->U32; c2 := c[2]->U32; c3 := c[3]->U32 + out_str = (c0 & 0b00001111) << 18 | (c1 & 0b00111111) << 12 | (c2 & 0b00111111) << 6 | (c3 & 0b00111111) + advance = 4 + + return out_str, advance +``` + ## What's missing ? - [x] Constant evaluation and constant folding - Folding and precomputing every expression that can be calculated at compile time. Which allows to check if a given constant expression is actually something that can be computed at compile time - - [ ] Constant expressions with concrete types + - [ ] Constant expressions with concrete types without casting - [x] Untyped types - Context dependent type assignment of constant expressions, this is a feature I really loved in Go, it makes constants work very well with a very strict type system and it makes errors like overflow of constants in C due to bad size specifier impossible - [x] Infinite precision integers in constants