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