Add examples, update README

This commit is contained in:
Krzosa Karol
2022-07-28 16:53:54 +02:00
parent eebb7e75e1
commit be508c0ae9
3 changed files with 116 additions and 95 deletions

View File

@@ -1,11 +1,11 @@
# The Core Language # 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. A compiled language with Go like type system, Jai like syntax, order indepent declarations using Ion algorithm. Made to practice language development, it's not supposed to be used. It has lot's of ideas from modern programming languages that you would not find in any compiler book.
## Language example code ## Language example code
``` C ``` C
#import "Windows.kl" W :: #import "Windows.kl"
#import "base.kl" #import "base.kl"
PAGE_SIZE :: 4096 PAGE_SIZE :: 4096
@@ -16,10 +16,10 @@ Memory :: struct
reserve :: (size: SizeU): Memory reserve :: (size: SizeU): Memory
result := Memory{reserve=align_up(size, PAGE_SIZE)} result := Memory{reserve=align_up(size, PAGE_SIZE)}
result.data = VirtualAlloc( result.data = W.VirtualAlloc(
flProtect = PAGE_READWRITE, flProtect = W.PAGE_READWRITE,
dwSize = result.reserve, dwSize = result.reserve,
flAllocationType = MEM_RESERVE, flAllocationType = W.MEM_RESERVE,
lpAddress = 0)->*U8 lpAddress = 0)->*U8
return result return result
@@ -29,23 +29,97 @@ commit :: (m: *Memory, size: SizeU): Bool
clamped_commit := clamp_top_sizeu(total_commit, m.reserve) clamped_commit := clamp_top_sizeu(total_commit, m.reserve)
adjusted_commit := clamped_commit - m.commit adjusted_commit := clamped_commit - m.commit
if adjusted_commit != 0 if adjusted_commit != 0
result := VirtualAlloc( result := W.VirtualAlloc(
lpAddress = (m.data + m.commit)->*void, lpAddress = (m.data + m.commit)->*void,
dwSize = adjusted_commit, dwSize = adjusted_commit,
flAllocationType = MEM_COMMIT, flAllocationType = W.MEM_COMMIT,
flProtect = PAGE_READWRITE, flProtect = W.PAGE_READWRITE,
) )
m.commit += adjusted_commit m.commit += adjusted_commit
return true return true
return false return false
// Examples that showcase language features can be found in /examples
``` ```
### Actual examples that explain language features can be found in /examples ## Building
# Building
1. Requires *Windows*, *Visual Studio* and *Clang* to be installed 1. Requires *Windows*, *Visual Studio* and *Clang* to be installed
1. Run *build.bat* 1. Run *build.bat*
1. They lived happily ever after 1. They lived happily ever after
## Done
[x] - Type as a parameter to a function, alloc :: (size: U64, type: Type)
[x] - Add token information to instructions
[-] - Mixing loads and imports leads to code duplication, is that what we want???
[x] - print those token lines nicely
[x] - Improve the python metaprogram
[x] - Implementing type Any
[x] - Runtime TypeInfo
[x] - Proper type Type support
[x] - Switch
[x] - Type aliases :: should probably be strictly typed, but assigning constant values should work
[x] - Array of inferred size
[x] - Casting pointers to and from void should be implicit
[x] - Multiple return values
[x] - Add c string
[-] - Should compound resolution use an algorithm to reorder compounds to initialize all fields in order
[x] - slices should be properly displayed in debugger
[x] - Imports inside of import shouldn't spill outside
[x] - Scope
[x] - #assert that handles constants at compile time and vars at runtime
[x] - Hex 0x42
[x] - Rewrite where # happen,
[x] - elif
[x] - cast ->
[x] - Remodel compound from call to {}
[x] - Fix codegen renames
[x] - Field access rewrite
[-] - Constants embeded in structs should be able to refer to other constants in that namespace without prefix
[-] - Order independent constants in structs
[-] - Fix recursive lambdas in structs
[x] - Error message when file not found
[x] - Better error messages when type difference
[-] - Fixing access to functions/structs, in C we cant have functons inside of structs / functions so we need to rewrite the tree
[x] - Emitting #line
[x] - Making sure debugger works
[x] - We need ++ -- operators
[x] - Arrays with size passed
[x] - Values inited to 0 by default
[x] - Some way to call foreign functions
[x] - We are parsing wrong here: (t.str=(&string_to_lex.str)[i]);
[x] - Test new operators, add constant eval for them
[x] - lvalue, rvalue concept so we cant assign value to some arbitrary weird expression
[x] - Passing down program to compile through command line
[x] - More basic types
[x] - Implementing required operations int128
[x] - Fix casting
[x] - More for loop variations
[x] - Add basic support for floats
[x] - Converting from U64 token to S64 Atom introduces unnanounced error (negates) - probably need big int
[x] - Add basic setup for new type system
[x] - Access through struct names to constants Arena.CONSTANT
[x] - Enums
[x] - Make sure pointer arithmetic works
[x] - Initial for loop
[x] - Enum . access to values
[x] - Character literal
[x] - Compiling and running a program
[x] - Infinite for loop
[x] - in new typesystem: Fix calls, fix all example programs
[x] - Fix arithmetic operations in new type system
[x] - Init statements, different kinds [+=] [-=] etc.
[x] - Struct calls
[x] - Operators: Bit negation, Not
[x] - Default values in calls
[x] - Resolving calls with default values
[x] - Pass statement
[x] - Lexer: Need to insert scope endings when hitting End of file
[x] - Resolving calls with named args, with indexed args
[x] - Structs
[x] - Struct field access
[x] - Struct field access with dots while compiling to arrows in c
[x] - Typespecs should probably be expressions so stuff like would be possible :: \*[32]int
[x] - Initial order independence algorithm
[x] - Think about compound expressions, unify with calls - maybe Thing(a=1) instead of Thing{a=1}

