(include-book "irun") (in-package "M5") (defconst *lecture-19-ct* (make-ct (list (make class :name "Point" :supers '("Object") :fields '("x" "y") :methods (list (make method :name "move" :formals '(dx dy) :sync nil :code '((load 0) (load 0) (getfield ("Point" "x")) (load 1) (add) (putfield ("Point" "x")) (load 0) (load 0) (getfield ("Point" "y")) (load 2) (add) (putfield ("Point" "y")) (return))) (make method :name "dist" :formals '(dx dy) :sync nil :code '((load 0) (getfield ("Point" "x")) (dup) (mul) (load 0) (getfield ("Point" "y")) (dup) (mul) (add) (xreturn))))) (make class :name "ColoredPoint" :supers '("Point" "Object") :fields '("color") :methods (list (make method :name "move" :formals '(dx dy) :sync nil :code '((load 0) (load 1) (load 2) (invokespecial ("Point" "move" 2)) ; super.move(dx,dy); (load 0) (getfield ("Point" "x")) (iflt 5) (load 0) (getfield ("Point" "y")) (iflt 2) (return) (load 0) (const "Red") (putfield ("ColoredPoint" "color")) (return))))) (make class :name "Top" :supers '("Object") :fields nil :methods (list (make method :name "main" :formals () :sync nil :code '((new "Point") (store 0) (new "ColoredPoint") (store 1) (load 0) (const -3) (const -4) (invokevirtual ("ColoredPoint" "move" 2)) (load 1) (const -7) (const -9) (invokevirtual ("ColoredPoint" "move" 2)) (halt)))))))) (irun (make state :tt (list (make thread :id 0 :cs (push (make frame :pc 0 :locs nil :stk nil :mloc '("Top" "main" 0)) nil) :stat 'active :ref nil)) :hp nil :ct *lecture-19-ct*))