summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ast.nim1
-rw-r--r--compiler/lexer.nim4
-rw-r--r--compiler/parser.nim5
-rw-r--r--compiler/renderer.nim9
-rw-r--r--compiler/semexprs.nim5
-rw-r--r--compiler/semstmts.nim9
-rw-r--r--compiler/wordrecg.nim4
7 files changed, 18 insertions, 19 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 21358ba3e..5c2349daa 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -221,7 +221,6 @@ type
     nkGotoState,          # used for the state machine (for iterators)
     nkState,              # give a label to a code section (for iterators)
     nkBreakState,         # special break statement for easier code generation
-    nkSigSection
   TNodeKinds* = set[TNodeKind]
 
 type
diff --git a/compiler/lexer.nim b/compiler/lexer.nim
index 8362436d8..69a0fea2a 100644
--- a/compiler/lexer.nim
+++ b/compiler/lexer.nim
@@ -45,7 +45,7 @@ type
     tkMacro, tkMethod, tkMixin, tkMod, tkNil, tkNot, tkNotin,
     tkObject, tkOf, tkOr, tkOut,
     tkProc, tkPtr, tkRaise, tkRef, tkReturn,
-    tkShl, tkShr, tkSig, tkStatic,
+    tkShl, tkShr, tkStatic,
     tkTemplate,
     tkTry, tkTuple, tkType, tkUsing,
     tkVar, tkWhen, tkWhile, tkWith, tkWithout, tkXor,
@@ -82,7 +82,7 @@ const
     "macro", "method", "mixin", "mod",
     "nil", "not", "notin", "object", "of", "or",
     "out", "proc", "ptr", "raise", "ref", "return",
-    "shl", "shr", "sig", "static",
+    "shl", "shr", "static",
     "template",
     "try", "tuple", "type", "using",
     "var", "when", "while", "with", "without", "xor",
diff --git a/compiler/parser.nim b/compiler/parser.nim
index e5a381b07..f22177ac1 100644
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -1908,7 +1908,7 @@ proc complexOrSimpleStmt(p: var TParser): PNode =
   #|                     | 'converter' routine
   #|                     | 'type' section(typeDef)
   #|                     | 'const' section(constant)
-  #|                     | ('let' | 'var') section(variable)
+  #|                     | ('let' | 'var' | 'using') section(variable)
   #|                     | bindStmt | mixinStmt)
   #|                     / simpleStmt
   case p.tok.tokType
@@ -1943,10 +1943,9 @@ proc complexOrSimpleStmt(p: var TParser): PNode =
   of tkLet: result = parseSection(p, nkLetSection, parseVariable)
   of tkWhen: result = parseIfOrWhen(p, nkWhenStmt)
   of tkVar: result = parseSection(p, nkVarSection, parseVariable)
-  of tkSig: result = parseSection(p, nkSigSection, parseVariable)
   of tkBind: result = parseBind(p, nkBindStmt)
   of tkMixin: result = parseBind(p, nkMixinStmt)
-  of tkUsing: result = parseBind(p, nkUsingStmt)
+  of tkUsing: result = parseSection(p, nkUsingStmt, parseVariable)
   else: result = simpleStmt(p)
 
 proc parseStmt(p: var TParser): PNode =
diff --git a/compiler/renderer.nim b/compiler/renderer.nim
index 2b552f130..12852ba3d 100644
--- a/compiler/renderer.nim
+++ b/compiler/renderer.nim
@@ -460,9 +460,12 @@ proc lsub(n: PNode): int =
     else:
       result = len("enum")
   of nkEnumFieldDef: result = lsons(n) + 3
-  of nkVarSection, nkLetSection, nkSigSection:
+  of nkVarSection, nkLetSection:
     if sonsLen(n) > 1: result = MaxLineLen + 1
     else: result = lsons(n) + len("var_")
+  of nkUsingStmt:
+    if sonsLen(n) > 1: result = MaxLineLen + 1
+    else: result = lsons(n) + len("using_")
   of nkReturnStmt: result = lsub(n.sons[0]) + len("return_")
   of nkRaiseStmt: result = lsub(n.sons[0]) + len("raise_")
   of nkYieldStmt: result = lsub(n.sons[0]) + len("yield_")
