Make memory sizes parameters

This commit is contained in:
Ian Gulliver
2021-11-20 18:27:06 -10:00
parent bd84a5b969
commit 5af90aa6ff
15 changed files with 127 additions and 28 deletions

View File

@@ -1,9 +1,13 @@
package asm
import "fmt"
import "gopkg.in/yaml.v2"
type program struct {
Functions []function `yaml:"functions"`
GlobalMemorySize uint64 `yaml:"global_memory_size"`
FunctionMemorySize uint64 `yaml:"function_memory_size"`
Functions []function `yaml:"functions"`
}
type function []instruction
@@ -18,5 +22,13 @@ func parse(src []byte) (*program, error) {
return nil, err
}
if prog.GlobalMemorySize == 0 {
return nil, fmt.Errorf("global_memory_size must be set and non-zero")
}
if prog.FunctionMemorySize == 0 {
return nil, fmt.Errorf("function_memory_size must be set and non-zero")
}
return prog, nil
}