oridb / mc

Myrddin Compiler
MIT License
387 stars 34 forks source link

Assigning a closure to a variable leads to errors #169

Closed typeless closed 6 years ago

typeless commented 6 years ago

var my_global : int = 123 const my_const : int = 123

const my_func = { std.put("hello\n") } const main = { var my_func2 = { std.put("hello\n") }

    std.put("&my_global:{} my_global:{}\n", &my_global, my_global)
    std.put("&my_const :{} my_const :{}\n", &my_const, my_const)
    std.put("&my_func  :{} my_func  :{}\n", &my_func, my_func)
    std.put("&my_func2 :{} my_func2 :{}\n", &my_func2, my_func2)

}

Output:

Building 6m -I /lib/myr in.myr ld -o a.out /lib/myr/_myrrt.o in.o -lstd -L/lib/myr -lsys &my_global:0x0000000000628a00 my_global:123 &my_const :0x0000000000628a04 my_const :123 0x0000000000411724: out of bounds access Internal error: /a.out: exited with signal 31


- Case 2

use std;

var my_global : int = 123 const my_const : int = 123

const my_func = { std.put("hello\n") } var my_func2 = { std.put("hello\n") } const main = { std.put("&my_global:{} my_global:{}\n", &my_global, my_global) std.put("&my_const :{} my_const :{}\n", &my_const, my_const) std.put("&my_func :{} my_func :{}\n", &my_func, my_func) std.put("&my_func2 :{} my_func2 :{}\n", &my_func2, my_func2) }

Output:

Building 6m -I /lib/myr in.myr ld -o a.out /lib/myr/_myrrt.o in.o -lstd -L/lib/myr -lsys in.o: In function main': //in.myr:20: undefined reference tomy_func2' //in.myr:20: undefined reference to `my_func2' FAIL: ld -o a.out /lib/myr/_myrrt.o in.o -lstd -L/lib/myr -lsys Internal error: mbld: exited with status 1



The only difference between case 1 and 2 is that the first `var my_func2` is declared in local and the other is in global. This is reproducible using the tip.
oridb commented 6 years ago

On Sun, 28 Jan 2018 23:19:46 -0800, Mura Li notifications@github.com wrote:

var my_func = { std.put("hello\n") }

We had a bug that skipped over the 'not yet supported' assertion:

https://github.com/oridb/mc/blob/30c662571c4f64f72171cca0efc7bedc59bd53fa/6/blob.c#L176

Anyways, I implemented the feature for you. Should be done as of 80f3197039716af937a80f3f3516c3c8af1a4b58.

-- Ori Bernstein

typeless commented 6 years ago

Now it works. Thanks 😄