Skip to content

Imperative programming language implemented in C that transpiles to C

License

Notifications You must be signed in to change notification settings

Paul-Passeron/Rocker

Repository files navigation

Rocker Programming Langauge

Rocker is meant to be a compiled programming language, with aspects of imperative programming and modern features like pattern-matching

The memory management is occulted from the user, no pointers. This is in part thanks to the simple allocator library RockerAlloc

Features (Goal):

  • user defined types
  • pattern matching
  • int literals
  • char literals
  • string literals
  • memory safety

This language is transpiled to C for the moment

Example code:

let main() : void => {
  print("Hello from Rocker!\n");
}

Compilation

To bootstrap the compiler:

./bootstrapper/bootstrap2 RockerSRC/main.rkr -o rocker

To compile a file:

./rocker examples/hello_world.rkr
./a.out

Usage:

Usage:
        ./rocker [flags] <input file> [output file]
Possible flags:
        '-o' or '--output'    :  Sets the output path of the executable and of the transpiled C file
        '-t' or '--tmp'       :  Does not remove the temporary transpiled C files
        '-c' or '--transpile' :  Only transpiles the Rocker to C but does not compile to a native executable
        '-l' or '--lexer'     :  Prints the tokens contained in the file and included files
        '-h' or '--help'      :  Displays this message
        '-v' or '--verbose'   :  Prints infos and commands ran by the compiler

Progress

  • Simple rec and pro type generation
  • Simple Hello World example compiling and working
  • Simple recursion example compiling and working
  • Deprecate Tuples (using record types because all types are forward-declared)
  • Allow assignments
  • Accessing fields of record types
  • Add integer for loops
  • Add while loops
  • Maybe add a dynamic array type -> Figure out syntax for pushing / poping
  • Use string views for lexemes (limit the ammount of allocated data)
  • Add including files support
  • Improve including files support
  • The Rocker version of the compiler can lex/tokenize itself
  • The Rocker version of the compiler can parse itself
  • Self-Hosting
  • Made exit memory-safe
  • Typechecking
  • Add foreach loop for array types (iter loop)

TODO

  • Pattern matching product types
  • Get type of an expression (for match cases)
  • Generation of match expressions
  • Add variadic functions support
  • Support multi-dim arrays
  • Support accessing constructors without name binding
  • Mark and sweep garbage collector
  • Add '=' support for comparison between strings (s1 = s2 <=> streq(s1, s2))
  • Remake the parsing of expression (better handling of parenthesis and subs)

Warning

The C version of the compiler is not actively maintained, only the rocker one is. The reason for that is that there is a bootstrapper compiler that can compile the current rocker compiler and that it is simpler to write the compiler in Rocker rather than in C.