Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Kirill Fuks
hal_interpreter
Commits
c803ea28
Verified
Commit
c803ea28
authored
Jun 09, 2020
by
Kirill Fuks
Browse files
IOPorts are now slices and not arrays
parent
f34f924f
Changes
4
Hide whitespace changes
Inline
Side-by-side
debugger/gui.go
View file @
c803ea28
...
...
@@ -104,7 +104,7 @@ func hht(currentInstruction hal.Instruction, hhtView *gocui.View) {
}
}
func
ioHandler
(
ioInput
chan
float64
,
ioPorts
[
4
]
chan
float64
,
g
*
gocui
.
Gui
)
{
func
ioHandler
(
ioInput
chan
float64
,
ioPorts
[]
chan
float64
,
g
*
gocui
.
Gui
)
{
select
{
case
input
:=
<-
ioInput
:
for
i
:=
0
;
i
<
4
;
i
++
{
...
...
@@ -283,7 +283,7 @@ func handleIOView(progMem []hal.Instruction, pc int, g *gocui.Gui) error {
return
nil
}
func
stepForward
(
debugInf
chan
hal
.
DebugInfo
,
debugStepToggle
chan
bool
,
ioPorts
[
4
]
chan
float64
,
func
stepForward
(
debugInf
chan
hal
.
DebugInfo
,
debugStepToggle
chan
bool
,
ioPorts
[]
chan
float64
,
ioInput
chan
float64
)
func
(
g
*
gocui
.
Gui
,
v
*
gocui
.
View
)
error
{
return
func
(
g
*
gocui
.
Gui
,
v
*
gocui
.
View
)
error
{
mutex
.
Lock
()
...
...
@@ -436,7 +436,7 @@ func inputFinished(ioInput chan float64) func(g *gocui.Gui, v *gocui.View) error
}
}
func
keybindings
(
g
*
gocui
.
Gui
,
debugInf
chan
hal
.
DebugInfo
,
debugStepToggle
chan
bool
,
ioPorts
[
4
]
chan
float64
,
func
keybindings
(
g
*
gocui
.
Gui
,
debugInf
chan
hal
.
DebugInfo
,
debugStepToggle
chan
bool
,
ioPorts
[]
chan
float64
,
ioInput
chan
float64
)
error
{
var
keys
=
[]
key
{
{
""
,
gocui
.
KeyCtrlC
,
quit
},
...
...
@@ -463,7 +463,7 @@ func setCurrentViewOnTop(g *gocui.Gui, name string) (*gocui.View, error) {
}
// GuiDebugger is a debugger for HAL
func
GuiDebugger
(
debugInf
chan
hal
.
DebugInfo
,
debugStepToggle
chan
bool
,
ioPorts
[
4
]
chan
float64
)
{
func
GuiDebugger
(
debugInf
chan
hal
.
DebugInfo
,
debugStepToggle
chan
bool
,
ioPorts
[]
chan
float64
)
{
g
,
err
:=
gocui
.
NewGui
(
gocui
.
Output256
,
true
)
if
err
!=
nil
{
...
...
hal/HALProcessor.go
View file @
c803ea28
...
...
@@ -14,7 +14,7 @@ type Processor struct {
Registers
[
32
]
float64
Accumulator
float64
ProgramCounter
int16
IoPorts
[
4
]
chan
float64
IoPorts
[]
chan
float64
debug
bool
}
...
...
@@ -27,7 +27,7 @@ type DebugInfo struct {
}
// NewProcessor is the constructor for Processor
func
NewProcessor
(
fileName
string
,
debug
bool
,
id
uint8
)
*
Processor
{
func
NewProcessor
(
fileName
string
,
debug
bool
,
id
uint8
,
maxPorts
int
)
*
Processor
{
proc
:=
new
(
Processor
)
proc
.
id
=
id
proc
.
debug
=
debug
...
...
@@ -41,7 +41,7 @@ func NewProcessor(fileName string, debug bool, id uint8) *Processor {
panic
(
err
)
}
code
:=
string
(
codeBytes
)
parsedInstructions
:=
ParseCommands
(
code
)
parsedInstructions
:=
ParseCommands
(
code
,
maxPorts
)
proc
.
ProgramMem
=
parsedInstructions
proc
.
Accumulator
=
0
...
...
@@ -62,8 +62,8 @@ func (p *Processor) passDebugInf(debugInf chan DebugInfo) {
}
// Run the file
func
(
p
*
Processor
)
Run
(
ioPorts
[
4
]
chan
float64
,
outputToggle
[
4
]
chan
bool
,
inputToggle
[
4
]
chan
bool
,
debugStepToggle
chan
bool
,
debugInf
chan
DebugInfo
)
{
func
(
p
*
Processor
)
Run
(
ioPorts
[]
chan
float64
,
outputToggle
[]
chan
bool
,
inputToggle
[]
chan
bool
,
debugStepToggle
chan
bool
,
debugInf
chan
DebugInfo
)
{
p
.
IoPorts
=
ioPorts
...
...
@@ -107,7 +107,7 @@ func (p *Processor) instStop(debugInf chan DebugInfo) {
p
.
passDebugInf
(
debugInf
)
}
func
(
p
*
Processor
)
instOut
(
debugInf
chan
DebugInfo
,
uint8Param
uint8
,
outputToggle
[
4
]
chan
bool
)
{
func
(
p
*
Processor
)
instOut
(
debugInf
chan
DebugInfo
,
uint8Param
uint8
,
outputToggle
[]
chan
bool
)
{
io
:=
p
.
IoPorts
[
uint8Param
]
if
p
.
debug
==
false
{
outputToggle
[
uint8Param
]
<-
true
...
...
@@ -115,7 +115,7 @@ func (p *Processor) instOut(debugInf chan DebugInfo, uint8Param uint8, outputTog
io
<-
p
.
Accumulator
}
func
(
p
*
Processor
)
instIn
(
debugInf
chan
DebugInfo
,
uint8Param
uint8
,
inputToggle
[
4
]
chan
bool
)
{
func
(
p
*
Processor
)
instIn
(
debugInf
chan
DebugInfo
,
uint8Param
uint8
,
inputToggle
[]
chan
bool
)
{
io
:=
p
.
IoPorts
[
uint8Param
]
if
p
.
debug
==
false
{
inputToggle
[
uint8Param
]
<-
true
...
...
@@ -159,7 +159,7 @@ func (p *Processor) instJump(debugInf chan DebugInfo, currentInstruction Instruc
}
func
(
p
*
Processor
)
execute
(
debugStepToggle
chan
bool
,
debugInf
chan
DebugInfo
,
outputToggle
[
4
]
chan
bool
,
inputToggle
[
4
]
chan
bool
)
{
outputToggle
[]
chan
bool
,
inputToggle
[]
chan
bool
)
{
currentInstruction
:=
p
.
ProgramMem
[
p
.
ProgramCounter
]
uint8Param
:=
uint8
(
currentInstruction
.
Parameter
)
...
...
hal/Parser.go
View file @
c803ea28
...
...
@@ -14,7 +14,7 @@ type Instruction struct {
}
// ParseCommands parses file intro a slice of Instructions
func
ParseCommands
(
command
string
)
[]
Instruction
{
func
ParseCommands
(
command
string
,
maxPort
int
)
[]
Instruction
{
parsedCommand
:=
[]
Instruction
{}
for
lineNumber
,
line
:=
range
strings
.
Split
(
strings
.
TrimSuffix
(
command
,
"
\n
"
),
"
\n
"
)
{
...
...
@@ -30,6 +30,11 @@ func ParseCommands(command string) []Instruction {
}
if
len
(
splitedLine
)
==
3
{
parameter
,
_
:=
strconv
.
ParseFloat
(
splitedLine
[
2
],
64
)
if
splitedLine
[
1
]
==
"IN"
||
splitedLine
[
1
]
==
"OUT"
{
if
int
(
parameter
)
>
maxPort
{
panic
(
"WTF "
+
strconv
.
Itoa
(
int
(
maxPort
)))
}
}
parsedCommand
=
append
(
parsedCommand
,
Instruction
{
splitedLine
[
1
],
parameter
})
}
else
if
len
(
splitedLine
)
==
2
{
parsedCommand
=
append
(
parsedCommand
,
Instruction
{
splitedLine
[
1
],
0
})
...
...
hal_interpreter.go
View file @
c803ea28
...
...
@@ -14,8 +14,8 @@ import (
"github.com/akamensky/argparse"
)
func
runProcessor
(
proc
*
hal
.
Processor
,
ioPorts
[
4
]
chan
float64
,
outputToggle
[
4
]
chan
bool
,
inputToggle
[
4
]
chan
bool
,
func
runProcessor
(
proc
*
hal
.
Processor
,
ioPorts
[]
chan
float64
,
outputToggle
[]
chan
bool
,
inputToggle
[]
chan
bool
,
debugStepToggle
chan
bool
,
debugInf
chan
hal
.
DebugInfo
,
finished
*
bool
)
{
proc
.
Run
(
ioPorts
,
outputToggle
,
inputToggle
,
debugStepToggle
,
debugInf
)
...
...
@@ -36,19 +36,19 @@ func main() {
}
// Initializing communication channels
ioPorts
:=
[
4
](
chan
float64
){}
outputToggle
:=
[
4
](
chan
bool
){}
inputToggle
:=
[
4
](
chan
bool
){}
ioPorts
:=
[](
chan
float64
){}
outputToggle
:=
[](
chan
bool
){}
inputToggle
:=
[](
chan
bool
){}
debugStepToggle
:=
make
(
chan
bool
)
debugInf
:=
make
(
chan
hal
.
DebugInfo
)
for
i
:=
0
;
i
<
4
;
i
++
{
ioPorts
[
i
]
=
make
(
chan
float64
)
outputToggle
[
i
]
=
make
(
chan
bool
)
inputToggle
[
i
]
=
make
(
chan
bool
)
ioPorts
=
append
(
ioPorts
,
make
(
chan
float64
)
)
outputToggle
=
append
(
outputToggle
,
make
(
chan
bool
)
)
inputToggle
=
append
(
inputToggle
,
make
(
chan
bool
)
)
}
// Creating HALProcessor instance
cpu
:=
hal
.
NewProcessor
(
*
fileName
,
*
debug
,
0
)
cpu
:=
hal
.
NewProcessor
(
*
fileName
,
*
debug
,
0
,
4
)
finished
:=
false
// Run the given file
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment