Esempio n. 1
0
void native_thread_invoke(u08_t mref) {	
	heap_id_t method_h,thread_h;
	u16_t method_id,thread_id;		
	if(mref == NATIVE_METHOD_THREAD_RUNNABLE)
	{
//		nvm_method_hdr_t mhdr, *mhdr_ptr;
		method_h = stack_pop();
		thread_h = stack_pop();
		
		method_id = ((nvm_ref_t*)heap_get_addr(method_h))[0];
		thread_id = ((nvm_ref_t*)heap_get_addr(thread_h))[0];
		Task_init(&SubThread[thread_id],vm_run, (void*)(method_id&0xFF), CONFIG_MAX_PRIORITY - 1, SubThread_stack[thread_id], sizeof(SubThread_stack[thread_id]));
				
//		mhdr_ptr = nvmfile_get_method_hdr(method_id&0xFF);	
		// load new method header into ram
//		nvmfile_read(&mhdr, mhdr_ptr, sizeof(nvm_method_hdr_t));
//		heap_steal(sizeof(nvm_stack_t) * (mhdr.max_locals + mhdr.max_stack + mhdr.args));
//		Task_setjsp(mhdr.
		//stack_push(NVM_TYPE_HEAP | thread_h);
	}
	else if(mref == NATIVE_METHOD_THREAD_START) {
		thread_h = stack_pop();		
		thread_id = ((nvm_ref_t*)heap_get_addr(thread_h))[0];
		SubThread[thread_id].j_sp = (unsigned int*)&heap[heap_base];
		SubThread[thread_id].j_stack = (unsigned int*)&heap[heap_base];
		Task_start(&SubThread[thread_id]);
		//Task_yield();
	}
}
Esempio n. 2
0
nvm_int_t array_length(heap_id_t id) {
  DEBUGF("arraylength %d = %d/%d\n", id, 
	 heap_get_len(id),
	 array_typelen(*(u08_t*)heap_get_addr(id)));

  return(heap_get_len(id)/
	 array_typelen(*(u08_t*)heap_get_addr(id)));
}
Esempio n. 3
0
void native_formatter_invoke(uint8_t mref) {
  char * fmt = stack_peek_addr(0);
  char res[50];
  
  formatDescr fmtdscr;
  make_format_descr(&fmtdscr, fmt);

  int len = 0;
  if(mref == NATIVE_METHOD_formatI) {
    nvm_int_t val = stack_peek_int(1);
    len = format_int(res, &fmtdscr, val);
  } else if(mref == NATIVE_METHOD_formatZ) {
    nvm_int_t val = stack_peek_int(1);
    len = format_bool(res, &fmtdscr, val);
  } else if(mref == NATIVE_METHOD_formatF) {
    nvm_float_t val = stack_peek_float(1);
    len = format_float(res, &fmtdscr, val);
  } else
    error(ERROR_NATIVE_UNKNOWN_METHOD);
    

  uint8_t add = 0;
  if (fmtdscr.width>len)
    add = (fmtdscr.width-len);
    
  // allocate heap and realign strings (address may be changed by gc...)
  heap_id_t id = heap_alloc(FALSE, len + add + fmtdscr.pre_len + fmtdscr.post_len + 1);
  int memoffset = (char*)stack_peek_addr(0)-(char*)fmt;
  fmt+=memoffset;
  fmtdscr.post+=memoffset;
  char * dst = heap_get_addr(id);
  
  // build result string
  native_strncpy(dst, fmt, fmtdscr.pre_len);
  dst+=fmtdscr.pre_len;

  if (!(fmtdscr.flags&0x01)){
    while(add--)
      *dst++=' ';
  }

  native_strncpy(dst, res, len);
  dst+=len;
  
  if (fmtdscr.flags&0x01){
    while(add--)
      *dst++=' ';
  }
  native_strncpy(dst, fmtdscr.post, fmtdscr.post_len);
  dst+=fmtdscr.post_len;
  *dst=0;
  stack_pop();
  stack_pop();
  stack_push(NVM_TYPE_HEAP | id);
}
Esempio n. 4
0
heap_id_t array_new(nvm_int_t length, u08_t type) {
	heap_id_t id;
  DEBUGF("newarray type %d len = %d: ", type, length);
  DEBUGF("total size = %d bytes\n", length * array_typelen(type));

  id = heap_alloc(FALSE, 1 + length * array_typelen(type));

  // store type in first byte
  *(u08_t*)(heap_get_addr(id)) = type;

  return id;
}
Esempio n. 5
0
uint8_t wkpf_load_component_to_wuobject_map(heap_id_t map_heap_id) {
  uint16_t number_of_entries = array_length(map_heap_id)/sizeof(remote_endpoint);
  remote_endpoint *map = (remote_endpoint *)((uint8_t *)heap_get_addr(map_heap_id)+1); // +1 to skip type byte

  DEBUGF_WKPF("WKPF: Registering %x components (%x bytes, %x each)\n\n", number_of_entries, array_length(map_heap_id), sizeof(remote_endpoint));

  if (number_of_entries>MAX_NUMBER_OF_COMPONENTS)
    return WKPF_ERR_OUT_OF_MEMORY;
  for(int i=0; i<number_of_entries; i++) {
    component_to_wuobject_map[i] = map[i];
    DEBUGF_WKPF("WKPF: Registered component wuobject: component %x -> (node %x, port %x)\n", i, component_to_wuobject_map[i].node_id, component_to_wuobject_map[i].port_number);
  }
  number_of_components = number_of_entries;
  return WKPF_OK;
}
Esempio n. 6
0
uint8_t wkpf_load_links(heap_id_t links_heap_id) {
  uint16_t number_of_entries = array_length(links_heap_id)/sizeof(link_entry);
  link_entry *links_p = (link_entry *)((uint8_t *)heap_get_addr(links_heap_id)+1); // +1 to skip type byte

  DEBUGF_WKPF("WKPF: Registering %x links (%x bytes, %x each)\n\n", number_of_entries, array_length(links_heap_id), sizeof(link_entry));
  
  if (number_of_entries>MAX_NUMBER_OF_LINKS)
    return WKPF_ERR_OUT_OF_MEMORY;
  for(int i=0; i<number_of_entries; i++) {
    links[i] = links_p[i];
    DEBUGF_WKPF("WKPF: Registered link: (component %x, property %x) -> (component %x, property %x, wuclass %x)\n",
                links[i].src_component_id, links[i].src_property_number,
                links[i].dest_component_id, links[i].dest_property_number,
                links[i].dest_wuclass_id);
  }
  number_of_links = number_of_entries;
  return WKPF_OK;
}
Esempio n. 7
0
void native_thread_init(u08_t mref)
{
	heap_id_t h;
	h = heap_alloc(TRUE, sizeof(nvm_word_t));
	stack_push(NVM_TYPE_HEAP | h);

	// store reference in object, so we can later determine which kind
	// of object this is. this is required for inheritance
	((nvm_ref_t*)heap_get_addr(h))[0] = SubThread_idx++;
	/*heap_id_t h;
	u16_t methodidx;
	h = stack_pop();
	methodidx = ((nvm_ref_t*)heap_get_addr(h))[0];
	
	//Task_init(&MainThread, Maintread_invoke, 0, CONFIG_MAX_PRIORITY - 1,MainThread_stack, sizeof(MainThread_stack));
	Task_init(&SubThread[SubThread_idx],vm_run, (void*)(methodidx&0xFF), CONFIG_MAX_PRIORITY - 1, SubThread_stack[SubThread_idx], sizeof(SubThread_stack[SubThread_idx]));
	//SubThread[5];
	//SubThread_stack[5][512];
	*/
}
Esempio n. 8
0
nvm_float_t array_faload(heap_id_t id, nvm_int_t index) {
  nvm_float_t * ptr = (nvm_float_t*)((u08_t*)heap_get_addr(id) + 1);
  DEBUGF("iaload id=%x, index=%d\n", id, index);
  return ptr[index];
}
Esempio n. 9
0
void array_fastore(heap_id_t id, nvm_int_t index, nvm_float_t value) {
  nvm_float_t * ptr = (nvm_float_t*)((u08_t*)heap_get_addr(id) + 1);
  DEBUGF("iastore id=%x, index=%d, value=%f\n", id, index, value);
  ptr[index] = value;
  HEAP_CHECK();
}
Esempio n. 10
0
nvm_byte_t array_baload(heap_id_t id, nvm_int_t index) {
  nvm_byte_t * ptr = (nvm_byte_t*)heap_get_addr(id) + 1;
  DEBUGF("baload id=%x, index=%d\n", id, index);
  return ptr[index];
}
Esempio n. 11
0
void array_bastore(heap_id_t id, nvm_int_t index, nvm_byte_t value) {
  nvm_byte_t * ptr = (nvm_byte_t *)heap_get_addr(id) + 1;
  DEBUGF("bastore id=%x, index=%d, value=%d\n", id, index, value);
  ptr[index] = value;
}