tungsten banner

tungsten

32 devlogs
95h 55m 34s

Updated Project: I've updated the syntax, kept working on the language and added some new features
This is my own compiled programming language written in C++ 20 using the LLVM framework, the syntax is inspired by C++, Java and rust and it's a …

Updated Project: I’ve updated the syntax, kept working on the language and added some new features
This is my own compiled programming language written in C++ 20 using the LLVM framework, the syntax is inspired by C++, Java and rust and it’s a statically typed language, for more information read the README

This project uses AI

copilot mostly for fixing build and release workflows, figuring out templates errors and for looking up material on the llvm api

Demo Repository

Loading README...

Ricardo

Changelog

  • got destructors working again
  • made it so if you don’t define a default constructor or copy constructor they get defined automatically
  • got copy constructors working
  • improved a couple of error messages for references

WIP

  • adding class memeber access
0
Ricardo

Shipped this project!

i’m still working on fully implementing classes tho i belive i’m like 50% if not more done, i’m implementing them on a separate branch cause i usually only push to the master branch already complete features to keep it as clean as possible
that said, i’m super locked in with this project and the sidequest, and another 20h is waiting for me next week

Ricardo

Changelog

  • got multiple arguments class constructors working
  • completetly broke destructors being called at the end of the scope
  • reworked how constructors worked, making them actual constructors instead of factories

WIP

  • pushing everything to master branch (currently everything is in the classes branch)
  • fixing destructors being called at the end of the scopes
  • class member access
0
Ricardo

kept working on classes

Changelog

  • made the compiler automatically pass the struct to the class methods and destructor
  • added constructors being called when allocating a class and destructor being called when exiting the scope
  • added break and continue statements to use inside loops

WIP

  • being able to call constructors other than the default one
  • constructors being called for arrays of classes
  • accessing classes members
0
Ricardo

Changelog

  • added location to FunctionPrototypeAST for better errors during semantic analysis
  • added codegen for:
    • class methods (kinda of a WIP still)
    • class constructors
    • class destructor
0
Ricardo

I’m still working on implementing classes

Changelog

  • got class allocation working
  • got sizeof to work with classes
  • got typeofto work with classes
0
Ricardo

Changelog

  • kept working on implementing classes
  • added debug info for the members of a class
  • improved a couple of error messages for variables, functions and classes

in the pictures below you can see the debug information generated from my class

Attachment
Attachment
0
Ricardo

really small devlog

Changelog

  • started working on implementing classes
  • implemented class declaration parsing, which includes:
    • class declaration
    • class constructors
    • class destructors
    • private and public members and methods
0
Ricardo

lil changes i did while i was at school

Changelog

  • Added comparison operators for pointers
  • added detection for unreachable code to stop generating code after exit or ret if in the middle of the program
  • fixed (hopefully) Ubuntu workflow
  • started introducing classes

i made a little video about the new additions

0
Ricardo

Shipped this project!

Hours: 8.38
Cookies: 🍪 150
Multiplier: 17.95 cookies/hr

I’ve added some preatty cool stuff since last ship, from debugging information and code optimization to various targets for the compiler to build to

Ricardo

stilll trying to fix the ubuntu workflow but this time i actually fixed it

Attachment
0
Ricardo

ok, so this isn’t a devlog per se, but i had to fix the build on my computer which completetly broke so i had to rebuild LLVM from source and do lots of other stuff to get it to work again. you can see in the image me recompiling llvm from source, which by its own took 52 minutes

Attachment
0
Ricardo

huge changes this time

Changelog

  • added debug metadata for functions, locals, and parameters so i can finally debug my programs and not go crazy
  • added --strip flag to strip debug info from the executables
  • fixed a bug where assembly output also included LLVM IR in the same file
Attachment
0
Ricardo

this time it took a bit to implement these features, but i’d say it was really worth it

Changelog:

  • Added these target options for the compiler:
    • Assembly -> -S flag
    • Object file -> -C flag
    • LLVM IR -> -emit-llvm flag
0
Ricardo

yet another really small devlog

Changelog

  • fixed a crash caused by incorrect handling of pointer index access in function call arguments (e.g. argv[i])
  • updated call argument codegen to avoid unintended extra loads on indexed pointer values
  • kept only the required checks in the final implementation to avoid overcomplicating the code path
  • verified generated IR now passes indexed pointer values directly without double dereference
0
Ricardo

really short devlog for the vscode extension

Changelog

  • Added two new settings to the vscode extension:
    • Save before run
    • Default code optimization value
0
Ricardo

small but at the same time huge devlog, cause i finally added code optimization which i thought would take much longer but ended up taking only around 30m

Changelog

  • added code optimization using llvm::ModulePassManager following this tutorial
  • Improved error messages for functions and variables inside namespaces
0
Ricardo

Shipped this project!

Hours: 10.93
Cookies: 🍪 198
Multiplier: 18.16 cookies/hr

I’ve updated a couple of things and added other since the last ship, i’ve reworked the nameof,sizeof and typeof functions to work with a lot more stuff, added a const keyword (idk why it took me this long to add one) and reworked the type definition parsing, making it possible to declare both pointers to arrays and arrays of pointers, ecc.

Ricardo

finally a kinda short devlog for once

Changelog:

  • added parsing and semantic analysis for const variables, both local and global
  • updated the vscode extension to recognize the const keyword (i’m dumb and i recorded the video before adding it)
0
Ricardo

this one is also a big one cause i’ve had to fix a lot of stuff to make the new feature work

