mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-13 06:43:52 +00:00
Merge branch 'master' into newparser
This commit is contained in:
@@ -78,5 +78,5 @@ Advanced options:
|
||||
--listCmd list the commands used to execute external programs
|
||||
--parallelBuild=0|1|... perform a parallel build
|
||||
value = number of processors (0 for auto-detect)
|
||||
--verbosity:0|1|2|3 set Nimrod's verbosity level (0 is default)
|
||||
--verbosity:0|1|2|3 set Nimrod's verbosity level (1 is default)
|
||||
-v, --version show detailed version information
|
||||
|
||||
@@ -68,6 +68,25 @@ ShadowIdent A local variable shadows another local
|
||||
User Some user defined warning.
|
||||
========================== ============================================
|
||||
|
||||
|
||||
Verbosity levels
|
||||
----------------
|
||||
|
||||
===== ============================================
|
||||
Level Description
|
||||
===== ============================================
|
||||
0 Minimal output level for the compiler.
|
||||
1 Displays compilation of all the compiled files, including those imported
|
||||
by other modules or through the `compile pragma<#compile-pragma>`_.
|
||||
This is the default level.
|
||||
2 Displays compilation statistics, enumerates the dynamic
|
||||
libraries that will be loaded by the final binary and dumps to
|
||||
standard output the result of applying `a filter to the source code
|
||||
<filters.html>`_ if any filter was used during compilation.
|
||||
3 In addition to the previous levels dumps a debug stack trace
|
||||
for compiler developers.
|
||||
===== ============================================
|
||||
|
||||
|
||||
Configuration files
|
||||
-------------------
|
||||
|
||||
18
doc/tut1.txt
18
doc/tut1.txt
@@ -1311,6 +1311,24 @@ integer.
|
||||
echo(person[0]) # "Peter"
|
||||
echo(person[1]) # 30
|
||||
|
||||
# You don't need to declare tuples in a separate type section.
|
||||
var building: tuple[street: string, number: int]
|
||||
building = ("Rue del Percebe", 13)
|
||||
echo(building.street)
|
||||
|
||||
# The following line does not compile, they are different tuples!
|
||||
#person = building
|
||||
# --> Error: type mismatch: got (tuple[street: string, number: int])
|
||||
# but expected 'TPerson'
|
||||
|
||||
# The following works because the field names and types are the same.
|
||||
var teacher: tuple[name: string, age: int] = ("Mark", 42)
|
||||
person = teacher
|
||||
|
||||
Even though you don't need to declare a type for a tuple to use it, tuples
|
||||
created with different field names will be considered different objects despite
|
||||
having the same field types.
|
||||
|
||||
|
||||
Reference and pointer types
|
||||
---------------------------
|
||||
|
||||
@@ -794,8 +794,11 @@ when not defined(ENOENT):
|
||||
var ENOENT {.importc, header: "<errno.h>".}: cint
|
||||
|
||||
proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
|
||||
## Removes the `file`. If this fails, `EOS` is raised. This does not fail
|
||||
## if the file never existed in the first place.
|
||||
## Removes the `file`.
|
||||
##
|
||||
## If this fails, `EOS` is raised. This does not fail if the file never
|
||||
## existed in the first place. Despite the name of this proc you can also
|
||||
## call it on directories, but they will only be removed if they are empty.
|
||||
if cremove(file) != 0'i32 and errno != ENOENT: OSError()
|
||||
|
||||
proc execShellCmd*(command: string): int {.rtl, extern: "nos$1",
|
||||
@@ -1076,8 +1079,12 @@ proc rawRemoveDir(dir: string) =
|
||||
proc removeDir*(dir: string) {.rtl, extern: "nos$1", tags: [
|
||||
FWriteDir, FReadDir].} =
|
||||
## Removes the directory `dir` including all subdirectories and files
|
||||
## in `dir` (recursively). If this fails, `EOS` is raised. This does not fail
|
||||
## if the directory never existed in the first place.
|
||||
## in `dir` (recursively).
|
||||
##
|
||||
## If this fails, `EOS` is raised. This does not fail if the directory never
|
||||
## existed in the first place. If you need non recursive directory removal
|
||||
## which fails when the directory contains files use the `removeFile` proc
|
||||
## instead.
|
||||
for kind, path in walkDir(dir):
|
||||
case kind
|
||||
of pcFile, pcLinkToFile, pcLinkToDir: removeFile(path)
|
||||
|
||||
@@ -153,15 +153,15 @@ proc TimeInfoToTime*(timeInfo: TTimeInfo): TTime {.tags: [].}
|
||||
## them from the other information in the broken-down time structure.
|
||||
|
||||
proc fromSeconds*(since1970: float): TTime {.tags: [].}
|
||||
## Takes a float which contains the number of seconds since 1970 and
|
||||
## Takes a float which contains the number of seconds since the unix epoch and
|
||||
## returns a time object.
|
||||
|
||||
proc fromSeconds*(since1970: int|int64): TTime = fromSeconds(float(since1970))
|
||||
## Takes an in which contains the number of seconds since 1970 and
|
||||
## Takes an int which contains the number of seconds since the unix epoch and
|
||||
## returns a time object.
|
||||
|
||||
proc toSeconds*(time: TTime): float {.tags: [].}
|
||||
## Returns the time in seconds since 1970.
|
||||
## Returns the time in seconds since the unix epoch.
|
||||
|
||||
proc `$` *(timeInfo: TTimeInfo): string {.tags: [].}
|
||||
## converts a `TTimeInfo` object to a string representation.
|
||||
@@ -226,14 +226,9 @@ proc getDaysInMonth(month: TMonth, year: int): int =
|
||||
of mApr, mJun, mSep, mNov: result = 30
|
||||
else: result = 31
|
||||
|
||||
proc `-`*(interval: TTimeInterval): TTimeInterval =
|
||||
for a, b in fields(result, interval):
|
||||
a = -b
|
||||
|
||||
proc toSeconds*(a: TTimeInfo, interval: TTimeInterval): float =
|
||||
## Returns the time the interval will be at that point in time. This
|
||||
## needs a time as well, because e.g. a month is not always the same
|
||||
## length.
|
||||
proc toSeconds(a: TTimeInfo, interval: TTimeInterval): float =
|
||||
## Calculates how many seconds the interval is worth by adding up
|
||||
## all the fields
|
||||
|
||||
var anew = a
|
||||
var newinterv = interval
|
||||
@@ -253,9 +248,6 @@ proc toSeconds*(a: TTimeInfo, interval: TTimeInterval): float =
|
||||
result += float(newinterv.seconds)
|
||||
result += newinterv.miliseconds / 1000
|
||||
|
||||
proc toSeconds*(a: TTime, interval: TTimeInterval): float =
|
||||
result = toSeconds(getGMTime(a), interval)
|
||||
|
||||
proc `+`*(a: TTimeInfo, interval: TTimeInterval): TTimeInfo =
|
||||
## adds ``interval`` time.
|
||||
##
|
||||
@@ -273,7 +265,12 @@ proc `-`*(a: TTimeInfo, interval: TTimeInterval): TTimeInfo =
|
||||
##
|
||||
## **Note:** This has been only briefly tested, it is inaccurate especially
|
||||
## when you subtract so much that you reach the Julian calendar.
|
||||
result = a + -interval
|
||||
let t = toSeconds(TimeInfoToTime(a))
|
||||
let secs = toSeconds(a, interval)
|
||||
if a.tzname == "UTC":
|
||||
result = getGMTime(fromSeconds(t - secs))
|
||||
else:
|
||||
result = getLocalTime(fromSeconds(t - secs))
|
||||
|
||||
when not defined(JS):
|
||||
proc epochTime*(): float {.rtl, extern: "nt$1", tags: [FTime].}
|
||||
@@ -742,4 +739,6 @@ when isMainModule:
|
||||
var t4 = getGMTime(fromSeconds(876124714)) # Mon 6 Oct 08:58:34 BST 1997
|
||||
assert t4.format("M MM MMM MMMM") == "10 10 Oct October"
|
||||
|
||||
|
||||
# Interval tests
|
||||
assert((t4 - initInterval(years = 2)).format("yyyy") == "1995")
|
||||
assert((t4 - initInterval(years = 7, minutes = 34, seconds = 24)).format("yyyy mm ss") == "1990 24 10")
|
||||
|
||||
Reference in New Issue
Block a user