Skip to content

feat: support multi-dimensional static initialisers #1579

@DavePearce

Description

@DavePearce

Summary

Currently, static initialisers work well for one-dimensional data (both in terms of inputs and outputs). However, they exhibit perhaps unexpected behaviour for multi-dimensional arrays. At this stage, its not completely clear to me what the right behaviour is.

Example 1 --- Multidimensional Input

static table(address:u16, flag:u1) -> (word:u8) {
  0x1, 0x2, 0x3, 0x4
}

pub output out(address:u16) -> (word:u8)

// copy input to output
fn main() {
  out[0] = table[0,0]
  out[1] = table[0,1]
  out[2] = table[1,0]
  out[3] = table[1,1]  
  return
}

This generates the output:

out = 0x01020304

This feels a little odd to me as, normally, arrays accesses bind with the most significant dimension first (e.g. in arr[x][y] is most significant).

Example 2 --- Multidimensional output

Likewise, the following cannot be made to compile for any replacement of ... other than the empty initialiser:

static table(address:u4, flag:u1) -> (left:u8, right:u4) {
  ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    zkcIssues related to ZkC language

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions