adrian-thurston / colm

The Colm Programming Language
MIT License
166 stars 32 forks source link

[colm] iterating and modifying a struct field does not leave field changed #61

Closed adrian-thurston closed 4 years ago

adrian-thurston commented 5 years ago

The following modification does not work. From genf

    Packet->PacketDef = PacketDef

    Offset: int = 0
    for FD: pkt_field_def in Packet->PacketDef {
        switch FD.pkt_field_type
        case [`bool] {
            FD.Offset = Offset
            Offset = Offset + 1
        }           
        case [`long] {
            FD.Offset = Offset
            Offset = Offset + 8
        }
        case [`string] {
            FD.Offset = Offset
            Offset = Offset + 4
        }   
        case [list_type] {
            FD.Offset = Offset
            Offset = Offset + 4
        }   
    }
adrian-thurston commented 4 years ago

self-contained reproduction:

struct structure
    GD: grammar_def
end

def grammar_def
    [level1]

def level1
    [level2]

def level2
    [id]

token id /[a-z]+/

global S: structure = new structure()

S->GD = cons grammar_def "id" 

for L: level1 in S->GD
{
    L.level2 = cons level2 "hi"
}   

print "[S->GD]
adrian-thurston commented 4 years ago

This is a bug only in the sense that the necessary instructions are not implemented. In actuality it should be unchanged because a reference of a non-referencable thing is made. What should be happening is the iterator made constant and the assignment prevented.

adrian-thurston commented 4 years ago

Implemented missing instruction in 06fbe467c0b900ce20705ad3b4eb8e8454b4a56e and opened #99 to capture the need to set iterators constant.