kyleect / locks

A toy language branched from Lox to learn language implementation and tooling. Forked from loxcraft
https://kyleect.github.io/locks/#/docs
MIT License
0 stars 0 forks source link

Disassembler #65

Closed kyleect closed 10 months ago

kyleect commented 10 months ago

It would be really nice to be able to take the byte code the compiler outputs and visualize it as test

Example

fn fizzBuzz(n) {
  for (var i = 1; i <= n; i = i + 1) {
      if (i % 15 == 0) {
        print "FizzBuzz";
      }
      else if (i % 3 == 0) {
        print "Fizz";
      }
      else if (i % 5 == 0) {
        print "Buzz";
      }
      else {
        print i;
      }
  }
}

fizzBuzz(100);
0000 OP_CLOSURE          0 == '<function fizzBuzz>'
0002 OP_DEFINE_GLOBAL    1 == 'fizzBuzz'
0004 OP_GET_GLOBAL       1 == 'fizzBuzz'
0006 OP_CONSTANT         2 == '100'
0008 OP_CALL             1
0010 OP_POP
0011 OP_NIL
0012 OP_RETURN
kyleect commented 10 months ago

This is implemented in the docs page but there seems to be a weird issue with function names

Screenshot_20231116_164903_Chrome.jpg

kyleect commented 10 months ago

Another weird issue Screenshot_20231116_170013_Chrome.jpg

kyleect commented 10 months ago

Both of those issues are solved. Closing this now. Will open future issues for new things.