Skip to content

Commit 1694208

Browse files
committed
misc: code refactor
1 parent d0a24af commit 1694208

File tree

20 files changed

+91
-95
lines changed

20 files changed

+91
-95
lines changed

instructions/const.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package instructions
22

33
import (
44
"fmt"
5-
"github.com/tinycedar/vanilla/runtime"
5+
"github.com/tinycedar/vanilla/runtime/thread"
66
)
77

88
type iconst_1 struct {
@@ -13,15 +13,15 @@ type iconst_2 struct {
1313
opCode uint8
1414
}
1515

16-
func (i *iconst_1) Execute(f *runtime.Frame) {
16+
func (i *iconst_1) Execute(f *thread.Frame) {
1717
f.OperandStack().PushInt(1)
1818
}
1919

2020
func (i *iconst_1) String() string {
2121
return fmt.Sprintf("{opcode: 0x%x, iconst_1}", i.opCode)
2222
}
2323

24-
func (i *iconst_2) Execute(f *runtime.Frame) {
24+
func (i *iconst_2) Execute(f *thread.Frame) {
2525
f.OperandStack().PushInt(2)
2626
}
2727

instructions/instruction.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package instructions
22

3-
import "github.com/tinycedar/vanilla/runtime"
3+
import (
4+
"github.com/tinycedar/vanilla/runtime/thread"
5+
)
46

57
type Instruction interface {
6-
Execute(frame *runtime.Frame)
8+
Execute(frame *thread.Frame)
79
}

instructions/invoke_virtual.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package instructions
33
import (
44
"fmt"
55
"github.com/tinycedar/classp/classfile"
6-
"github.com/tinycedar/vanilla/runtime"
6+
"github.com/tinycedar/vanilla/runtime/thread"
77
"strings"
88
)
99

@@ -12,7 +12,7 @@ type invokevirtual struct {
1212
opCode uint8
1313
}
1414

15-
func (i *invokevirtual) Execute(f *runtime.Frame) {
15+
func (i *invokevirtual) Execute(f *thread.Frame) {
1616
method := f.Method()
1717
if cp, ok := method.Cp[i.offset].(*classfile.ConstantMethodrefInfo); ok {
1818
invoked := cp.String(method.Cp)

instructions/invokestatic.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package instructions
33
import (
44
"fmt"
55
"github.com/tinycedar/classp/classfile"
6-
"github.com/tinycedar/vanilla/runtime"
6+
"github.com/tinycedar/vanilla/runtime/thread"
77
)
88

99
type invokestatic struct {
1010
index uint16
1111
opCode uint8
1212
}
1313

14-
func (i *invokestatic) Execute(f *runtime.Frame) {
14+
func (i *invokestatic) Execute(f *thread.Frame) {
1515
s := f.Method().Cp.GetConstantInfo(i.index).(*classfile.ConstantMethodrefInfo)
16-
f.Thread().Push(runtime.NewFrame(f.Thread(), f.Method().Class.FindMethod(s)))
16+
f.Thread().Push(thread.NewFrame(f.Thread(), f.Method().Class.FindMethod(s)))
1717
//TODO add method arg related
1818
}
1919

instructions/ldc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ package instructions
33
import (
44
"fmt"
55
"github.com/tinycedar/classp/classfile"
6-
"github.com/tinycedar/vanilla/runtime"
6+
"github.com/tinycedar/vanilla/runtime/thread"
77
)
88

99
type ldc struct {
1010
opCode uint8
1111
index uint8
1212
}
1313

14-
func (i *ldc) Execute(f *runtime.Frame) {
14+
func (i *ldc) Execute(f *thread.Frame) {
1515
_ldc(f, i.index)
1616
}
1717

18-
func _ldc(frame *runtime.Frame, index uint8) {
18+
func _ldc(frame *thread.Frame, index uint8) {
1919
stack := frame.OperandStack()
2020
if cp, ok := frame.Method().Cp[index].(*classfile.ConstantStringInfo); ok {
2121
stack.PushString(cp.String(frame.Method().Cp))

instructions/load.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package instructions
22

33
import (
44
"fmt"
5-
"github.com/tinycedar/vanilla/runtime"
5+
"github.com/tinycedar/vanilla/runtime/thread"
66
)
77

88
type iload_1 struct {
99
opCode uint8
1010
}
1111

12-
func (i *iload_1) Execute(f *runtime.Frame) {
12+
func (i *iload_1) Execute(f *thread.Frame) {
1313
_iload(f, 1)
1414
}
1515

@@ -21,15 +21,15 @@ type iload_2 struct {
2121
opCode uint8
2222
}
2323

24-
func (i *iload_2) Execute(f *runtime.Frame) {
24+
func (i *iload_2) Execute(f *thread.Frame) {
2525
_iload(f, 2)
2626
}
2727

2828
func (i *iload_2) String() string {
2929
return fmt.Sprintf("{opcode: 0x%x, iload_2}", i.opCode)
3030
}
3131

32-
func _iload(f *runtime.Frame, index int) {
32+
func _iload(f *thread.Frame, index int) {
3333
val := f.LocalVars().GetInt(index)
3434
f.OperandStack().PushInt(val)
3535
}

instructions/math.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package instructions
22

33
import (
44
"fmt"
5-
"github.com/tinycedar/vanilla/runtime"
5+
"github.com/tinycedar/vanilla/runtime/thread"
66
)
77

88
type iadd struct {
99
opCode uint8
1010
}
1111

12-
func (i *iadd) Execute(f *runtime.Frame) {
12+
func (i *iadd) Execute(f *thread.Frame) {
1313
stack := f.OperandStack()
1414
v2 := stack.PopInt()
1515
v1 := stack.PopInt()

instructions/return.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package instructions
22

3-
import "github.com/tinycedar/vanilla/runtime"
3+
import (
4+
"fmt"
5+
"github.com/tinycedar/vanilla/runtime/thread"
6+
)
47

58
type _return struct {
69
opCode uint8
710
}
811

9-
func (i *_return) Execute(f *runtime.Frame) {
10-
f.Thread().Stack().Pop()
12+
func (i *_return) Execute(f *thread.Frame) {
13+
f.Thread().Pop()
14+
}
15+
16+
func (i *_return) String() string {
17+
return fmt.Sprintf("{opcode: 0x%x, return}", i.opCode)
1118
}

instructions/store.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package instructions
22

33
import (
44
"fmt"
5-
"github.com/tinycedar/vanilla/runtime"
5+
"github.com/tinycedar/vanilla/runtime/thread"
66
)
77

88
type istore_1 struct {
99
opCode uint8
1010
}
1111

12-
func (i *istore_1) Execute(f *runtime.Frame) {
12+
func (i *istore_1) Execute(f *thread.Frame) {
1313
val := f.OperandStack().PopInt()
1414
f.LocalVars().SetInt(1, val)
1515
}
@@ -22,7 +22,7 @@ type istore_2 struct {
2222
opCode uint8
2323
}
2424

25-
func (i *istore_2) Execute(f *runtime.Frame) {
25+
func (i *istore_2) Execute(f *thread.Frame) {
2626
val := f.OperandStack().PopInt()
2727
f.LocalVars().SetInt(2, val)
2828
}

interpreter.go

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)