Skip to content

Typecast constants in compile time #244

Description

@neilsf

Members of an expression are converted to the same type in runtime only. For example, the expression

DIM x AS FLOAT, y AS FLOAT
x = y + 1

will be compiled to the following runtime code sequence:

  1. Push y as float onto stack
  2. Push 1 as byte onto stack
  3. Convert top byte on stack to float
  4. Add top two floats on stack
  5. Pull float result off of stack

We should avoid conversion in runtime and do the work in compile time.

Note: using floating point literals solves the problem, but programmers aren't always aware of this, e. g:

x = y + 1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions