diff options
Diffstat (limited to 'ruby.h')
-rw-r--r-- | ruby.h | 123 |
1 files changed, 73 insertions, 50 deletions
@@ -6,7 +6,7 @@ $Date: 1995/01/12 08:54:52 $ created at: Thu Jun 10 14:26:32 JST 1993 - Copyright (C) 1993-1995 Yukihiro Matsumoto + Copyright (C) 1993-1996 Yukihiro Matsumoto *************************************************/ @@ -26,12 +26,19 @@ # else # define const # endif +# define _(args) +#else +# define _(args) args #endif #if defined(HAVE_ALLOCA_H) && !defined(__GNUC__) #include <alloca.h> #endif +#ifdef _AIX +#pragma alloca +#endif + typedef unsigned int UINT; typedef UINT VALUE; typedef UINT ID; @@ -66,6 +73,7 @@ typedef unsigned short USHORT; #define FIXNUM_FLAG 0x01 #define INT2FIX(i) (VALUE)(((int)(i))<<1 | FIXNUM_FLAG) VALUE int2inum(); +#define INT2NUM(v) int2inum(v) #if (-1==(((-1)<<1)&FIXNUM_FLAG)>>1) # define RSHIFT(x,y) ((x)>>y) @@ -80,19 +88,20 @@ VALUE int2inum(); #define NEGFIXABLE(f) ((f) >= FIXNUM_MIN) #define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f)) -#define NIL_P(p) ((p) == Qnil) - +/* special contants - i.e. non-zero and non-fixnum constants */ +#define FALSE 0 #undef TRUE -extern VALUE TRUE; -#define FALSE Qnil +#define TRUE 2 +#define Qnil 4 + +int rb_test_false_or_nil(); +# define RTEST(v) rb_test_false_or_nil(v) +#define NIL_P(v) ((VALUE)(v) == Qnil) extern VALUE cObject; -extern VALUE cNil; -extern VALUE cFixnum; -extern VALUE cData; -#define CLASS_OF(obj) (FIXNUM_P(obj)?cFixnum: NIL_P(obj)?cNil:\ - RBASIC(obj)->class) +VALUE rb_class_of(); +#define CLASS_OF(v) rb_class_of(v) #define T_NIL 0x00 #define T_OBJECT 0x01 @@ -107,9 +116,12 @@ extern VALUE cData; #define T_HASH 0x0a #define T_STRUCT 0x0b #define T_BIGNUM 0x0c +#define T_FILE 0x0d -#define T_DATA 0x10 -#define T_MATCH 0x11 +#define T_TRUE 0x20 +#define T_FALSE 0x21 +#define T_DATA 0x22 +#define T_MATCH 0x23 #define T_VARMAP 0xfd #define T_SCOPE 0xfe @@ -118,8 +130,11 @@ extern VALUE cData; #define T_MASK 0xff #define BUILTIN_TYPE(x) (((struct RBasic*)(x))->flags & T_MASK) -#define TYPE(x) (FIXNUM_P(x)?T_FIXNUM:NIL_P(x)?T_NIL:BUILTIN_TYPE(x)) -#define Check_Type(x,t) {if (TYPE(x)!=(t)) WrongType(x,t);} + +int rb_type(); +#define TYPE(x) rb_type(x) + +void Check_Type(); #define Need_Fixnum(x) {if (!FIXNUM_P(x)) (x) = num2fix(x);} #define NUM2INT(x) (FIXNUM_P(x)?FIX2INT(x):num2int(x)) VALUE num2fix(); @@ -180,6 +195,11 @@ struct RHash { struct st_table *tbl; }; +struct RFile { + struct RBasic basic; + struct OpenFile *fptr; +}; + struct RData { struct RBasic basic; void (*dmark)(); @@ -189,23 +209,16 @@ struct RData { #define DATA_PTR(dta) (RDATA(dta)->data) -VALUE data_new(); -VALUE rb_ivar_get(); -VALUE rb_ivar_set(); - -#define Get_Data_Struct(obj, iv, type, sval) {\ - VALUE _data_;\ - _data_ = rb_ivar_get(obj, iv);\ - Check_Type(_data_, T_DATA);\ - sval = (type*)DATA_PTR(_data_);\ -} +VALUE data_object_alloc(); +#define Make_Data_Struct(class,type,mark,free,sval) (\ + sval = ALLOC(type),\ + memset(sval, 0, sizeof(type)),\ + data_object_alloc(class,sval,mark,free)\ +) -#define Make_Data_Struct(obj, iv, type, mark, free, sval) {\ - VALUE _new_;\ - sval = ALLOC(type);\ - _new_ = data_new(sval,mark,free);\ - memset(sval, 0, sizeof(type));\ - rb_ivar_set(obj, iv, _new_);\ +#define Get_Data_Struct(obj,type,sval) {\ + Check_Type(obj, T_DATA); \ + sval = (type*)DATA_PTR(obj);\ } struct RStruct { @@ -233,28 +246,27 @@ struct RBignum { #define RDATA(obj) (R_CAST(RData)(obj)) #define RSTRUCT(obj) (R_CAST(RStruct)(obj)) #define RBIGNUM(obj) (R_CAST(RBignum)(obj)) +#define RFILE(obj) (R_CAST(RFile)(obj)) -#define FL_SINGLE (1<<8) -#define FL_MARK (1<<9) +#define FL_SINGLETON (1<<8) +#define FL_MARK (1<<9) -#define FL_USER0 (1<<10) -#define FL_USER1 (1<<11) -#define FL_USER2 (1<<12) -#define FL_USER3 (1<<13) -#define FL_USER4 (1<<14) -#define FL_USER5 (1<<15) -#define FL_USER6 (1<<16) -#define FL_USER7 (1<<17) +#define FL_USER0 (1<<10) +#define FL_USER1 (1<<11) +#define FL_USER2 (1<<12) +#define FL_USER3 (1<<13) +#define FL_USER4 (1<<14) +#define FL_USER5 (1<<15) +#define FL_USER6 (1<<16) -#define FL_UMASK (0xff<<10) +#define FL_UMASK (0x7f<<10) -#define FL_ABLE(x) (!(FIXNUM_P(x)||NIL_P(x))) +int rb_special_const_p(); +#define FL_ABLE(x) (!(FIXNUM_P(x)||rb_special_const_p(x))) #define FL_TEST(x,f) (FL_ABLE(x)?(RBASIC(x)->flags&(f)):0) #define FL_SET(x,f) if (FL_ABLE(x)) {RBASIC(x)->flags |= (f);} #define FL_UNSET(x,f) if(FL_ABLE(x)){RBASIC(x)->flags &= ~(f);} - -extern VALUE Qself; -#define Qnil 0 +#define FL_REVERSE(x,f) if(FL_ABLE(x)){RBASIC(x)->flags ^= f;} #define ALLOC_N(type,n) (type*)xmalloc(sizeof(type)*(n)) #define ALLOC(type) (type*)xmalloc(sizeof(type)) @@ -277,6 +289,7 @@ void rb_extend_object(); void rb_define_variable(); void rb_define_const(); +void rb_define_global_const(); void rb_define_method(); void rb_define_singleton_method(); @@ -289,26 +302,30 @@ char *rb_id2name(); ID rb_to_id(); char *rb_class2name(); -VALUE rb_method_boundp(); +int rb_method_boundp(); VALUE rb_eval_string(); VALUE rb_funcall(); VALUE rb_funcall2(); int rb_scan_args(); +VALUE rb_ivar_get(); +VALUE rb_ivar_set(); + VALUE rb_iv_get(); VALUE rb_iv_set(); void rb_const_set(); VALUE rb_yield(); -VALUE iterator_p(); +int iterator_p(); -VALUE rb_equal(); +int rb_equal(); extern int verbose, debug; #ifdef __GNUC__ typedef void voidfn (); +volatile voidfn Raise; volatile voidfn Fail; volatile voidfn Fatal; volatile voidfn Bug; @@ -316,8 +333,11 @@ volatile voidfn WrongType; volatile voidfn rb_sys_fail; volatile voidfn rb_break; volatile voidfn rb_exit; -volatile voidfn rb_fail; +volatile voidfn rb_fatal; +volatile voidfn rb_raise; +volatile voidfn rb_notimplement; #else +void Raise(); void Fail(); void Fatal(); void Bug(); @@ -325,9 +345,12 @@ void WrongType(); void rb_sys_fail(); void rb_break(); void rb_exit(); -void rb_fail(); +void rb_fatal(); +void rb_raise(); +void rb_notimplement(); #endif +void Error(); void Warning(); #if defined(EXTLIB) && defined(USE_DLN_A_OUT) |