feat: replace CODE_NEW instruction with instantiate method call for class and Fn
Refactor the 'new' operator compilation to emit a method call to 'instantiate' on the class instead of using a dedicated bytecode instruction. This allows built-in types like Fn to override instantiation behavior, enabling `new Fn { ... }` to return the block argument directly. Remove the CODE_NEW opcode from the VM, compiler, and debug printer, and add native methods `class_instantiate`, `fn_instantiate`, `fn_new`, and `object_instantiate` to handle the new dispatch. Update test files to reflect the renamed `Function` class to `Fn`.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
IO.print((fn 0) is Function) // expect: true
|
||||
IO.print((fn 0) is Object) // expect: true
|
||||
IO.print((fn 0) is String) // expect: false
|
||||
IO.print((fn 0).type == Function) // expect: true
|
||||
IO.print((fn 0) is Fn) // expect: true
|
||||
IO.print((fn 0) is Object) // expect: true
|
||||
IO.print((fn 0) is String) // expect: false
|
||||
IO.print((fn 0).type == Fn) // expect: true
|
||||
|
||||
+2
-2
@@ -1,13 +1,13 @@
|
||||
IO.print(Num is Class) // expect: true
|
||||
IO.print(true is Bool) // expect: true
|
||||
IO.print((fn 1) is Function) // expect: true
|
||||
IO.print((fn 1) is Fn) // expect: true
|
||||
IO.print(123 is Num) // expect: true
|
||||
IO.print(null is Null) // expect: true
|
||||
IO.print("s" is String) // expect: true
|
||||
|
||||
IO.print(Num is Bool) // expect: false
|
||||
IO.print(null is Class) // expect: false
|
||||
IO.print(true is Function) // expect: false
|
||||
IO.print(true is Fn) // expect: false
|
||||
IO.print((fn 1) is Num) // expect: false
|
||||
IO.print("s" is Null) // expect: false
|
||||
IO.print(123 is String) // expect: false
|
||||
|
||||
Reference in New Issue
Block a user