2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2008-03-22 22:34:50 +01:00
|
|
|
value.h
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-22 22:34:50 +01:00
|
|
|
Datatype management routines. Conversions between each Gambas datatype,
|
|
|
|
and conversions between Gambas datatypes and native datatypes.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-22 22:34:50 +01:00
|
|
|
(c) 2000-2007 Benoit Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-22 22:34:50 +01:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 1, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-22 22:34:50 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-22 22:34:50 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __GBX_VALUE_H
|
|
|
|
#define __GBX_VALUE_H
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "gbx_type.h"
|
|
|
|
#include "gbx_class.h"
|
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
int value;
|
|
|
|
#if __WORDSIZE == 64
|
|
|
|
int _pad;
|
|
|
|
#endif
|
|
|
|
intptr_t _reserved[2];
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_BOOLEAN;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
int value;
|
|
|
|
#if __WORDSIZE == 64
|
|
|
|
int _pad;
|
|
|
|
#endif
|
|
|
|
intptr_t _reserved[2];
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_BYTE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
int value;
|
|
|
|
#if __WORDSIZE == 64
|
|
|
|
int _pad;
|
|
|
|
#endif
|
|
|
|
intptr_t _reserved[2];
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_SHORT;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
int value;
|
|
|
|
#if __WORDSIZE == 64
|
|
|
|
int _pad;
|
|
|
|
#endif
|
|
|
|
intptr_t _reserved[2];
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_INTEGER;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
int64_t value;
|
|
|
|
#if __WORDSIZE == 64
|
|
|
|
intptr_t _reserved[2];
|
|
|
|
#else
|
|
|
|
int _reserved;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_LONG;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
intptr_t value;
|
|
|
|
intptr_t _reserved[2];
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_POINTER;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
#if __WORDSIZE == 64
|
|
|
|
#else
|
|
|
|
int _pad;
|
|
|
|
#endif
|
|
|
|
double value;
|
2008-03-21 16:39:46 +01:00
|
|
|
#if __WORDSIZE == 64
|
2008-03-22 22:34:50 +01:00
|
|
|
intptr_t _reserved[2];
|
2008-03-21 16:39:46 +01:00
|
|
|
#endif
|
2008-03-22 22:34:50 +01:00
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_SINGLE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
#if __WORDSIZE == 64
|
|
|
|
#else
|
|
|
|
int _pad;
|
|
|
|
#endif
|
|
|
|
double value;
|
2008-03-21 16:39:46 +01:00
|
|
|
#if __WORDSIZE == 64
|
2008-03-22 22:34:50 +01:00
|
|
|
intptr_t _reserved[2];
|
2008-03-21 16:39:46 +01:00
|
|
|
#endif
|
2008-03-22 22:34:50 +01:00
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_FLOAT;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
int date; /* number of days */
|
|
|
|
int time; /* number of milliseconds */
|
|
|
|
#if __WORDSIZE == 64
|
|
|
|
intptr_t _reserved[2];
|
|
|
|
#else
|
|
|
|
int _reserved;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_DATE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
char *addr;
|
|
|
|
int start;
|
|
|
|
int len;
|
|
|
|
#if __WORDSIZE == 64
|
|
|
|
intptr_t _reserved;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_STRING;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
CLASS *class;
|
|
|
|
void *object;
|
|
|
|
char kind;
|
|
|
|
char defined;
|
|
|
|
short index;
|
|
|
|
/*long function;*/
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_FUNCTION;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2008-03-22 22:34:50 +01:00
|
|
|
FUNCTION_NULL = 0,
|
|
|
|
FUNCTION_NATIVE = 1,
|
|
|
|
FUNCTION_PRIVATE = 2,
|
|
|
|
FUNCTION_PUBLIC = 3,
|
|
|
|
FUNCTION_EVENT = 4,
|
|
|
|
FUNCTION_EXTERN = 5,
|
|
|
|
FUNCTION_UNKNOWN = 6,
|
|
|
|
FUNCTION_CALL = 7,
|
2007-12-30 17:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
TYPE ptype;
|
|
|
|
intptr_t value[2];
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_VOID;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
TYPE vtype;
|
|
|
|
/*
|
|
|
|
union {
|
|
|
|
char _boolean;
|
|
|
|
char _byte;
|
|
|
|
short _short;
|
|
|
|
double _double;
|
|
|
|
int _int;
|
|
|
|
long long _int64;
|
|
|
|
long long _date;
|
|
|
|
char *_string;
|
|
|
|
void *_object;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
char value[8];
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_VARIANT;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
CLASS *class;
|
|
|
|
void *object;
|
|
|
|
void *super;
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_OBJECT;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
CLASS *class;
|
|
|
|
void *super;
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_CLASS;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
struct {
|
|
|
|
TYPE type;
|
|
|
|
CLASS *class;
|
|
|
|
void *addr;
|
|
|
|
short index;
|
|
|
|
unsigned keep : 1;
|
|
|
|
}
|
|
|
|
PACKED
|
|
|
|
VALUE_ARRAY;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2008-03-22 22:34:50 +01:00
|
|
|
union value {
|
|
|
|
TYPE type;
|
|
|
|
VALUE_BOOLEAN _boolean;
|
|
|
|
VALUE_BYTE _byte;
|
|
|
|
VALUE_SHORT _short;
|
|
|
|
VALUE_INTEGER _integer;
|
|
|
|
VALUE_LONG _long;
|
|
|
|
VALUE_SINGLE _single;
|
|
|
|
VALUE_FLOAT _float;
|
|
|
|
VALUE_DATE _date;
|
|
|
|
VALUE_STRING _string;
|
|
|
|
VALUE_FUNCTION _function;
|
|
|
|
VALUE_VARIANT _variant;
|
|
|
|
VALUE_CLASS _class;
|
|
|
|
VALUE_OBJECT _object;
|
|
|
|
VALUE_ARRAY _array;
|
|
|
|
VALUE_VOID _void;
|
|
|
|
VALUE_POINTER _pointer;
|
|
|
|
}
|
|
|
|
VALUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
#define VALUE_copy(_dst, _src) \
|
|
|
|
(_dst)->_void.type = (_src)->_void.type; \
|
|
|
|
(_dst)->_void.ptype = (_src)->_void.ptype; \
|
|
|
|
(_dst)->_void.value[0] = (_src)->_void.value[0]; \
|
|
|
|
(_dst)->_void.value[1] = (_src)->_void.value[1];
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#define VALUE_is_object(val) (TYPE_is_object((val)->type))
|
|
|
|
#define VALUE_is_string(val) ((val)->type == T_STRING || (val)->type == T_CSTRING)
|
|
|
|
#define VALUE_is_number(val) ((val)->type >= T_BYTE && (val)->type <= T_FLOAT)
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_default(VALUE *value, TYPE type);
|
|
|
|
void VALUE_convert(VALUE *value, TYPE type);
|
|
|
|
void VALUE_read(VALUE *value, void *addr, TYPE type);
|
|
|
|
void VALUE_write(VALUE *value, void *addr, TYPE type);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
//void VALUE_put(VALUE *value, void *addr, TYPE type);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_free(void *addr, TYPE type);
|
|
|
|
void VALUE_to_string(VALUE *value, char **addr, int *len);
|
|
|
|
void VALUE_from_string(VALUE *value, const char *addr, int len);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_class_read(CLASS *class, VALUE *value, char *addr, CTYPE ctype);
|
|
|
|
void VALUE_class_write(CLASS *class, VALUE *value, char *addr, CTYPE ctype);
|
|
|
|
void VALUE_class_constant(CLASS *class, VALUE *value, int ind);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
bool VALUE_is_null(VALUE *val);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void VALUE_get_string(VALUE *val, char **text, int *length);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#define VALUE_conv(_value, _type) \
|
|
|
|
{ \
|
2008-03-22 22:34:50 +01:00
|
|
|
if ((_value)->type != (_type)) \
|
|
|
|
VALUE_convert(_value, _type); \
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-03-11 14:29:47 +01:00
|
|
|
#define VALUE_conv_string(_value) \
|
|
|
|
{ \
|
2008-03-22 22:34:50 +01:00
|
|
|
if ((_value)->type != T_STRING && (_value)->type != T_CSTRING) \
|
|
|
|
VALUE_convert(_value, T_STRING); \
|
2008-03-11 14:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#define VALUE_is_super(_value) (EXEC_super && EXEC_super == (_value)->_object.super)
|
|
|
|
|
2008-03-21 16:39:46 +01:00
|
|
|
#endif
|