Skip to content
This repository has been archived by the owner on Dec 18, 2020. It is now read-only.

Should there be a makeArray primitive, and for what? #27

Open
Bastacyclop opened this issue Feb 10, 2020 · 2 comments
Open

Should there be a makeArray primitive, and for what? #27

Bastacyclop opened this issue Feb 10, 2020 · 2 comments
Labels
question Further information is requested

Comments

@Bastacyclop
Copy link
Member

Bastacyclop commented Feb 10, 2020

Currently we have a makeArray primitive that works very much like an array literal, except that it works with elements that are expressions, instead of plain data like literals do. Currently we only generate code for makeArray if indices are constant (we know which element to pick at codegen time).

  1. Why can our normal array literals not contain arbitrary expressions?
  2. Should we generate code for non-constant indices, and how?
  3. Why do we need array literals when we can use array constructors like makeArray?

Personally, I would like to solve both of these questions by removing the makeArray primitive. Instead of plain data, normal array literals would take elements of expression kind.

Additonnaly, a selectArray -- or differently named high-level construct -- would also allow to create arrays as a combination of generate and select. This would generate C code with if statements or ternaries to pick the right element. If indices are constant, we should simplify the branching away.

@rise-lang/core

@Bastacyclop Bastacyclop added the question Further information is requested label Feb 10, 2020
@bastian-koepcke
Copy link
Member

  1. A literal is always a value. The name would not be correct anymore if it was build out of expressions (e.g., 5 value, 2 + 3 expression).
  2. Would the combination of generate and select be able to generate code for non-constant indices, because generate already uses non-constant indices?

@Bastacyclop
Copy link
Member Author

Bastacyclop commented Feb 12, 2020

2. Would the combination of `generate` and `select` be able to generate code for non-constant indices, because `generate` already uses non-constant indices?

Yes, I already descibed that above. In more details for a 2-element array this would look like:

generate (i => select (i = 0) first second)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants