 CompileState a
extendScope m = do
  fr <- use frame
  ret <- m
  frame .= fr
  return ret

-- 整数の変数を，シンボルテーブルから引っ張ってくる．
lookupVar :: Var -> State CompileState Reg
lookupVar var@(Var s) = do
  vars <- use (frame.intVars)
  case lookup var vars of
    Nothing -> error $ "undefined variable: " ++ s
    Just rg -> return rg

-- ポインタ変数を，シンボルテーブルから引っ張ってくる．
lookupPtr :: Var -> State CompileState PReg
lookupPtr ptr@(Var s) = do
  vars <- use (frame.ptrVars)
  case lookup ptr vars of
    N
apiList = [("api_drawPoint", (Imm 0x0002, [Reg 0x31 .. Reg 0x34])),
           ("api_drawLine",  (Imm 0x0003, [Reg 0x31 .. Reg 0x36])),
           ("api_drawRect",  (Imm 0x0004, [Reg 0x31 .. Reg 0x36])),
           ("api_drawOval",  (Imm 0x0005, [Reg 0x31 .. Reg 0x36])),
           ("api_exit",      (Imm 0x0008, [Reg 0x31 .. Reg 0x31])),
           ("api_sleep",     (Imm 0x0009, [Reg 0x31 .. Reg 0x32])),
           ("api_openWin",   (Imm 0x0010, [Reg 0x31 .. Reg 0x34]))
          ]
apiList = [("api_drawPoint", (Imm 0x0002, [Reg 0x31 .. Reg 0x34])),
           ("api_drawLine",  (Imm 0x0003, [Reg 0x31 .. Reg 0x36])),
           ("api_drawRect",  (Imm 0x0004, [Reg 0x31 .. Reg 0x36])),
           ("api_drawOval",  (Imm 0x0005, [Reg 0x31 .. Reg 0x36])),
           ("api_exit",      (Imm 0x0008, [Reg 0x31 .. Reg 0x31])),
           ("api_sleep",     (Imm 0x0009, [Reg 0x31 .. Reg 0x32])),
           ("api_openWin",   (Imm 0x0010, [Reg 0x31 .. Reg 0x34]))
          ]