hlorenzi / customasm

💻 An assembler for custom, user-defined instruction sets! https://hlorenzi.github.io/customasm/web/
Apache License 2.0
719 stars 56 forks source link

Stack overflow / Index out of bounds with recursive rules #157

Closed Zsigio closed 1 year ago

Zsigio commented 2 years ago

If I reference the instruction I'm currently defining inside an asm{} block, I get a runtime error. (Index out of bounds when in the browser, stack overflow in cli) For example:

#ruledef {
  a => asm { a }
}
a

Kind of a silly issue; I encountered it while trying to create a recursive rule, something like this: (which also results in an error)

#ruledef {
  a {a} => {
    assert(a == 0)
    0`1
  }
  a {a} => {
    1`1 @ asm {
      a (a-1)
    }
  }
}
a 3 ; Expected result: 0b1110

Recursive rules allowed or not, the expected behavior would be an error message, and not a runtime error.