Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Oct 24, 2023
1 parent 6af52c2 commit 13576bf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vm/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,12 @@ impl SysState
{
let mut syscalls = HashMap::<String, SysCallFn>::new();

// Core VM syscalls
self.reg_syscall(VM_HEAP_SIZE, SysCallFn::Fn0_1(vm_heap_size));
self.reg_syscall(VM_RESIZE_HEAP, SysCallFn::Fn1_1(vm_resize_heap));
self.reg_syscall(MEMSET, SysCallFn::Fn3_0(memset));
self.reg_syscall(MEMSET32, SysCallFn::Fn3_0(memset32));
self.reg_syscall(MEMCPY, SysCallFn::Fn3_0(memcpy));
self.reg_syscall(VM_HEAP_SIZE, SysCallFn::Fn0_1(vm_heap_size));
self.reg_syscall(VM_RESIZE_HEAP, SysCallFn::Fn1_1(vm_resize_heap));

self.reg_syscall(PRINT_I64, SysCallFn::Fn1_0(print_i64));
self.reg_syscall(PRINT_F32, SysCallFn::Fn1_0(print_f32));
Expand All @@ -177,6 +178,8 @@ impl SysState
self.reg_syscall(WINDOW_ON_TEXTINPUT, SysCallFn::Fn2_0(window_on_textinput));

self.reg_syscall(AUDIO_OPEN_OUTPUT, SysCallFn::Fn4_1(audio_open_output));

// TODO: NET_, networking syscalls
}
}

Expand Down
31 changes: 31 additions & 0 deletions vm/src/sys/net.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
use std::net::{TcpListener, TcpStream};
use std::io::{self, Read};
use crate::vm::{VM, Value};



// We could create a thread for the listening socket that accepts connections,
// and so simply use this socket in blocking mode

// However, for individual TCP streams, how do we poll?
// We could use the polling crate: https://crates.io/crates/polling



/*
Expand All @@ -28,3 +35,27 @@ fn main() -> std::io::Result<()> {
}
*/





// Non-blocking read from a TCP stream
/*
let mut stream = TcpStream::connect("127.0.0.1:7878")
.expect("Couldn't connect to the server...");
stream.set_nonblocking(true).expect("set_nonblocking call failed");
let mut buf = vec![];
loop {
match stream.read_to_end(&mut buf) {
Ok(_) => break,
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
// wait until network socket is ready, typically implemented
// via platform-specific APIs such as epoll or IOCP
wait_for_fd();
}
Err(e) => panic!("encountered IO error: {e}"),
};
};
println!("bytes: {buf:?}");
*/

0 comments on commit 13576bf

Please sign in to comment.