Compact definition formats

This commit is contained in:
Ian Gulliver
2021-11-20 20:14:35 -10:00
parent 68ae25192e
commit 24db692859
5 changed files with 47 additions and 66 deletions

View File

@@ -2,15 +2,11 @@ global_memory_size: 1
function_memory_size: 1
instruction_limit: 2
samples:
- global_memory_inputs:
0: 0
global_memory_outputs:
0: 1
- global_memory_inputs:
0: 1
global_memory_outputs:
0: 2
- global_memory_inputs:
0: 100
global_memory_outputs:
0: 101
- in: [0]
out: [1]
- in: [1]
out: [2]
- in: [100]
out: [101]

View File

@@ -2,19 +2,14 @@ global_memory_size: 1
function_memory_size: 1
instruction_limit: 2
samples:
- global_memory_inputs:
0: 0
global_memory_outputs:
0: 0
- global_memory_inputs:
0: 1
global_memory_outputs:
0: 5
- global_memory_inputs:
0: 2
global_memory_outputs:
0: 10
- global_memory_inputs:
0: 100
global_memory_outputs:
0: 500
- in: [0]
out: [0]
- in: [1]
out: [5]
- in: [2]
out: [10]
- in: [100]
out: [500]

View File

@@ -2,19 +2,14 @@ global_memory_size: 1
function_memory_size: 1
instruction_limit: 2
samples:
- global_memory_inputs:
0: 0
global_memory_outputs:
0: 0
- global_memory_inputs:
0: 1
global_memory_outputs:
0: 4
- global_memory_inputs:
0: 2
global_memory_outputs:
0: 8
- global_memory_inputs:
0: 100
global_memory_outputs:
0: 400
- in: [0]
out: [0]
- in: [1]
out: [4]
- in: [2]
out: [8]
- in: [100]
out: [400]

View File

@@ -2,19 +2,14 @@ global_memory_size: 1
function_memory_size: 1
instruction_limit: 2
samples:
- global_memory_inputs:
0: 0
global_memory_outputs:
0: 0
- global_memory_inputs:
0: 1
global_memory_outputs:
0: 2
- global_memory_inputs:
0: 2
global_memory_outputs:
0: 4
- global_memory_inputs:
0: 100
global_memory_outputs:
0: 200
- in: [0]
out: [0]
- in: [1]
out: [2]
- in: [2]
out: [4]
- in: [100]
out: [200]

View File

@@ -3,19 +3,19 @@ package grow
import "github.com/firestuff/subcoding/vm"
type Sample struct {
GlobalMemoryInputs map[uint64]uint64 `yaml:"global_memory_inputs"`
GlobalMemoryOutputs map[uint64]uint64 `yaml:"global_memory_outputs"`
In []uint64 `yaml:"in,flow"`
Out []uint64 `yaml:"out,flow"`
}
func (s *Sample) SetInputs(state *vm.State) {
for i, val := range s.GlobalMemoryInputs {
state.GlobalMemory().WriteUnsigned(i, val)
for i, val := range s.In {
state.GlobalMemory().WriteUnsigned(uint64(i), val)
}
}
func (s *Sample) OutputsMatch(state *vm.State) bool {
for i, val := range s.GlobalMemoryOutputs {
if state.GlobalMemory().MustReadUnsigned(i) != val {
for i, val := range s.Out {
if state.GlobalMemory().MustReadUnsigned(uint64(i)) != val {
return false
}
}