Make memory sizes parameters
This commit is contained in:
@@ -13,7 +13,10 @@ func Assemble(src []byte) (*vm.Program, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := &vm.Program{}
|
||||
ret := &vm.Program{
|
||||
GlobalMemorySize: parsed.GlobalMemorySize,
|
||||
FunctionMemorySize: parsed.FunctionMemorySize,
|
||||
}
|
||||
|
||||
for f, fnc := range parsed.Functions {
|
||||
instrs, err := assembleFunction(fnc)
|
||||
|
||||
@@ -21,7 +21,14 @@ func Disassemble(prog *vm.Program) (string, error) {
|
||||
fncs = append(fncs, dis)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("functions:\n%s", strings.Join(fncs, "")), nil
|
||||
return fmt.Sprintf(`global_memory_size: %d
|
||||
function_memory_size: %d
|
||||
functions:
|
||||
%s`,
|
||||
prog.GlobalMemorySize,
|
||||
prog.FunctionMemorySize,
|
||||
strings.Join(fncs, ""),
|
||||
), nil
|
||||
}
|
||||
|
||||
func disassembleFunction(fnc *vm.Function) (string, error) {
|
||||
|
||||
14
asm/parse.go
14
asm/parse.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user