TYPE AS  ZSTRING gchar
TYPE AS     BYTE gint8, char
TYPE AS    UBYTE guint8, guchar
TYPE AS    SHORT gint16, gshort, gunichar2
TYPE AS   USHORT guint16, gushort
TYPE AS  INTEGER gint32, gint, time_t, FILE
TYPE AS UINTEGER guint32, guint, gboolean, gsize, gssize, GType
TYPE AS  LONGINT gint64, glong
TYPE AS ULONGINT guint64, gulong
TYPE AS   SINGLE gfloat
TYPE AS   DOUBLE gdouble

TYPE AS   ZSTRING PTR utf8, filename, gunichar
TYPE AS       ANY PTR gpointer, va_list
TYPE AS CONST ANY PTR gconstpointer

#DEFINE NULL CAST(ANY PTR, 0)

#DEFINE G_TYPE_FUNDAMENTAL(type)(g_type_fundamental_(type))
'#DEFINE G_TYPE_FUNDAMENTAL_MAX (255  SHL G_TYPE_FUNDAMENTAL_SHIFT)
#DEFINE G_TYPE_INVALID G_TYPE_MAKE_FUNDAMENTAL(0)
#DEFINE G_TYPE_NONE G_TYPE_MAKE_FUNDAMENTAL(1)
#DEFINE G_TYPE_INTERFACE G_TYPE_MAKE_FUNDAMENTAL(2)
#DEFINE G_TYPE_CHAR G_TYPE_MAKE_FUNDAMENTAL(3)
#DEFINE G_TYPE_UCHAR G_TYPE_MAKE_FUNDAMENTAL(4)
#DEFINE G_TYPE_BOOLEAN G_TYPE_MAKE_FUNDAMENTAL(5)
#DEFINE G_TYPE_INT G_TYPE_MAKE_FUNDAMENTAL(6)
#DEFINE G_TYPE_UINT G_TYPE_MAKE_FUNDAMENTAL(7)
#DEFINE G_TYPE_LONG G_TYPE_MAKE_FUNDAMENTAL(8)
#DEFINE G_TYPE_ULONG G_TYPE_MAKE_FUNDAMENTAL(9)
#DEFINE G_TYPE_INT64 G_TYPE_MAKE_FUNDAMENTAL(10)
#DEFINE G_TYPE_UINT64 G_TYPE_MAKE_FUNDAMENTAL(11)
#DEFINE G_TYPE_ENUM G_TYPE_MAKE_FUNDAMENTAL(12)
#DEFINE G_TYPE_FLAGS G_TYPE_MAKE_FUNDAMENTAL(13)
#DEFINE G_TYPE_FLOAT G_TYPE_MAKE_FUNDAMENTAL(14)
#DEFINE G_TYPE_DOUBLE G_TYPE_MAKE_FUNDAMENTAL(15)
#DEFINE G_TYPE_STRING G_TYPE_MAKE_FUNDAMENTAL(16)
#DEFINE G_TYPE_POINTER G_TYPE_MAKE_FUNDAMENTAL(17)
#DEFINE G_TYPE_BOXED G_TYPE_MAKE_FUNDAMENTAL(18)
#DEFINE G_TYPE_PARAM G_TYPE_MAKE_FUNDAMENTAL(19)
'#DEFINE G_TYPE_OBJECT G_TYPE_MAKE_FUNDAMENTAL(20)
#DEFINE G_TYPE_VARIANT G_TYPE_MAKE_FUNDAMENTAL(21)
'#DEFINE G_TYPE_FUNDAMENTAL_SHIFT(2)
#DEFINE G_TYPE_MAKE_FUNDAMENTAL(x) (CAST(GType, (x SHL G_TYPE_FUNDAMENTAL_SHIFT)))

#DEFINE G_TYPE_IS_FUNDAMENTAL(type) ((type)  <= G_TYPE_FUNDAMENTAL_MAX)
#DEFINE G_TYPE_IS_DERIVED(type) ((type)  > G_TYPE_FUNDAMENTAL_MAX)
#DEFINE G_TYPE_IS_INTERFACE(type) (G_TYPE_FUNDAMENTAL(type) = G_TYPE_INTERFACE)
#DEFINE G_TYPE_IS_CLASSED(type) (g_type_test_flags((type), G_TYPE_FLAG_CLASSED))
#DEFINE G_TYPE_IS_INSTANTIATABLE(type) (g_type_test_flags((type), G_TYPE_FLAG_INSTANTIATABLE))
#DEFINE G_TYPE_IS_DERIVABLE(type) (g_type_test_flags((type), G_TYPE_FLAG_DERIVABLE))
#DEFINE G_TYPE_IS_DEEP_DERIVABLE(type) (g_type_test_flags((type), G_TYPE_FLAG_DEEP_DERIVABLE))
#DEFINE G_TYPE_IS_ABSTRACT(type) (g_type_test_flags((type), G_TYPE_FLAG_ABSTRACT))
#DEFINE G_TYPE_IS_VALUE_ABSTRACT(type) (g_type_test_flags((type), G_TYPE_FLAG_VALUE_ABSTRACT))
#DEFINE G_TYPE_IS_VALUE_TYPE(type) (g_type_check_is_value_type(type))
#DEFINE G_TYPE_HAS_VALUE_TABLE(type) (g_type_value_table_peek(type) <> NULL)