Changelog

  • restored type parsing so int[]* and int*[] are both accepted again
  • initialize uninitialized pointer variables to nullptr
  • updated new and free to follow the restored pointer semantics
  • simplified VariableDeclarationAST::codegen() by sharing the common init flow between globals and locals
0
Ricardo

Changelog

  • made nameof accept every statement which has a name, ex. function calls, index access, ecc.
  • made typeof accept every statement which has a type
  • made sizeof accept every statement which returns a variable or pointer which has a size and also accept a type on its own
  • reworked function calls to cast number types when passing them, ex.
    fun b(f32 fl) -> void {}
    fun main(i32 argc, char** argv) -> i32 {
       i32 a = 0:
       b(a): // this now works
    }
    
  • removed String as a type and just set it as a char* as i should’ve done since the start
0
Ricardo

Shipped this project!

Hours: 15.69
Cookies: 🍪 348
Multiplier: 22.15 cookies/hr

These are probably the biggest changes i made to my language yet:
i’ve finally introduced an actual type system, so no more num type and now i have lots of numeric types; and i also introduced namespaces, which were kinda hard to implement the parsing for

Ricardo

another pretty long devlog that’s the result of threee different commits:

Changelog:

  • started introducing namespaces
  • changed how namespaces were handled, from having an ast node for them to just keeping track of the current namespace prefix in the parser and adding it to the variable/function/class name, this way i’m not required to add other semantic analysis and codegen code
  • added parsing for qualified names for functions and variables both inside and outside namespace blocks as shown in the video and in this block of code:
namespace math {
   f64 pi = 3.141592653589793;
}
fun math::add(f32 a, f32 b) -> f32 {
   ret a + b;
}
0
Ricardo

finally a really small devlog for once:

Changelog:

  • Updated vscode extension with support for :
    • new types
    • builtin functions
    • format specifier in print and input functions
Attachment
0
Ricardo

this one is a long one cause it’s the result of two different commits which i forgot to make a devlog for

Changelog 1

  • Introduced the staticCast expression so now it’s possible to allocate stuff with malloc and cast the pointer type from void* to the type needed
  • Added the possibility to declare global variables by declaring them outside functions

Changelog 2

  • Added support for multiple numeric types:

    • int/i32
    • uint/u32
    • float/f32
    • double/ f64
    • i8
    • i16
    • i64
    • i128
    • u8
    • u16
    • u64
    • u128

    removed num

  • Fixed pointers assignment doing a copy assignment instead of assigning the address

0
Ricardo

Changelog:

  • added the type Reference which just like in C++ is a pointer which can’t be reassigned, tho contrary to c++ and like in rust, references have to be passed explicitly like this: fun(&ref);.
  • added the decay of arrays to pointers when passing them to functions which take pointers
0
Ricardo

Changelog

  • fixed how multidimensional arrays were allocated in memory, before if you did num[4][5] you’d actually get an array like this: num[5][4], so now i’ve inverted the way the array type gets initialized
  • reworked sizeof(), typeof() and nameof() to work with more expressions and not only variables, ex. index access operations
  • added a size() method to the Type base class
0
Ricardo

Shipped this project!

Hours: 23.16
Cookies: 🍪 425
Multiplier: 18.33 cookies/hr

SHIPPING AGAIN

since the last ship i’ve implemented a decent error handling system and also added an index access operator for arrays, i’ve also made sure it was possible to pass command line arguments to the programs made with tungsten.

Ricardo

added an index access operator which works for both pointers and arrays, even on multidimensional ones, i’m currently working on adding the new and free operators to allocate memory on the heap for both pointers and dynamic arrays

0
Ricardo

kept working on error and warning generation:
added a warning for unused variable expresions as shown in the picture below, fixed a bug where the filename inside the error would be wrong and also made it so functions would go through semantic analysis even if they have errors

Attachment
0
Ricardo

had to fix a couple of errors with error messages showing the wrong position of the error inside the code, i also added some color to the error messages and worked on improving the extension for the language

0
Ricardo

I reworked the error messages for both Parser.cppm and SemanticAnalyzer.cppm now they both follow this format

main.tgs:24:21: error: missing semicolon after ')'
24 | print("hello world")
                                   ^
Attachment
0
Ricardo

i refactored the error handling in the compiler.
i improved error handling in the function code generation by returning nullptr at the end of a function if an error was found instead of logging an error message and returning instantly.
I also enhanced error detection for missing semicolons, now when a statement has an error the parser will ignore every next token untill it finds the next semicolon as it’s possible to see in the video

Attachment
0
Ricardo

i started working on the compile options module adding argument parsing and error handling, reworked the main file for better clarity, added a filesystem library, also worked on the vscode extension for the language fixing the build and run shortcut, added an option to clear the terminal before running and reuse the same terminal every time instead of creating a new one

Attachment
Attachment
Attachment
0
Ricardo

Shipped this project!

Hours: 9.24
Cookies: 🍪 209
Multiplier: 22.61 cookies/hr

I built a compiler for my own programming language, i already submitted this during SoM but i’ve since cchanged the syntax and rewrote some of the code

Ricardo

fixed a couple bugs that made declaring function overloads crash the compiler and one that didn’t let you declare bool functions and variables

0
Ricardo

made base type follow the camelCase naming convention instead of PascalCase and kept classes and structs with PascalCase the same way that rust does it

Attachment
0
Ricardo

started reworking the syntax, lexer and parser for better readability

0