Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
commit
50fb98d260
3 changed files with 18 additions and 3 deletions
|
|
@ -496,7 +496,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode,
|
||||||
if hasAttribute in CC[cCompiler].props:
|
if hasAttribute in CC[cCompiler].props:
|
||||||
add(unionBody, "struct __attribute__((__packed__)){" )
|
add(unionBody, "struct __attribute__((__packed__)){" )
|
||||||
else:
|
else:
|
||||||
addf(unionBody, "#pragma pack(1)$nstruct{", [])
|
addf(unionBody, "#pragma pack(push, 1)$nstruct{", [])
|
||||||
add(unionBody, a)
|
add(unionBody, a)
|
||||||
addf(unionBody, "} $1;$n", [sname])
|
addf(unionBody, "} $1;$n", [sname])
|
||||||
if tfPacked in rectype.flags and hasAttribute notin CC[cCompiler].props:
|
if tfPacked in rectype.flags and hasAttribute notin CC[cCompiler].props:
|
||||||
|
|
@ -551,7 +551,7 @@ proc getRecordDesc(m: BModule, typ: PType, name: Rope,
|
||||||
if hasAttribute in CC[cCompiler].props:
|
if hasAttribute in CC[cCompiler].props:
|
||||||
result = structOrUnion(typ) & " __attribute__((__packed__))"
|
result = structOrUnion(typ) & " __attribute__((__packed__))"
|
||||||
else:
|
else:
|
||||||
result = "#pragma pack(1)" & tnl & structOrUnion(typ)
|
result = "#pragma pack(push, 1)" & tnl & structOrUnion(typ)
|
||||||
else:
|
else:
|
||||||
result = structOrUnion(typ)
|
result = structOrUnion(typ)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -221,8 +221,10 @@ template callFormat(res, arg) {.dirty.} =
|
||||||
template callFormatOption(res, arg, option) {.dirty.} =
|
template callFormatOption(res, arg, option) {.dirty.} =
|
||||||
when compiles(format(arg, option, res)):
|
when compiles(format(arg, option, res)):
|
||||||
format(arg, option, res)
|
format(arg, option, res)
|
||||||
else:
|
elif compiles(format(arg, option)):
|
||||||
res.add format(arg, option)
|
res.add format(arg, option)
|
||||||
|
else:
|
||||||
|
format($arg, option, res)
|
||||||
|
|
||||||
macro fmt*(pattern: string{lit}): untyped =
|
macro fmt*(pattern: string{lit}): untyped =
|
||||||
## For a specification of the ``fmt`` macro, see the module level documentation.
|
## For a specification of the ``fmt`` macro, see the module level documentation.
|
||||||
|
|
|
||||||
13
tests/stdlib/tstrformat.nim
Normal file
13
tests/stdlib/tstrformat.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
discard """
|
||||||
|
action: "run"
|
||||||
|
"""
|
||||||
|
|
||||||
|
import strformat
|
||||||
|
|
||||||
|
type Obj = object
|
||||||
|
|
||||||
|
proc `$`(o: Obj): string = "foobar"
|
||||||
|
|
||||||
|
var o: Obj
|
||||||
|
doAssert fmt"{o}" == "foobar"
|
||||||
|
doAssert fmt"{o:10}" == "foobar "
|
||||||
Loading…
Add table
Add a link
Reference in a new issue