6.6 KiB
The Core Language
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 and stb libraries style design.
Simple drawing to window example
#import "Multimedia.core"
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
Features
- Debuggers(Visual Studio, Remedybg) fully work with the language, you can step through the program
- No external dependencies, you just setup clang and call build.bat
- 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
- Conditional compilation
- Runtime type reflection
- Typesafe variadic arguments
- Operator overloading
- Slices
- Multiple return values
What's missing ?
-
Typechecking - very strict typesystem, inspired by Go, no implicit conversions outside of special types like void or Any.
- Constant evaluation and constant folding - Folding and precomputing every expression that can be calculated at compile time.
- 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
- Infinite precision integers in constants using big ints! No more overflows or underflows (at least at compile time).
-
Module system
- Lazy evaluation of modules (unused code is not compiled or typechecked)
- Import module, load project file distinction
- Linking to libraries through importing a module, module calls
#linkand that is added to linked libraries.
-
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
-
Synchronize generated C code with original source using line directives so that debuggers work
- Fix overshoots when debugger goes to brace in c code
-
Expressions
- Compounds with named fields and numbered fields
- Functions calls with named arguments
- All the standard binary, unary expressions
- Pointer arithmetic and pointer as array
- Dot access expression needs a redesign because it doesn't handle expressions after the dot, requires identifiers
- Casting might need a redesign not sure. From '->' to 'cast', and maybe more options like Odin
transmute.
-
Runtime reflection
- Package of type and pointer which enables dynamic typing
- Types are values holding type ids, this way we can do if TypeOf(value) == S64 ;; blah
- Typesafe variadic arguments using []Any slice (no more var args!)
- Any semantics that make it easy to use (automatic unpacking to pointer and type)
- Optional type information dump which allows an application to recursively serialize the data. Something you would need special tools for in C++.
- Is the design of this correct? That's a lot of data.
-
Builtin data structures
- Arrays
- Slices
- Dynamic arrays. (Do we want this?)
- Hash tables. (Do we want this?)
-
Multiple return values
-
Polymorphism
- C like void type
- Dynamic typing using Any and operator overloading
- Generics aka compile time polymorphism aka parametric polymorphism
- Something akin to inheritence
- Something akin to C unions or Rust's enums
-
Operator overloading
- Binary operators
- Unary operators
- Bulletproof
- Assignment expressions?
-
Conditional compilation, you can include files based on a pattern:
- "$os_multimedia.core" expands to "win32_multimedia.core" or "unix_multimedia.core" depending on the platform.
-
Platforms
- Conditional compilation
- Windows
- Fully working
- Multimedia library
- Linux (Only tested on ubuntu)
- Paths
- Reading files
- Listing files
- Virtual memory
- Multimedia library (maybe using SDL)
-
Language constructs
- Standard constructs like if, for loop etc.
- Jai like using statement
- Defer statement
- Unions (or something like unions)
- Unnamed blocks
Building
- Install Visual Studio and Clang
- Run build.bat
Resources
Stuff that helped me a lot programming the compiler. Hopefully they also will be helpful to you!
- https://bitwise.handmade.network/ - series by Per Vognsen where he actually creates a C like language, very helpful, very hands on!
- https://hero.handmade.network/episode/code/day206/ - this episode of handmade hero started me on the entire compiler journey a long, long time ago.
- https://www.youtube.com/watch?v=TH9VCN6UkyQ&list=PLmV5I2fxaiCKfxMBrNsU1kgKJXD3PkyxO - I have rewatched this playlist many this, searching for keywords and ideas. Jonathan Blow's compiler was a big inspiration of mine when learning programming languages.
- A Retargetable C Compiler: Design and Implementation by Christopher W. Fraser and David R. Hanson - sometimes looked at this as a reference to figure stuff out. Very helpful resource on compiler construction, the way it's written reads more like documentation but you use what you have.
- https://github.com/JoshuaManton/sif - looked at this as a reference from time to time, author seems like a Jonathan Blow fan so it was a good resource informed by similar resources as I used.
- 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.
- https://github.com/gingerbill/odin - I sometimes peeked at the compiler to figure stuff out when I was confused about stuff. Also we get a free code indexing and syntax highlighting using odin sublime text plugin ! :D