feat: add toString method for numbers and strings with AS_NUM/AS_STRING macros
Introduce num_toString primitive that converts numeric values to string representation via sprintf with "%g" format, and add AS_NUM and AS_STRING accessor macros to vm.h for cleaner type extraction. Refactor existing numeric and string primitives to use these macros instead of direct struct member access. Include test files for number_toString and string_toString with basic equality checks (skipped due to unimplemented == operator).
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
// skip: == not implemented yet
|
||||
|
||||
io.write(123.toString == "123") // expect: true
|
||||
io.write(-123.toString == "-123") // expect: true
|
||||
io.write(-0.toString == "0") // expect: true
|
||||
|
||||
// TODO(bob): Floating point numbers.
|
||||
@@ -0,0 +1,4 @@
|
||||
// skip: == not implemented yet
|
||||
|
||||
io.write("".toString == "") // expect: true
|
||||
io.write("blah".toString == "blah") // expect: true
|
||||
Reference in New Issue
Block a user