Skip to content
Pieter van Ginkel edited this page Jun 13, 2015 · 4 revisions

As much of the standard library of rjs is implemented in JavaScript. To make it easier to implement the standard library as polyfills, the cast expression has been added to the language. This feature is only available for setup code and cannot be enabled via a public API.

The cast operator has as the following grammar

cast_expr ::= '(' type ')' expr ;

type ::=
    'sprim'  // ToPrimitive with String as the hint
  | 'nprim'  // ToPrimitive with Number as the hint
  | 'prim'   // ToPrimitive without a hint
  | 'bool'   // ToBoolean
  | 'number' // ToNumber
  | 'int'    // ToInteger
  | 'i32'    // ToInt32
  | 'u32'    // ToUint32
  | 'u16'    // ToUint16
  | 'string' // ToString
  | 'object' // ToObject
  ;

In the interpreter, the integer operations are cast back to a floating point number (i.e. a JsNumber). The JIT compiler will actually use these casts both as a cast operation and as type hints to force lowering the IR instructions and locals to the correct type.

Clone this wiki locally