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

@@ -6,6 +6,8 @@ import "github.com/firestuff/subcoding/asm"
func TestTooManyOperands(t *testing.T) {
_, err := asm.AssembleString(`
global_memory_size: 4
function_memory_size: 4
functions:
- - [nop, 0]
`)
@@ -16,6 +18,8 @@ functions:
func TestTooFewOperands(t *testing.T) {
_, err := asm.AssembleString(`
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0]
`)
@@ -26,6 +30,8 @@ functions:
func TestIncorrectSigned(t *testing.T) {
_, err := asm.AssembleString(`
global_memory_size: 4
function_memory_size: 4
functions:
- - [ltu, 0, -1]
`)
@@ -36,6 +42,8 @@ functions:
func TestHex(t *testing.T) {
prog, err := asm.AssembleString(`
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 0xfeedc0de]
`)
@@ -51,6 +59,8 @@ functions:
func TestBinary(t *testing.T) {
prog, err := asm.AssembleString(`
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 0b100101]
`)

View File

@@ -4,6 +4,8 @@ import "testing"
func TestLoop(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [add, f0, 1]
- [call, +1]

View File

@@ -6,7 +6,9 @@ import "github.com/firestuff/subcoding/asm"
import "github.com/firestuff/subcoding/vm"
func TestRoundTrip(t *testing.T) {
src := `functions:
src := `global_memory_size: 4
function_memory_size: 4
functions:
- - [nop]
- [mov, g0, 1]
- [add, f0, 5]

View File

@@ -7,7 +7,7 @@ import "github.com/firestuff/subcoding/asm"
func TestRandProgram(t *testing.T) {
for i := 0; i < 100; i++ {
prog := gen.RandProgram()
prog := gen.RandProgram(4, 4)
src, err := asm.Disassemble(prog)
if err != nil {

View File

@@ -4,6 +4,8 @@ import "testing"
func TestNop(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [nop]
`)
@@ -13,6 +15,8 @@ functions:
func TestMov(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 1]
- [mov, g1, g0]
@@ -27,6 +31,8 @@ functions:
func TestAdd(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [add, g0, 5]
- [add, g0, 2]
@@ -41,6 +47,8 @@ functions:
func TestSub(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [sub, g0, 2]
- [sub, g0, -5]
@@ -53,6 +61,8 @@ functions:
func TestMul(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 5]
- [mul, g0, 3]
@@ -67,6 +77,8 @@ functions:
func TestDivU(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 15]
- [divu, g0, 3]
@@ -80,6 +92,8 @@ functions:
func TestDivS(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 15]
- [divs, g0, -3]
@@ -96,6 +110,8 @@ functions:
func TestNot(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 8]
- [not, g0]
@@ -107,6 +123,8 @@ functions:
func TestAnd(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 7]
- [and, g0, 18]
@@ -117,6 +135,8 @@ functions:
func TestOr(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 7]
- [or, g0, 18]
@@ -127,6 +147,8 @@ functions:
func TestXor(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 7]
- [xor, g0, 18]
@@ -137,6 +159,8 @@ functions:
func TestShR(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 53]
- [shr, g0, 2]
@@ -147,6 +171,8 @@ functions:
func TestShL(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 53]
- [shl, g0, 2]
@@ -157,6 +183,8 @@ functions:
func TestEq(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 5]
- [eq, g0, 5]
@@ -172,6 +200,8 @@ functions:
func TestLTU(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 5]
- [ltu, g0, 4]
@@ -190,6 +220,8 @@ functions:
func TestLTS(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 0]
- [lts, g0, -1]
@@ -208,6 +240,8 @@ functions:
func TestGTU(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 5]
- [gtu, g0, 4]
@@ -226,6 +260,8 @@ functions:
func TestGTS(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 0]
- [gts, g0, -1]
@@ -244,6 +280,8 @@ functions:
func TestLTEU(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 5]
- [lteu, g0, 4]
@@ -262,6 +300,8 @@ functions:
func TestLTES(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 0]
- [ltes, g0, -1]
@@ -280,6 +320,8 @@ functions:
func TestGTEU(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 5]
- [gteu, g0, 4]
@@ -298,6 +340,8 @@ functions:
func TestGTES(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [mov, g0, 0]
- [gtes, g0, -1]
@@ -316,6 +360,8 @@ functions:
func TestJmp(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [jmp, +2]
- [add, g0, 1]
@@ -329,6 +375,8 @@ functions:
func TestJmpT(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [eq, 0, 0]
- [jmpt, +2]
@@ -344,6 +392,8 @@ functions:
func TestJmpF(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [eq, 0, 0]
- [jmpf, +2]
@@ -359,6 +409,8 @@ functions:
func TestCal(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [cal, +1]
- [add, g0, 1]
@@ -373,6 +425,8 @@ functions:
func TestCalT(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [eq, 0, 0]
- [calt, +1]
@@ -391,6 +445,8 @@ functions:
func TestCalF(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [eq, 0, 0]
- [calf, +1]
@@ -409,6 +465,8 @@ functions:
func TestRet(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [cal, +1]
- [add, g0, 1]
@@ -424,6 +482,8 @@ functions:
func TestRetT(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [cal, +1]
- [add, g0, 1]
@@ -442,6 +502,8 @@ functions:
func TestRetF(t *testing.T) {
state := assembleAndExecute(t, `
global_memory_size: 4
function_memory_size: 4
functions:
- - [cal, +1]
- [add, g0, 1]