brenhinkeller / StaticTools.jl

Enabling StaticCompiler.jl-based compilation of (some) Julia code to standalone native binaries by avoiding GC allocations and llvmcall-ing all the things!
MIT License
167 stars 12 forks source link

Implement readline #8

Closed PallHaraldsson closed 2 years ago

PallHaraldsson commented 2 years ago

Hi, I'm trying your example, now works (in 1.8), real fast!, and am now modifying it.

I do see (as expected) for StaticCompiler:

GC-tracked allocations and global variables do work with compile, but the way they are implemented is brittle and can be dangerous. Allocate with care.

e.g. println(c"Hello world!") didn't work with it for me without the c.

But you made it work, could readline also be made to work?

I think it can't (at least not up to your package), since it tries to make the unsupported string, not your c-variant, and thus out of your hands, unless you implement:

t = readline_as_cstring()

would it be a lot of work? I like to reimplement one at the Debian Benchmark Game...

brenhinkeller commented 2 years ago

Ah, a version of readline that reads to StaticString or MallocString could probably be implemented

brenhinkeller commented 2 years ago

We have an implementation now! In addition to readline you may also consider readline! (in-place version) which is actually equivalent to gets! (which we added a little bit earlier)