Improve type system

This commit is contained in:
2024-01-26 01:52:46 +07:00
parent 692babe938
commit dfd21f0596
9 changed files with 141 additions and 98 deletions

Binary file not shown.

View File

@@ -108,7 +108,7 @@ func parseProgramFromFile(m* Machine, f *os.File) error {
if err != nil {
return err
}
m.Push(Inst{Operation: PUSH, Operand: int32(op)})
m.Push(Inst{Operation: PUSH, Operand: int64(op)})
} else if (strings.HasPrefix(line, "POP")) {
m.Push(Inst{Operation: POP})
} else if (strings.HasPrefix(line, "DUP")) {
@@ -116,7 +116,7 @@ func parseProgramFromFile(m* Machine, f *os.File) error {
if err != nil {
return err
}
m.Push(Inst{Operation: DUP, Operand: int32(op)})
m.Push(Inst{Operation: DUP, Operand: int64(op)})
} else if (strings.HasPrefix(line, "ADD")) {
m.Push(Inst{Operation: ADD})
} else if (strings.HasPrefix(line, "SUB")) {
@@ -130,13 +130,13 @@ func parseProgramFromFile(m* Machine, f *os.File) error {
if err != nil {
return err
}
m.Push(Inst{Operation: JMPIF, Operand: int32(op)})
m.Push(Inst{Operation: JMPIF, Operand: int64(op)})
} else if (strings.HasPrefix(line, "JMP")) {
op, err := parseLabelledOperand(line, preprocessed)
if err != nil {
return err
}
m.Push(Inst{Operation: JMP, Operand: int32(op)})
m.Push(Inst{Operation: JMP, Operand: int64(op)})
} else if (strings.HasPrefix(line, "EQ")) {
m.Push(Inst{Operation: EQ})
} else if (strings.HasPrefix(line, "CALL")) {
@@ -144,7 +144,7 @@ func parseProgramFromFile(m* Machine, f *os.File) error {
if err != nil {
return err
}
m.Push(Inst{Operation: CALL, Operand: int32(op)})
m.Push(Inst{Operation: CALL, Operand: int64(op)})
} else if (strings.HasPrefix(line, "RET")) {
m.Push(Inst{Operation: RET})
} else if (strings.HasPrefix(line, "STORE")) {
@@ -152,13 +152,13 @@ func parseProgramFromFile(m* Machine, f *os.File) error {
if err != nil {
return err
}
m.Push(Inst{Operation: STORE, Operand: int32(op)})
m.Push(Inst{Operation: STORE, Operand: int64(op)})
} else if (strings.HasPrefix(line, "GET")) {
op, err := strconv.Atoi(strings.Fields(line)[1])
if err != nil {
return err
}
m.Push(Inst{Operation: GET, Operand: int32(op)})
m.Push(Inst{Operation: GET, Operand: int64(op)})
} else {
return errors.New("Unknown instruction: " + line)
}

View File

@@ -4,4 +4,6 @@ go 1.20
replace e1lama/elm => ../core
require e1lama/elm v0.0.0-00010101000000-000000000000
require e1lama/elm v0.0.0-00010101000000-000000000000
require golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect

View File

@@ -1,4 +1,6 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=