devicescript icon indicating copy to clipboard operation
devicescript copied to clipboard

implicitly call `.toString()` (maybe)

Open mmoskal opened this issue 2 years ago • 1 comments

The concatenation operator (+) as well as the indexing operator need to convert arguments to string. This may involve calling user-defined .toString() method.

The plan:

  • add a flag to devs_activation saying it's an implicit toString frame
  • when .toString() needs to be called move back pc by one, copy any stack items, attach them to the activation frame for toString(), reset stack to zero
  • upon return from toString frame - restore stack, in the calling opcode skip stuff based on the toString flag somehow

Alternative - STMT2_PLUS - stack is always empty

Alternative currently preferred - don't call .toString() implicitly and have the compiler warn about .toString()

mmoskal avatar Dec 13 '22 14:12 mmoskal

I want to add the toString function to String.prototype, and the compiler shows the same infomation that this issue mentioned. I am curious about what is the plan of this issue?

JackTam1993 avatar Sep 15 '23 06:09 JackTam1993