mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix regression for parsing types and switch to the "new" generic syntax that's being tested.
This commit is contained in:
@@ -75,7 +75,7 @@ import std::collections::list;
|
||||
|
||||
const BITS = Type.sizeof * 8;
|
||||
|
||||
def GrowableBitSetList = List(<Type>);
|
||||
def GrowableBitSetList = List<[Type]>;
|
||||
|
||||
struct GrowableBitSet
|
||||
{
|
||||
|
||||
@@ -462,7 +462,7 @@ fn Object* Object.get_or_create_obj(&self, String key)
|
||||
return container;
|
||||
}
|
||||
|
||||
def ObjectInternalMap = HashMap(<String, Object*>) @private;
|
||||
def ObjectInternalList = List(<Object*>) @private;
|
||||
def ObjectInternalMapEntry = Entry(<String, Object*>) @private;
|
||||
def ObjectInternalMap = HashMap<[String, Object*]> @private;
|
||||
def ObjectInternalList = List<[Object*]> @private;
|
||||
def ObjectInternalMapEntry = Entry<[String, Object*]> @private;
|
||||
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
module std::collections::priorityqueue(<Type>);
|
||||
import std::collections::priorityqueue::private;
|
||||
|
||||
distinct PriorityQueue = inline PrivatePriorityQueue(<Type, false>);
|
||||
distinct PriorityQueueMax = inline PrivatePriorityQueue(<Type, true>);
|
||||
distinct PriorityQueue = inline PrivatePriorityQueue<[Type, false]>;
|
||||
distinct PriorityQueueMax = inline PrivatePriorityQueue<[Type, true]>;
|
||||
|
||||
module std::collections::priorityqueue::private(<Type, MAX>);
|
||||
import std::collections::list, std::io;
|
||||
|
||||
def Heap = List(<Type>);
|
||||
def Heap = List<[Type]>;
|
||||
|
||||
struct PrivatePriorityQueue (Printable)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ struct Allocation
|
||||
void*[MAX_BACKTRACE] backtrace;
|
||||
}
|
||||
|
||||
def AllocMap = HashMap(<uptr, Allocation>);
|
||||
def AllocMap = HashMap<[uptr, Allocation]>;
|
||||
|
||||
// A simple tracking allocator.
|
||||
// It tracks allocations using a hash map but
|
||||
|
||||
@@ -26,7 +26,7 @@ macro slice2d(array_ptr, x = 0, xlen = 0, y = 0, ylen = 0)
|
||||
if (xlen < 1) xlen = $typeof((*array_ptr)[0]).len + xlen;
|
||||
if (ylen < 1) ylen = $typeof((*array_ptr)).len + ylen;
|
||||
var $ElementType = $typeof((*array_ptr)[0][0]);
|
||||
return Slice2d(<$ElementType>) { ($ElementType*)array_ptr, $typeof((*array_ptr)[0]).len, y, ylen, x, xlen };
|
||||
return Slice2d<[$ElementType]> { ($ElementType*)array_ptr, $typeof((*array_ptr)[0]).len, y, ylen, x, xlen };
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ struct Md5
|
||||
uint[16] block;
|
||||
}
|
||||
|
||||
def HmacMd5 = Hmac(<Md5, HASH_BYTES, BLOCK_BYTES>);
|
||||
def hmac = hmac::hash(<Md5, HASH_BYTES, BLOCK_BYTES>);
|
||||
def pbkdf2 = hmac::pbkdf2(<Md5, HASH_BYTES, BLOCK_BYTES>);
|
||||
def HmacMd5 = Hmac<[Md5, HASH_BYTES, BLOCK_BYTES]>;
|
||||
def hmac = hmac::hash<[Md5, HASH_BYTES, BLOCK_BYTES]>;
|
||||
def pbkdf2 = hmac::pbkdf2<[Md5, HASH_BYTES, BLOCK_BYTES]>;
|
||||
|
||||
fn char[HASH_BYTES] hash(char[] data)
|
||||
{
|
||||
|
||||
@@ -18,9 +18,9 @@ struct Sha1
|
||||
char[BLOCK_BYTES] buffer;
|
||||
}
|
||||
|
||||
def HmacSha1 = Hmac(<Sha1, HASH_BYTES, BLOCK_BYTES>);
|
||||
def hmac = hmac::hash(<Sha1, HASH_BYTES, BLOCK_BYTES>);
|
||||
def pbkdf2 = hmac::pbkdf2(<Sha1, HASH_BYTES, BLOCK_BYTES>);
|
||||
def HmacSha1 = Hmac<[Sha1, HASH_BYTES, BLOCK_BYTES]>;
|
||||
def hmac = hmac::hash<[Sha1, HASH_BYTES, BLOCK_BYTES]>;
|
||||
def pbkdf2 = hmac::pbkdf2<[Sha1, HASH_BYTES, BLOCK_BYTES]>;
|
||||
|
||||
fn char[HASH_BYTES] hash(char[] data)
|
||||
{
|
||||
|
||||
@@ -34,9 +34,9 @@ struct Sha256
|
||||
char[BLOCK_SIZE] buffer;
|
||||
}
|
||||
|
||||
def HmacSha256 = Hmac(<Sha256, HASH_SIZE, BLOCK_SIZE>);
|
||||
def hmac = hmac::hash(<Sha256, HASH_SIZE, BLOCK_SIZE>);
|
||||
def pbkdf2 = hmac::pbkdf2(<Sha256, HASH_SIZE, BLOCK_SIZE>);
|
||||
def HmacSha256 = Hmac<[Sha256, HASH_SIZE, BLOCK_SIZE]>;
|
||||
def hmac = hmac::hash<[Sha256, HASH_SIZE, BLOCK_SIZE]>;
|
||||
def pbkdf2 = hmac::pbkdf2<[Sha256, HASH_SIZE, BLOCK_SIZE]>;
|
||||
|
||||
fn char[HASH_SIZE] hash(char[] data)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ const char PREFERRED_SEPARATOR_WIN32 = '\\';
|
||||
const char PREFERRED_SEPARATOR_POSIX = '/';
|
||||
const char PREFERRED_SEPARATOR = env::WIN32 ? PREFERRED_SEPARATOR_WIN32 : PREFERRED_SEPARATOR_POSIX;
|
||||
|
||||
def PathList = List(<Path>);
|
||||
def PathList = List<[Path]>;
|
||||
|
||||
fault PathResult
|
||||
{
|
||||
|
||||
@@ -90,33 +90,33 @@ fault MatrixError
|
||||
MATRIX_INVERSE_DOESNT_EXIST,
|
||||
}
|
||||
|
||||
def Complexf = Complex(<float>);
|
||||
def Complex = Complex(<double>);
|
||||
def COMPLEX_IDENTITY = complex::IDENTITY(<double>);
|
||||
def COMPLEXF_IDENTITY = complex::IDENTITY(<float>);
|
||||
def Complexf = Complex<[float]>;
|
||||
def Complex = Complex<[double]>;
|
||||
def COMPLEX_IDENTITY = complex::IDENTITY<[double]>;
|
||||
def COMPLEXF_IDENTITY = complex::IDENTITY<[float]>;
|
||||
|
||||
def Quaternionf = Quaternion(<float>);
|
||||
def Quaternion = Quaternion(<double>);
|
||||
def QUATERNION_IDENTITY = quaternion::IDENTITY(<double>);
|
||||
def QUATERNIONF_IDENTITY = quaternion::IDENTITY(<float>);
|
||||
def Quaternionf = Quaternion<[float]>;
|
||||
def Quaternion = Quaternion<[double]>;
|
||||
def QUATERNION_IDENTITY = quaternion::IDENTITY<[double]>;
|
||||
def QUATERNIONF_IDENTITY = quaternion::IDENTITY<[float]>;
|
||||
|
||||
def Matrix2f = Matrix2x2(<float>);
|
||||
def Matrix2 = Matrix2x2(<double>);
|
||||
def Matrix3f = Matrix3x3(<float>);
|
||||
def Matrix3 = Matrix3x3(<double>);
|
||||
def Matrix4f = Matrix4x4(<float>);
|
||||
def Matrix4 = Matrix4x4(<double>);
|
||||
def matrix4_ortho = matrix::ortho(<double>);
|
||||
def matrix4_perspective = matrix::perspective(<double>);
|
||||
def matrix4f_ortho = matrix::ortho(<float>);
|
||||
def matrix4f_perspective = matrix::perspective(<float>);
|
||||
def Matrix2f = Matrix2x2<[float]>;
|
||||
def Matrix2 = Matrix2x2<[double]>;
|
||||
def Matrix3f = Matrix3x3<[float]>;
|
||||
def Matrix3 = Matrix3x3<[double]>;
|
||||
def Matrix4f = Matrix4x4<[float]>;
|
||||
def Matrix4 = Matrix4x4<[double]>;
|
||||
def matrix4_ortho = matrix::ortho<[double]>;
|
||||
def matrix4_perspective = matrix::perspective<[double]>;
|
||||
def matrix4f_ortho = matrix::ortho<[float]>;
|
||||
def matrix4f_perspective = matrix::perspective<[float]>;
|
||||
|
||||
def MATRIX2_IDENTITY = matrix::IDENTITY2(<double>);
|
||||
def MATRIX2F_IDENTITY = matrix::IDENTITY2(<float>);
|
||||
def MATRIX3_IDENTITY = matrix::IDENTITY3(<double>);
|
||||
def MATRIX3F_IDENTITY = matrix::IDENTITY3(<float>);
|
||||
def MATRIX4_IDENTITY = matrix::IDENTITY4(<double>);
|
||||
def MATRIX4F_IDENTITY = matrix::IDENTITY4(<float>);
|
||||
def MATRIX2_IDENTITY = matrix::IDENTITY2<[double]>;
|
||||
def MATRIX2F_IDENTITY = matrix::IDENTITY2<[float]>;
|
||||
def MATRIX3_IDENTITY = matrix::IDENTITY3<[double]>;
|
||||
def MATRIX3F_IDENTITY = matrix::IDENTITY3<[float]>;
|
||||
def MATRIX4_IDENTITY = matrix::IDENTITY4<[double]>;
|
||||
def MATRIX4F_IDENTITY = matrix::IDENTITY4<[float]>;
|
||||
|
||||
|
||||
<*
|
||||
|
||||
@@ -66,8 +66,8 @@ fn Vec3 Vec3.refract(self, Vec3 n, double r) => refract3(self, n, r);
|
||||
fn void ortho_normalize(Vec3f* v1, Vec3f* v2) => ortho_normalize3(v1, v2);
|
||||
fn void ortho_normalized(Vec3* v1, Vec3* v2) => ortho_normalize3(v1, v2);
|
||||
|
||||
fn Matrix4f matrix4f_look_at(Vec3f eye, Vec3f target, Vec3f up) @deprecated => matrix::look_at(<float>)(eye, target, up);
|
||||
fn Matrix4 matrix4_look_at(Vec3 eye, Vec3 target, Vec3 up) @deprecated => matrix::look_at(<double>)(eye, target, up);
|
||||
fn Matrix4f matrix4f_look_at(Vec3f eye, Vec3f target, Vec3f up) @deprecated => matrix::look_at<[float]>(eye, target, up);
|
||||
fn Matrix4 matrix4_look_at(Vec3 eye, Vec3 target, Vec3 up) @deprecated => matrix::look_at<[double]>(eye, target, up);
|
||||
|
||||
fn Vec3f Vec3f.rotate_quat(self, Quaternionf q) => rotate_by_quat3(self, q);
|
||||
fn Vec3 Vec3.rotate_quat(self, Quaternion q) => rotate_by_quat3(self, q);
|
||||
|
||||
@@ -243,11 +243,11 @@ fn String Url.to_string(&self, Allocator allocator = allocator::heap()) @dynamic
|
||||
};
|
||||
}
|
||||
|
||||
def UrlQueryValueList = List(<String>);
|
||||
def UrlQueryValueList = List<[String]>;
|
||||
|
||||
struct UrlQueryValues
|
||||
{
|
||||
inline HashMap(<String, UrlQueryValueList>) map;
|
||||
inline HashMap<[String, UrlQueryValueList]> map;
|
||||
UrlQueryValueList key_order;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ fn void*[] capture_current(void*[] buffer)
|
||||
$endswitch
|
||||
}
|
||||
|
||||
def BacktraceList = List(<Backtrace>);
|
||||
def BacktraceList = List<[Backtrace]>;
|
||||
|
||||
def symbolize_backtrace = linux::symbolize_backtrace @if(env::LINUX);
|
||||
def symbolize_backtrace = win32::symbolize_backtrace @if(env::WIN32);
|
||||
|
||||
@@ -11,17 +11,17 @@ Sort list using the counting sort algorithm.
|
||||
macro countingsort(list, key_fn = EMPTY_MACRO_SLOT) @builtin
|
||||
{
|
||||
usz len = sort::len_from_list(list);
|
||||
cs::csort(<$typeof(list), $typeof(key_fn)>)(list, 0, len, key_fn, ~((uint)0));
|
||||
cs::csort<[$typeof(list), $typeof(key_fn)]>(list, 0, len, key_fn, ~((uint)0));
|
||||
}
|
||||
|
||||
macro insertionsort_indexed(list, start, end, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin
|
||||
{
|
||||
is::isort(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, (usz)start, (usz)end, cmp, context);
|
||||
is::isort<[$typeof(list), $typeof(cmp), $typeof(context)]>(list, (usz)start, (usz)end, cmp, context);
|
||||
}
|
||||
|
||||
macro quicksort_indexed(list, start, end, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin
|
||||
{
|
||||
qs::qsort(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, (isz)start, (isz)(end-1), cmp, context);
|
||||
qs::qsort<[$typeof(list), $typeof(cmp), $typeof(context)]>(list, (isz)start, (isz)(end-1), cmp, context);
|
||||
}
|
||||
|
||||
module std::sort::cs(<Type, KeyFn>);
|
||||
|
||||
@@ -10,10 +10,10 @@ macro insertionsort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @b
|
||||
{
|
||||
$if @typekind(list) == POINTER &&& (@typekind(*list) == ARRAY || @typekind(*list) == VECTOR):
|
||||
$typeof((*list)[0])[] list2 = list;
|
||||
is::isort(<$typeof(list2), $typeof(cmp), $typeof(context)>)(list2, 0, list.len, cmp, context);
|
||||
is::isort<[$typeof(list2), $typeof(cmp), $typeof(context)]>(list2, 0, list.len, cmp, context);
|
||||
$else
|
||||
usz len = sort::len_from_list(list);
|
||||
is::isort(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, 0, (isz)len, cmp, context);
|
||||
is::isort<[$typeof(list), $typeof(cmp), $typeof(context)]>(list, 0, (isz)len, cmp, context);
|
||||
$endif
|
||||
}
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@ macro quicksort(list, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @built
|
||||
{
|
||||
$if @typekind(list) == POINTER &&& (@typekind(*list) == ARRAY || @typekind(*list) == VECTOR):
|
||||
$typeof((*list)[0])[] list2 = list;
|
||||
qs::qsort(<$typeof(list2), $typeof(cmp), $typeof(context)>)(list2, 0, (isz)list.len - 1, cmp, context);
|
||||
qs::qsort<[$typeof(list2), $typeof(cmp), $typeof(context)]>(list2, 0, (isz)list.len - 1, cmp, context);
|
||||
$else
|
||||
usz len = sort::len_from_list(list);
|
||||
qs::qsort(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, 0, (isz)len - 1, cmp, context);
|
||||
qs::qsort<[$typeof(list), $typeof(cmp), $typeof(context)]>(list, 0, (isz)len - 1, cmp, context);
|
||||
$endif
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ list will be partially sorted.
|
||||
macro quickselect(list, isz k, cmp = EMPTY_MACRO_SLOT, context = EMPTY_MACRO_SLOT) @builtin
|
||||
{
|
||||
usz len = sort::len_from_list(list);
|
||||
return qs::qselect(<$typeof(list), $typeof(cmp), $typeof(context)>)(list, 0, (isz)len - 1, k, cmp, context);
|
||||
return qs::qselect<[$typeof(list), $typeof(cmp), $typeof(context)]>(list, 0, (isz)len - 1, k, cmp, context);
|
||||
}
|
||||
|
||||
module std::sort::qs(<Type, CmpFn, Context>);
|
||||
|
||||
@@ -615,7 +615,11 @@ TypeInfo *parse_type_with_base(ParseContext *c, TypeInfo *type_info)
|
||||
type_info = parse_array_type_index(c, type_info);
|
||||
break;
|
||||
case TOKEN_LESS:
|
||||
if (c->lexer.token_type != TOKEN_LBRACKET) break;
|
||||
if (c->lexer.token_type != TOKEN_LBRACKET)
|
||||
{
|
||||
PRINT_ERROR_HERE("This looks like you're comparing a type? Or did you intend to write a generic type? In that case the syntax is 'Foo<[int]>'.");
|
||||
return poisoned_type_info;
|
||||
}
|
||||
type_info = parse_generic_type(c, type_info, true);
|
||||
break;
|
||||
case TOKEN_LGENPAR:
|
||||
|
||||
22
test/test_suite/generic/generic_parsing.c3
Normal file
22
test/test_suite/generic/generic_parsing.c3
Normal file
@@ -0,0 +1,22 @@
|
||||
module test;
|
||||
import std;
|
||||
def ListStr = List(<String>);
|
||||
fn void test()
|
||||
{
|
||||
List<String> a = List<...>.new_init(); // #error: This looks like you're comparing a
|
||||
}
|
||||
|
||||
fn void test2()
|
||||
{
|
||||
List<[String]> a = List<...>.new_init(); // #error: This looks like you're comparing a
|
||||
}
|
||||
|
||||
fn void test3()
|
||||
{
|
||||
List(<String>) a = List<[...]>.new_init(); // #error: An expression was expected
|
||||
}
|
||||
|
||||
fn void main()
|
||||
{
|
||||
List<String> a = List<String>.new_init(); // #error: This looks like you're comparing a
|
||||
}
|
||||
Reference in New Issue
Block a user