mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
* system refactor, move out 600 lines * compilation, slice, backwardsindex, misc_num moved out of system * some procs/types moved into arithmetics, basic_types * system no longer depends on syncio * some procs moved around to fit with their surroundings * make exceptions an import, old ops to misc_num * move instantiationInfo back * move back nim version, fix windows echo * include compilation * better docs for imported modules, fix unsigned ops also remove ze, ze64, toU8, toU16, toU32 with nimPreviewSlimSystem * fix terminal * workaround IC test & weird csize bug, changelog * move NimMajor etc back to compilation, rebase for CI * try ic fix * form single `indices`, slim out TaintedString, try fix IC * fix CI, update changelog, addQuitProc * fix CI * try fix CI * actually fix CI finally hopefully * Update lib/system/compilation.nim Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> * update kochdocs * hopefully fix csize uses for slimsystem * fix tquit Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
40 lines
1.1 KiB
Nim
40 lines
1.1 KiB
Nim
discard """
|
|
targets: "cpp"
|
|
output: '''test1
|
|
xest1
|
|
'''
|
|
"""
|
|
{.passC: "-std=c++14".}
|
|
|
|
{.experimental: "dotOperators".}
|
|
|
|
import macros
|
|
|
|
type
|
|
stdString {.importcpp: "std::string", header: "<string>".} = object
|
|
stdUniquePtr[T] {.importcpp: "std::unique_ptr", header: "<memory>".} = object
|
|
|
|
proc c_str(a: stdString): cstring {.importcpp: "(char *)(#.c_str())", header: "<string>".}
|
|
|
|
proc len(a: stdString): csize_t {.importcpp: "(#.length())", header: "<string>".}
|
|
|
|
proc setChar(a: var stdString, i: csize_t, c: char) {.importcpp: "(#[#] = #)", header: "<string>".}
|
|
|
|
proc `*`*[T](this: stdUniquePtr[T]): var T {.noSideEffect, importcpp: "(* #)", header: "<memory>".}
|
|
|
|
proc make_unique_str(a: cstring): stdUniquePtr[stdString] {.importcpp: "std::make_unique<std::string>(#)", header: "<string>".}
|
|
|
|
macro `.()`*[T](this: stdUniquePtr[T], name: untyped, args: varargs[untyped]): untyped =
|
|
result = nnkCall.newTree(
|
|
nnkDotExpr.newTree(
|
|
newNimNode(nnkPar).add(prefix(this, "*")),
|
|
name
|
|
)
|
|
)
|
|
copyChildrenTo(args, result)
|
|
|
|
var val = make_unique_str("test1")
|
|
echo val.c_str()
|
|
val.setChar(0, 'x')
|
|
echo val.c_str()
|