SerenityOS / jakt

The Jakt Programming Language
BSD 2-Clause "Simplified" License
2.82k stars 241 forks source link

runtime+selfhost: Use `StringBuilder::appendff` instead of `append(format` #1568

Closed cg-jl closed 3 months ago

cg-jl commented 3 months ago

This way we can remove a lot of duplicated effort where we format into a String to then copy the string directly to the StringBuffer.

The parser had a little choke, where it would error in the rparen after varargs: ..). It thought it had just passed over a comma, which was the only possible case until now. runtime/prelude.jakt has appendff which is the test for it passing.

alimpfard commented 3 months ago

🤔 you can declare functions as variadic, why not add extern fn appendff(mut this, anon format: StringView, ..) -> void?

cg-jl commented 3 months ago

oh, I searched through the samples and didn't find any tests so I thought you had dropped them! That is much easier 😉

alimpfard commented 3 months ago

I'm pretty bad at adding tests for things I add "on the way" to a different feature... oops!

cg-jl commented 3 months ago

Glad the tests run under Windows. My build is broken under Windows; the linker shows garbage errors about StaticDebug and StaticRelease mixed with bad encoding:

sample ``` [ FAIL ] tests/codegen/type_pretty_printers.jakt : error LNK2038: se detectaron diferencias para 'RuntimeLibrary': el valor 'MTd_StaticDebug' no coincide con el valor 'MT_StaticRelease' en ns_level_circular_dependency-0b4664.o LINK : warning LNK4098: la biblioteca predeterminada'libcmtd.lib' entra en conflicto con otras bibliotecas; use la biblioteca /NODEFAULTLIB:biblioteca jakt_main_amd64-unknown-windows-unknown.lib(Main.cpp.obC:j\)U s:e resr\rgosru sL\NAKp2p0D3a8t:a \sLeo cdaelt\eTcetmapro\nj adkitfteersetn\cjiaakst tpeasrta- t'm_pI-T0E\RoAuTtOpRu_tD E:B UfGa_tLaElV EeLr'r:o re lL NvKa1l3o1r9 :'2 'd infoe rceonciinacsi ddee tceocnt aedla sv:a l3o4r '0' en optional_chaining_class-e4be19.o jakt_main_amd64-unknown-windows-unknown.lib(Main.cpp.obj) : error LNK2038: se detectaron diferencias para 'RuntimeLibrary': el valor 'MTd_StaticDebug' no coincide con el valor 'MT_StaticRelease' en optional_chaining_class-e4be19.o LINK : warning LNK4098: la biblioteca predeterminada'libcmtd.lib' entra en conflicto con otras bibliotecas; use la biblioteca /NODEFAULTLIB:biblioteca jakt_main_amd64C-:u\nUksneorwsn\-gwsiunsd\oAwpsp-Duantkan\oLwonc.alli\bT(eMmapi\nj.ackptpt.eosbtj\)j a:k tetrersotr- tLmNpK-220\3o8u:tp uste : dfeatteaclt aerrorno rd iLfNeKr1e3n1c9i:as dpiafrear e'n_cIiTaEsR AdTeOtRe_cDtEaBdUaGs_:L E3V6E L': el valor '2' no coincide con el valor '0' en optional_chaining-3b051e.o jakt_main_amd64-unknown-windows-unknown.lib(Main.cpp.obj) : error LNK2038: se detectaron diferencias para 'RuntimeLibrary': el valor 'MTd_StaticDebug' no coincide con el valor 'MT_StaticRelease' en optional_chaining-3b051e.o LINK : warning LNK4098: la biblioteca predeterminada'libcmtd.lib' entra en conflicto con otras bibliotecas; use la biblioteca /NODEFAULTLIB:biblioteca ```

The garbage is probably due to an encoding mishap since we use SetConsoleOutputCp(UTF8) and lld-link probably expects it to stay as UTF16.