Files
  • main.sh
main.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
server is the interpter
client is whatver sends and recieves commands from the interpter

example 0, eval:
S: {command: 'ready'}
C: {command: 'eval', data: '1+1'}
S: {command: 'result', data: '2'}

example 1, eval with output:
S: {command: 'ready'}
C: {command: 'eval', data: 'puts 1' }
S: {command: 'output', data: '1' }
S: {command: 'result', data: 'nil'}

example 2, eval with input:
S: {command: 'ready'}
C: {command: 'eval', data: 'puts gets'}
C: {command: 'input', data: 'hi'}
S: {command: 'output', data: 'hi'}
S: {command: 'result', 'nil'}

server commands:

ready, no data: when server is started and ready, only happens
once per session.

output, with data: can happen any number of times and at any
time within the session. Most cases, however, will happen within an eval loop
but could happen in asynchrounous calls

read, no data: asks to read data from the client. Can only happen within an eval
loop.

result, with data: can only be a response to the client eval command and will
carry the data back.

client commands:

eval, with data: asks the server to evaluate code.

read_result, with data: after the server asks to read data the client must respond with
read_result before anything else can happen.


State machines:

# (ext) defines external events.
# (int) internal event

Server:
        start_state
                (int) ready -> ready_state
                (int) error -> error_state
        ready_state
                (int) output -> ready_state
                (ext) eval -> eval_state
        eval_state
                (int) output -> eval_state
                (ext) input -> input_state
                (int) result -> ready_state
                (int) error -> error_state
Client:
        start_state
               (ext) ready -> ready_state
               (ext) error -> error_state
        ready_state
               (int) eval -> eval_state
               (ext) error -> error_state
        eval_state
               (int) input -> eval_state
               (ext) result -> ready_state
               (ext) error -> error_state