janet-lang / jpm

Janet Project Manager
MIT License
70 stars 22 forks source link

Switch from case to match in cgen parsing #44

Closed pepe closed 2 years ago

pepe commented 2 years ago

After #43, where I used match for resolving in the emit-janet function, I examined where we are resolving actions and concluded that for many of them, usage of match with the new & rest is a better choice.

This PR also adds the implicit block for while when more than one statement is in its body.

pepe commented 2 years ago

I found some issues with array type definition I need to investigate.

pepe commented 2 years ago

So it looks to me that the problem was present before changes from this PR. With the code from the current master, when I run:

janet -l /jpm/cgen -e "(ir (defn fun [] int (def a (array int) (array 1)) (return (index a 0))))"

The script prints:

int fun() {
  (int[]) a = {1};
  return a[0];
}

The result does not seem to be the correct array type declaration.

pepe commented 2 years ago

The last commit redoes the array variable definition:

janet -l /jpm/cgen -e "(ir (defn fun [] int (def (array a) int) (return (index a 0))))"
# prints
int fun() {
  int a[];
  return a[0];
}

But I have feeling I fight the original intentions

pepe commented 2 years ago

I guess let's see