move since from inclrtl to std/private/since (#14188)

* move since from inclrtl to std/private/since
* move since import in system below for HCR
This commit is contained in:
hlaaftana
2020-05-03 00:51:59 +03:00
committed by GitHub
parent 3be669be32
commit fbc97e712a
27 changed files with 60 additions and 59 deletions

View File

@@ -8,6 +8,7 @@
#
include "system/inclrtl"
import std/private/since
## This module contains the interface to the compiler's abstract syntax
## tree (`AST`:idx:). Macros operate on this tree.

View File

@@ -9,7 +9,7 @@
## Declaration of the Document Object Model for the `JavaScript backend
## <backends.html#backends-the-javascript-target>`_.
include "system/inclrtl"
import std/private/since
when not defined(js) and not defined(Nimdoc):
{.error: "This module only works on the JavaScript platform".}

View File

@@ -95,12 +95,8 @@
## runForever()
##
include "system/inclrtl"
import asyncdispatch
import nativesockets
import net
import os
import std/private/since
import asyncdispatch, nativesockets, net, os
export SOBool

View File

@@ -12,8 +12,9 @@
##
## Unstable API.
import std/private/since
import strutils
include "system/inclrtl"
when defined(windows):
import winlean

View File

@@ -12,7 +12,7 @@
## by Adam Langley.
## (A crit bit tree is a form of `radix tree`:idx: or `patricia trie`:idx:.)
include "system/inclrtl"
import std/private/since
type
NodeObj[T] {.acyclic.} = object

View File

@@ -51,7 +51,7 @@
## * `lists module <lists.html>`_ for singly and doubly linked lists and rings
## * `channels module <channels.html>`_ for inter-thread communication
include system/inclrtl
import std/private/since
import math

View File

@@ -73,7 +73,7 @@
## heterogeneous members
include "system/inclrtl"
import std/private/since
import macros

View File

@@ -217,9 +217,9 @@
## * `hashes module<hashes.html>`_ for helper functions for hashing
import hashes, math, algorithm
import std/private/since
include "system/inclrtl"
import hashes, math, algorithm
type
KeyValuePair[A, B] = tuple[hcode: Hash, key: A, val: B]

View File

@@ -44,7 +44,7 @@
## * `std/sha1 module <sha1.html>`_ for a sha1 encoder and decoder
## * `tables module <tables.html>`_ for hash tables
include "system/inclrtl"
import std/private/since
type
Hash* = int ## A hash value. Hash tables using these values should

View File

@@ -200,7 +200,7 @@
## let client = newHttpClient(maxRedirects = 0)
##
include "system/inclrtl"
import std/private/since
import net, strutils, uri, parseutils, base64, os, mimetypes, streams,
math, random, httpcore, times, tables, streams, std/monotimes

View File

@@ -52,7 +52,7 @@
## are on system directly, to name a few ``shr``, ``shl``, ``xor``, ``clamp``, etc.
include "system/inclrtl"
import std/private/since
{.push debugger: off.} # the user does not want to trace a part
# of the standard library!

View File

@@ -64,7 +64,7 @@
## socket.acceptAddr(client, address)
## echo("Client connected from: ", address)
include "system/inclrtl"
import std/private/since
import nativesockets, os, strutils, times, sets, options, std/monotimes
from ssl_certs import scanSSLCertificates

View File

@@ -42,6 +42,7 @@
## * `streams module <streams.html>`_
include "system/inclrtl"
import std/private/since
import
strutils, pathnorm

View File

@@ -94,7 +94,7 @@
## * `asyncstreams module <asyncstreams.html>`_
## * `io module <io.html>`_ for `FileMode enum <io.html#FileMode>`_
include "system/inclrtl"
import std/private/since
const taintMode = compileOption("taintmode")

View File

@@ -48,6 +48,7 @@ runnableExamples:
## * `json module<json.html>`_ for table-like structure which allows
## heterogeneous members
import std/private/since
import
hashes, strutils

View File

@@ -10,8 +10,7 @@
## This module implements nice syntactic sugar based on Nim's
## macro system.
include system/inclrtl
import std/private/since
import macros
import typetraits

View File

@@ -194,6 +194,7 @@
import strutils, math, options
import std/private/since
include "system/inclrtl"
when defined(js):
@@ -980,7 +981,7 @@ proc low*(typ: typedesc[Time]): Time =
# DateTime & Timezone
#
proc isLeapDay*(t: DateTime): bool {.since: (1,1).} =
proc isLeapDay*(t: DateTime): bool {.since: (1, 1).} =
## returns whether `t` is a leap day, ie, Feb 29 in a leap year. This matters
## as it affects time offset calculations.
runnableExamples:

View File

@@ -12,10 +12,9 @@
##
## Unstable API.
import std/private/since
export system.`$` # for backward compatibility
include "system/inclrtl"
proc name*(t: typedesc): string {.magic: "TypeTrait".}
## Returns the name of the given type.
##
@@ -79,15 +78,13 @@ since (1, 1):
doAssert 12.MyInt.distinctBase == 12
distinctBase(type(a))(a)
proc tupleLen*(T: typedesc[tuple]): int {.magic: "TypeTrait", since: (1, 1).}
## Return number of elements of `T`
proc tupleLen*(T: typedesc[tuple]): int {.magic: "TypeTrait".}
## Return number of elements of `T`
since (1, 1):
template tupleLen*(t: tuple): int =
## Return number of elements of `t`
tupleLen(type(t))
since (1, 1):
template get*(T: typedesc[tuple], i: static int): untyped =
## Return `i`\th element of `T`
# Note: `[]` currently gives: `Error: no generic parameters allowed for ...`

View File

@@ -93,11 +93,11 @@
##
## echo "suite teardown: run once after the tests"
import std/private/since
import
macros, strutils, streams, times, sets, sequtils
include "system/inclrtl"
when declared(stdout):
import os

View File

@@ -44,7 +44,7 @@
## doAssert getDataUri("Hello World", "text/plain") == "data:text/plain;charset=utf-8;base64,SGVsbG8gV29ybGQ="
## doAssert getDataUri("Nim", "text/plain") == "data:text/plain;charset=utf-8;base64,Tmlt"
include "system/inclrtl"
import std/private/since
import strutils, parseutils, base64
type

View File

@@ -34,8 +34,8 @@
## * `parsexml module <parsexml.html>`_ for low-level XML parsing
## * `htmlgen module <htmlgen.html>`_ for html code generator
import std/private/since
import macros, strtabs, strutils
include "system/inclrtl"
type
XmlNode* = ref XmlNodeObj ## An XML tree consisting of XML nodes.
@@ -103,7 +103,7 @@ proc newText*(text: string): XmlNode =
result = newXmlNode(xnText)
result.fText = text
proc newVerbatimText*(text: string): XmlNode {.since:(1, 3).} =
proc newVerbatimText*(text: string): XmlNode {.since: (1, 3).} =
## Creates a new ``XmlNode`` of kind ``xnVerbatimText`` with the text `text`.
## **Since**: Version 1.3.
result = newXmlNode(xnVerbatimText)

19
lib/std/private/since.nim Normal file
View File

@@ -0,0 +1,19 @@
template since*(version: (int, int), body: untyped) {.dirty.} =
## Evaluates `body` if the ``(NimMajor, NimMinor)`` is greater than
## or equal to `version`. Usage:
##
## .. code-block:: Nim
## proc fun*() {.since: (1, 3).}
## since (1, 3): fun()
when (NimMajor, NimMinor) >= version:
body
template since*(version: (int, int, int), body: untyped) {.dirty.} =
## Evaluates `body` if ``(NimMajor, NimMinor, NimPatch)`` is greater than
## or equal to `version`. Usage:
##
## .. code-block:: Nim
## proc fun*() {.since: (1, 3, 1).}
## since (1, 3, 1): fun()
when (NimMajor, NimMinor, NimPatch) >= version:
body

View File

@@ -1124,6 +1124,8 @@ elif hostOS != "standalone":
var programResult* {.compilerproc, exportc: "nim_program_result".}: int
## deprecated, prefer ``quit``
import std/private/since
proc align(address, alignment: int): int =
if alignment == 0: # Actually, this is illegal. This branch exists to actively
# hide problems.
@@ -2054,8 +2056,8 @@ const
## is the major number of Nim's version. Example:
##
## .. code-block:: Nim
## when (NimMajor, NimMinor, NimPatch) >= (1, 3, 1): discard
# See also private symbol `since: (1, 3)` reserved for stdlib
## when (NimMajor, NimMinor, NimPatch) >= (1, 3, 1): discard
# see also std/private/since
NimMinor* {.intdefine.}: int = 3
## is the minor number of Nim's version.

View File

@@ -1,4 +1,4 @@
include system/inclrtl
import std/private/since
proc `$`*(x: int): string {.magic: "IntToStr", noSideEffect.}
## The stringify operator for an integer argument. Returns `x`

View File

@@ -48,21 +48,3 @@ when defined(nimlocks):
{.pragma: benign, gcsafe, locks: 0.}
else:
{.pragma: benign, gcsafe.}
template isSince(version: (int, int)): bool =
(NimMajor, NimMinor) >= version
template isSince(version: (int, int, int)): bool =
(NimMajor, NimMinor, NimPatch) >= version
template since(version, body: untyped) {.dirty, used.} =
## Usage:
##
## .. code-block:: Nim
## proc fun*() {since: (1, 3).}
## proc fun*() {since: (1, 3, 1).}
##
## Limitation: can't be used to annotate a template (eg typetraits.get), would
## error: cannot attach a custom pragma.
# `dirty` needed because `NimMajor` may not yet be defined in caller.
when isSince(version):
body

View File

@@ -11,6 +11,7 @@
include inclrtl
import std/private/since
import formatfloat
# ----------------- IO Part ------------------------------------------------

View File

@@ -1,9 +1,9 @@
include system/inclrtl
import std/private/since
proc fun1(): int {.since: (1,3).} = 12
proc fun1Bad(): int {.since: (99,3).} = 12
proc fun2(): int {.since: (1,3,1).} = 12
proc fun2Bad(): int {.since: (99,3,1).} = 12
proc fun1(): int {.since: (1, 3).} = 12
proc fun1Bad(): int {.since: (99, 3).} = 12
proc fun2(): int {.since: (1, 3, 1).} = 12
proc fun2Bad(): int {.since: (99, 3, 1).} = 12
doAssert fun1() == 12
doAssert declared(fun1)
@@ -23,7 +23,7 @@ since (1, 3, 1):
ok = true
doAssert ok
since (99,3):
since (99, 3):
doAssert false
when false: