diff --git a/src/ast.nim b/src/ast.nim index c483c62..b7831ca 100644 --- a/src/ast.nim +++ b/src/ast.nim @@ -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] diff --git a/src/parser.nim b/src/parser.nim index 0bd84b3..f9b927b 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -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: diff --git a/tests/hir_test b/tests/hir_test index 74cfee1..130276f 100755 Binary files a/tests/hir_test and b/tests/hir_test differ diff --git a/tests/parser_test b/tests/parser_test index 56c0f17..ab4987e 100755 Binary files a/tests/parser_test and b/tests/parser_test differ diff --git a/tests/sema_test b/tests/sema_test index 604d73b..b87ff90 100755 Binary files a/tests/sema_test and b/tests/sema_test differ