diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-04-24 17:41:28 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-04-24 17:41:28 +0900 |
| commit | 8b367098ac493cc458f731cc780070ffb103f2f4 (patch) | |
| tree | 681fd1277aa80018f8dc6523af897fca236b5423 /src | |
| parent | 2970b6aadbb0d5afef683854e0fe36b05024fc36 (diff) | |
| download | mruby-8b367098ac493cc458f731cc780070ffb103f2f4.tar.gz mruby-8b367098ac493cc458f731cc780070ffb103f2f4.zip | |
move header files {irep,dump,cdump,ritehash}.h to /include/mruby
Diffstat (limited to 'src')
| -rw-r--r-- | src/cdump.c | 6 | ||||
| -rw-r--r-- | src/cdump.h | 14 | ||||
| -rw-r--r-- | src/class.c | 2 | ||||
| -rw-r--r-- | src/codegen.c | 2 | ||||
| -rw-r--r-- | src/dump.c | 4 | ||||
| -rw-r--r-- | src/dump.h | 124 | ||||
| -rw-r--r-- | src/error.c | 2 | ||||
| -rw-r--r-- | src/gc.c | 2 | ||||
| -rw-r--r-- | src/hash.c | 2 | ||||
| -rw-r--r-- | src/irep.h | 29 | ||||
| -rw-r--r-- | src/kernel.c | 2 | ||||
| -rw-r--r-- | src/load.c | 4 | ||||
| -rw-r--r-- | src/re.c | 2 | ||||
| -rw-r--r-- | src/ritehash.h | 204 | ||||
| -rw-r--r-- | src/state.c | 2 | ||||
| -rw-r--r-- | src/symbol.c | 2 | ||||
| -rw-r--r-- | src/variable.c | 2 | ||||
| -rw-r--r-- | src/vm.c | 2 |
18 files changed, 18 insertions, 389 deletions
diff --git a/src/cdump.c b/src/cdump.c index 131a9891a..47c89300c 100644 --- a/src/cdump.c +++ b/src/cdump.c @@ -4,11 +4,11 @@ ** See Copyright Notice in mruby.h */ -#include "cdump.h" +#include "mruby/cdump.h" #include <string.h> -#include "irep.h" +#include "mruby/irep.h" #include "mruby/string.h" #include "re.h" @@ -169,7 +169,7 @@ mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname) irep_num = mrb->irep_len - n; SOURCE_CODE0("#include \"mruby.h\""); - SOURCE_CODE0("#include \"irep.h\""); + SOURCE_CODE0("#include \"mruby/irep.h\""); SOURCE_CODE0("#include \"mruby/string.h\""); SOURCE_CODE0("#include \"mruby/proc.h\""); SOURCE_CODE0(""); diff --git a/src/cdump.h b/src/cdump.h deleted file mode 100644 index f74d7a046..000000000 --- a/src/cdump.h +++ /dev/null @@ -1,14 +0,0 @@ -/* -** cdump.h - mruby binary dumper (C source format) -** -** See Copyright Notice in mruby.h -*/ - -#include "mruby.h" -#include <stdio.h> - -int mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname); - -/* error code */ -#define MRB_CDUMP_OK 0 -#define MRB_CDUMP_GENERAL_FAILURE -1 diff --git a/src/class.c b/src/class.c index 51926b019..f884f91ba 100644 --- a/src/class.c +++ b/src/class.c @@ -15,7 +15,7 @@ #include "mruby/array.h" #include "error.h" -#include "ritehash.h" +#include "mruby/khash.h" #ifdef INCLUDE_REGEXP #define mrb_usascii_str_new2 mrb_usascii_str_new_cstr diff --git a/src/codegen.c b/src/codegen.c index 582008a69..5eca94ad0 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -8,7 +8,7 @@ #define CODEGEN_DUMP #include "mruby.h" -#include "irep.h" +#include "mruby/irep.h" #include "compile.h" #include "mruby/proc.h" #include "opcode.h" diff --git a/src/dump.c b/src/dump.c index a6ba1350a..61297eb10 100644 --- a/src/dump.c +++ b/src/dump.c @@ -5,13 +5,13 @@ */ #include <string.h> -#include "dump.h" +#include "mruby/dump.h" #include "mruby/string.h" #ifdef INCLUDE_REGEXP #include "re.h" #endif -#include "irep.h" +#include "mruby/irep.h" static const unsigned char def_rite_binary_header[] = RITE_FILE_IDENFIFIER diff --git a/src/dump.h b/src/dump.h deleted file mode 100644 index 1f211aa0b..000000000 --- a/src/dump.h +++ /dev/null @@ -1,124 +0,0 @@ -/* -** dump.h - mruby binary dumper (Rite binary format) -** -** See Copyright Notice in mruby.h -*/ - -#include "mruby.h" -#include <stdio.h> -#include <stdint.h> - -int mrb_dump_irep(mrb_state*,int,FILE*); -int mrb_load_irep(mrb_state*,FILE*); -int mrb_load_irep_offset(mrb_state*,FILE*,long); -int mrb_read_irep(mrb_state*,char*); - -int mrb_bdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname); - -/* dump type */ -#define DUMP_TYPE_CODE 0 -#define DUMP_TYPE_BIN 1 -#define DUMP_TYPE_HEX 2 - -/* dump/load error code */ -#define MRB_DUMP_OK 0 -#define MRB_DUMP_GENERAL_FAILURE -1 -#define MRB_DUMP_WRITE_FAULT -2 -#define MRB_DUMP_READ_FAULT -3 -#define MRB_DUMP_CRC_ERROR -4 -#define MRB_DUMP_INVALID_FILE_HEADER -5 -#define MRB_DUMP_INVALID_IREP -6 -#define MRB_DUMP_INVALID_ARGUMENT -7 - -/* size of long/int/short value on dump/load */ -#define MRB_DUMP_SIZE_OF_LONG 4 -#define MRB_DUMP_SIZE_OF_INT 4 -#define MRB_DUMP_SIZE_OF_SHORT 2 - -/* null symbol length */ -#define MRB_DUMP_NULL_SYM_LEN 0xFFFF - -/* Use HEX format string */ -#define RITE_FILE_IS_HEX - -#ifdef RITE_FILE_IS_HEX -#define RITE_FILE_HEX_SIZE 2 -#else -#define RITE_FILE_HEX_SIZE 1 -#endif - -/* Rite Binary File header */ -#define RITE_FILE_IDENFIFIER "RITE" -#define RITE_FILE_FORMAT_VER "00090000" -#define RITE_VM_VER "00090000" -#define RITE_COMPILER_TYPE "MATZ " -#define RITE_COMPILER_VER "00090000" -#define RITE_RESERVED " " - -/* irep header */ -#define RITE_IREP_IDENFIFIER 'S' -#define RITE_IREP_TYPE_CLASS 'C' -#define RITE_IREP_TYPE_MODULE 'M' - -#define MRB_DUMP_DEFAULT_STR_LEN 128 - -//Rite Binary file_header -typedef struct _rite_binary_header { - unsigned char rbfi[4]; //Rite Binary File Identify - unsigned char rbfv[8]; //Rite Binary File Format Version - unsigned char risv[8]; //Rite Instruction Specification Version - unsigned char rct[8]; //Rite Compiler Type - unsigned char rcv[8]; //Rite Compiler Version - unsigned char rbds[4]; //Rite Binary Data Size - unsigned char nirep[2]; //Number of ireps - unsigned char sirep[2]; //Start index - unsigned char rsv[8]; //Reserved -} rite_binary_header; - -// Rite File file_header -typedef struct _rite_file_header { - unsigned char rbfi[4]; //Rite Binary File Identify - unsigned char rbfv[8]; //Rite Binary File Format Version - unsigned char risv[8]; //Rite Instruction Specification Version - unsigned char rct[8]; //Rite Compiler Type - unsigned char rcv[8]; //Rite Compiler Version - unsigned char rbds[8]; //Rite Binary Data Size - unsigned char nirep[4]; //Number of ireps - unsigned char sirep[4]; //Start index - unsigned char rsv[8]; //Reserved - unsigned char hcrc[4]; //HCRC -} rite_file_header; - -static inline int -uint16_to_bin(uint16_t s, char *bin) -{ - *bin++ = (s >> 8) & 0xff; - *bin = s & 0xff; - return (MRB_DUMP_SIZE_OF_SHORT); -} - -static inline int -uint32_to_bin(uint32_t l, char *bin) -{ - *bin++ = (l >> 24) & 0xff; - *bin++ = (l >> 16) & 0xff; - *bin++ = (l >> 8) & 0xff; - *bin = l & 0xff; - return (MRB_DUMP_SIZE_OF_LONG); -} - -static inline uint32_t -bin_to_uint32(unsigned char bin[]) -{ - return (uint32_t)bin[0] << 24 | - (uint32_t)bin[1] << 16 | - (uint32_t)bin[2] << 8 | - (uint32_t)bin[3]; -} - -static inline uint16_t -bin_to_uint16(unsigned char bin[]) -{ - return (uint16_t)bin[0] << 8 | - (uint16_t)bin[1]; -} diff --git a/src/error.c b/src/error.c index e80a24e45..2dbfe0ac2 100644 --- a/src/error.c +++ b/src/error.c @@ -11,7 +11,7 @@ #include <setjmp.h> #include "error.h" #include "opcode.h" -#include "irep.h" +#include "mruby/irep.h" #include "mruby/proc.h" #include "mruby/numeric.h" #include "mruby/variable.h" @@ -11,7 +11,7 @@ #include "mruby/string.h" #include "mruby/hash.h" #include "mruby/range.h" -#include "ritehash.h" +#include "mruby/khash.h" #include <string.h> #include <stdio.h> #include "mruby/struct.h" diff --git a/src/hash.c b/src/hash.c index e96c2e210..bb530ff96 100644 --- a/src/hash.c +++ b/src/hash.c @@ -6,7 +6,7 @@ #include "mruby.h" #include "mruby/hash.h" -#include "ritehash.h" +#include "mruby/khash.h" #include "mruby/class.h" #include "mruby/array.h" #include "error.h" diff --git a/src/irep.h b/src/irep.h deleted file mode 100644 index b3f9e8d87..000000000 --- a/src/irep.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -** irep.h - mrb_irep structure -** -** See Copyright Notice in mruby.h -*/ - -#ifndef MRUBY_IREP_H -#define MRUBY_IREP_H - -typedef struct mrb_irep { - int idx; - - int flags; - int nlocals; - int nregs; - - mrb_code *iseq; - mrb_value *pool; - mrb_sym *syms; - - int ilen, plen, slen; -} mrb_irep; - -#define MRB_IREP_NOFREE 3 -#define MRB_ISEQ_NOFREE 1 - -void mrb_add_irep(mrb_state *mrb, int n); - -#endif /* MRUBY_IREP_H */ diff --git a/src/kernel.c b/src/kernel.c index 0aaa49d95..dce9e249b 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -17,7 +17,7 @@ #include "mruby/class.h" #include "mruby/struct.h" #include "mruby/variable.h" -#include "ritehash.h" +#include "mruby/khash.h" #include "error.h" #include "method.h" diff --git a/src/load.c b/src/load.c index 7a8178621..dfad68622 100644 --- a/src/load.c +++ b/src/load.c @@ -5,13 +5,13 @@ */ #include <string.h> -#include "dump.h" +#include "mruby/dump.h" #include "mruby/string.h" #ifdef INCLUDE_REGEXP #include "re.h" #endif -#include "irep.h" +#include "mruby/irep.h" #ifndef FALSE #define FALSE 0 @@ -7,7 +7,7 @@ #include "mruby.h" #include <string.h> #include "mruby/string.h" -#include "ritehash.h" +#include "mruby/khash.h" #include "encoding.h" #include "re.h" #include "mruby/numeric.h" diff --git a/src/ritehash.h b/src/ritehash.h deleted file mode 100644 index a17db425a..000000000 --- a/src/ritehash.h +++ /dev/null @@ -1,204 +0,0 @@ -/* -** ritehash.c - Rite Hash for mruby -** -** See Copyright Notice in mruby.h -*/ - -#include <stdint.h> -#include <stdlib.h> -#include <string.h> - -typedef uint32_t khint_t; -typedef khint_t khiter_t; - -#define INITIAL_HASH_SIZE 32 -#define UPPER_BOUND(x) ((x)>>2|(x>>1)) - -//extern uint8_t __m[]; - -/* mask for flags */ -static uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; - - -#define __ac_isempty(e_flag, d_flag, i) (e_flag[(i)/8]&__m[(i)%8]) -#define __ac_isdel(e_flag, d_flag, i) (d_flag[(i)/8]&__m[(i)%8]) -#define __ac_iseither(e_flag, d_flag, i) (__ac_isempty(e_flag,d_flag,i)||__ac_isdel(e_flag,d_flag,i)) - - -/* struct kh_xxx - - name: ash name - khkey_t: key data type - khval_t: value data type - kh_is_map: (not implemented / not used in RiteVM ) - __hash_func: hash function - __hash_equal: hash comparation function -*/ -#define KHASH_INIT(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ - typedef struct kh_##name { \ - khint_t n_buckets; \ - khint_t size; \ - khint_t n_occupied; \ - khint_t upper_bound; \ - uint8_t *e_flags; \ - uint8_t *d_flags; \ - khkey_t *keys; \ - khval_t *vals; \ - khint_t mask; \ - khint_t inc; \ - mrb_state *mrb; \ - } kh_##name##_t; \ - static void kh_alloc_##name(kh_##name##_t *h) \ - { \ - khint_t sz = h->n_buckets; \ - h->size = h->n_occupied = 0; \ - h->upper_bound = UPPER_BOUND(sz); \ - h->e_flags = (uint8_t *)mrb_malloc(h->mrb, sizeof(uint8_t)*sz/4); \ - h->d_flags = h->e_flags + sz/8; \ - memset(h->e_flags, 0xff, sz/8*sizeof(uint8_t)); \ - memset(h->d_flags, 0x00, sz/8*sizeof(uint8_t)); \ - h->keys = (khkey_t *)mrb_malloc(h->mrb, sizeof(khkey_t)*sz); \ - h->vals = (khval_t *)mrb_malloc(h->mrb, sizeof(khval_t)*sz); \ - h->mask = sz-1; \ - h->inc = sz/2-1; \ - } \ - static inline kh_##name##_t *kh_init_##name(mrb_state *mrb){ \ - kh_##name##_t *h = (kh_##name##_t*)mrb_calloc(mrb, 1, sizeof(kh_##name##_t)); \ - h->n_buckets = INITIAL_HASH_SIZE; \ - h->mrb = mrb; \ - kh_alloc_##name(h); \ - return h; \ - } \ - static inline void kh_destroy_##name(kh_##name##_t *h) \ - { \ - if( h ){ \ - mrb_free(h->mrb, h->keys); \ - mrb_free(h->mrb, h->vals); \ - mrb_free(h->mrb, h->e_flags); \ - mrb_free(h->mrb, h); \ - } \ - } \ - static inline void kh_clear_##name(kh_##name##_t *h) \ - { \ - if( h && h->e_flags ){ \ - memset(h->e_flags, 0xff, h->n_buckets/8*sizeof(uint8_t)); \ - memset(h->d_flags, 0x00, h->n_buckets/8*sizeof(uint8_t)); \ - h->size = h->n_occupied = 0; \ - } \ - } \ - static inline khint_t kh_get_##name(kh_##name##_t *h, khkey_t key) \ - { \ - khint_t k = __hash_func(h->mrb,key) & (h->mask); \ - while( !__ac_isempty(h->e_flags, h->d_flags, k) ){ \ - if( !__ac_isdel(h->e_flags, h->d_flags, k) ){ \ - if( __hash_equal(h->mrb,h->keys[k], key) ) return k; \ - } \ - k = (k+h->inc) & (h->mask); \ - } \ - return h->n_buckets; \ - } \ - static inline khint_t kh_put_##name(kh_##name##_t *h, khkey_t key); \ - static void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \ - { \ - if( new_n_buckets<INITIAL_HASH_SIZE ){ \ - new_n_buckets = INITIAL_HASH_SIZE; \ - } else { \ - khint_t limit = new_n_buckets; \ - new_n_buckets = INITIAL_HASH_SIZE; \ - while( new_n_buckets < limit ) new_n_buckets *= 2; \ - } \ - uint8_t *old_e_flags = h->e_flags; \ - uint8_t *old_d_flags = h->d_flags; \ - khkey_t *old_keys = h->keys; \ - khval_t *old_vals = h->vals; \ - khint_t old_n_buckets = h->n_buckets; \ - h->n_buckets = new_n_buckets; \ - kh_alloc_##name(h); \ - /* relocate */ \ - khint_t i; \ - for( i=0 ; i<old_n_buckets ; i++ ){ \ - if( !__ac_isempty(old_e_flags, old_d_flags, i) ){ \ - khint_t k = kh_put_##name(h, old_keys[i]); \ - kh_value(h,k) = old_vals[i]; \ - } \ - } \ - } \ - static inline khint_t kh_put_##name(kh_##name##_t *h, khkey_t key) \ - { \ - khint_t k; \ - if( h->n_occupied >= h->upper_bound ){ \ - kh_resize_##name(h, h->n_buckets*2); \ - } \ - k = __hash_func(h->mrb,key) & (h->mask); \ - while( !__ac_iseither(h->e_flags, h->d_flags, k) ){ \ - if( __hash_equal(h->mrb,h->keys[k], key) ) break; \ - k = (k+h->inc) & (h->mask); \ - } \ - if( __ac_isempty(h->e_flags, h->d_flags, k) ) { \ - /* put at empty */ \ - h->keys[k] = key; \ - h->e_flags[k/8] &= ~__m[k%8]; \ - h->size++; \ - h->n_occupied++; \ - } else if( __ac_isdel(h->e_flags, h->d_flags, k) ) { \ - /* put at del */ \ - h->keys[k] = key; \ - h->d_flags[k/8] &= ~__m[k%8]; \ - h->size++; \ - } \ - return k; \ - } \ - static inline void kh_del_##name(kh_##name##_t *h, khint_t x) \ - { \ - h->d_flags[x/8] |= __m[x%8]; \ - h->size--; \ - } \ - static inline void kh_debug_##name(kh_##name##_t *h) \ - { \ - khint_t i; \ - printf("idx:e_flag:d_flag\n"); \ - for( i=0 ; i<h->n_buckets/8 ; i++ ){ \ - printf("%4d:%02X:%02X\n", i, h->e_flags[i], h->d_flags[i]); \ - } \ - } \ - -#define khash_t(name) kh_##name##_t - -#define kh_init(name,mrb) kh_init_##name(mrb) -#define kh_destroy(name, h) kh_destroy_##name(h) -#define kh_clear(name, h) kh_clear_##name(h) -#define kh_resize(name, h, s) kh_resize_##name(h, s) -#define kh_put(name, h, k, r) kh_put_##name(h, k) -#define kh_get(name, h, k) kh_get_##name(h, k) -#define kh_del(name, h, k) kh_del_##name(h, k) -#define kh_debug(name, h) kh_debug_##name(h) - -#define kh_exist(h, x) (!__ac_iseither((h)->e_flags, (h)->d_flags, (x))) -#define kh_key(h, x) ((h)->keys[x]) -#define kh_val(h, x) ((h)->vals[x]) -#define kh_value(h, x) ((h)->vals[x]) -#define kh_begin(h) (khint_t)(0) -#define kh_end(h) ((h)->n_buckets) -#define kh_size(h) ((h)->size) -#define kh_n_buckets(h) ((h)->n_buckets) - -//#define kh_int_hash_func(mrb,key) (uint32_t)(key) -#define kh_int_hash_func(mrb,key) (uint32_t)((key)^((key)<<2)^((key)>>2)) -#define kh_int_hash_equal(mrb,a, b) (a == b) -#define kh_int64_hash_func(mrb,key) (uint32_t)((key)>>33^(key)^(key)<<11) -#define kh_int64_hash_equal(mrb,a, b) (a == b) -static inline khint_t __ac_X31_hash_string(const char *s) -{ - khint_t h = *s; - if (h) for (++s ; *s; ++s) h = (h << 5) - h + *s; - return h; -} -#define kh_str_hash_func(mrb,key) __ac_X31_hash_string(key) -#define kh_str_hash_equal(mrb,a, b) (strcmp(a, b) == 0) - -#define KHASH_MAP_INIT_INT(name, khval_t) \ - KHASH_INIT(name, uint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal) -typedef const char *kh_cstr_t; -#define KHASH_MAP_INIT_STR(name, khval_t) \ - KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal) - diff --git a/src/state.c b/src/state.c index 913c186e4..f705060e8 100644 --- a/src/state.c +++ b/src/state.c @@ -5,7 +5,7 @@ */ #include "mruby.h" -#include "irep.h" +#include "mruby/irep.h" #include <string.h> void mrb_init_heap(mrb_state*); diff --git a/src/symbol.c b/src/symbol.c index 679b3c35a..14721e0a2 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -5,7 +5,7 @@ */ #include "mruby.h" -#include "ritehash.h" +#include "mruby/khash.h" #include <string.h> #include <stdarg.h> diff --git a/src/variable.c b/src/variable.c index f5506d779..a9f04538b 100644 --- a/src/variable.c +++ b/src/variable.c @@ -7,7 +7,7 @@ #include <stdio.h> #include "mruby.h" #include "mruby/class.h" -#include "ritehash.h" +#include "mruby/khash.h" #include "mruby/variable.h" #include "mruby/string.h" #include "mruby/range.h" @@ -6,7 +6,7 @@ #include "mruby.h" #include "opcode.h" -#include "irep.h" +#include "mruby/irep.h" #include "mruby/variable.h" #include "mruby/proc.h" #include "mruby/array.h" |
