aardappel / lobster

The Lobster Programming Language
http://strlen.com/lobster
2.27k stars 120 forks source link

[Bug] write_file fails when transpiled to C++ #275

Closed jinyus closed 10 months ago

jinyus commented 10 months ago

Works in JIT mode but fails when compiled.

Test repo: https://github.com/jinyus/lobster_io_demo

Code

let content = read_file("input.txt")

assert(content)

print("input length: {content.length()}")

let result = write_file("output.txt", content)

print("write result: {result}")

Output

Lobster (C++)
input length: 20
write result: false

Lobster (JIT)
input length: 20
write result: true

How to reproduce

git clone https://github.com/jinyus/lobster_io_demo.git 
cd lobster_io_demo
./run.sh
aardappel commented 10 months ago

I am pretty sure this line is to blame: https://github.com/aardappel/lobster/blob/master/dev/src/compiler.cpp#L522

Such that if you changed that 2nd arg, or just a md src in your script, you'd end up with the output file there.

I can't test that right now though.. gotta think what the proper solution is.. will try later.

jinyus commented 10 months ago

You're right, a bit hacky but I got it working.

aardappel commented 10 months ago

@jinyus I just fixed the reliance on src being hardcoded. If you get latest, it should output the output file to the same dir the source was in instead