Flower is a programming language

July 2023 status update

What's going on?

Hey, back to writing some status updates!

Things are still moving quite slowly, but again, at least they are moving. After getting the better foundation for the VM and the disassembler, the work is already starting to pay off. While the new base there actually seems to make things progress a bit slower at first (which was expected), it is much easier now to make things correct and cross-reference them. I'd expect this to actually improve the development pace, if it hasn't done so already.

Anyways, the gist is that I'm still at getting all the bytecode and VM stuff into order.

Even more complex calculator

At one-year-mark, the compiler was a complex calculator. But there was a small hitch still. While the compiler passed all my tests, it used to do some automatic typecasting (e.g. varint types to appropriate fixed-size-integer types) and resolved some expressions internally before writing them to bytecode (e.g. 1 + 1 would just be a literal 2).

This made some things easy, but it also made it hard to write code that could be used as a simple tests for VM functionality. So, I needed to create a switch to the compiler to disable it, and make the calculator even more complex!

Oh boy did I run into problems. This innocent piece of code turned out to be an absolute nightmare.

def func main() -> s32 as {
    return -2;
}

return -2

The simple return -2; statement looks simple, but it required quite a lot of VM functionality that simply wasn't there. It worked fine when the compiler gave a hand and actually made the -2 an actual s32 literal automatically.

But now I had to deal how the VM could handle such a case. Disassembing the function breaks down to.

func main[<auto>]() -> s32:
    mov %0 <- <varint> 2
    neg <varint> %1 <- %0
    cast <s32> %2 <- <varint> %1
    ret <s32> %2

And of course, I didn't handle the mov, the neg or the cast correctly before, since they never came up before.

I'm still not sure if the codegen should create that bytecode, or would it be better to look-forward to get rid of the varint as soon as possible -- so the cast would be first instruction, and after that everything would've been simple and working already. But that requires more complex logic, and will be a exercise for a later date.

I'm really starting to get why people don't usually bake varint type into their language. But well, I still think the complexity it adds to the compiler is worth it. I already do see next problem with that coming, though.

Anyways, now the VM / disassembler handles this super-complex case like it should, and it only required me a week worth of work fixing stuff and pondering serialisation/deserialisation issues and so forth.

Stats

Well, stats are back. Enjoy.

 README.md                                                      |  36 +++++
 include/fir/bytecode.hpp                                       | 109 ++++++-------
 include/fir/opcodes.hpp                                        |  11 +-
 include/fir/program.hpp                                        |  54 +++++--
 include/fir/type.hpp                                           |  31 ++--
 include/fir/value.hpp                                          | 100 +++++++++++-
 include/fir/varint.hpp                                         |  70 +++++++--
 include/flvm/disassembler.hpp                                  |  12 ++
 include/flvm/flvm.hpp                                          | 121 ---------------
 include/flvm/flvm2.hpp                                         | 265 +++++++++++++++++++++++++++++++
 include/flvm/program.hpp                                       |   2 +
 src/fir/bytecode.cpp                                           |  84 +++++++---
 src/fir/program.cpp                                            | 109 +------------
 src/fir/value.cpp                                              |  34 ++--
 src/flower-parser/codegen/codegen_result.hpp                   | 164 +++++++++++++++++++
 src/{ => flower-parser}/codegen/flir.cpp                       | 313 ++++++++++---------------------------
 src/{ => flower-parser}/context/compiler_context.cpp           |   0
 src/{ => flower-parser}/context/definition.cpp                 |   0
 src/{ => flower-parser}/context/scope.cpp                      |   0
 src/{ => flower-parser}/context/symbol_table.cpp               |   0
 src/{ => flower-parser}/context/types.cpp                      |   0
 src/{ => flower-parser}/lexer/lexer-api.cpp                    |   0
 src/{ => flower-parser}/lexer/lexer.cpp                        |   0
 src/{ => flower-parser}/lexer/unicode.hpp                      |   0
 src/flower-parser/meson.build                                  |  43 +++++
 src/{ => flower-parser}/semantic/asg_node.cpp                  |   0
 src/{ => flower-parser}/semantic/generate_root_asg.cpp         |   0
 src/{ => flower-parser}/semantic/node_storage.cpp              |   0
 src/{ => flower-parser}/semantic/parser_util.cpp               |   0
 src/{ => flower-parser}/semantic/parser_util.hpp               |   0
 src/{ => flower-parser}/semantic/resolve_expression_chains.cpp |   0
 src/flvm/disassembler.cpp                                      | 144 +++++++++++++++++
 src/flvm/flvm_cli.cpp                                          |   9 +-
 src/flvm/meson.build                                           |   7 +-
 src/flvm/vm.cpp                                                | 449 -----------------------------------------------------
 src/meson.build                                                |  47 +-----
 tests/flvm/meson.build                                         |  12 +-
 tests/flvm/type.cpp                                            |   5 +
 tools/flc/flc.cpp                                              |   7 +-
 tools/meson.build                                              |   4 +-
 40 files changed, 1121 insertions(+), 1121 deletions(-)

Posted 2023-08-03 in status