ev3dev / lmsasm

Assembler for LEGO MINDSTORMS EV3
Other
7 stars 5 forks source link

block objects #5

Open dlech opened 5 years ago

dlech commented 5 years ago

Currently, block objects are not properly implemented.

Block objects have a couple of interesting properties:

  1. They share local variables with an "owner" object
  2. They have a trigger count n that must be > 0 and the object must be triggered n times before it actually starts (via OBJECT_TRIG)

So, we need to figure out how to encode these two properties in the assembly language.

Also we need to fix the allocation of local variables. There are comments in the LMS2012 source code that indicate that the object header for blocks should have a local variable size of 0. However, code generated by the official EV3 programming software uses the same size as the owner object instead of 0.

dlech commented 5 years ago

One idea I had for designating the "owner" of a block is only allowing block objects to be declared within the body of another block.

// compile error: block object cannot be top-level object
block Bad {
}

vmthread Thread1 {
    DATA8 v1

    block Block1 {
        // compile error: block cannot contain local variables
        DATA8 v2

        MOVE8_8(1,v1) // OK

        block Block2 {
             // block in block is OK
             // is owner Block1 or Thread1? probably Thread1 since it has the local variables
        }
    }
}
iCheh commented 5 years ago

Hello. Are there any changes in using a block object in a program?

dlech commented 5 years ago

No, these changes have not been made yet. So using block objects is limited at this time.