include system/inclrtl when defined(nimPreviewSlimSystem): import std/formatfloat proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".} ## imported from typetraits proc distinctBase(T: typedesc, recursive: static bool = true): typedesc {.magic: "TypeTrait".} ## imported from typetraits proc rangeBase(T: typedesc): typedesc {.magic: "TypeTrait".} # skip one level of range; return the base type of a range type proc repr*(x: NimNode): string {.magic: "Repr", noSideEffect.} template dollarAlias(T: typedesc) = proc repr*(x: T): string {.noSideEffect.} = ## Same as $x $x # need to declare for bit types as well to not clash with converters: dollarAlias int dollarAlias int8 dollarAlias int16 dollarAlias int32 dollarAlias int64 dollarAlias uint dollarAlias uint8 dollarAlias uint16 dollarAlias uint32 dollarAlias uint64 dollarAlias float dollarAlias float32 proc repr*(x: bool): string {.magic: "BoolToStr", noSideEffect.} ## repr for a boolean argument. Returns `x` ## converted to the string "false" or "true". proc repr*(x: char): string {.noSideEffect, raises: [].} = ## repr for a character argument. Returns `x` ## converted to an escaped string. ## ## ```Nim ## assert repr('c') == "'c'" ## ``` result = "'" # Elides string creations if not needed if x in {'\\', '\0'..'\31', '\127'..'\255'}: result.add '\\' if x in {'\0'..'\31', '\127'..'\255'}: result.add $x.uint8 else: result.add x result.add '\'' proc repr*(x: string | cstring): string {.noSideEffect, raises: [].} = ## repr for a string argument. Returns `x` ## converted to a quoted and escaped string. result = "\"" for i in 0..