summary refs log tree commit diff stats
path: root/compiler/cbuilder.nim
Commit message (Collapse)AuthorAgeFilesLines
* use cbuilder for seq type generation (#24202)metagn2024-10-031-28/+81
| | | | | | | | | | | | | | `addSimpleStruct` is just so the compiler doesn't use so much extra computation on analyzing the `typ` parameter for `addStruct`, which doesn't change anything for `seq` types. We could probably still get away with using `addStruct` instead, or making `addStruct` accept `nil` as the `typ` argument but this would be even more computation. There were a lot of hidden issues with `addStruct` being a template & template argument substitution, so most of the behavior is moved into `startStruct`/`finishStruct` procs. This is turning out to be a lot of code for just a couple of changed lines, we might have to split `cbuilder` into multiple modules.
* use cbuilder for tuple/object generation (#24145)metagn2024-09-271-0/+121
based on #24127 Needs some tweaks to replace the other `struct` type generations, e.g. seqs, maybe by exposing `BaseTypeKind` as a parameter. C++ and codegenDecl etc seem like they are going to need attention. Also `Builder` should really be `distinct string` that one has to call `extract` on, but for this to be optimal in the current codegen, we would need something like: ```nim template buildInto(s: var string, builderName: untyped, body) = template `builderName`: untyped = Builder(s) body buildInto(result, builder): builder.add ... ``` but this could be a separate PR since it might not work with the compiler. The possibly-not-optimal alternative is to do: ```nim template build(builderName: untyped, body): string = var `builderName` = Builder("") body extract(`builderName`) result = build(builder): builder.add ... ``` where the compiler maybe copies the built string but shouldn't. --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>