#DEFINE G_TYPE_CHECK_INSTANCE(instance) (_G_TYPE_CHI(CAST(GTypeInstance PTR, (instance))))
#DEFINE G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_G_TYPE_CIC((instance), (g_type), c_type))
#DEFINE G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type) (_G_TYPE_CIT((instance), (g_type)))
#DEFINE G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type) (_G_TYPE_IGC((instance), (g_type), c_type))
#DEFINE G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI((instance), (g_type), c_type))
#DEFINE G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type) (_G_TYPE_CCC((g_class), (g_type), c_type))
#DEFINE G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT((g_class), (g_type)))
#DEFINE G_TYPE_CHECK_VALUE(value) (_G_TYPE_CHV((value)))
#DEFINE G_TYPE_CHECK_VALUE_TYPE(value, g_type) (_G_TYPE_CVH((value), (g_type)))
#DEFINE G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS((CAST(GTypeInstance PTR, (instance)))->g_class))
#DEFINE G_TYPE_FROM_CLASS(g_class) ((CAST(GTypeClass PTR, (g_class)))->g_type)
#DEFINE G_TYPE_FROM_INTERFACE(g_iface) ((CAST(GTypeInterface PTR, (g_iface)))->g_type)
#DEFINE G_TYPE_INSTANCE_GET_PRIVATE(instance, g_type, c_type) (CAST(c_type PTR, g_type_instance_get_private_(CAST(GTypeInstance PTR, (instance)), (g_type))))
#DEFINE G_TYPE_CLASS_GET_PRIVATE(klass, g_type, c_type) (CAST(c_type PTR, g_type_class_get_private_(CAST(GTypeClass PTR, (klass)), (g_type))))

#IFNDEF G_DISABLE_CAST_CHECKS
#DEFINE _G_TYPE_CIC(ip, gt, ct) _
    (CAST(ct PTR, g_type_check_instance_cast_(CAST(GTypeInstance PTR, ip), gt)))
#DEFINE _G_TYPE_CCC(cp, gt, ct) _
    (CAST(ct PTR, g_type_check_class_cast_(CAST(GTypeClass PTR, cp), gt)))
#ELSE ' G_DISABLE_CAST_CHECKS
#DEFINE _G_TYPE_CIC(ip, gt, ct) (CAST(ct PTR, ip))
#DEFINE _G_TYPE_CCC(cp, gt, ct) (CAST(ct PTR, cp))
#ENDIF ' G_DISABLE_CAST_CHECKS

#DEFINE _G_TYPE_CHI(ip) (g_type_check_instance_(CAST(GTypeInstance PTR, ip)))
#DEFINE _G_TYPE_CHV(vl) (g_type_check_value_(CAST(GValue PTR, vl)))
#DEFINE _G_TYPE_IGC(ip, gt, ct) (CAST(ct PTR,((CAST(GTypeInstance PTR, ip))->g_class)))
#DEFINE _G_TYPE_IGI(ip, gt, ct) (CAST(ct PTR, g_type_interface_peek((CAST(GTypeInstance PTR, ip))->g_class, gt)))

'#IFDEF __GNUC__

'#DEFINE _G_TYPE_CIT(ip, gt) _
  'IIF(0 = CAST(GTypeInstance PTR, ip), FALSE, _
      'IIF(CAST(GTypeInstance PTR, ip)->g_class ANDALSO CAST(GTypeInstance PTR, ip)->g_class->g_type = gt, TRUE, _
          'g_type_check_instance_is_a(CAST(GTypeInstance PTR, ip), gt)))
'#DEFINE _G_TYPE_CCT(cp, gt) _
  'IIF(0 = CAST(GTypeClass PTR, cp), FALSE, _
      'IIF(CAST(GTypeClass PTR, cp)->g_type = gt, TRUE, _
          'g_type_check_class_is_a(CAST(GTypeClass PTR, cp), gt)))
'#DEFINE _G_TYPE_CVH(vl, gt) _
  'IIF(0 = CAST(GValue PTR, vl), FALSE, _
      'IIF(CAST(GValue PTR, vl)->g_type = gt, TRUE, _
          'g_type_check_value_holds(CAST(GValue PTR, vl), gt)))

'#ELSE ' __GNUC__

#DEFINE _G_TYPE_CIT(ip, gt) (g_type_check_instance_is_a(CAST(GTypeInstance PTR, ip), gt))
#DEFINE _G_TYPE_CCT(cp, gt) (g_type_check_class_is_a(CAST(GTypeClass PTR, cp), gt))
#DEFINE _G_TYPE_CVH(vl, gt) (g_type_check_value_holds(CAST(GValue PTR, vl), gt))

'#ENDIF ' __GNUC__

#DEFINE GPOINTER_TO_INT(p) (CAST(gint, (p)))
#DEFINE GINT_TO_POINTER(i) (CAST(gpointer, (i)))