@@ -1173,12 +1176,12 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
     initContext(a)
     incl(a.flags, rfInConstExpr)
     gsection(g, n, a, tkConst, "const")
-  of nkVarSection, nkLetSection, nkSigSection:
+  of nkVarSection, nkLetSection, nkUsingStmt:
     var L = sonsLen(n)
     if L == 0: return
     if n.kind == nkVarSection: putWithSpace(g, tkVar, "var")
     elif n.kind == nkLetSection: putWithSpace(g, tkLet, "let")
-    else: putWithSpace(g, tkSig, "sig")
+    else: putWithSpace(g, tkUsing, "using")
     if L > 1:
       gcoms(g)
       indentNL(g)
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index a2f1940f7..16b4ee479 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -1556,10 +1556,6 @@ proc newAnonSym(kind: TSymKind, info: TLineInfo,
   result = newSym(kind, idAnon, owner, info)
   result.flags = {sfGenSym}
 
-proc semUsing(c: PContext, n: PNode): PNode =
-  result = newNodeI(nkEmpty, n.info)
-  localError(n.info, "'using' statement is obsolete")
-
 proc semExpandToAst(c: PContext, n: PNode): PNode =
   var macroCall = n[1]
   var expandedSym = expectMacroOrTemplateCall(c, macroCall)
@@ -2354,7 +2350,6 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
     if not n.sons[0].typ.isEmptyType and not implicitlyDiscardable(n.sons[0]):
       localError(n.info, errGenerated, "'defer' takes a 'void' expression")
     #localError(n.info, errGenerated, "'defer' not allowed in this context")
-  of nkSigSection: result = semSigSection(c, n)
   else:
     localError(n.info, errInvalidExpressionX,
                renderTree(n, {renderNoComments}))
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 20bca4c90..5d16f2fba 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -386,8 +386,11 @@ proc isDiscardUnderscore(v: PSym): bool =
     v.flags.incl(sfGenSym)
     result = true
 
-proc semSigSection(c: PContext; n: PNode): PNode =
+proc semUsing(c: PContext; n: PNode): PNode =
   result = ast.emptyNode
+  if not isTopLevel(c): localError(n.info, errXOnlyAtModuleScope, "using")
+  if not experimentalMode(c):
+    localError(n.info, "use the {.experimental.} pragma to enable 'using'")
   for i in countup(0, sonsLen(n)-1):
     var a = n.sons[i]
     if gCmd == cmdIdeTools: suggestStmt(c, a)
@@ -402,10 +405,10 @@ proc semSigSection(c: PContext; n: PNode): PNode =
         v.typ = typ
         strTableIncl(c.signatures, v)
     else:
-      localError(a.info, "'sig' section must have a type")
+      localError(a.info, "'using' section must have a type")
     var def: PNode
     if a.sons[length-1].kind != nkEmpty:
-      localError(a.info, "'sig' sections cannot contain assignments")
+      localError(a.info, "'using' sections cannot contain assignments")
 
 proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
   var b: PNode
diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim
index 62848c078..3e0e05a94 100644
--- a/compiler/wordrecg.nim
+++ b/compiler/wordrecg.nim
@@ -30,7 +30,7 @@ type
     wInclude, wInterface, wIs, wIsnot, wIterator, wLet,
     wMacro, wMethod, wMixin, wMod, wNil,
     wNot, wNotin, wObject, wOf, wOr, wOut, wProc, wPtr, wRaise, wRef, wReturn,
-    wShl, wShr, wSig, wStatic, wTemplate, wTry, wTuple, wType, wUsing, wVar,
+    wShl, wShr, wStatic, wTemplate, wTry, wTuple, wType, wUsing, wVar,
     wWhen, wWhile, wWith, wWithout, wXor, wYield,
 
     wColon, wColonColon, wEquals, wDot, wDotDot,
@@ -114,7 +114,7 @@ const
     "macro", "method", "mixin", "mod", "nil", "not", "notin",
     "object", "of", "or",
     "out", "proc", "ptr", "raise", "ref", "return",
-    "shl", "shr", "sig", "static",
+    "shl", "shr", "static",
     "template", "try", "tuple", "type", "using", "var",
     "when", "while", "with", "without", "xor",
     "yield",