mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-01 03:24:41 +00:00
semLambda removed, semProcAux reworked (#17379)
* simplified proc-like name ident to symbol code * wip - reworking generic param sem * wip - closer to removing nkEmpty generic params * it's hacky but tests pass * slowly tweaking semProcAux to take on semLambda * fix pragma superset check proto vs current * Set the symbol owner earlier * partial progress reworking proto found bug where default values between forward and impl lead to overload resolution issues. * simplified pragma handling and callConv checks Co-authored-by: Clyybber <Clyybber@users.noreply.github.com> * partially working * cgexprs issue * It works! * comment clean-up * clean-up asserts, comments, and other bits * add isGenericParams, inline isGeneric queries * seeing if this is sufficiently consistent * can use this approach or continue it in a further PR * commentary about nullary generics and clean-ups * fixed a mistake in PNode isGenericRoutine * Some small cleanups * Small cleanup * for func lambdas ensure we use lambda pragmas * add some basic compileTime func tests * [ci skip] remove comments Co-authored-by: Clyybber <Clyybber@users.noreply.github.com> Co-authored-by: Clyybber <darkmine956@gmail.com>
This commit is contained in:
14
tests/constr/tnocompiletimefunc.nim
Normal file
14
tests/constr/tnocompiletimefunc.nim
Normal file
@@ -0,0 +1,14 @@
|
||||
discard """
|
||||
errormsg: "request to generate code for .compileTime proc: foo"
|
||||
"""
|
||||
|
||||
# ensure compileTime funcs can't be called from runtime
|
||||
|
||||
func foo(a: int): int {.compileTime.} =
|
||||
a * a
|
||||
|
||||
proc doAThing(): int =
|
||||
for i in 0..2:
|
||||
result += foo(i)
|
||||
|
||||
echo doAThing()
|
||||
6
tests/constr/tnocompiletimefunclambda.nim
Normal file
6
tests/constr/tnocompiletimefunclambda.nim
Normal file
@@ -0,0 +1,6 @@
|
||||
discard """
|
||||
errormsg: "request to generate code for .compileTime proc: :anonymous"
|
||||
"""
|
||||
|
||||
let a = func(a: varargs[int]) {.compileTime, closure.} =
|
||||
discard a[0]
|
||||
11
tests/converter/tconverter.nim
Normal file
11
tests/converter/tconverter.nim
Normal file
@@ -0,0 +1,11 @@
|
||||
discard """
|
||||
output: '''fooo fooo'''
|
||||
"""
|
||||
|
||||
converter intToString[T](i: T): string = "fooo"
|
||||
|
||||
let
|
||||
foo: string = 1
|
||||
bar: string = intToString(2)
|
||||
|
||||
echo foo, " ", bar
|
||||
26
tests/generics/tnullary_generics.nim
Normal file
26
tests/generics/tnullary_generics.nim
Normal file
@@ -0,0 +1,26 @@
|
||||
discard """
|
||||
nimout: '''
|
||||
hah
|
||||
hey
|
||||
hey
|
||||
hah
|
||||
'''
|
||||
"""
|
||||
|
||||
# non-generic
|
||||
proc foo(s: string) =
|
||||
static: echo "hah"
|
||||
echo s
|
||||
|
||||
static: echo "hey"
|
||||
|
||||
foo("hoo")
|
||||
|
||||
# nullary generic
|
||||
proc bar[](s: string) =
|
||||
static: echo "hah"
|
||||
echo s
|
||||
|
||||
static: echo "hey"
|
||||
|
||||
bar("hoo")
|
||||
@@ -2,6 +2,8 @@ discard """
|
||||
nimout: '''
|
||||
staticAlialProc instantiated with 358
|
||||
staticAlialProc instantiated with 368
|
||||
0: Foo
|
||||
1: Bar
|
||||
'''
|
||||
output: '''
|
||||
16
|
||||
@@ -289,8 +291,10 @@ macro fooParam(x: static array[2, string]): untyped =
|
||||
echo i, ": ", val
|
||||
|
||||
macro barParam(x: static Table[int, string]): untyped =
|
||||
for i, val in x:
|
||||
let barParamInsides = proc(i: int, val: string): NimNode =
|
||||
echo i, ": ", val
|
||||
for i, val in x:
|
||||
discard barParamInsides(i, val)
|
||||
|
||||
fooM()
|
||||
barM()
|
||||
|
||||
Reference in New Issue
Block a user