summary refs log tree commit diff stats
path: root/compiler/cgen.nim
Commit message (Collapse)AuthorAgeFilesLines
* * fix for the debug line info code generation (#23488)Nikolay Nikolov2024-04-221-19/+66
| | | | Previously, in certain cases, the compiler would generate debug info for the correct line number, but for the wrong .nim source file.
* allow having {.noinit.} on a complex type avoid memsets to 0 for its … ↵heterodoxic2024-04-181-1/+1
| | | | | | | | | | | | | | | | | | | | | (#23388) …instantiations (C/C++ backend) AFAIK, #22802 expanded `noinit`'s utility by allowing the pragma to be attached to types (thanks @jmgomez !). I suggest broadening the scope a bit further: try to avoid `nimZeroMem`s on a type level beyond imported C/C++ types[^1], saving us from annotating the type instantiations with `noinit`. If this change is deemed acceptable, I will also adjust the docs, of course. Adding tests for this change seems a bit problematic, as the effect of this type annotation will be to work with uninitialized memory, which *might* match 0 patterns. [^1]: "complex value types" as already defined here: https://github.com/nim-lang/Nim/blob/94c599687796f4ee3872c8aa866827b9ed33f52b/compiler/cgen.nim#L470-L471
* apply the new mangle algorithm to JS backend for parameters and procs (#23476)ringabout2024-04-051-1/+2
| | | | | | | | | | | | | | the function name extension encoded by paths could be useful for debugging where the function is from Before: ```js function newSeq_33556909(len_33556911) ``` After: ```js function newSeq__system_u2477(len_p0) ```
* [Cpp] Fixes an issue when mixing hooks and calls (#23428)Juan M Gómez2024-03-211-0/+1
|
* fixes #20945; fixes #18262; provides C API `NimDestroyGlobals` for ↵ringabout2024-03-041-0/+23
| | | | | | | | | static/dynlib libraries (#23357) fixes #20945 fixes #18262 todo - [ ] perhaps export with lib prefix when the option is enabled
* make use of C++11's auto type deduction for temporary variables (#23327)heterodoxic2024-03-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is just one of those tiny steps towards the goal of an "optimized" C and C++ codegen I raised elsewhere before - what does me babbling "optimized" mainly entail? (not mutually-exclusive ascertainment proposals following:) - less and simplified resulting code: easier to pick up/grasp for the C/C++ compiler for to do its own optimization heuristics, less parsing effort for us mere humans trying to debug, especially in the case of interop - build time reduction: less code emission I/O, runtime string formatting for output... - easier access for fresh contributors and better maintainability - interop improvements - further runtime optimizations I am eagerly looking forward to the results of the LLVM-based undertakings, but I also think we can do a bit better (as outlined above) with our current C/C++ backends till those come to fruition. **Long story short**: this PR here focuses on the C++ backend, augmenting the current codegen method of establishing "temporary" variables by using C++11's auto type deduction. The reasons for adopting an "Almost Always Auto" style have been collected [here ](https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/) for the C++ world. For those hopping between C++'s and Nim's realms, this change also results in a bit less code and less work for the codegen part (no redundant `getTypeDesc`s): no need to tell the C++ compiler the type it already knows of (in most cases).
* fixes regression #22909; don't optimize result init if statements can raise ↵ringabout2024-02-011-9/+19
| | | | | | | | | | | | | | | | which corrupts the compiler (#23271) fixes #22909 required by https://github.com/nim-lang/Nim/pull/23267 ```nim proc foo: string = assert false result = "" ``` In the function `foo`, `assert false` raises an exception, which can cause `result` to be uninitialized if the default result initialization is optimized out
* fixes #22597; avoid side effects for call returning openArray types (#23257)ringabout2024-01-261-0/+1
| | | | | | | | | | | | | | fixes #22597 ```nim proc autoToOpenArray*[T](s: Slice[T]): openArray[T] = echo "here twice" result = toOpenArray(s.p, s.first, s.last) ``` For functions returning openarray types, `fixupCall` creates a temporary variable to store the return value: `let tmp = autoToOpenArray()`. But `genOpenArrayConv` cannot handle openarray assignements with side effects. It should have stored the right part of the assignment first instead of calling the right part twice.
* type refactoring: part 2 (#23059)Andreas Rumpf2023-12-131-1/+1
|
* Types: Refactorings; step 1 (#23055)Andreas Rumpf2023-12-121-2/+2
|
* enable vtable implementation for C++ and make it an experimental feature ↵ringabout2023-11-301-2/+1
| | | | | | | | | | | (#23004) follow up https://github.com/nim-lang/Nim/pull/22991 - [x] turning it into an experimental feature --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* rework the vtable implementation embedding the vtable array directly with ↵ringabout2023-11-281-4/+10
| | | | | | | | | | | | | | | | | | | | | | | | new strictions on methods (#22991) **TODO** - [x] fixes changelog With the new option `nimPreviewVtables`, `methods` are confined in the same module where the type of the first parameter is defined - [x] make it opt in after CI checks its feasibility ## In the following-up PRs - [ ] in the following PRs, refactor code into a more efficient one - [ ] cpp needs special treatments since it cannot embed array in light of the preceding limits: ref https://github.com/nim-lang/Nim/pull/20977#discussion_r1035528927; we can support cpp backends with vtable implementations later on the comprise that uses indirect vtable access --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* prepare for the enforcement of `std` prefix (#22873)ringabout2023-10-291-6/+6
| | | follow up https://github.com/nim-lang/Nim/pull/22851
* NIR: progress (#22817)Andreas Rumpf2023-10-121-1/+1
| | | | | | Done: - [x] Implement conversions to openArray/varargs. - [x] Implement index/range checking.
* NIR: Nim intermediate representation (#22777)Andreas Rumpf2023-10-111-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Theoretical Benefits / Plans: - Typed assembler-like language. - Allows for a CPS transformation. - Can replace the existing C backend by a new C backend. - Can replace the VM. - Can do more effective "not nil" checking and static array bounds checking. - Can be used instead of the DFA. - Easily translatable to LLVM. - Reasonably easy to produce native code from. - Tiny memory consumption. No pointers, no cry. **In very early stages of development.** Todo: - [x] Map Nim types to IR types. - [ ] Map Nim AST to IR instructions: - [x] Map bitsets to bitops. - [ ] Implement string cases. - [ ] Implement range and index checks. - [x] Implement `default(T)` builtin. - [x] Implement multi string concat. - [ ] Write some analysis passes. - [ ] Write a backend. - [x] Integrate into the compilation pipeline.
* `constructor` now uses `result` instead of `this` (#22724)Juan M Gómez2023-09-191-5/+1
|
* implements RFC: [C++] Constructors as default initializers (#22694)Juan M Gómez2023-09-141-4/+8
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* produce better code for object constructions and 'result' [backport] (#22668)Andreas Rumpf2023-09-111-6/+16
|
* fixes #22680 Nim zero clear an object inherits C++ imported class when a ↵Juan M Gómez2023-09-111-3/+10
| | | | proc return it (#22684)
* fixes #22669 constructor pragma doesnt init Nim default fields (#22670)Juan M Gómez2023-09-101-0/+5
| | | | | | | fixes #22669 constructor pragma doesnt init Nim default fields --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #22679 Nim zero clear an object contains C++ imported class when a ↵Juan M Gómez2023-09-101-3/+4
| | | | proc return it (#22681)
* Fix #22366 by making nimlf_/nimln_ part of the same line (#22503)Alberto Torres2023-08-181-2/+2
| | | Fix #22366 by making nimlf_/nimln_ part of the same line so the debugger doesn't advance to the next line before executing it
* fixes #22469; generates nimTestErrorFlag for top level statements (#22472)ringabout2023-08-141-2/+2
| | | fixes #22469; generates `nimTestErrorFlag` for top level statements
* `initNodeTable` and friends now return (#22444)ringabout2023-08-111-1/+1
|
* `getTemp` and friends now return `TLoc` as requested (#22440)ringabout2023-08-101-3/+3
| | | getTemp and friends now return `TLoc`
* `initLocExpr` and friends now return `TLoc` (#22434)ringabout2023-08-101-21/+14
| | | `initLocExpr` and friends now return TLoc
* makes asmnostackframe work with cpp member #22411 (#22429)Juan M Gómez2023-08-091-3/+4
|
* fix #22287 nimlf_ undefined error (#22382)Bung2023-08-081-0/+1
|
* use out parameters for getTemp (#22399)ringabout2023-08-071-18/+10
|
* [C++] Member pragma RFC (https://github.com/nim-lang/RFCs/issues/530) (#22272)Juan M Gómez2023-08-071-2/+2
| | | | | | | | | | * [C++] Member pragma RFC #530 rebase devel * changes the test so `echo` is not used before Nim is init * rebase devel * fixes Error: use explicit initialization of X for clarity [Uninit]
* use strictdefs for compiler (#22365)ringabout2023-08-061-9/+18
| | | | | | | | | | | | | | | * wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
* fixes #22321; fixes building DLL with --noMain still produces a DllMain (#22323)ringabout2023-07-241-1/+1
| | | | | * fixes #22321; Building DLL with --noMain produces an unexpected DllMain on devel branch * remove implicit nomain
* Expands codegenDecl to work in function params. fixes #22306 (#22307)Juan M Gómez2023-07-231-2/+2
| | | | | | | * Expands codegenDecl to work in function params. fixes #22306 * makes the test more concrete so T{lit} params dont match * adds sfCodegenDecl
* implemented 'push quirky' switch for fine grained control over the ex… ↵Andreas Rumpf2023-07-231-5/+5
| | | | | | | (#22318) * implemented 'push quirky' switch for fine grained control over the exception handling overhead * documentation
* adds nimbasePattern compiler option (#22144)Juan M Gómez2023-06-241-1/+3
| | | adds optonal --nimbasepattern
* Implements: [C++] constructor pragma improvement (fix #21921) (#21916)Juan M Gómez2023-05-301-7/+9
| | | | | | | | | | | | | | | * implements: [C++] constructor pragma improvement (fix #21921) t * fix test so it doesnt use echo in globals * Update compiler/ccgtypes.nim * Update lib/std/private/dragonbox.nim --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* simple micro-optimizations of ropes' runtime-formatting (#21962)heterodoxic2023-05-301-7/+3
|
* hot code reloading: fix regression? and PreMain with arc/orc (#21940)metagn2023-05-301-6/+9
| | | | | * fix PreMain for hot code reloading with arc/orc * fix regression? actually test nimhcr_basic
* prevent spamming of thread local forward declarations in C/C++ output (#21955)heterodoxic2023-05-291-1/+1
|
* fix & add test for basic hot code reloading case (#21915)metagn2023-05-261-1/+4
| | | fixes #21885
* fix #21501 by making --app:lib and --app:staticLib imply --noMain (#21910)heterodoxic2023-05-261-7/+5
|
* actually fixes #21889 "constructor pragma doing nothing in globals" (#21897)Juan M Gómez2023-05-241-2/+15
| | | actually fixes #21889
* small refactor in preparation to fix #21889 (#21892)Juan M Gómez2023-05-231-17/+23
|
* implements allow byref to work in params #21873 (#21875)Juan M Gómez2023-05-211-15/+15
|
* refactor gettypedesc so it accepts its own kind instead of symkind (#21867)Juan M Gómez2023-05-191-22/+22
|
* Cpp Vfunctions draft (#21790)Juan M Gómez2023-05-171-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * introduces virtual pragma, modifies proc def, prevents proc decl * marks virtual procs as infix * forward declare vfuncs inside the typedef * adds naked callConv to virtual * virtual proc error if not defined in the same top level scope as the type * first param is now this. extracts genvirtualheaderproc * WIP syntax * supports obj. Removes the need for the prefix * parameter count starts as this. Cleanup * clean up * sem tests * adds integration tests * uses constraint to store the virtual content * introduces genVirtualProcParams --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* ignore inline hint for dynlib procs in codegen [backport] (#21817)metagn2023-05-091-14/+14
|
* adds an experimental `mm:atomicArc` switch (#21798)ringabout2023-05-081-4/+4
|
* amends #21690 to fix broken Nim to C++ source line mappings (#21784)heterodoxic2023-05-041-32/+36
| | | resync fork
* improve C/C++ debug output readability (1/N) (#21690)heterodoxic