View File

@@ -1,11 +1,30 @@
main :: (): int main :: (): int
// Language has a bunch of standard builtin types: // Language has a bunch of standard builtin types:
// Signed integer types = S64, S32, S16, S8, int // Signed integer types
s64val: S64 = 0
s32val: S32 = 0
s16val: S16 = 0
s8val : S8 = 0
intval: int = 0
// Unsigned integer types = U64, U32, U16, U8, // Unsigned integer types = U64, U32, U16, U8,
u64val: U64 = 0
u32val: U32 = 0
u16val: U16 = 0
u8val : U8 = 0
// Floating point types = F64, F32 // Floating point types = F64, F32
f64val: F64 = 0
f32val: F32 = 0
// String type = String // String type = String
// Character type for compatibility with C = char string_val: String = "String type"
cstring_val: *char = "CString type"
assert(s64val == 0 && s32val == 0 && s16val == 0 && s8val == 0 && intval == 0 && u64val == 0 && u32val == 0 && u16val == 0 && u8val == 0 && f64val == 0 && f32val == 0)
assert(string_val[0] == 'S) //'
// @todo: Fix error here !!
// assert(cstring_val[0] == 'C) //'
// This is how we can assign variables // This is how we can assign variables
// There is no need for prefixes, compiler figures // There is no need for prefixes, compiler figures
@@ -38,9 +57,10 @@ main :: (): int
// When it comes to runtime variables it's a bit different // When it comes to runtime variables it's a bit different
// To do this we need a cast // To do this we need a cast
combining_types := this_is_s64_by_default->F64 + this_is_f64_by_default combining_types := this_is_s64_by_default->F64 + this_is_f64_by_default
combining_s64_and_s32 := signed_variable->S64 + this_is_s64_by_default
combining_unsigned_with_signed := unsigned_variable->F64 + combining_types
// Silence unused variable warning
assert(combining_s64_and_s32->F64 + combining_unsigned_with_signed > 0)
assert(signed_variable == 10 && unsigned_variable == 10)
assert(INT_VALUE == 10)
assert(FLOAT_VALUE == 124.125)
assert(this_is_f64_by_default == 15.1255)
assert(combining_types == 15.1255 + 20)

View File

@@ -57,6 +57,7 @@ For modules it's a bit different cause they should be distributed as valid.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@todo @todo
[ ] - Fix language_basics.kl string index error
[ ] - Split Bc into builder and interpreter [ ] - Split Bc into builder and interpreter
[ ] - Implement functions in the bytecode [ ] - Implement functions in the bytecode
@@ -97,80 +98,6 @@ For modules it's a bit different cause they should be distributed as valid.
[ ] - Conditional compilation #if [ ] - Conditional compilation #if
[ ] - Polymorphism - create declaration of a polymorphic thing, when it's called just copy it, replace types and typecheck normally, when someone calls again you just search for the instantiation again [ ] - Polymorphism - create declaration of a polymorphic thing, when it's called just copy it, replace types and typecheck normally, when someone calls again you just search for the instantiation again
@donzo
[x] - Type as a parameter to a function, alloc :: (size: U64, type: Type)
[x] - Add token information to instructions
[-] - Mixing loads and imports leads to code duplication, is that what we want???
[x] - print those token lines nicely
[x] - Improve the python metaprogram
[x] - Implementing type Any
[x] - Runtime TypeInfo
[x] - Proper type Type support
[x] - Switch
[x] - Type aliases :: should probably be strictly typed, but assigning constant values should work
[x] - Array of inferred size
[x] - Casting pointers to and from void should be implicit
[x] - Multiple return values
[x] - Add c string
[-] - Should compound resolution use an algorithm to reorder compounds to initialize all fields in order
[x] - slices should be properly displayed in debugger
[x] - Imports inside of import shouldn't spill outside
[x] - Scope
[x] - #assert that handles constants at compile time and vars at runtime
[x] - Hex 0x42
[x] - Rewrite where # happen,
[x] - elif
[x] - cast ->
[x] - Remodel compound from call to {}
[x] - Fix codegen renames
[x] - Field access rewrite
[-] - Constants embeded in structs should be able to refer to other constants in that namespace without prefix
[-] - Order independent constants in structs
[-] - Fix recursive lambdas in structs
[x] - Error message when file not found
[x] - Better error messages when type difference
[-] - Fixing access to functions/structs, in C we cant have functons inside of structs / functions so we need to rewrite the tree
[x] - Emitting #line
[x] - Making sure debugger works
[x] - We need ++ -- operators
[x] - Arrays with size passed
[x] - Values inited to 0 by default
[x] - Some way to call foreign functions
[x] - We are parsing wrong here: (t.str=(&string_to_lex.str)[i]);
[x] - Test new operators, add constant eval for them
[x] - lvalue, rvalue concept so we cant assign value to some arbitrary weird expression
[x] - Passing down program to compile through command line
[x] - More basic types
[x] - Implementing required operations int128
[x] - Fix casting
[x] - More for loop variations
[x] - Add basic support for floats
[x] - Converting from U64 token to S64 Atom introduces unnanounced error (negates) - probably need big int
[x] - Add basic setup for new type system
[x] - Access through struct names to constants Arena.CONSTANT
[x] - Enums
[x] - Make sure pointer arithmetic works
[x] - Initial for loop
[x] - Enum . access to values
[x] - Character literal
[x] - Compiling and running a program
[x] - Infinite for loop
[x] - in new typesystem: Fix calls, fix all example programs
[x] - Fix arithmetic operations in new type system
[x] - Init statements, different kinds [+=] [-=] etc.
[x] - Struct calls
[x] - Operators: Bit negation, Not
[x] - Default values in calls
[x] - Resolving calls with default values
[x] - Pass statement
[x] - Lexer: Need to insert scope endings when hitting End of file
[x] - Resolving calls with named args, with indexed args
[x] - Structs
[x] - Struct field access
[x] - Struct field access with dots while compiling to arrows in c
[x] - Typespecs should probably be expressions so stuff like would be possible :: *[32]int
[x] - Initial order independence algorithm
[x] - Think about compound expressions, unify with calls - maybe Thing(a=1) instead of Thing{a=1}
*/ */
#include "base.cpp" #include "base.cpp"