StaticCompiler.jl
StaticCompiler.jl copied to clipboard
MallocString or StaticString from a simple string
Hi, I try to get copmiled abspath() or pwd(). Therefore it would be great, if it possibe to construct a MallocString or StaticString from a "simple" Julia string. Is this possible?
The following function can be compiled:
function f()
a = @c_str("e")
b = @m_str("e")
println(a)
println(b)
0
end
using
compile_executable(b, (), "C:\\jul\\staticcompiler")
But as soon I use a local variable for the macro, I get LLVM IR errors when compiling:
function f()
a = "r"
@c_str(a)
0
end
The same negative result I get from using the constructors StaticString and MallocString:
function f()
b = MallocString("r")
0
end
function f()
b = StaticString("r")
0
end
In the test suites I don't find an example for constructing a MallocString or StaticString out from a String.
Do you have any ideas to get compiled constucting a MallocString or StaticString from a String?
The problem is that you cannot construct Julia String
s in StaticCompiled code — we would need libjulia for that. That is why there are the workarounds with string macros
so when you write
a = “r"
this is already not static-compileable, even if it’s only a temporary variable.
If you can get a C-style string from the system, that’s fine, and you can convert that to a MallocString or StaticString. If you could get your hands on a Julia string, you could convert that too, but the problem is you cannot make one in the first place