Indexing Proposal in Jade Release

In MufiZ's v0.7.0 Jade Release Milestone: I made an issue of bringing indexing support to Arrays and Float Vectors. This issue can be found [here](

Here's further thought of how we can implement this; however with more time to think about it after writing the initial issue, we will not be adding an OP_INDEX instruction, we will be adding two new instructions: OP_INDEX_GET and OP_INDEX_SET . To describe these better, let's look at an example:

var a = array(5);
push(a, 1, 2, 3, 4, 5);

for(var i=0; i < 5; i++){
    // update value by 1 then print 
    a(i) += 1; // will use OP_INDEX_SET
    print a(i); // will use OP_INDEX_GET

So OP_INDEX_SET is used to mutably set a value in the array at the given index (granted it in bounds), while OP_INDEX_GET it will be used to return the value associated at the given index.

The difficulty is recognizing when to use it, which involves checking if we are mutating the value. The thing with OP_INDEX_SET this is the expression requires an assignment operator to the right. While OP_INDEX_GET it can be assumed to be used anytime else.

The grammar can look like the following:

OP_INDEX_GET: <ident> <left paren> <integer constant> <right paren> <semicolon>
           Translated: <ident> ( <int const> ) ; 
OP_INDEX_SET: <ident> <left paren> <integer constant> <right paren> <assignment>
<expression> <semicolon> 
            Translated: <ident> ( <int const> ) <assign> <expr>;

In this grammar, we assume the following, <ident> is an identifier where the type is either ObjArray* or FloatVector*. Another is <assign> can be either one of the following:

  • =

  • +=

  • -=

  • *=

  • /=

I hope to slowly add this support into the Jade release and add in the end keyword inspired by Matlab for indexing. It will work like the following:

    <ident> ( <end> ) ...
<end> => <ident> => Array Type => return count-1 into stack

Did you find this article valuable?

Support MufiZ-Lang News by becoming a sponsor. Any amount is appreciated!