Giter Site home page Giter Site logo

Comments (10)

FanyuYe avatar FanyuYe commented on May 13, 2024

Hi. For declaring a variable with an array type I used "&[i32]" rather than "[i32]". Hope this helps.

from impala.

cod3monk avatar cod3monk commented on May 13, 2024

@FanyuYe Where? In the struct definition? That leads to lvalue required for unary '&' operand

from impala.

FanyuYe avatar FanyuYe commented on May 13, 2024

This is because you try to assign value to it. So you have to declare it use 'mut' key word.
E.g.
let mut cache_sizes = ...;

from impala.

richardmembarth avatar richardmembarth commented on May 13, 2024
  • You can either use an definite array (of size 3):
struct CS {
    sizes : [i32 * 3],
    count : i32,
}

let cache_sizes = CS {sizes: [32*1024, 256*1024, 20*1024*1024], count: 3}; // in bytes

for i in range(0, cache_sizes.count) {
    print_int(cache_sizes.sizes(i));
} 

Writing to cache_sizes.sizes requires cache_sizes to be mutable: let mut cache_sizes.

  • You can use a reference to an indefinite array:
struct CS {
    sizes : &[i32],
    count : i32,
}   

let cache_sizes = CS {sizes: [32*1024, 256*1024, 20*1024*1024], count: 3}; // in bytes

for i in range(0, cache_sizes.count) {
    print_int(cache_sizes.sizes(i));
}

Writing to cache_sizes.sizes requires then sizes of the CS struct to be mutable: sizes: &mut[i32].

from impala.

cod3monk avatar cod3monk commented on May 13, 2024

The latter does not work here (also not with making cache_size mutable), the first I already had as a work-around.

from impala.

cod3monk avatar cod3monk commented on May 13, 2024

It is not a big issue, just an annoyance.

from impala.

leissa avatar leissa commented on May 13, 2024

Originally, the idea was to support variable length arrays and flexible array members as in C99. But this has never been thoroughly implemented. Also, we'd like to change a couple of things how anydsl handles arrays in future versions anyway.
However, in the meantime I can add a check in the semantic analysis which rejects such usage of indefinite arrays.

from impala.

cod3monk avatar cod3monk commented on May 13, 2024

Sounds good, would have saved me some time ;)

from impala.

leissa avatar leissa commented on May 13, 2024

Can I close this bug with the last commit?

from impala.

cod3monk avatar cod3monk commented on May 13, 2024

Works for me. Thanks

from impala.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.