VM Protocol - matianfu/redbank GitHub Wiki
The Javascript Compiler/Debugger/Tester (CDT) runs on host PC. The VM runs on either host PC or MCU. They communicate through tcp connenction or serial/comport, using Red Bank VM Protocol.
The VM protocol is currently under design. Features are incrementally added through the VM development. Here is only a draft description.
Roles and Formats
The VM (implemented in C language) works as tcp socket server, the Compiler/Debugger/Tester works as a client.
The server and client exchange information in text, line by line. Using linefeed (LF) '\n' as new line character is preferred, though CR/LF '\r\n' will also be supported in the future.
Sometimes, a blank line has meaning. So be sure not to emit blank line unneccessarily.
On VM side (server), there is a readline implementation. Each line (received from client) will be parsed to argc/argv[] in the way similar to command shell. Blank line is usually used as the ending of a sequence line. For example: the client emit test cases or bytecodes line by line to server, a blank line tells the server the sequence ends.
On CDT side, JSON is convenient for structured data. So the VM server send data to client in the format of:
{
"command" : "somecommand",
"argument" : "someargument"
}
Protocol and Commands
After a connection is established, the server send a READY command to client.
The client then send Bycodes line by line to server, ending with a blank line.
The VM then try parse and run the codes, if any error occurs, the VM will emit an ERROR command with argument for reason.
When TEST instruction is encountered during execution, the VM will emit a TEST command with given test case name to client. The client should send test codes to VM accordingly. If there are some errors in finding the test case or generating test code, the client can send an ABORT command to VM, and VM should abort the current execution.