Merge remote-tracking branch 'nim-lang/devel' into emscripten-support
This commit is contained in:
commit
76a49bfcea
7 changed files with 87 additions and 8 deletions
|
|
@ -474,7 +474,7 @@ proc execWithEcho(cmd: string, msg = hintExecuting): int =
|
||||||
|
|
||||||
proc execExternalProgram*(cmd: string, msg = hintExecuting) =
|
proc execExternalProgram*(cmd: string, msg = hintExecuting) =
|
||||||
if execWithEcho(cmd, msg) != 0:
|
if execWithEcho(cmd, msg) != 0:
|
||||||
rawMessage(errExecutionOfProgramFailed, "")
|
rawMessage(errExecutionOfProgramFailed, cmd)
|
||||||
|
|
||||||
proc generateScript(projectFile: string, script: Rope) =
|
proc generateScript(projectFile: string, script: Rope) =
|
||||||
let (dir, name, ext) = splitFile(projectFile)
|
let (dir, name, ext) = splitFile(projectFile)
|
||||||
|
|
@ -680,7 +680,7 @@ proc callCCompiler*(projectfile: string) =
|
||||||
if gNumberOfProcessors <= 1:
|
if gNumberOfProcessors <= 1:
|
||||||
for i in countup(0, high(cmds)):
|
for i in countup(0, high(cmds)):
|
||||||
res = execWithEcho(cmds[i])
|
res = execWithEcho(cmds[i])
|
||||||
if res != 0: rawMessage(errExecutionOfProgramFailed, [])
|
if res != 0: rawMessage(errExecutionOfProgramFailed, cmds[i])
|
||||||
elif optListCmd in gGlobalOptions or gVerbosity > 1:
|
elif optListCmd in gGlobalOptions or gVerbosity > 1:
|
||||||
res = execProcesses(cmds, {poEchoCmd, poUsePath, poParentStreams},
|
res = execProcesses(cmds, {poEchoCmd, poUsePath, poParentStreams},
|
||||||
gNumberOfProcessors)
|
gNumberOfProcessors)
|
||||||
|
|
@ -692,9 +692,11 @@ proc callCCompiler*(projectfile: string) =
|
||||||
gNumberOfProcessors)
|
gNumberOfProcessors)
|
||||||
if res != 0:
|
if res != 0:
|
||||||
if gNumberOfProcessors <= 1:
|
if gNumberOfProcessors <= 1:
|
||||||
rawMessage(errExecutionOfProgramFailed, [])
|
rawMessage(errExecutionOfProgramFailed, cmds.join())
|
||||||
else:
|
else:
|
||||||
rawMessage(errGenerated, " execution of an external program failed; " &
|
rawMessage(errGenerated,
|
||||||
|
" execution of an external compiler program failed: " &
|
||||||
|
cmds.join() & "; " &
|
||||||
"rerun with --parallelBuild:1 to see the error message")
|
"rerun with --parallelBuild:1 to see the error message")
|
||||||
if optNoLinking notin gGlobalOptions:
|
if optNoLinking notin gGlobalOptions:
|
||||||
# call the linker:
|
# call the linker:
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,7 @@ const
|
||||||
errUseQualifier: "ambiguous identifier: \'$1\' -- use a qualifier",
|
errUseQualifier: "ambiguous identifier: \'$1\' -- use a qualifier",
|
||||||
errTypeExpected: "type expected",
|
errTypeExpected: "type expected",
|
||||||
errSystemNeeds: "system module needs \'$1\'",
|
errSystemNeeds: "system module needs \'$1\'",
|
||||||
errExecutionOfProgramFailed: "execution of an external program failed",
|
errExecutionOfProgramFailed: "execution of an external program failed: '$1'",
|
||||||
errNotOverloadable: "overloaded \'$1\' leads to ambiguous calls",
|
errNotOverloadable: "overloaded \'$1\' leads to ambiguous calls",
|
||||||
errInvalidArgForX: "invalid argument for \'$1\'",
|
errInvalidArgForX: "invalid argument for \'$1\'",
|
||||||
errStmtHasNoEffect: "statement has no effect",
|
errStmtHasNoEffect: "statement has no effect",
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,26 @@
|
||||||
## the `FileStream` and the `StringStream` which implement the stream
|
## the `FileStream` and the `StringStream` which implement the stream
|
||||||
## interface for Nim file objects (`File`) and strings. Other modules
|
## interface for Nim file objects (`File`) and strings. Other modules
|
||||||
## may provide other implementations for this standard stream interface.
|
## may provide other implementations for this standard stream interface.
|
||||||
|
##
|
||||||
|
## Examples:
|
||||||
|
##
|
||||||
|
## .. code-block:: Nim
|
||||||
|
##
|
||||||
|
## import streams
|
||||||
|
## var
|
||||||
|
## ss = newStringStream("""The first line
|
||||||
|
## the second line
|
||||||
|
## the third line""")
|
||||||
|
## line = ""
|
||||||
|
## while ss.readLine(line):
|
||||||
|
## echo line
|
||||||
|
## ss.close()
|
||||||
|
##
|
||||||
|
## var fs = newFileStream("somefile.txt", fmRead)
|
||||||
|
## if not isNil(fs):
|
||||||
|
## while fs.readLine(line):
|
||||||
|
## echo line
|
||||||
|
## fs.close()
|
||||||
|
|
||||||
include "system/inclrtl"
|
include "system/inclrtl"
|
||||||
|
|
||||||
|
|
@ -371,7 +391,7 @@ when not defined(js):
|
||||||
result.writeDataImpl = fsWriteData
|
result.writeDataImpl = fsWriteData
|
||||||
result.flushImpl = fsFlush
|
result.flushImpl = fsFlush
|
||||||
|
|
||||||
proc newFileStream*(filename: string, mode: FileMode): FileStream =
|
proc newFileStream*(filename: string, mode: FileMode = fmRead): FileStream =
|
||||||
## creates a new stream from the file named `filename` with the mode `mode`.
|
## creates a new stream from the file named `filename` with the mode `mode`.
|
||||||
## If the file cannot be opened, nil is returned. See the `system
|
## If the file cannot be opened, nil is returned. See the `system
|
||||||
## <system.html>`_ module for a list of available FileMode enums.
|
## <system.html>`_ module for a list of available FileMode enums.
|
||||||
|
|
|
||||||
|
|
@ -221,11 +221,21 @@ proc high*[T](x: T): T {.magic: "High", noSideEffect.}
|
||||||
## the highest possible value of an ordinal value `x`. As a special
|
## the highest possible value of an ordinal value `x`. As a special
|
||||||
## semantic rule, `x` may also be a type identifier.
|
## semantic rule, `x` may also be a type identifier.
|
||||||
## ``high(int)`` is Nim's way of writing `INT_MAX`:idx: or `MAX_INT`:idx:.
|
## ``high(int)`` is Nim's way of writing `INT_MAX`:idx: or `MAX_INT`:idx:.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## var arr = [1,2,3,4,5,6,7]
|
||||||
|
## high(arr) #=> 6
|
||||||
|
## high(2) #=> 9223372036854775807
|
||||||
|
|
||||||
proc low*[T](x: T): T {.magic: "Low", noSideEffect.}
|
proc low*[T](x: T): T {.magic: "Low", noSideEffect.}
|
||||||
## returns the lowest possible index of an array, a sequence, a string or
|
## returns the lowest possible index of an array, a sequence, a string or
|
||||||
## the lowest possible value of an ordinal value `x`. As a special
|
## the lowest possible value of an ordinal value `x`. As a special
|
||||||
## semantic rule, `x` may also be a type identifier.
|
## semantic rule, `x` may also be a type identifier.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## var arr = [1,2,3,4,5,6,7]
|
||||||
|
## high(arr) #=> 0
|
||||||
|
## high(2) #=> -9223372036854775808
|
||||||
|
|
||||||
type
|
type
|
||||||
range*{.magic: "Range".}[T] ## Generic type to construct range types.
|
range*{.magic: "Range".}[T] ## Generic type to construct range types.
|
||||||
|
|
@ -584,6 +594,10 @@ proc sizeof*[T](x: T): int {.magic: "SizeOf", noSideEffect.}
|
||||||
## its usage is discouraged - using ``new`` for the most cases suffices
|
## its usage is discouraged - using ``new`` for the most cases suffices
|
||||||
## that one never needs to know ``x``'s size. As a special semantic rule,
|
## that one never needs to know ``x``'s size. As a special semantic rule,
|
||||||
## ``x`` may also be a type identifier (``sizeof(int)`` is valid).
|
## ``x`` may also be a type identifier (``sizeof(int)`` is valid).
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## sizeof('A') #=> 1
|
||||||
|
## sizeof(2) #=> 8
|
||||||
|
|
||||||
when defined(nimtypedescfixed):
|
when defined(nimtypedescfixed):
|
||||||
proc sizeof*(x: typedesc): int {.magic: "SizeOf", noSideEffect.}
|
proc sizeof*(x: typedesc): int {.magic: "SizeOf", noSideEffect.}
|
||||||
|
|
@ -705,12 +719,22 @@ template excl*[T](s: var set[T], flags: set[T]) =
|
||||||
proc card*[T](x: set[T]): int {.magic: "Card", noSideEffect.}
|
proc card*[T](x: set[T]): int {.magic: "Card", noSideEffect.}
|
||||||
## returns the cardinality of the set ``x``, i.e. the number of elements
|
## returns the cardinality of the set ``x``, i.e. the number of elements
|
||||||
## in the set.
|
## in the set.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## var i = {1,2,3,4}
|
||||||
|
## card(i) #=> 4
|
||||||
|
|
||||||
proc ord*[T](x: T): int {.magic: "Ord", noSideEffect.}
|
proc ord*[T](x: T): int {.magic: "Ord", noSideEffect.}
|
||||||
## returns the internal int value of an ordinal value ``x``.
|
## returns the internal int value of an ordinal value ``x``.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## ord('A') #=> 65
|
||||||
|
|
||||||
proc chr*(u: range[0..255]): char {.magic: "Chr", noSideEffect.}
|
proc chr*(u: range[0..255]): char {.magic: "Chr", noSideEffect.}
|
||||||
## converts an int in the range 0..255 to a character.
|
## converts an int in the range 0..255 to a character.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## chr(65) #=> A
|
||||||
|
|
||||||
# --------------------------------------------------------------------------
|
# --------------------------------------------------------------------------
|
||||||
# built-in operators
|
# built-in operators
|
||||||
|
|
@ -1315,6 +1339,10 @@ proc add *[T](x: var seq[T], y: openArray[T]) {.noSideEffect.} =
|
||||||
## containers should also call their adding proc `add` for consistency.
|
## containers should also call their adding proc `add` for consistency.
|
||||||
## Generic code becomes much easier to write if the Nim naming scheme is
|
## Generic code becomes much easier to write if the Nim naming scheme is
|
||||||
## respected.
|
## respected.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## var s: seq[string] = @["test2","test2"]
|
||||||
|
## s.add("test") #=> @[test2, test2, test]
|
||||||
let xl = x.len
|
let xl = x.len
|
||||||
setLen(x, xl + y.len)
|
setLen(x, xl + y.len)
|
||||||
for i in 0..high(y): x[xl+i] = y[i]
|
for i in 0..high(y): x[xl+i] = y[i]
|
||||||
|
|
@ -1329,6 +1357,10 @@ proc shallowCopy*[T](x: var T, y: T) {.noSideEffect, magic: "ShallowCopy".}
|
||||||
proc del*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
|
proc del*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
|
||||||
## deletes the item at index `i` by putting ``x[high(x)]`` into position `i`.
|
## deletes the item at index `i` by putting ``x[high(x)]`` into position `i`.
|
||||||
## This is an O(1) operation.
|
## This is an O(1) operation.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## var i = @[1,2,3,4,5]
|
||||||
|
## i.del(2) #=> @[1, 2, 5, 4]
|
||||||
let xl = x.len - 1
|
let xl = x.len - 1
|
||||||
shallowCopy(x[i], x[xl])
|
shallowCopy(x[i], x[xl])
|
||||||
setLen(x, xl)
|
setLen(x, xl)
|
||||||
|
|
@ -1336,6 +1368,10 @@ proc del*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
|
||||||
proc delete*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
|
proc delete*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
|
||||||
## deletes the item at index `i` by moving ``x[i+1..]`` by one position.
|
## deletes the item at index `i` by moving ``x[i+1..]`` by one position.
|
||||||
## This is an O(n) operation.
|
## This is an O(n) operation.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## var i = @[1,2,3,4,5]
|
||||||
|
## i.delete(2) #=> @[1, 2, 4, 5]
|
||||||
template defaultImpl =
|
template defaultImpl =
|
||||||
let xl = x.len
|
let xl = x.len
|
||||||
for j in i..xl-2: shallowCopy(x[j], x[j+1])
|
for j in i..xl-2: shallowCopy(x[j], x[j+1])
|
||||||
|
|
@ -1351,6 +1387,10 @@ proc delete*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
|
||||||
|
|
||||||
proc insert*[T](x: var seq[T], item: T, i = 0.Natural) {.noSideEffect.} =
|
proc insert*[T](x: var seq[T], item: T, i = 0.Natural) {.noSideEffect.} =
|
||||||
## inserts `item` into `x` at position `i`.
|
## inserts `item` into `x` at position `i`.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## var i = @[1,2,3,4,5]
|
||||||
|
## i.insert(2,4) #=> @[1, 2, 3, 4, 2, 5]
|
||||||
template defaultImpl =
|
template defaultImpl =
|
||||||
let xl = x.len
|
let xl = x.len
|
||||||
setLen(x, xl+1)
|
setLen(x, xl+1)
|
||||||
|
|
@ -1371,6 +1411,12 @@ proc repr*[T](x: T): string {.magic: "Repr", noSideEffect.}
|
||||||
## takes any Nim variable and returns its string representation. It
|
## takes any Nim variable and returns its string representation. It
|
||||||
## works even for complex data graphs with cycles. This is a great
|
## works even for complex data graphs with cycles. This is a great
|
||||||
## debugging tool.
|
## debugging tool.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## var s: seq[string] = @["test2","test2"]
|
||||||
|
## var i = @[1,2,3,4,5]
|
||||||
|
## repr(s) #=> 0x1055eb050[0x1055ec050"test2", 0x1055ec078"test2"]
|
||||||
|
## repr(i) #=> 0x1055ed050[1, 2, 3, 4, 5]
|
||||||
|
|
||||||
type
|
type
|
||||||
ByteAddress* = int
|
ByteAddress* = int
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
discard """
|
discard """
|
||||||
test that closing a closed file is ignored (no error raised)
|
|
||||||
file: "tmemfiles1.nim"
|
file: "tmemfiles1.nim"
|
||||||
"""
|
"""
|
||||||
import memfiles, os
|
import memfiles, os
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
discard """
|
discard """
|
||||||
test creating/reading/writing/changing memfiles
|
|
||||||
file: "tmemfiles2.nim"
|
file: "tmemfiles2.nim"
|
||||||
output: '''Full read size: 20
|
output: '''Full read size: 20
|
||||||
Half read size: 10 Data: Hello'''
|
Half read size: 10 Data: Hello'''
|
||||||
|
|
|
||||||
13
tests/stdlib/tstreams2.nim
Normal file
13
tests/stdlib/tstreams2.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
discard """
|
||||||
|
file: "tstreams2.nim"
|
||||||
|
output: '''fs is: nil'''
|
||||||
|
"""
|
||||||
|
import streams
|
||||||
|
var
|
||||||
|
fs = newFileStream("amissingfile.txt")
|
||||||
|
line = ""
|
||||||
|
echo "fs is: ",repr(fs)
|
||||||
|
if not isNil(fs):
|
||||||
|
while fs.readLine(line):
|
||||||
|
echo line
|
||||||
|
fs.close()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue