Skip to content

Commit 7a24aaa

Browse files
committed
Add basic logging.
1 parent c1f5c2d commit 7a24aaa

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

frame.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
type Frame struct {
88
stack []interface{}
9-
localVariables []interface{} // function parameters basically
9+
localVariables []interface{}
1010
code []byte
1111
instructionPointer uint32
1212
class *Class

jvm.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"errors"
5+
"fmt"
6+
"log"
57
"os"
68
)
79

@@ -60,5 +62,18 @@ func (jvm *JVM) executeMethod(className string, methodName string, methodDescrip
6062
frame := code.toFrame(class, args...)
6163
result := jvm.Exec(&frame)
6264

65+
argString := ""
66+
for i, arg := range args {
67+
if i > 0 {
68+
argString += ","
69+
}
70+
switch arg.(type) {
71+
case *Object:
72+
argString += "this"
73+
default:
74+
argString += fmt.Sprintf("%v", arg)
75+
}
76+
}
77+
log.Printf("%s.%s(%s) --> %v\n", className, methodName, argString, result)
6378
return result, nil
6479
}

main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package main
22

3+
import (
4+
"fmt"
5+
"log"
6+
)
7+
38
func main() {
49
jvm := JVM{classes: make([]*Class, 0)}
510
_, err := jvm.addClass("Main")
@@ -8,7 +13,10 @@ func main() {
813
}
914
_, err = jvm.executeMethod("Main", "main", "([Ljava/lang/String;)V")
1015
if err != nil {
16+
fmt.Printf("JVM failed with error %v", err)
1117
return
1218
}
1319

20+
log.Println("JVM exited successfully.")
21+
1422
}

0 commit comments

Comments
 (0)