Ejemplo n.º 1
0
static void
features_index_add_single(const char* str, size_t len, VALUE offset)
{
    struct st_table *features_index;
    VALUE this_feature_index = Qnil;
    st_data_t short_feature_key;

    Check_Type(offset, T_FIXNUM);
    short_feature_key = feature_key(str, len);

    features_index = get_loaded_features_index_raw();
    st_lookup(features_index, short_feature_key, (st_data_t *)&this_feature_index);

    if (NIL_P(this_feature_index)) {
	st_insert(features_index, short_feature_key, (st_data_t)offset);
    }
    else if (RB_TYPE_P(this_feature_index, T_FIXNUM)) {
	VALUE feature_indexes[2];
	feature_indexes[0] = this_feature_index;
	feature_indexes[1] = offset;
	this_feature_index = (VALUE)xcalloc(1, sizeof(struct RArray));
	RBASIC(this_feature_index)->flags = T_ARRAY; /* fake VALUE, do not mark/sweep */
	rb_ary_cat(this_feature_index, feature_indexes, numberof(feature_indexes));
	st_insert(features_index, short_feature_key, (st_data_t)this_feature_index);
    }
    else {
	Check_Type(this_feature_index, T_ARRAY);
	rb_ary_push(this_feature_index, offset);
    }
}
Ejemplo n.º 2
0
int
avro_schema_record_field_append(const avro_schema_t record_schema,
				const char *field_name,
				const avro_schema_t field_schema)
{
	check_param(EINVAL, is_avro_schema(record_schema), "record schema");
	check_param(EINVAL, is_avro_record(record_schema), "record schema");
	check_param(EINVAL, field_name, "field name");
	check_param(EINVAL, is_avro_schema(field_schema), "field schema");

	if (!is_avro_id(field_name)) {
		avro_set_error("Invalid Avro identifier");
		return EINVAL;
	}

	if (record_schema == field_schema) {
		avro_set_error("Cannot create a circular schema");
		return EINVAL;
	}

	struct avro_record_schema_t *record = avro_schema_to_record(record_schema);
	struct avro_record_field_t *new_field = (struct avro_record_field_t *) avro_new(struct avro_record_field_t);
	if (!new_field) {
		avro_set_error("Cannot allocate new record field");
		return ENOMEM;
	}
	new_field->index = record->fields->num_entries;
	new_field->name = avro_strdup(field_name);
	new_field->type = avro_schema_incref(field_schema);
	st_insert(record->fields, record->fields->num_entries,
		  (st_data_t) new_field);
	st_insert(record->fields_byname, (st_data_t) new_field->name,
		  (st_data_t) new_field);
	return 0;
}
Ejemplo n.º 3
0
void initSymTab(void)
{
	st_insert("integer", "integer", -1, -1);
	st_insert("boolean", "boolean", -1, -1);
	st_insert("string", "string", -1, -1);
	st_insert("real", "real", -1, -1);
}
Ejemplo n.º 4
0
static void
features_index_add_single(VALUE short_feature, VALUE offset)
{
    struct st_table *features_index;
    VALUE this_feature_index = Qnil;
    char *short_feature_cstr;

    Check_Type(offset, T_FIXNUM);
    Check_Type(short_feature, T_STRING);
    short_feature_cstr = StringValueCStr(short_feature);

    features_index = get_loaded_features_index_raw();
    st_lookup(features_index, (st_data_t)short_feature_cstr, (st_data_t *)&this_feature_index);

    if (NIL_P(this_feature_index)) {
	st_insert(features_index, (st_data_t)ruby_strdup(short_feature_cstr), (st_data_t)offset);
    }
    else if (RB_TYPE_P(this_feature_index, T_FIXNUM)) {
	VALUE feature_indexes[2];
	feature_indexes[0] = this_feature_index;
	feature_indexes[1] = offset;
	this_feature_index = (VALUE)xcalloc(1, sizeof(struct RArray));
	RBASIC(this_feature_index)->flags = T_ARRAY; /* fake VALUE, do not mark/sweep */
	rb_ary_cat(this_feature_index, feature_indexes, numberof(feature_indexes));
	st_insert(features_index, (st_data_t)short_feature_cstr, (st_data_t)this_feature_index);
    }
    else {
	Check_Type(this_feature_index, T_ARRAY);
	rb_ary_push(this_feature_index, offset);
    }
}
Ejemplo n.º 5
0
static char *
load_lock(const char *ftptr)
{
    st_data_t data;
    st_table *loading_tbl = get_loading_table();

    if (!st_lookup(loading_tbl, (st_data_t)ftptr, &data)) {
	/* partial state */
	ftptr = ruby_strdup(ftptr);
	data = (st_data_t)rb_thread_shield_new();
	st_insert(loading_tbl, (st_data_t)ftptr, data);
	return (char *)ftptr;
    }
    else if (RB_TYPE_P((VALUE)data, T_IMEMO) && imemo_type((VALUE)data) == imemo_memo) {
	struct MEMO *memo = MEMO_CAST(data);
	void (*init)(void) = (void (*)(void))memo->u3.func;
	data = (st_data_t)rb_thread_shield_new();
	st_insert(loading_tbl, (st_data_t)ftptr, data);
	(*init)();
	return (char *)"";
    }
    if (RTEST(ruby_verbose)) {
	rb_warning("loading in progress, circular require considered harmful - %s", ftptr);
	rb_backtrace_print_to(rb_stderr);
    }
    switch (rb_thread_shield_wait((VALUE)data)) {
      case Qfalse:
	data = (st_data_t)ftptr;
	st_insert(loading_tbl, data, (st_data_t)rb_thread_shield_new());
	return 0;
      case Qnil:
	return 0;
    }
    return (char *)ftptr;
}
Ejemplo n.º 6
0
/* Procedure insertNode inserts 
 * identifiers stored in t into 
 * the symbol table 
 */
static void insertNode( TreeNode * t)
{ switch (t->nodekind)
    {
    case ExpK:
      switch (t->kind.exp)
	{ case IdK:
	    if (st_lookup(t->attr.name) == -1)
	      printf("Id wasn't declared.\n");
	    else
	      st_insert(t, 0, 0);
	    break;
	default:
	  break;
	}
      break;
    case DeclK:
      if (t->array_size >= 0) { // if variable is not void
	if (st_advanced_lookup(t->attr.name, t->scope) == -1) {
	  st_insert(t, location++, 1);
	} else {
	  printf("Declation Error %s\n",t->attr.name); location--;
	}
      }
      break;
    default:
      break;
    }
}
Ejemplo n.º 7
0
void
avro_memoize_set(avro_memoize_t *mem,
		 void *key1, void *key2,
		 void *result)
{
	/*
	 * First see if there's already a cached value for this key.  If
	 * so, we don't want to allocate a new avro_memoize_key_t
	 * instance.
	 */

	avro_memoize_key_t  key;
	key.key1 = key1;
	key.key2 = key2;

	union {
		st_data_t  data;
		void  *value;
	} val;

	if (st_lookup(mem->cache, (st_data_t) &key, &val.data)) {
		st_insert(mem->cache, (st_data_t) &key, (st_data_t) result);
		return;
	}

	/*
	 * If it's a new key pair, then we do need to allocate.
	 */

	avro_memoize_key_t  *real_key = avro_new(avro_memoize_key_t);
	real_key->key1 = key1;
	real_key->key2 = key2;

	st_insert(mem->cache, (st_data_t) real_key, (st_data_t) result);
}
Ejemplo n.º 8
0
VALUE st_spec_st_foreach(VALUE self) {
  int total = 0;
  st_table *tbl = st_init_numtable_with_size(128);
  st_insert(tbl, 1, 3);
  st_insert(tbl, 2, 4);
  st_foreach(tbl, sum, (st_data_t)&total);
  st_free_table(tbl);
  return INT2FIX(total);
}
Ejemplo n.º 9
0
VALUE st_spec_st_lookup(VALUE self) {
  st_data_t result = (st_data_t)0;
  st_table *tbl = st_init_numtable_with_size(128);
  st_insert(tbl, 7, 42);
  st_insert(tbl, 2, 4);
  st_lookup(tbl, (st_data_t)7, &result);
  st_free_table(tbl);
#if SIZEOF_LONG == SIZEOF_VOIDP
  return ULONG2NUM(result);
#else
  return ULL2NUM(result);
#endif
}
Ejemplo n.º 10
0
NODE(sl_node_def_t, def)
{
    sl_vm_insn_t insn;
    sl_compile_state_t sub_cs;
    size_t i, on_reg;
    init_compile_state(&sub_cs, cs->vm, cs, node->req_arg_count + node->opt_arg_count + 1);
    for(i = 0; i < node->req_arg_count; i++) {
        st_insert(sub_cs.vars, (st_data_t)node->req_args[i], (st_data_t)(i + 1));
    }
    for(i = 0; i < node->opt_arg_count; i++) {
        st_insert(sub_cs.vars, (st_data_t)node->opt_args[i].name, (st_data_t)(node->req_arg_count + i + 1));
    }
    sub_cs.section->name = node->name;
    sub_cs.section->req_registers = node->req_arg_count;
    sub_cs.section->arg_registers = node->req_arg_count + node->opt_arg_count;
    sub_cs.section->opt_skip = sl_alloc(cs->vm->arena, sizeof(size_t) * (node->opt_arg_count + 1));
    
    for(i = 0; i < node->opt_arg_count; i++) {
        sub_cs.section->opt_skip[i] = sub_cs.section->insns_count;
        compile_node(&sub_cs, node->opt_args[i].default_value, node->req_arg_count + i + 1);
    }
    sub_cs.section->opt_skip[node->opt_arg_count] = sub_cs.section->insns_count;
    
    compile_node(&sub_cs, node->body, 0);
    insn.opcode = SL_OP_RETURN;
    emit(&sub_cs, insn);
    insn.uint = 0;
    emit(&sub_cs, insn);
    
    if(node->on) {
        on_reg = reg_alloc(cs);
        compile_node(cs, node->on, on_reg);
        insn.opcode = SL_OP_DEFINE_ON;
        emit(cs, insn);
        insn.uint = on_reg;
        emit(cs, insn);
        reg_free(cs, on_reg);
    } else {
        insn.opcode = SL_OP_DEFINE;
        emit(cs, insn);
    }
    insn.imm = node->name;
    emit(cs, insn);
    insn.section = sub_cs.section;
    emit(cs, insn);
    insn.uint = dest;
    emit(cs, insn);
}
Ejemplo n.º 11
0
static int _reverse_merge_func(VALUE k, VALUE v, VALUE self_st) {
  st_table* t = (st_table*)self_st;
  if (!st_is_member(t, k)) {
    st_insert(t, (st_data_t)k, (st_data_t)v);
  }
  return ST_CONTINUE;
}
Ejemplo n.º 12
0
NODE(sl_node_lambda_t, lambda)
{
    sl_vm_insn_t insn;
    sl_compile_state_t sub_cs;
    size_t i;
    init_compile_state(&sub_cs, cs->vm, cs, node->arg_count + 1);
    for(i = 0; i < node->arg_count; i++) {
        st_insert(sub_cs.vars, (st_data_t)node->args[i], (st_data_t)(i + 1));
    }
    sub_cs.section->req_registers = node->arg_count;
    sub_cs.section->arg_registers = node->arg_count;
    sub_cs.section->name = sl_make_cstring(cs->vm, "<lambda>");
    compile_node(&sub_cs, node->body, 0);
    insn.opcode = SL_OP_RETURN;
    emit(&sub_cs, insn);
    insn.uint = 0;
    emit(&sub_cs, insn);
    
    insn.opcode = SL_OP_LAMBDA;
    emit(cs, insn);
    insn.section = sub_cs.section;
    emit(cs, insn);
    insn.uint = dest;
    emit(cs, insn);
}
Ejemplo n.º 13
0
int main(void)
{
    size_t max = 100;
    size_t n = 20;
    char buf[strsiz];
    size_t i;
    st_t st = st_init(max);

    for (i = 0; i < n; i++) {
        item_t t = newitem(randkey(), randstr(buf, strsiz));
        st_insert(st, t);
    }

    st_sort(st, print);
    printf("\nThe item with key 11 is: ");
    print(st_search(st, 11));
    printf("\nThe 4th smallest key is: ");
    print(st_select(st, 4));
    st_delete(st, st_search(st, 11));
    printf("\n delete the item with key 11.\n");
    st_sort(st, print);

    /* delete all item */
    while (!st_empty(st)) {
        item_t x = st_select(st, 0);
        printf("delete item: ");
        print(x);
        st_delete(st, st_select(st, 0));
    }

    st_finalize(&st);
    return 0;
}
Ejemplo n.º 14
0
static int
clone_method(ID mid, NODE *body, VALUE nklass)
{
    NODE *fbody = body->nd_body;

    if (fbody) {
	VALUE nbody;

	switch (nd_type(fbody)) {
	  case NODE_SCOPE:
	    fbody = rb_copy_node_scope(fbody, ruby_cref);
    	    break;
	  case NODE_BMETHOD:
	    nbody = rb_block_dup(fbody->nd_cval, nklass, (VALUE)ruby_cref);
	    fbody = NEW_BMETHOD(nbody);
	    break;
	  case NODE_DMETHOD:
	    nbody = rb_method_dup(fbody->nd_cval, nklass, (VALUE)ruby_cref);
	    fbody = NEW_DMETHOD(nbody);
	    break;
	}
    }
    st_insert(RCLASS(nklass)->m_tbl, mid, (st_data_t)NEW_METHOD(fbody, body->nd_noex));
    return ST_CONTINUE;
}
Ejemplo n.º 15
0
/**Function********************************************************************

  Synopsis    [Check that minterm counts have not changed.]

  Description [Counts the minterms in the global functions of the
  primary outputs of the network passed as argument.
  When it is calld with the second argument set to NULL, it allocates
  a symbol table and stores, for each output, the minterm count. If
  an output does not have a BDD, it stores a NULL pointer for it.
  If it is called with a non-null second argument, it assumes that
  the symbol table contains the minterm counts measured previously
  and it compares the new counts to the old ones. Finally, it frees
  the symbol table.
  check_minterms is designed so that it can be called twice: once before
  reordering, and once after reordering.
  Returns a pointer to the symbol table on the first invocation and NULL
  on the second invocation.]

  SideEffects [None]

  SeeAlso     []

******************************************************************************/
st_table *
checkMinterms(
  BnetNetwork * net,
  DdManager * dd,
  st_table * previous)
{
    BnetNode *po;
    int numPi;
    char *name;
    double *count, newcount, *oldcount;
    int flag,err,i;

    numPi = net->ninputs;

    if (previous == NULL) {
	previous = st_init_table(strcmp,st_strhash);
	if (previous == NULL) {
	    (void) printf("checkMinterms out-of-memory\n");
	    return(NULL);
	}
	for (i = 0; i < net->noutputs; i++) {
	    if (!st_lookup(net->hash,net->outputs[i],&po)) {
		exit(2);
	    }
	    name = net->outputs[i];
	    if (po->dd != NULL) {
		count = ALLOC(double,1);
		*count = Cudd_CountMinterm(dd,po->dd,numPi);
		err = st_insert(previous, name, (char *) count);
	    } else {
Ejemplo n.º 16
0
symbol_table * create_symbol_table(){
	char * lib_functions[] = {
					"print","input","objectmemberkeys","objecttotalmembers",
				  	"objectcopy","totalarguments","argument","typeof","strtonum",
				  	"sqrt","cos","sin" };
	
	unsigned int i;
	st_entry * symbol;
	symbol_table * st = (symbol_table *)malloc(sizeof(symbol_table));
	if(memerror(st,"symbol table"))
		return NULL;

	for(i=0;i<BUCKET_SIZE;i++)
		st->hash_table[i] = NULL;
	st->scope_list = NULL;

	// We add all the library functions from the beginning in the symbol table.
	for(i=0;i<12;i++){
		symbol = create_symbol(lib_functions[i],1,0,0,LIBFUNC,0,0);
		if(memerror(symbol,"initalize lib func")){
			free(st);
			return NULL;
		}
		st_insert(&st,&symbol);
	}

	return st;
}
Ejemplo n.º 17
0
static struct cov_array * coverage_increase_counter_uncached(char *sourcefile, unsigned int sourceline, char mark_only) {
  struct cov_array *carray = NULL;
 
  if(sourcefile == NULL) {
    /* "can't happen", just ignore and avoid segfault */
    return NULL;
  } 
  else if(!st_lookup(coverinfo, (st_data_t)sourcefile, (st_data_t*)&carray)) {
    VALUE arr;
    
    arr = rb_hash_aref(oSCRIPT_LINES__, rb_str_new2(sourcefile));
    if(NIL_P(arr)) 
      return 0;
    rb_check_type(arr, T_ARRAY);
    carray = calloc(1, sizeof(struct cov_array));
    carray->ptr = calloc(RARRAY(arr)->len, sizeof(unsigned int));
    carray->len = RARRAY(arr)->len;
    st_insert(coverinfo, (st_data_t)strdup(sourcefile), (st_data_t) carray);
  } 
  else {
    /* recovered carray, sanity check */
    assert(carray && "failed to create valid carray");
  }

  if(mark_only) {
    if(!carray->ptr[sourceline])
      carray->ptr[sourceline] = 1;
  } else {
    if (carray && carray->len > sourceline) {
      carray->ptr[sourceline]++;
    }
  }

  return carray;
}
Ejemplo n.º 18
0
Archivo: encoding.c Proyecto: 217/ruby
static int
enc_set_default_encoding(struct default_encoding *def, VALUE encoding, const char *name)
{
    int overridden = FALSE;

    if (def->index != -2)
	/* Already set */
	overridden = TRUE;

    if (NIL_P(encoding)) {
	def->index = -1;
	def->enc = 0;
	st_insert(enc_table.names, (st_data_t)strdup(name),
		  (st_data_t)UNSPECIFIED_ENCODING);
    }
    else {
	def->index = rb_enc_to_index(rb_to_encoding(encoding));
	def->enc = 0;
	enc_alias_internal(name, def->index);
    }

    if (def == &default_external)
	enc_set_filesystem_encoding();

    return overridden;
}
Ejemplo n.º 19
0
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
st_table * Map_CreateTableGate2Super( Map_Man_t * pMan )
{
    Map_Super_t * pSuper;
    st_table * tTable;
    int i, nInputs, v;
    tTable = st_init_table(strcmp, st_strhash);
    for ( i = 0; i < pMan->pSuperLib->nSupersAll; i++ )
    {
        pSuper = pMan->pSuperLib->ppSupers[i];
        if ( pSuper->nGates == 1 )
        {
            // skip different versions of the same root gate
            nInputs = Mio_GateReadInputs(pSuper->pRoot);
            for ( v = 0; v < nInputs; v++ )
                if ( pSuper->pFanins[v]->Num != nInputs - 1 - v )
                    break;
            if ( v != nInputs )
                continue;
//            printf( "%s\n", Mio_GateReadName(pSuper->pRoot) );
            if ( st_insert( tTable, (char *)pSuper->pRoot, (char *)pSuper ) )
            {
                assert( 0 );
            }
        }
    }
    return tTable;
}
Ejemplo n.º 20
0
static VALUE
find_class_path(VALUE klass)
{
    struct fc_result arg;

    arg.name = 0;
    arg.path = 0;
    arg.klass = klass;
    arg.track = rb_cObject;
    arg.prev = 0;
    if (RCLASS_CONST_TBL(rb_cObject)) {
	st_foreach_safe(RCLASS_CONST_TBL(rb_cObject), fc_i, (st_data_t)&arg);
    }
    if (arg.path == 0) {
	st_foreach_safe(rb_class_tbl, fc_i, (st_data_t)&arg);
    }
    if (arg.path) {
	st_data_t tmp = tmp_classpath;
	if (!RCLASS_IV_TBL(klass)) {
	    RCLASS_IV_TBL(klass) = st_init_numtable();
	}
	st_insert(RCLASS_IV_TBL(klass), (st_data_t)classpath, arg.path);
	st_delete(RCLASS_IV_TBL(klass), &tmp, 0);
	return arg.path;
    }
    return Qnil;
}
Ejemplo n.º 21
0
static VALUE
classname(VALUE klass)
{
    VALUE path = Qnil;
    st_data_t n;

    if (!klass) klass = rb_cObject;
    if (RCLASS_IV_TBL(klass)) {
	if (!st_lookup(RCLASS_IV_TBL(klass), (st_data_t)classpath, &n)) {
	    if (!st_lookup(RCLASS_IV_TBL(klass), (st_data_t)classid, &n)) {
		return find_class_path(klass);
	    }
	    path = rb_str_dup(rb_id2str(SYM2ID((VALUE)n)));
	    OBJ_FREEZE(path);
	    st_insert(RCLASS_IV_TBL(klass), (st_data_t)classpath, (st_data_t)path);
	    n = classid;
	    st_delete(RCLASS_IV_TBL(klass), &n, 0);
	}
	else {
	    path = (VALUE)n;
	}
	if (TYPE(path) != T_STRING) {
	    rb_bug("class path is not set properly");
	}
	return path;
    }
    return find_class_path(klass);
}
Ejemplo n.º 22
0
static VALUE
newobj_tramp()
{
  VALUE ret = rb_newobj();
  struct obj_track *tracker = NULL;

  if (track_objs) {
    tracker = malloc(sizeof(*tracker));

    if (tracker) {
      if (ruby_current_node && ruby_current_node->nd_file && *ruby_current_node->nd_file) {
        tracker->source = strdup(ruby_current_node->nd_file);
        tracker->line = nd_line(ruby_current_node);
      } else if (ruby_sourcefile) {
        tracker->source = strdup(ruby_sourcefile);
        tracker->line = ruby_sourceline;
      } else {
        tracker->source = strdup("__null__");
        tracker->line = 0;
      }

      tracker->obj = ret;
      st_insert(objs, (st_data_t)ret, (st_data_t)tracker);
    } else {
      fprintf(stderr, "Warning, unable to allocate a tracker. You are running dangerously low on RAM!\n");
    }
  }

  return ret;
}
Ejemplo n.º 23
0
static void
link_undef(const char *name, long base, struct relocation_info *reloc)
{
    static int u_no = 0;
    struct undef *obj;
    char *addr = (char*)(reloc->r_address + base);

    obj = (struct undef*)xmalloc(sizeof(struct undef));
    obj->name = strdup(name);
    obj->reloc = *reloc;
    obj->base = base;
    switch (R_LENGTH(reloc)) {
      case 0:		/* byte */
	obj->u.c = *addr;
	break;
      case 1:		/* word */
	obj->u.s = *(short*)addr;
	break;
      case 2:		/* long */
	obj->u.l = *(long*)addr;
	break;
    }
    if (reloc_tbl == NULL) {
	reloc_tbl = st_init_numtable();
    }
    st_insert(reloc_tbl, u_no++, obj);
}
Ejemplo n.º 24
0
int referInsert(TreeNode *t, ErrorObj errObj)
{
	if (st_lookup(t->attr.name) == -1)
	{
		/* not yet in table, variable using without definition error */
		switch(errObj)
		{
		case TYPE:
			typeError(t, "Type not defined");
			break;

		case VAR:
			typeError(t, "Variable not defined");
			break;

		case FUNC:
			typeError(t, "Function not defined");
			break;

		default:
			typeError(t, "Unknown not defined error");
			break;
		}

		return -1;
	}
	else
	{
		/* already in table, so ignore location, 
		add line number of use only */ 
		st_insert(t->attr.name, NULL, t->lineno, 0);

		return 0;
	}
}
Ejemplo n.º 25
0
Archivo: encoding.c Proyecto: 217/ruby
static const char *
enc_alias_internal(const char *alias, int idx)
{
    alias = strdup(alias);
    st_insert(enc_table.names, (st_data_t)alias, (st_data_t)idx);
    return alias;
}
Ejemplo n.º 26
0
Archivo: encoding.c Proyecto: 217/ruby
static int
enc_register_at(int index, const char *name, rb_encoding *encoding)
{
    struct rb_encoding_entry *ent = &enc_table.list[index];
    VALUE list;

    if (!valid_encoding_name_p(name)) return -1;
    if (!ent->name) {
	ent->name = name = strdup(name);
    }
    else if (STRCASECMP(name, ent->name)) {
	return -1;
    }
    if (!ent->enc) {
	ent->enc = xmalloc(sizeof(rb_encoding));
    }
    if (encoding) {
	*ent->enc = *encoding;
    }
    else {
	memset(ent->enc, 0, sizeof(*ent->enc));
    }
    encoding = ent->enc;
    encoding->name = name;
    encoding->ruby_encoding_index = index;
    st_insert(enc_table.names, (st_data_t)name, (st_data_t)index);
    list = rb_encoding_list;
    if (list && NIL_P(rb_ary_entry(list, index))) {
	/* initialize encoding data */
	rb_ary_store(list, index, enc_new(encoding));
    }
    return index;
}
Ejemplo n.º 27
0
DmNode* dm_create_func_def_node(char* func_name, DmNode* param_list, DmNode* stmt_list, 
      DM_USHORT lineno)
{
   _GLOBAL_TBL_ASSERT_;
   DM_ULONG func_id;
   DmNode* func_node;
   if (st_lookup(g_name_id_tbl, func_name, (char**)&func_id)) {
      //TODO
      printf("function redefined:%s\n", func_name);
      abort();
   }
   else {
      DmNodeList* node_list = DM_MALLOC(sizeof(DmNodeList));
      int bin_num = 2;
      node_list->bin_num = bin_num;
      node_list->node_bin = DM_CALLOC(bin_num, sizeof(DmNode*));
      node_list->m_nd_func_param_list = param_list;
      node_list->m_nd_func_stmt_list = stmt_list;
      func_node = dm_create_node(nd_func_def, lineno);
      func_node->m_nd_func_name = func_name;
      func_node->m_nd_func_body = node_list;
      st_insert(g_name_id_tbl, func_name, (char*)func_node);
      /*st_insert(g_str_val_tbl, (char*)func_node, func_name);*/
   }

   return func_node; 
}
Ejemplo n.º 28
0
static void insertIOFunc(void)
{   TreeNode *func;
    TreeNode *typeSpec;
    TreeNode *param;
    TreeNode *compStmt;

    func = newDeclNode(FuncK);

    typeSpec = newTypeNode(FuncK);
    typeSpec->attr.type = INT;
    func->type = Integer;

    compStmt = newStmtNode(CompK);
    compStmt->child[0] = NULL;      // no local var
    compStmt->child[1] = NULL;      // no stmt

    func->lineno = 0;
    func->attr.name = "input";
    func->child[0] = typeSpec;
    func->child[1] = NULL;          // no param
    func->child[2] = compStmt;

    st_insert("input", -1, addLocation(), func);

    func = newDeclNode(FuncK);

    typeSpec = newTypeNode(FuncK);
    typeSpec->attr.type = VOID;
    func->type = Void;

    param = newParamNode(NonArrParamK);
    param->attr.name = "arg";
    param->child[0] = newTypeNode(FuncK);
    param->child[0]->attr.type = INT;

    compStmt = newStmtNode(CompK);
    compStmt->child[0] = NULL;      // no local var
    compStmt->child[1] = NULL;      // no stmt

    func->lineno = 0;
    func->attr.name = "output";
    func->child[0] = typeSpec;
    func->child[1] = param;
    func->child[2] = compStmt;

    st_insert("output", -1, addLocation(), func);
}
Ejemplo n.º 29
0
/**Function********************************************************************

  Synopsis    [Annotates every node in the BDD node with its minterm count.]

  Description [Annotates every node in the BDD node with its minterm count.
  In this function, every node and the minterm count represented by it are
  stored in a hash table.]

  SideEffects [Fills up 'table' with the pair <node,minterm_count>.]

******************************************************************************/
static double
bddAnnotateMintermCount(
  DdManager * manager,
  DdNode * node,
  double  max,
  st_table * table)
{

    DdNode *N,*Nv,*Nnv;
    register double min_v,min_nv;
    register double min_N;
    double *pmin;
    double *dummy;

    statLine(manager);
    N = Cudd_Regular(node);
    if (cuddIsConstant(N)) {
	if (node == DD_ONE(manager)) {
	    return(max);
	} else {
	    return(0.0);
	}
    }

    if (st_lookup(table, node, &dummy)) {
	return(*dummy);
    }	
  
    Nv = cuddT(N);
    Nnv = cuddE(N);
    if (N != node) {
	Nv = Cudd_Not(Nv);
	Nnv = Cudd_Not(Nnv);
    }

    /* Recur on the two branches. */
    min_v  = bddAnnotateMintermCount(manager,Nv,max,table) / 2.0;
    if (min_v == (double)CUDD_OUT_OF_MEM)
	return ((double)CUDD_OUT_OF_MEM);
    min_nv = bddAnnotateMintermCount(manager,Nnv,max,table) / 2.0;
    if (min_nv == (double)CUDD_OUT_OF_MEM)
	return ((double)CUDD_OUT_OF_MEM);
    min_N  = min_v + min_nv;

    pmin = ALLOC(double,1);
    if (pmin == NULL) {
	manager->errorCode = CUDD_MEMORY_OUT;
	return((double)CUDD_OUT_OF_MEM);
    }
    *pmin = min_N;

    if (st_insert(table,(char *)node, (char *)pmin) == ST_OUT_OF_MEM) {
	FREE(pmin);
	return((double)CUDD_OUT_OF_MEM);
    }
    
    return(min_N);

} /* end of bddAnnotateMintermCount */
Ejemplo n.º 30
0
int
avro_schema_union_append(const avro_schema_t union_schema,
			 const avro_schema_t schema)
{
	check_param(EINVAL, is_avro_schema(union_schema), "union schema");
	check_param(EINVAL, is_avro_union(union_schema), "union schema");
	check_param(EINVAL, is_avro_schema(schema), "schema");

	struct avro_union_schema_t *unionp = avro_schema_to_union(union_schema);
	int  new_index = unionp->branches->num_entries;
	st_insert(unionp->branches, new_index, (st_data_t) schema);
	const char *name = avro_schema_type_name(schema);
	st_insert(unionp->branches_byname, (st_data_t) name,
		  (st_data_t) new_index);
	avro_schema_incref(schema);
	return 0;
}