-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathvm.yaml
95 lines (79 loc) · 3.8 KB
/
vm.yaml
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
.SimpleChecks: &SimpleChecks
one_argument:
assert: "len(f.args)"
eq: 1
function_name:
assert: "f.name"
eq: "assemble"
input_name_0:
assert: "f.args[0].name"
eq: "program"
test_halt:
assert: f.call(["CONTROL 42", "CONTROL", "CONTROL -1"])
eq: [0,42,0,0,0,255]
weight: 6
test_comments:
assert: |-
f.call(["CONTROL 1 #comment", "SWP # comment"])
eq: [0,1,8,0]
weight: 4
test_loads_swaps:
assert: |-
f.call([
"LOAD 4",
"SWP",
"LOAD -1"
])
eq: [4,4,8,0,4,255]
weight: 6
test_push_pop:
assert: |-
f.call([
"PUSH 0",
"POP 1",
"PUSH 1",
"POP"
])
eq: [32,0,33,1,32,1,33,0]
weight: 8
VMAssemblerSimple:
Signature: "assemble(program)"
Input: "with a list input `program` each entry representing one line of program text"
Output: |-
a list of numbers representing bytes of VM CPU instructions.
The assembler syntax is one instruction per line in the following form:
```OPCODE [argument] [# comment]```
- Required OPCODE (see OPCODE table below)
- Optional argument, an integer immediate value (default 0). Convert negative argument values to unit8 (twos complement).
- Optional comment prefixed by `#` that should be ignored
Instructions are always 2 encoded as bytes: [command_byte] [argument_byte]
The valid OPCODE values, their corresponding command_byte values and explanations of their arguments are:
- CONTROL (command_byte=0) run control - halts the program and return the stack when argument is 255, otherwise does nothing.
- COND (command_byte=128) conditional - skip the next instruction (program counter +4 instead of the usual +2) if R0 is less then or equal to argument byte
- LOAD (command_byte=4) load - loads the argument byte into R0
- SWP (command_byte=8) swap - swaps R0 and R1, ignores argument
- PUSH (command_byte=32) push - pushes to stack, R0 if argument is 0 otherwise R1
- POP (command_byte=33) pop - pops R0 from stack, R0 if argument is 0 otherwise R1
Important details:
- Return value should be a list of uint8 byte values in the range [0,255]
Description: "See if the model is capable of implementing a complex text to numeric transformation."
Checks:
<<: *SimpleChecks
VMAssemblerSimple2:
Signature: "assemble(program)"
Input: "with a single input `program`, a list of strings with each entry representing one line of program text"
Output: |-
the compiled program as a list of numbers representing uint8 bytes of VM CPU instructions.
Each line of program text starts with an OPCODE followed by an optional argument and an optional comment: OPCODE [argument] [# comment]
Each OPCODE should then be encoded as 2 bytes: [command_byte] [argument_byte]
The OPCODE=>command_byte mappings are:
- CONTROL=>0 run control - halts the program and return the stack when argument is 255, otherwise does nothing.
- COND=>128 conditional - skip the next instruction (program counter +4 instead of the usual +2) if R0 is less then or equal to argument byte
- LOAD=>4 load - loads the argument byte into R0
- SWP=>8 swap - swaps R0 and R1, ignores argument
- PUSH=>32 push - pushes to stack, R0 if argument is 0 otherwise R1
- POP=>33 pop - pops R0 from stack, R0 if argument is 0 otherwise R1
If no argument is provided, default to argument_byte to 0. Convert negative argument values to unit8 (twos complement).
Description: "See if the model is capable of implementing a complex text to numeric transformation."
Checks:
<<: *SimpleChecks