normal destructuring with one line changed
This commit is contained in:
@@ -291,7 +291,7 @@ func main[argc: i64, argv: ptr] : i64
|
||||
c := new CHIP8
|
||||
c->init()
|
||||
|
||||
~buffer, ok := io.read_binary_file(path)
|
||||
buffer, ok := io.read_binary_file(path)
|
||||
if !ok
|
||||
panic("failed to read file")
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ func main[argc: i64, argv: ptr] : i64
|
||||
if i < url_len
|
||||
path = url->substr(i, url_len - i)
|
||||
|
||||
~s, ok := net.connect(host, 80)
|
||||
s, ok := net.connect(host, 80)
|
||||
if !ok
|
||||
panic("failed to connect")
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ include "std/io.zr"
|
||||
include "std/net.zr"
|
||||
|
||||
func main[] : i64
|
||||
~s, ok := net.listen("127.0.0.1", 8000)
|
||||
s, ok := net.listen("127.0.0.1", 8000)
|
||||
if !ok
|
||||
panic("failed to listen")
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ include "std/io.zr"
|
||||
include "std/net.zr"
|
||||
|
||||
func main[] : i64
|
||||
~s, ok := net.create_udp_server("127.0.0.1", 8000)
|
||||
s, ok := net.create_udp_server("127.0.0.1", 8000)
|
||||
if !ok
|
||||
panic("net.create_udp_server failed")
|
||||
|
||||
|
||||
@@ -342,7 +342,7 @@ impl Parser {
|
||||
Ok(Stmt::Break)
|
||||
} else if self.match_token(&[TokenType::KeywordContinue]) {
|
||||
Ok(Stmt::Continue)
|
||||
} else if self.match_token(&[TokenType::Tilde]) {
|
||||
} else if self.check(&TokenType::Identifier) && self.check_ahead(&TokenType::Comma) {
|
||||
let mut targets = vec![];
|
||||
loop {
|
||||
targets.push(self.consume(Identifier, "expected an identifier")?);
|
||||
|
||||
@@ -30,7 +30,6 @@ pub enum TokenType {
|
||||
ShiftLeft,
|
||||
ShiftRight,
|
||||
Arrow,
|
||||
Tilde,
|
||||
|
||||
Equal,
|
||||
DoubleEqual,
|
||||
@@ -179,7 +178,6 @@ impl<'a> Tokenizer<'a> {
|
||||
'%' => self.add_token(TokenType::Mod)?,
|
||||
'^' => self.add_token(TokenType::Xor)?,
|
||||
':' => self.add_token(TokenType::Colon)?,
|
||||
'~' => self.add_token(TokenType::Tilde)?,
|
||||
'-' => {
|
||||
if self.match_char('=') {
|
||||
self.add_token(TokenType::MinusEqual)?
|
||||
|
||||
10
std/net.zr
10
std/net.zr
@@ -22,7 +22,7 @@ func net.listen[host: str, port: i64] : i64, bool
|
||||
_builtin_syscall(SYS_close, s)
|
||||
return -1, false
|
||||
|
||||
~packed_host, ok := net.resolve(host)
|
||||
packed_host, ok := net.resolve(host)
|
||||
if !ok
|
||||
return -1, false
|
||||
|
||||
@@ -44,7 +44,7 @@ func net.connect[host: str, port: i64] : i64, bool
|
||||
if s < 0
|
||||
return -1, false
|
||||
|
||||
~packed_host, ok := net.resolve(host)
|
||||
packed_host, ok := net.resolve(host)
|
||||
if !ok
|
||||
return -1, false
|
||||
|
||||
@@ -106,7 +106,7 @@ func net.UDPSocket.close_and_free[s: net.UDPSocket] : void
|
||||
func net.create_udp_client[host: str, port: i64] : net.UDPSocket, bool
|
||||
s := new* net.UDPSocket
|
||||
|
||||
~packed_host, ok := net.resolve(host)
|
||||
packed_host, ok := net.resolve(host)
|
||||
if !ok
|
||||
return 0 as net.UDPSocket, false
|
||||
|
||||
@@ -120,7 +120,7 @@ func net.create_udp_client[host: str, port: i64] : net.UDPSocket, bool
|
||||
return s, true
|
||||
|
||||
func net.create_udp_server[host: str, port: i64] : net.UDPSocket, bool
|
||||
~s, ok := net.create_udp_client(host, port)
|
||||
s, ok := net.create_udp_client(host, port)
|
||||
if !ok
|
||||
return 0 as net.UDPSocket, false
|
||||
|
||||
@@ -172,7 +172,7 @@ func net.resolve[domain: str] : i64, bool
|
||||
query := net.build_dns_query(domain, DNS_TYPE_A)
|
||||
|
||||
// TODO: this probably shouldnt be hardcoded
|
||||
~s, ok := net.create_udp_client("1.1.1.1", 53)
|
||||
s, ok := net.create_udp_client("1.1.1.1", 53)
|
||||
if !ok
|
||||
query->free()
|
||||
return -1, false
|
||||
|
||||
12
test.zr
12
test.zr
@@ -8,7 +8,7 @@ struct TestRunner
|
||||
custom_run_args: HashMap
|
||||
|
||||
func TestRunner.run_directory[tr: TestRunner, dir: str] : void
|
||||
~files, ok := os.list_directory(dir)
|
||||
files, ok := os.list_directory(dir)
|
||||
if !ok
|
||||
panic("failed to open test directory")
|
||||
for i in 0..files->size
|
||||
@@ -28,12 +28,12 @@ func TestRunner.run_test[tr: TestRunner, x: str] : void
|
||||
io.printf("Building %s...\n", x)
|
||||
|
||||
build_cmd := "./target/release/zern "->concat(x)
|
||||
~custom_build_flags, ok := tr->custom_build_flags->get(name)
|
||||
custom_build_flags, ok := tr->custom_build_flags->get(name)
|
||||
if ok
|
||||
build_cmd = build_cmd->concat(" ")->concat(custom_build_flags)
|
||||
|
||||
build_start_time := os.time()
|
||||
~status, ok := os.run_shell_command(build_cmd)
|
||||
status, ok := os.run_shell_command(build_cmd)
|
||||
if !ok || status != 0
|
||||
os.exit(1)
|
||||
build_end_time := os.time()
|
||||
@@ -47,12 +47,12 @@ func TestRunner.run_test[tr: TestRunner, x: str] : void
|
||||
io.printf("Running %s...\n", x)
|
||||
|
||||
run_cmd := "./out"
|
||||
~custom_run_args, ok := tr->custom_run_args->get(name)
|
||||
custom_run_args, ok := tr->custom_run_args->get(name)
|
||||
if ok
|
||||
run_cmd = run_cmd->concat(" ")->concat(custom_run_args)
|
||||
|
||||
run_start_time := os.time()
|
||||
~status, ok := os.run_shell_command(run_cmd)
|
||||
status, ok := os.run_shell_command(run_cmd)
|
||||
if !ok || status != 0
|
||||
io.println("Test failed.")
|
||||
os.exit(1)
|
||||
@@ -61,7 +61,7 @@ func TestRunner.run_test[tr: TestRunner, x: str] : void
|
||||
io.printf("Running %s took %dms\n", x, run_end_time - run_start_time)
|
||||
|
||||
func main[] : i64
|
||||
~status, ok := os.run_shell_command("cargo build --release")
|
||||
status, ok := os.run_shell_command("cargo build --release")
|
||||
if !ok || status != 0
|
||||
os.exit(1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user