Skip to content

WASM: Support const type #2296

Description

@ubaidsk

related #1485

$ cat integration_tests/const_01.py 
from lpython import Const, i32, i64, f32, f64

def test_const_variables():
    xci: Const[i32] = i32(0.0)
    xi: i32 = 0

    yci: Const[i64] = int(1)
    yi: i64 = int(1)

    xcf: Const[f32] = f32(2)
    xf: f32 = f32(2.0)

    ycf: Const[f64] = 3.0
    yf: f64 = 3.0

    print(xci, xi)
    print(yci, yi)
    print(xcf, xf)
    print(ycf, yf)

    assert xci == xi
    assert yci == yi
    assert xcf == xf
    assert ycf == yf

test_const_variables()
$ lpython_in_main integration_tests/const_01.py 
0 0
1 1
2.00000000e+00 2.00000000e+00
3.00000000000000000e+00 3.00000000000000000e+00
$ lpython_in_main integration_tests/const_01.py --backend wasm
warning: Unsupported variable type: real const
  --> integration_tests/const_01.py:10:5
   |
10 |     xcf: Const[f32] = f32(2)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ Only integer, floats, logical and complex supported currently

warning: Unsupported variable type: integer const
 --> integration_tests/const_01.py:4:5
  |
4 |     xci: Const[i32] = i32(0.0)
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ Only integer, floats, logical and complex supported currently

warning: Unsupported variable type: real const
  --> integration_tests/const_01.py:13:5
   |
13 |     ycf: Const[f64] = 3.0
   |     ^^^^^^^^^^^^^^^^^^^^^ Only integer, floats, logical and complex supported currently

warning: Unsupported variable type: integer const
 --> integration_tests/const_01.py:7:5
  |
7 |     yci: Const[i64] = int(1)
  |     ^^^^^^^^^^^^^^^^^^^^^^^^ Only integer, floats, logical and complex supported currently

code generation error: Only Integer, Float, Bool, Character, Complex variable types supported currently


Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that must be fixed).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions