|
|
@ -7,23 +7,23 @@ const maxInstructions = 1000 |
|
|
|
type Program map[int64]*ProgrammedInstruction |
|
|
|
type Program map[int64]*ProgrammedInstruction |
|
|
|
|
|
|
|
|
|
|
|
type Module struct { |
|
|
|
type Module struct { |
|
|
|
Accumulator float64 |
|
|
|
accumulator float64 |
|
|
|
ProgramStorage Program |
|
|
|
programStorage Program |
|
|
|
Register []float64 |
|
|
|
register []float64 |
|
|
|
IO []float64 |
|
|
|
IO []float64 |
|
|
|
isStopped bool |
|
|
|
isStopped bool |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (h *Module) ProgramCounter() int64 { |
|
|
|
func (h *Module) ProgramCounter() int64 { |
|
|
|
return int64(h.Register[0]) |
|
|
|
return int64(h.register[0]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (h *Module) increaseProgramCounter() { |
|
|
|
func (h *Module) increaseProgramCounter() { |
|
|
|
h.Register[0]++ |
|
|
|
h.register[0]++ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (h *Module) Step() { |
|
|
|
func (h *Module) Step() { |
|
|
|
instruction := h.ProgramStorage[h.ProgramCounter()] |
|
|
|
instruction := h.programStorage[h.ProgramCounter()] |
|
|
|
h.increaseProgramCounter() |
|
|
|
h.increaseProgramCounter() |
|
|
|
if instruction == nil { |
|
|
|
if instruction == nil { |
|
|
|
return |
|
|
|
return |
|
|
@ -46,8 +46,8 @@ func NewHALModule(program Program, registerSize uint64, ioSize uint64) (*Module, |
|
|
|
return nil, fmt.Errorf("register size must be greater then 10 [ registerSize = %d ]", registerSize) |
|
|
|
return nil, fmt.Errorf("register size must be greater then 10 [ registerSize = %d ]", registerSize) |
|
|
|
} |
|
|
|
} |
|
|
|
return &Module{ |
|
|
|
return &Module{ |
|
|
|
ProgramStorage: program, |
|
|
|
programStorage: program, |
|
|
|
Register: make([]float64, registerSize), |
|
|
|
register: make([]float64, registerSize), |
|
|
|
IO: make([]float64, ioSize), |
|
|
|
IO: make([]float64, ioSize), |
|
|
|
}, nil |
|
|
|
}, nil |
|
|
|
} |
|
|
|
} |
|
|
|