chaos-lang / chaos

The Chaos Programming Language
https://chaos-lang.org
GNU General Public License v3.0
280 stars 17 forks source link

Not freed symbols in the called function scope (compiler) #88

Closed mertyildiran closed 3 years ago

mertyildiran commented 3 years ago
any def anyF1()
    any a = false
    return a
end

print anyF1()
symbol_table

The output of above Chaos program with interpreter:

false
[start] =>
[end]

with compiler:

false
[start] =>
    {id: 2, name: (null), 2nd_name: (null), key: (null), scope: N/A, depth: 1, type: 3, 2nd_type: 0, value_type: 0, role: 0, param_of: } =>
[end]

means that in case of compiler there are variables leaking.

mertyildiran commented 3 years ago

Another case:

num def f7()
    num x = 5
    return x
end

num def f6(num x)
    num y = x - 1
end {
    y == 1 : f7()
}

num def f5(num x)
    num y = x - 1
end {
    y == 2 : f6(y)
}

print f5(3)
symbol_table

Output:

5
[start] =>
    {id: 0, name: (null), 2nd_name: x, key: (null), scope: N/A, depth: 0, type: 1, 2nd_type: 3, value_type: 4, role: 1, param_of: f6, value: N/A} =>
    {id: 1, name: (null), 2nd_name: x, key: (null), scope: N/A, depth: 0, type: 1, 2nd_type: 3, value_type: 4, role: 1, param_of: f5, value: N/A} =>
    {id: 7, name: (null), 2nd_name: (null), key: (null), scope: (null), depth: 3, type: 1, 2nd_type: 0, value_type: 1, role: 0, param_of: , value: 5} =>
    {id: 9, name: (null), 2nd_name: (null), key: (null), scope: , depth: 2, type: 1, 2nd_type: 0, value_type: 1, role: 0, param_of: , value: 5} =>
[end]
mertyildiran commented 3 years ago

Fixed with: