Phase 8.4: const func syntax — compile-time function declarations
This commit is contained in:
@@ -323,6 +323,7 @@ type
|
||||
of dkFunc:
|
||||
declFuncAsm*: bool
|
||||
declFuncCallConv*: CallingConvention
|
||||
declFuncConst*: bool ## const func — evaluable at compile time
|
||||
declFuncName*: string
|
||||
declFuncTypeParams*: seq[string]
|
||||
declFuncParams*: seq[Param]
|
||||
|
||||
+8
-2
@@ -889,7 +889,7 @@ proc parseParamList(p: var Parser, allowVariadic: bool = false): seq[Param] =
|
||||
discard p.advance()
|
||||
discard p.expect(tkRParen, "expected ')' to close parameter list")
|
||||
|
||||
proc parseFuncDecl(p: var Parser, isPublic: bool, isAsm: bool, attrs: ParsedAttrs): Decl =
|
||||
proc parseFuncDecl(p: var Parser, isPublic: bool, isAsm: bool, attrs: ParsedAttrs, isConst: bool = false): Decl =
|
||||
let loc = p.currentLoc
|
||||
discard p.expect(tkFunc, "expected 'func'")
|
||||
let name = p.expect(tkIdent, "expected function name").text
|
||||
@@ -909,6 +909,7 @@ proc parseFuncDecl(p: var Parser, isPublic: bool, isAsm: bool, attrs: ParsedAttr
|
||||
return Decl(kind: dkFunc, loc: loc, isPublic: isPublic,
|
||||
declAttrs: declAttrs,
|
||||
declFuncAsm: isAsm, declFuncCallConv: attrs.callConv,
|
||||
declFuncConst: isConst,
|
||||
declFuncName: name, declFuncTypeParams: typeParams,
|
||||
declFuncParams: params, declFuncReturnType: retType,
|
||||
declFuncBody: body)
|
||||
@@ -1186,9 +1187,14 @@ proc parseDecl(p: var Parser): Decl =
|
||||
if p.check(tkAt):
|
||||
attrs = p.parseAttrs()
|
||||
|
||||
var isConst = false
|
||||
if p.check(tkConst) and p.peek(1) == tkFunc:
|
||||
isConst = true
|
||||
discard p.advance()
|
||||
|
||||
case p.peek()
|
||||
of tkFunc:
|
||||
return p.parseFuncDecl(isPublic, false, attrs)
|
||||
return p.parseFuncDecl(isPublic, false, attrs, isConst)
|
||||
of tkStruct:
|
||||
return p.parseStructDecl(isPublic)
|
||||
of tkEnum:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user