Updated grammar. Removal of elif. Removal of ':' ';' in some ct statements. Empty faults is now an error. Remove "define" for types. Remove "private". Better errors on incorrect bitstruct syntax. Introduction of wildcard type rather than optional wildcard. Removal of scaled vector type. mkdir and rmdir. Disallow define @Foo() = { @inline }. Add handling for @optreturn and change it to @return!. Restrict interface style functions. Updated x64 ABI. stdlib updates to string. Removed deprecated functions. Update how variadics are implemented. Extended error messages. x86 ABI fixes. Shift check fixes. '!' and '?' are flipped. No trailing ',' allowed in functions. Fix to string parsing. Allow l suffix. Simplifying flatpath. any replaces variant, anyfault replaces anyerr. Allow getting the underlying type of anyfault. De-duplicate string constants. Fix of readme. Extended list. Fix of "(MyEnum)x + 1". Clock and DateTime types. Fixes to array concat.

This commit is contained in:
Christoffer Lerno
2023-03-23 14:49:51 +01:00
committed by Christoffer Lerno
parent d14e778232
commit 809321e20c
270 changed files with 8777 additions and 7237 deletions

View File

@@ -48,10 +48,10 @@ fn void! InetAddress.to_format(InetAddress* addr, Formatter* formatter)
{
formatter.printf("%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
addr.ipv6.a, addr.ipv6.b, addr.ipv6.c, addr.ipv6.d,
addr.ipv6.e, addr.ipv6.f, addr.ipv6.g, addr.ipv6.h)?;
addr.ipv6.e, addr.ipv6.f, addr.ipv6.g, addr.ipv6.h)!;
return;
}
formatter.printf("%d.%d.%d.%d", addr.ipv4.a, addr.ipv4.b, addr.ipv4.c, addr.ipv4.d)?;
formatter.printf("%d.%d.%d.%d", addr.ipv4.a, addr.ipv4.b, addr.ipv4.c, addr.ipv4.d)!;
}
fn String! InetAddress.to_string(InetAddress* addr, Allocator* using = mem::heap())
@@ -61,22 +61,22 @@ fn String! InetAddress.to_string(InetAddress* addr, Allocator* using = mem::heap
char[8 * 5 + 1] buffer;
String res = (String)io::bprintf(&buffer, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
addr.ipv6.a, addr.ipv6.b, addr.ipv6.c, addr.ipv6.d,
addr.ipv6.e, addr.ipv6.f, addr.ipv6.g, addr.ipv6.h)?;
addr.ipv6.e, addr.ipv6.f, addr.ipv6.g, addr.ipv6.h)!;
return res.copy(using);
}
char[3 * 4 + 3 + 1] buffer;
String res = (String)io::bprintf(&buffer, "%d.%d.%d.%d", addr.ipv4.a, addr.ipv4.b, addr.ipv4.c, addr.ipv4.d)?;
String res = (String)io::bprintf(&buffer, "%d.%d.%d.%d", addr.ipv4.a, addr.ipv4.b, addr.ipv4.c, addr.ipv4.d)!;
return res.copy(using);
}
fn InetAddress! ipv6_from_str(String s)
{
uint sections = 0;
if (s.len < 2) return NetError.INVALID_IP_STRING!;
if (s.len < 2) return NetError.INVALID_IP_STRING?;
foreach (c : s) if (c == ':') sections++;
int zero_segment_len = s[0] == ':' || s[^1] == ':' ? 9 - sections : 8 - sections;
if (zero_segment_len == 7 && s.len == 2) return { .is_ipv6 = true };
if (zero_segment_len > 7) return NetError.INVALID_IP_STRING!;
if (zero_segment_len > 7) return NetError.INVALID_IP_STRING?;
usz index = 0;
bool last_was_colon, found_zero;
int current = -1;
@@ -92,7 +92,7 @@ fn InetAddress! ipv6_from_str(String s)
last_was_colon = true;
continue;
}
if (current < 0 || current > 65535) return NetError.INVALID_IP_STRING!;
if (current < 0 || current > 65535) return NetError.INVALID_IP_STRING?;
addr.ipv6arr[index++].val = (ushort)current;
current = -1;
last_was_colon = true;
@@ -100,9 +100,9 @@ fn InetAddress! ipv6_from_str(String s)
}
assert(current == -1);
// Check that this is the first ::
if (found_zero) return NetError.INVALID_IP_STRING!;
if (found_zero) return NetError.INVALID_IP_STRING?;
// Also check that the zeroed section is at least 2
if (zero_segment_len < 2) return NetError.INVALID_IP_STRING!;
if (zero_segment_len < 2) return NetError.INVALID_IP_STRING?;
// Skip (will be zero by default
index += zero_segment_len;
found_zero = true;
@@ -110,7 +110,7 @@ fn InetAddress! ipv6_from_str(String s)
continue;
}
last_was_colon = false;
if (index > 7 || !c.is_xdigit()) return NetError.INVALID_IP_STRING!;
if (index > 7 || !c.is_xdigit()) return NetError.INVALID_IP_STRING?;
if (current < 0) current = 0;
current = current * 16 + (c <= '9' ? c - '0' : (c | 32) - 'a' + 10);
}
@@ -118,7 +118,7 @@ fn InetAddress! ipv6_from_str(String s)
if (index == 8 && current == -1) return addr;
// Ends with number
if (index != 7 || current < 0 || current > 65535) return NetError.INVALID_IP_STRING!;
if (index != 7 || current < 0 || current > 65535) return NetError.INVALID_IP_STRING?;
addr.ipv6arr[7].val = (ushort)current;
return addr;
}
@@ -132,20 +132,20 @@ fn InetAddress! ipv4_from_str(String s)
{
if (c == '.')
{
if (current < 0) return NetError.INVALID_IP_STRING!;
if (current > 255) return NetError.INVALID_IP_STRING!;
if (current < 0) return NetError.INVALID_IP_STRING?;
if (current > 255) return NetError.INVALID_IP_STRING?;
switch (element)
{
case 0: addr.ipv4.a = (char)current;
case 1: addr.ipv4.b = (char)current;
case 2: addr.ipv4.c = (char)current;
default: return NetError.INVALID_IP_STRING!;
default: return NetError.INVALID_IP_STRING?;
}
current = -1;
element++;
continue;
}
if (element > 3 || c < '0' || c > '9') return NetError.INVALID_IP_STRING!;
if (element > 3 || c < '0' || c > '9') return NetError.INVALID_IP_STRING?;
if (current < 0)
{
current = c - '0';
@@ -153,7 +153,7 @@ fn InetAddress! ipv4_from_str(String s)
}
current = current * 10 + c - '0';
}
if (element != 3 || current < 0 || current > 255) return NetError.INVALID_IP_STRING!;
if (element != 3 || current < 0 || current > 255) return NetError.INVALID_IP_STRING?;
addr.ipv4.d = (char)current;
return addr;
}

