diff --git a/README.md b/README.md index 88ac81e..fef6489 100644 --- a/README.md +++ b/README.md @@ -74,79 +74,55 @@ Stuff that helped me a lot programming the compiler. Hopefully they also will be * https://github.com/c3lang/c3c - I sometimes looked at C3 compiler as a reference, the author also let me use his big int library he wrote sometime in the past! Thanks a lot! * https://go.dev/blog/constants - article on golang type system, untyped types, constants that kind of stuff. - ## 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} \ No newline at end of file +- [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 types specified by the user. + +- [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. + - [x] Resolution of all untyped types in the typechecking stage. + - [x] Special case of booleans and their type propagation. + +- [x] Module system + - [x] Lazy evaluation of modules (unused code is not compiled or typechecked) + - [x] Import module, load project file distinction + +- [x] Order independent declarations - The ordering of functions in code files or modules does not matter, compiler figures all that stuff out for you. "main" can be wherever you want it to be and all functions should be available without problems. + - [ ] Should constants and others be disallowed inside of structs? + +- [x] Synchronize generated C code with original source using line directives so that debuggers work. + +- [ ] Expressions + - [x] Compounds with named fields and numbered fields + - [x] Functions calls with named arguments + - [x] All the standard binary, unary expressions + - [ ] Dot access expression needs a redesign + - [ ] Casting might need a redesign not sure + - [x] Pointer arithmetic and pointer as array + +- [ ] Tuples + - [x] Multiple return values from a function + - [ ] Some kind of tuple expressions + - [ ] Using tuples as single values without unpacking + +- [x] Runtime reflection + - [x] Dumping info + - [ ] Is the design of this correct? That's a lot of data. + +- [ ] Builtin data structures + - [x] Arrays + - [x] Slices + - [ ] Dynamic arrays + - [ ] Hash tables + +- [ ] Generics + +- [ ] Language constructs + - [x] If + - [x] For loops + - [x] Functions + - [x] Structures + - [ ] Unions (or something like unions) + - [x] Switch (but maybe needs redesign?) + - [ ] Unnamed blocks diff --git a/core_codegen_c_language.cpp b/core_codegen_c_language.cpp index b0e66ba..efd656c 100644 --- a/core_codegen_c_language.cpp +++ b/core_codegen_c_language.cpp @@ -302,9 +302,8 @@ gen_expr(Ast_Expr *ast, Ast_Type *type_of_var){ CASE(INDEX, Index){ gen("("); gen_expr(node->expr); - if(is_string(node->resolved_type)){ - if(!(type_of_var && type_of_var == type_pointer_to_char)) - gen(".str"); + if(node->index_original_type == type_string){ + gen(".str"); } else if(is_slice(node->index_original_type)){ gen(".data"); diff --git a/core_main.cpp b/core_main.cpp index ecd3f6b..964f0cd 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -98,6 +98,82 @@ For modules it's a bit different cause they should be distributed as valid. [ ] - 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 + +## 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} */ #include "base.cpp" diff --git a/core_typechecking.cpp b/core_typechecking.cpp index 05f4380..d924eab 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -1055,6 +1055,14 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context){ node->index_original_type = left.type; node->resolved_type = left.type->arr.base; + if(is_string(left.type)){ + if(left.type == type_pointer_to_char){ + node->resolved_type = type_char; + } + else { + node->resolved_type = type_u8; + } + } // @todo: type_architecture? // we only try to convert the index cause array can't be const diff --git a/examples/drawing_to_screen_using_windows_api.kl b/examples/drawing_to_screen_using_windows_api.kl index dad3608..22879f1 100644 --- a/examples/drawing_to_screen_using_windows_api.kl +++ b/examples/drawing_to_screen_using_windows_api.kl @@ -98,7 +98,6 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS frame_time := time() - frame_start_time - print_float(frame_time) if frame_time < requested_time_per_frame if good_scheduling time_to_sleep := (requested_time_per_frame - frame_time) * 1000