import Mate.Types
import Mate.Utilities
import Mate.ClassPool
+import Mate.Strings
+
foreign import ccall "dynamic"
code_int :: FunPtr (CInt -> CInt -> IO CInt) -> (CInt -> CInt -> IO CInt)
newNamedLabel (show mi) >>= defineLabel
-- objref lives somewhere on the argument stack
mov eax (Disp ((*4) $ fromIntegral $ length args), esp)
- -- get methodtable ref
+ -- get method-table-ptr
mov eax (Disp 0, eax)
-- get method offset
let nameAndSig = methodname `B.append` (encode msig)
when (argcnt > 0) (add esp argcnt)
-- push result on stack if method has a return value
when (methodHaveReturnValue cls cpidx) (push eax)
- return $ Just $ (calladdr, MI mi)
+ -- note, the "mi" has the wrong class reference here.
+ -- we figure that out at run-time, in the methodpool,
+ -- depending on the method-table-ptr
+ return $ Just $ (calladdr, VI mi)
emit' (PUTSTATIC cpidx) = do
pop eax
trapaddr <- getCurrentOffset
-- set method table pointer
let mtable = unsafePerformIO $ getMethodTable objname
mov (Disp 0, eax) mtable
+ emit (CHECKCAST _) = nop -- TODO(bernhard): ...
emit (BIPUSH val) = push ((fromIntegral val) :: Word32)
emit (SIPUSH val) = push ((fromIntegral $ ((fromIntegral val) :: Int16)) :: Word32)
emit (ICONST_0) = push (0 :: Word32)
pop eax
mov (Disp (cArgs x), ebp) eax
+ emit (LDC1 x) = emit (LDC2 $ fromIntegral x)
+ emit (LDC2 x) = do
+ let value = case (constsPool cls) M.! x of
+ (CString s) -> unsafePerformIO $ getUniqueStringAddr s
+ _ -> error $ "LDCI... missing impl."
+ push value
emit (GETFIELD x) = do
pop eax -- this pointer
let (cname, fname) = buildFieldOffset cls x
emit (IINC x imm) = do
add (Disp (cArgs x), ebp) (s8_w32 imm)
+ emit (IF_ACMP cond x) = emit (IF_ICMP cond x)
emit (IF_ICMP cond _) = do
pop eax -- value2
pop ebx -- value1
jmp $ getLabel sid lmap
emit RETURN = do mov esp ebp; pop ebp; ret
+ emit ARETURN = emit IRETURN
emit IRETURN = do
pop eax
mov esp ebp