mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Update .len for subarray to not require ()
This commit is contained in:
@@ -46,7 +46,7 @@ func void encode(char[] in, char *out)
|
||||
{
|
||||
int j = 0;
|
||||
char c = LUT_ENC[1];
|
||||
for (int i = 0; i < in.len(); i++)
|
||||
for (int i = 0; i < in.len; i++)
|
||||
{
|
||||
switch (i % 3)
|
||||
{
|
||||
@@ -61,7 +61,7 @@ func void encode(char[] in, char *out)
|
||||
}
|
||||
|
||||
// move back
|
||||
usize last = in.len() - 1;
|
||||
usize last = in.len - 1;
|
||||
// check the last and add padding
|
||||
switch (last % 3)
|
||||
{
|
||||
@@ -80,7 +80,7 @@ func int! decode(char[] in, char* out, int* invalid_char_index = null)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
for (int i = 0; i < in.len(); i++)
|
||||
for (int i = 0; i < in.len; i++)
|
||||
{
|
||||
char value = in[i];
|
||||
if (value == PAD) return j;
|
||||
@@ -100,13 +100,13 @@ func int! decode(char[] in, char* out, int* invalid_char_index = null)
|
||||
case 1:
|
||||
out[j++] += c >> 4 & 0x3;
|
||||
// if not last char with padding
|
||||
if (i < (in.len() - 3) || in[(long)(in.len()) - 2] != PAD)
|
||||
if (i < (in.len - 3) || in[(long)(in.len) - 2] != PAD)
|
||||
{
|
||||
out[j] = (c & 0xF) << 4;
|
||||
}
|
||||
case 2:
|
||||
out[j++] += c >> 2 & 0xF;
|
||||
if (i < (in.len() - 2) || in[(long)(in.len()) - 1] != PAD)
|
||||
if (i < (in.len - 2) || in[(long)(in.len) - 1] != PAD)
|
||||
{
|
||||
out[j] = (c & 0x3) << 6;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ const LINELEN = 60;
|
||||
// slowest character-at-a-time output
|
||||
func void repeat_fasta(char[] seq, int n)
|
||||
{
|
||||
usize len = seq.len();
|
||||
usize len = seq.len;
|
||||
int i = void;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
@@ -69,8 +69,8 @@ func void repeat_fasta(char[] seq, int n)
|
||||
|
||||
func void random_fasta(char[] symb, double[] probability, int n)
|
||||
{
|
||||
assert(symb.len() == probability.len());
|
||||
int len = (int)(probability.len());
|
||||
assert(symb.len == probability.len);
|
||||
int len = probability.len;
|
||||
int i = void;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ struct Planet
|
||||
|
||||
func void advance(Planet[] bodies) @noinline
|
||||
{
|
||||
usize nbodies = bodies.len();
|
||||
usize nbodies = bodies.len;
|
||||
foreach (i, Planet* &b : bodies)
|
||||
{
|
||||
for (usize j = i + 1; j < nbodies; j++)
|
||||
@@ -45,7 +45,7 @@ func void advance(Planet[] bodies) @noinline
|
||||
func double energy(Planet[] bodies)
|
||||
{
|
||||
double e;
|
||||
usize nbodies = bodies.len();
|
||||
usize nbodies = bodies.len;
|
||||
|
||||
foreach (i, Planet* &b : bodies)
|
||||
{
|
||||
|
||||
@@ -4,8 +4,8 @@ func int levenshtein(String s, String t)
|
||||
{
|
||||
// if either string is empty, difference is inserting all chars
|
||||
// from the other
|
||||
if (!s.len()) return t.len();
|
||||
if (!t.len()) return s.len();
|
||||
if (!s.len) return t.len;
|
||||
if (!t.len) return s.len;
|
||||
|
||||
// if last letters are the same, the difference is whatever is
|
||||
// required to edit the rest of the strings
|
||||
|
||||
@@ -101,7 +101,7 @@ func void testArrays()
|
||||
{
|
||||
printf("index[%d]: %d\n", i, a);
|
||||
}
|
||||
printf("Length is a runtime value: %d\n", y.len());
|
||||
printf("Length is a runtime value: %d\n", y.len);
|
||||
puts("Getting a slice from the beginning to an offset of the end---");
|
||||
y = x[..^2]; // Same as x[0..^2]
|
||||
foreach (i, a : y)
|
||||
|
||||
@@ -26,9 +26,9 @@ struct TopoList
|
||||
public func void sort(InputPair[] pairs, uint elements)
|
||||
{
|
||||
printf(.x = "fe");
|
||||
InputPair[] result = @array::make(InputPair, pairs.len());
|
||||
InputPair[] result = @array::make(InputPair, pairs.len);
|
||||
TopoList* top = mem::calloc(TopoList.sizeof, elements);
|
||||
for (int i = 0; i < pairs.len(); i++)
|
||||
for (int i = 0; i < pairs.len; i++)
|
||||
{
|
||||
InputPair pair = pairs[i];
|
||||
assert(pair.value >= 0 && pair.value < elements);
|
||||
|
||||
@@ -1758,14 +1758,6 @@ static inline bool sema_expr_analyse_call(Context *context, Type *to, Expr *expr
|
||||
decl = func_expr->macro_expansion_expr.decl;
|
||||
macro = true;
|
||||
break;
|
||||
case EXPR_LEN:
|
||||
if (func_expr->type == type_void)
|
||||
{
|
||||
expr_replace(expr, func_expr);
|
||||
expr_set_type(expr, type_usize);
|
||||
return true;
|
||||
}
|
||||
FALLTHROUGH;
|
||||
case EXPR_TYPEINFO:
|
||||
if (func_expr->type_expr->resolve_status == RESOLVE_DONE)
|
||||
{
|
||||
@@ -2399,7 +2391,8 @@ CHECK_DEEPER:
|
||||
{
|
||||
expr->expr_kind = EXPR_LEN;
|
||||
expr->len_expr.inner = parent;
|
||||
expr_set_type(expr, type_void);
|
||||
expr->original_type = type_compint;
|
||||
expr->type = type_usize;
|
||||
expr->resolve_status = RESOLVE_DONE;
|
||||
return true;
|
||||
}
|
||||
@@ -6139,10 +6132,6 @@ static inline bool sema_cast_rvalue(Context *context, Type *to, Expr *expr)
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case EXPR_LEN:
|
||||
if (expr->type != type_void) return true;
|
||||
SEMA_ERROR(expr, "Expected () after 'len' for subarrays.");
|
||||
return false;
|
||||
case EXPR_TYPEINFO:
|
||||
SEMA_ERROR(expr, "A type must be followed by either (...) or '.'.");
|
||||
return false;
|
||||
|
||||
@@ -86,7 +86,7 @@ define Argh2 = func int(double, Bobo);
|
||||
func int sum_us(int... x)
|
||||
{
|
||||
int sum = 0;
|
||||
if (x.len() == 0) return 0;
|
||||
if (x.len == 0) return 0;
|
||||
sum += x[0] + sum_us(...x[1..^1]);
|
||||
return sum;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ define Frob = long;
|
||||
func int sumd(int[] x)
|
||||
{
|
||||
int sum = 0;
|
||||
for (int i = 0; i < x.len(); i++) sum += x[i];
|
||||
for (int i = 0; i < x.len; i++) sum += x[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ define Argh2 = func int(double, Bobo);
|
||||
func int sum_us(int... x)
|
||||
{
|
||||
int sum = 0;
|
||||
if (x.len() == 0) return 0;
|
||||
if (x.len == 0) return 0;
|
||||
sum += x[0] + sum_us(...x[1..^1]);
|
||||
return sum;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ define Frob = long;
|
||||
func int sumd(int[] x)
|
||||
{
|
||||
int sum = 0;
|
||||
for (int i = 0; i < x.len(); i++) sum += x[i];
|
||||
for (int i = 0; i < x.len; i++) sum += x[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ func FooIterator Foo.iterator(Foo *f)
|
||||
|
||||
func bool FooIterator.next(FooIterator *it, int *value)
|
||||
{
|
||||
if (it.index == it.f.x.len()) return false;
|
||||
if (it.index == it.f.x.len) return false;
|
||||
*value = it.f.x[it.index++];
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ macro FooIterator Foo.iterator(Foo *f)
|
||||
|
||||
macro bool FooIterator.next(FooIterator *it, int *value)
|
||||
{
|
||||
if (it.index == it.f.x.len()) return false;
|
||||
if (it.index == it.f.x.len) return false;
|
||||
*value = it.f.x[it.index++];
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user