separate number into float and integer
This commit is contained in:
parent
10f55313b0
commit
daab50d54c
22 changed files with 848 additions and 428 deletions
126
core/vm_test.go
126
core/vm_test.go
|
|
@ -49,7 +49,7 @@ func TestNewVM(t *testing.T) {
|
|||
chunk := NewChunk([]Bytecode{
|
||||
InstructionConstant, 0,
|
||||
}, []Value{
|
||||
&NumberValue{0},
|
||||
&FloatValue{0},
|
||||
})
|
||||
stackSize := Pos(256)
|
||||
callstackSize := Pos(256)
|
||||
|
|
@ -104,13 +104,13 @@ func GetExecutionTestData() map[string]struct {
|
|||
NewChunk([]Bytecode{
|
||||
InstructionConstant, 0,
|
||||
InstructionConstant, 1,
|
||||
InstructionAdd,
|
||||
InstructionAddFloat,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{1}, &NumberValue{2},
|
||||
&FloatValue{1}, &FloatValue{2},
|
||||
}),
|
||||
[]Value{
|
||||
&NumberValue{3},
|
||||
&FloatValue{3},
|
||||
},
|
||||
},
|
||||
"push_constant": {
|
||||
|
|
@ -119,11 +119,11 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionConstant, 0,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{1},
|
||||
&FloatValue{1},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&NumberValue{1},
|
||||
&FloatValue{1},
|
||||
},
|
||||
},
|
||||
"push_true": {
|
||||
|
|
@ -172,20 +172,20 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Bytecode{
|
||||
InstructionConstant, 0,
|
||||
InstructionConstant, 1,
|
||||
InstructionAdd,
|
||||
InstructionAddFloat,
|
||||
InstructionConstant, 2,
|
||||
InstructionMul,
|
||||
InstructionMulFloat,
|
||||
InstructionConstant, 3,
|
||||
InstructionConstant, 0,
|
||||
InstructionSub,
|
||||
InstructionDiv,
|
||||
InstructionSubFloat,
|
||||
InstructionDivFloat,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{2}, &NumberValue{1}, &NumberValue{5}, &NumberValue{6},
|
||||
&FloatValue{2}, &FloatValue{1}, &FloatValue{5}, &FloatValue{6},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&NumberValue{3.75},
|
||||
&FloatValue{3.75},
|
||||
},
|
||||
},
|
||||
"equality_true": {
|
||||
|
|
@ -196,7 +196,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionEquals,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{1},
|
||||
&FloatValue{1},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
|
|
@ -211,7 +211,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionEquals,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{1}, &NumberValue{2},
|
||||
&FloatValue{1}, &FloatValue{2},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
|
|
@ -226,7 +226,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionNotEqual,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{1},
|
||||
&FloatValue{1},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
|
|
@ -241,7 +241,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionNotEqual,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{1}, &NumberValue{2},
|
||||
&FloatValue{1}, &FloatValue{2},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
|
|
@ -280,11 +280,11 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionConstant, 1, // should execute
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{0}, &NumberValue{1},
|
||||
&FloatValue{0}, &FloatValue{1},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&NumberValue{1},
|
||||
&FloatValue{1},
|
||||
},
|
||||
},
|
||||
"jump_false/false": {
|
||||
|
|
@ -296,11 +296,11 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionConstant, 1, // should execute
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{0}, &NumberValue{1},
|
||||
&FloatValue{0}, &FloatValue{1},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&NumberValue{1},
|
||||
&FloatValue{1},
|
||||
},
|
||||
},
|
||||
"jump_false/true": {
|
||||
|
|
@ -312,11 +312,11 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionConstant, 1, // should execute
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{0}, &NumberValue{1},
|
||||
&FloatValue{0}, &FloatValue{1},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&NumberValue{0}, &NumberValue{1},
|
||||
&FloatValue{0}, &FloatValue{1},
|
||||
},
|
||||
},
|
||||
"declare_local": {
|
||||
|
|
@ -326,13 +326,13 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionDeclareLocal, 1,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{0}, &StringValue{"a"},
|
||||
&FloatValue{0}, &StringValue{"a"},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&VariableValue{
|
||||
"a",
|
||||
&NumberValue{0},
|
||||
&FloatValue{0},
|
||||
0,
|
||||
},
|
||||
},
|
||||
|
|
@ -346,13 +346,13 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionSetLocal, 1, // reassign
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{0}, &StringValue{"a"}, &NumberValue{1},
|
||||
&FloatValue{0}, &StringValue{"a"}, &FloatValue{1},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&VariableValue{
|
||||
"a",
|
||||
&NumberValue{1},
|
||||
&FloatValue{1},
|
||||
0,
|
||||
},
|
||||
},
|
||||
|
|
@ -365,16 +365,16 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionGetLocal, 1, // reassign
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{0}, &StringValue{"a"},
|
||||
&FloatValue{0}, &StringValue{"a"},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&VariableValue{
|
||||
"a",
|
||||
&NumberValue{0},
|
||||
&FloatValue{0},
|
||||
0,
|
||||
},
|
||||
&NumberValue{0},
|
||||
&FloatValue{0},
|
||||
},
|
||||
},
|
||||
"get_reassigned_local": {
|
||||
|
|
@ -388,17 +388,17 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionGetLocal, 1,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{0}, &StringValue{"a"}, &NumberValue{1},
|
||||
&FloatValue{0}, &StringValue{"a"}, &FloatValue{1},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&VariableValue{
|
||||
"a",
|
||||
&NumberValue{1},
|
||||
&FloatValue{1},
|
||||
0,
|
||||
},
|
||||
&NumberValue{0},
|
||||
&NumberValue{1},
|
||||
&FloatValue{0},
|
||||
&FloatValue{1},
|
||||
},
|
||||
},
|
||||
"variable_scope": {
|
||||
|
|
@ -416,15 +416,15 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionAscend,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{0}, &StringValue{"a"},
|
||||
&NumberValue{1}, &StringValue{"b"},
|
||||
&NumberValue{2}, &StringValue{"c"},
|
||||
&FloatValue{0}, &StringValue{"a"},
|
||||
&FloatValue{1}, &StringValue{"b"},
|
||||
&FloatValue{2}, &StringValue{"c"},
|
||||
},
|
||||
),
|
||||
[]Value{
|
||||
&VariableValue{
|
||||
"a",
|
||||
&NumberValue{0},
|
||||
&FloatValue{0},
|
||||
0,
|
||||
},
|
||||
},
|
||||
|
|
@ -438,25 +438,25 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionCall,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{1},
|
||||
&NumberValue{2},
|
||||
&FloatValue{1},
|
||||
&FloatValue{2},
|
||||
&FunctionValue{
|
||||
Name: "sum",
|
||||
Params: []FunctionParameter{
|
||||
{
|
||||
"a",
|
||||
&NumberSignature{},
|
||||
&FloatSignature{},
|
||||
},
|
||||
{
|
||||
"b",
|
||||
&NumberSignature{},
|
||||
&FloatSignature{},
|
||||
},
|
||||
},
|
||||
Chunk: NewChunk(
|
||||
[]Bytecode{
|
||||
InstructionGetLocal, 0,
|
||||
InstructionGetLocal, 1,
|
||||
InstructionAdd,
|
||||
InstructionAddFloat,
|
||||
InstructionReturn,
|
||||
},
|
||||
[]Value{
|
||||
|
|
@ -467,7 +467,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
},
|
||||
),
|
||||
[]Value{
|
||||
&NumberValue{3},
|
||||
&FloatValue{3},
|
||||
},
|
||||
},
|
||||
"function_calling_function": {
|
||||
|
|
@ -481,18 +481,18 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionCall,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{1},
|
||||
&NumberValue{2},
|
||||
&FloatValue{1},
|
||||
&FloatValue{2},
|
||||
&FunctionValue{
|
||||
Name: "sum",
|
||||
Params: []FunctionParameter{
|
||||
{
|
||||
"a",
|
||||
&NumberSignature{},
|
||||
&FloatSignature{},
|
||||
},
|
||||
{
|
||||
"b",
|
||||
&NumberSignature{},
|
||||
&FloatSignature{},
|
||||
},
|
||||
},
|
||||
Chunk: NewChunk(
|
||||
|
|
@ -501,7 +501,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
InstructionGetLocal, 2, InstructionCall, // square the number
|
||||
InstructionGetLocal, 1,
|
||||
InstructionGetLocal, 2, InstructionCall, // square the number
|
||||
InstructionAdd,
|
||||
InstructionAddFloat,
|
||||
InstructionReturn,
|
||||
},
|
||||
[]Value{
|
||||
|
|
@ -514,14 +514,14 @@ func GetExecutionTestData() map[string]struct {
|
|||
Params: []FunctionParameter{
|
||||
{
|
||||
"n",
|
||||
&NumberSignature{},
|
||||
&FloatSignature{},
|
||||
},
|
||||
},
|
||||
Chunk: NewChunk(
|
||||
[]Bytecode{
|
||||
InstructionGetLocal, 0,
|
||||
InstructionGetLocal, 0,
|
||||
InstructionMul,
|
||||
InstructionMulFloat,
|
||||
InstructionReturn,
|
||||
},
|
||||
[]Value{
|
||||
|
|
@ -540,14 +540,14 @@ func GetExecutionTestData() map[string]struct {
|
|||
Params: []FunctionParameter{
|
||||
{
|
||||
"n",
|
||||
&NumberSignature{},
|
||||
&FloatSignature{},
|
||||
},
|
||||
},
|
||||
Chunk: NewChunk(
|
||||
[]Bytecode{
|
||||
InstructionGetLocal, 0,
|
||||
InstructionGetLocal, 0,
|
||||
InstructionMul,
|
||||
InstructionMulFloat,
|
||||
InstructionReturn,
|
||||
},
|
||||
[]Value{
|
||||
|
|
@ -557,7 +557,7 @@ func GetExecutionTestData() map[string]struct {
|
|||
},
|
||||
0,
|
||||
},
|
||||
&NumberValue{5},
|
||||
&FloatValue{5},
|
||||
},
|
||||
},
|
||||
"list_concat": {
|
||||
|
|
@ -570,13 +570,13 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&ListValue{
|
||||
[]Value{
|
||||
&NumberValue{1},
|
||||
&NumberValue{2},
|
||||
&FloatValue{1},
|
||||
&FloatValue{2},
|
||||
},
|
||||
},
|
||||
&ListValue{
|
||||
[]Value{
|
||||
&NumberValue{3},
|
||||
&FloatValue{3},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -584,9 +584,9 @@ func GetExecutionTestData() map[string]struct {
|
|||
[]Value{
|
||||
&ListValue{
|
||||
[]Value{
|
||||
&NumberValue{1},
|
||||
&NumberValue{2},
|
||||
&NumberValue{3},
|
||||
&FloatValue{1},
|
||||
&FloatValue{2},
|
||||
&FloatValue{3},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -630,7 +630,7 @@ func TestVM_NextByte(t *testing.T) {
|
|||
InstructionConstant, 0,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{0},
|
||||
&FloatValue{0},
|
||||
},
|
||||
),
|
||||
16,
|
||||
|
|
@ -741,7 +741,7 @@ func TestVM_Jump(t *testing.T) {
|
|||
InstructionConstant, 2,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{0}, &NumberValue{1}, &NumberValue{2},
|
||||
&FloatValue{0}, &FloatValue{1}, &FloatValue{2},
|
||||
},
|
||||
),
|
||||
16,
|
||||
|
|
@ -766,7 +766,7 @@ func TestVM_JumpFalse(t *testing.T) {
|
|||
InstructionConstant, 2,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{0}, &NumberValue{1}, &NumberValue{2},
|
||||
&FloatValue{0}, &FloatValue{1}, &FloatValue{2},
|
||||
},
|
||||
),
|
||||
16,
|
||||
|
|
@ -792,7 +792,7 @@ func TestVM_DontJumpFalse(t *testing.T) {
|
|||
InstructionConstant, 2,
|
||||
},
|
||||
[]Value{
|
||||
&NumberValue{0}, &NumberValue{1}, &NumberValue{2},
|
||||
&FloatValue{0}, &FloatValue{1}, &FloatValue{2},
|
||||
},
|
||||
),
|
||||
16,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue