From e4ce7f658741a7428597da4872435a1b0bae944c Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 3 Oct 2026 20:51:22 +0200 Subject: Rework generics for parameters to be plain types --- testsuite/compilable/generic_alias.elna | 10 +++++----- testsuite/compilable/generic_arguments.elna | 18 +++++++++--------- testsuite/compilable/generic_base_chain.elna | 14 +++++++------- testsuite/compilable/generic_const_inference.elna | 4 ++-- testsuite/compilable/generic_inference.elna | 10 +++++----- testsuite/compilable/generic_pointee.elna | 17 +++++++++++++++++ 6 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 testsuite/compilable/generic_pointee.elna (limited to 'testsuite/compilable') diff --git a/testsuite/compilable/generic_alias.elna b/testsuite/compilable/generic_alias.elna index 47ac638..da9501a 100644 --- a/testsuite/compilable/generic_alias.elna +++ b/testsuite/compilable/generic_alias.elna @@ -6,7 +6,7 @@ type Node#[T] = record next: ^Node#[T]; - value: T + value: ^T end Ref#[T] = ^T @@ -16,10 +16,10 @@ type end var - chain: Node#[^File] - aliased: Ref#[^File] - raw: ^^File - boxed: Boxed#[^File] + chain: Node#[File] + aliased: Ref#[File] + raw: ^File + boxed: Boxed#[File] begin chain.next := nil; diff --git a/testsuite/compilable/generic_arguments.elna b/testsuite/compilable/generic_arguments.elna index 4d33db5..1cda57f 100644 --- a/testsuite/compilable/generic_arguments.elna +++ b/testsuite/compilable/generic_arguments.elna @@ -5,22 +5,22 @@ type end Pair#[K, V] = record - key: K; - value: V + key: ^K; + value: ^V end var - entry: Pair#[^File, ^Word8] + entry: Pair#[File, Word8] -proc allocate#[T](size: Word) -> T +proc allocate#[T](size: Word) -> ^T extern -proc first#[K, V](entry_ptr: ^Pair#[K, V]) -> K +proc first#[K, V](entry_ptr: ^Pair#[K, V]) -> ^K return entry_ptr^.key begin - entry.key := allocate#[^File](#size(File)); - assert(#size(Pair#[^File, ^Word8]) = #size(Pointer) * 2u); - assert(#offset(Pair#[^File, ^Word8], value) = #size(Pointer)); - assert(first#[^File, ^Word8](@entry) = entry.key) + entry.key := allocate#[File](#size(File)); + assert(#size(Pair#[File, Word8]) = #size(Pointer) * 2u); + assert(#offset(Pair#[File, Word8], value) = #size(Pointer)); + assert(first#[File, Word8](@entry) = entry.key) end. diff --git a/testsuite/compilable/generic_base_chain.elna b/testsuite/compilable/generic_base_chain.elna index c303e6d..1abe199 100644 --- a/testsuite/compilable/generic_base_chain.elna +++ b/testsuite/compilable/generic_base_chain.elna @@ -5,20 +5,20 @@ type end Map#[K, V] = record - key: K; - value: V + key: ^K; + value: ^V end - Cache#[K, V] = record(Map#[^Word8, V]) - newest: K + Cache#[K, V] = record(Map#[Word8, V]) + newest: ^K end var - store: Cache#[^Int, ^File] + store: Cache#[Int, File] byte_key: ^Word8 - upcast: ^Map#[^Word8, ^File] + upcast: ^Map#[Word8, File] -proc put#[K2, V2](target: ^Map#[K2, V2]; key: K2) +proc put#[K2, V2](target: ^Map#[K2, V2]; key: ^K2) begin target^.key := key return diff --git a/testsuite/compilable/generic_const_inference.elna b/testsuite/compilable/generic_const_inference.elna index a9fc41f..7ce197f 100644 --- a/testsuite/compilable/generic_const_inference.elna +++ b/testsuite/compilable/generic_const_inference.elna @@ -10,10 +10,10 @@ var nested: NestedConst := nil direct_const: const ^Word8 := nil -proc write#[T](fd: Int; buf: T; count: Int) -> Int +proc write#[T](fd: Int; buf: ^T; count: Int) -> Int return 0 -proc write_const#[T](fd: Int; buf: const T; count: Int) -> Int +proc write_const#[T](fd: Int; buf: ^const T; count: Int) -> Int return 0 begin diff --git a/testsuite/compilable/generic_inference.elna b/testsuite/compilable/generic_inference.elna index 860eab1..9d7fed6 100644 --- a/testsuite/compilable/generic_inference.elna +++ b/testsuite/compilable/generic_inference.elna @@ -5,20 +5,20 @@ type end Cell#[T] = record - held: T + held: ^T end var - files: Cell#[^File] - bytes: Cell#[^Word8] + files: Cell#[File] + bytes: Cell#[Word8] f: File b: Word8 -proc store#[T](target: ^Cell#[T]; value: T) +proc store#[T](target: ^Cell#[T]; value: ^T) target^.held := value return -proc relay#[T](target: ^Cell#[T]; value: T) +proc relay#[T](target: ^Cell#[T]; value: ^T) store(target, value) return diff --git a/testsuite/compilable/generic_pointee.elna b/testsuite/compilable/generic_pointee.elna new file mode 100644 index 0000000..5ecaedf --- /dev/null +++ b/testsuite/compilable/generic_pointee.elna @@ -0,0 +1,17 @@ +program() + +type + File = record + fd: Int + end + +proc allocate#[T](size: Word) -> ^T +extern + +var + f: ^File + +begin + f := allocate#[File](#size(File)); + assert(f = nil) +end. -- cgit v1.2.3