View File

@@ -19,13 +19,13 @@ fn uint! ipv4toint(String s)
{
if (c == '.')
{
if (current < 0) return NetError.INVALID_IP_STRING!;
if (current < 0) return NetError.INVALID_IP_STRING?;
out = out << 8 + current;
current = -1;
element++;
continue;
}
if (element > 3 || c < '0' || c > '9') return NetError.INVALID_IP_STRING!;
if (element > 3 || c < '0' || c > '9') return NetError.INVALID_IP_STRING?;
if (current < 0)
{
current = c - '0';
@@ -33,7 +33,7 @@ fn uint! ipv4toint(String s)
}
current = current * 10 + c - '0';
}
if (element != 3 || current < 0) return NetError.INVALID_IP_STRING!;
if (element != 3 || current < 0) return NetError.INVALID_IP_STRING?;
out = out << 8 + current;
return out;
}
@@ -41,6 +41,6 @@ fn uint! ipv4toint(String s)
fn String! inttoipv4(uint val, Allocator* using = mem::heap())
{
char[3 * 4 + 3 + 1] buffer;
String res = (String)io::bprintf(&buffer, "%d.%d.%d.%d", val >> 24, (val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF)?;
String res = (String)io::bprintf(&buffer, "%d.%d.%d.%d", val >> 24, (val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF)!;
return res.copy(using);
}

View File

@@ -1,7 +1,7 @@
module std::net::os;
import libc;
$if (env::OS_TYPE == OsType.MACOSX)
$if (env::OS_TYPE == OsType.MACOS)
const AI_NUMERICSERV = 0x1000;
const AI_ALL = 0x100;

View File

@@ -19,8 +19,8 @@ macro void! NativeSocket.close(NativeSocket this)
{
if (close(this))
{
if (libc::errno() == errno::EBADF) return NetError.INVALID_SOCKET!;
return NetError.GENERAL_ERROR!;
if (libc::errno() == errno::EBADF) return NetError.INVALID_SOCKET?;
return NetError.GENERAL_ERROR?;
}
}
@@ -29,8 +29,8 @@ macro void! NativeSocket.set_non_blocking(NativeSocket this)
int flags = fcntl(this, F_GETFL, 0);
if (fcntl(this, F_SETFL, flags | O_NONBLOCK) == -1)
{
if (libc::errno() == errno::EBADF) return NetError.INVALID_SOCKET!;
return NetError.GENERAL_ERROR!;
if (libc::errno() == errno::EBADF) return NetError.INVALID_SOCKET?;
return NetError.GENERAL_ERROR?;
}
}