Exemple #1
0
void main(void){
  init_general();// Set general runtime configuration bits
  init_gpio_pins(); // Set all I/O pins to low outputs
  init_oscillator(0);// Initialize oscillator configuration bits
  init_timer2();// Initialize timer2 (millis)
  init_adc(NULL); // Initialize ADC module
  init_termination(NOT_TERMINATING);
  init_adcs();// Initialize all of the ADC's
  init_can(); // Initialize CAN

  canAnalogMillis = canDiagMillis = 0;
  ADCCON3bits.GSWTRG = 1; // Initial ADC Conversion?
  STI();// Enable interrupts


  while(1){
    update_analog_channels();
    strain_calc();

    if(millis - canAnalogMillis >= CAN_ANALOG_INTV){
      CANAnalogChannels();
      canAnalogMillis = millis;
    }

    if(millis - canDiagMillis >= CAN_DIAG_INTV){
      CANdiag();
      canDiagMillis = millis;
    }

    sample_temp(); // Sample internal and external temperature sensors

  }
}
Exemple #2
0
byte I2CRecieve(byte* data,word size)
{
  if (!size) 
  {                         
    return ERROR_NONE;                     
  }
  if((IIC1S_BUSY)||(ReadBufferSize)||(I2C_Status&(CHAN_BUSY))) 
  { 
    return ERROR_BUSBUSY;
  }
  CLI();
  IIC1C1_TX = 1;                // Set TX Mode.
  ReadBufferSize = size; 
  pReadPointer = data;               
                     
  if(IIC1C1_MST) 
  {  
    // If we are already in master mode, the do a repeat start
    IIC1C1_RSTA = 1;         
  }
  else 
  {
    // This will send a start.
    IIC1C1_MST = 1;
  }
  IIC1D = (byte)(DeviceAddress+1);      // Set LSB to indicate write.
  STI();
  return ERROR_NONE;
}
Exemple #3
0
/*
 *   I2C_Send(byte *data,word size)
 */
byte I2CSend(byte *data,word size)
{
  if (0 == size) 
  {                          
    return ERROR_NONE;                  
  }
  // If the chip says busy, or we think we are busy or we are reading
  if((IIC1S_BUSY)||(I2C_Status & CHAN_BUSY)||(ReadBufferSize)) 
  { 
    return ERROR_BUSBUSY;                 
  }

  CLI(); 
  IIC1C1_TX = 1; 
  pWritePointer = data;           
  WriteBufferSize = size;            
             
  I2C_Status |= CHAN_BUSY;  
  if(IIC1C1_MST) 
  {  
    // If we are already in master mode, the do a repeat start
    IIC1C1_RSTA = 1;        
  }
  else 
  {
    // This also generates a start signal.
    IIC1C1_MST = 1;
  }
  IIC1D = DeviceAddress;
  STI();           
  return ERROR_NONE;
}
Exemple #4
0
MVM_Object *
create_array_literal_int(MVM_VirtualMachine *mvm, int size)
{
    MVM_Object *array;
    int i;

    array = mvm_create_array_int_i(mvm, size);
    for (i = 0; i < size; i++) {
        array->u.array.u.int_array[i] = STI(mvm, -size+i);
    }

    return array;
}
Exemple #5
0
void BucketAlloc::free(void* ptr) {
    CLI();
    lock.lock();
    // get a pointer to the memory region (just memory + header)
    size_t* reg = (size_t*)((char*)(ptr) - 2 * sizeof(size_t));

    // remove the used flag
    reg[0] = reg[0] ^ USED_FLAG;

    // and insert it into a bucket
    insertIntoBucket(reg);
    lock.release();
    STI();
}
Exemple #6
0
void osmain()
{
  setup();

  Task task1, task2;
  // 0x9FFFF - Дно стека ядра, т.е. task0
  createTask( &task1, (u32) &entryTask1, 0x9FFFF-1024 );
  createTask( &task2, (u32) &entryTask2, 0x9FFFF-2048 );

  STI();
  while(1)
  {
    ++videomem[0].character;
    HLT();
  };
};
Exemple #7
0
MVM_Object *
create_array_sub(MVM_VirtualMachine *mvm, int dim, int dim_index,
                 MVM_TypeSpecifier *type)
{
    MVM_Object *ret = malloc(sizeof(MVM_Object));
    int size;
    int i;

    size = STI(mvm, -dim);

    if (dim_index == type->derive_count-1) {
        switch (type->basic_type) {
        case MVM_BOOLEAN_TYPE:
        case MVM_INTEGER_TYPE:
            ret = MVM_create_array_int(mvm, size);
            break;
        case MVM_DECIMAL_TYPE:
            ret = MVM_create_array_double(mvm, size);
            break;
        case MVM_STRING_TYPE:
            ret = MVM_create_array_object(mvm, size);
            break;
        case MVM_NULL_TYPE:
        case MVM_BASE_TYPE:
        case MVM_CLASS_TYPE:
        case MVM_VOID_TYPE:
        default:
            break;
        }
    } else if (type->derive[dim_index].tag == MVM_FUNCTION_DERIVE) {
        /* BUGBUG */
        ret = NULL;
    } else {
        ret = MVM_create_array_object(mvm, size);
        if (dim_index < dim - 1) {
            STO_WRITE(mvm, 0, ret);
            mvm->stack.stack_pointer++;
            for (i = 0; i < size; i++) {
                MVM_Object *child;
                child = create_array_sub(mvm, dim, dim_index+1, type);
                MVM_array_set_object(mvm, ret, i, child);
            }
            mvm->stack.stack_pointer--;
        }
    }
    return ret;
}
Exemple #8
0
void addTask( Task *task, u32 entry, u32 stack )
{
  task->tss.eip = entry;

  task->tss.es = task->tss.ds = task->tss.ss = task->tss.fs = task->tss.gs = 0x10;
  task->tss.cs = 0x08;

  task->tss.ebp = task->tss.esp = stack;
  task->tss.eflags = 0x200; // IF = 1
  task->tss.cr3 = 0;
  task->tss.iomap = sizeof(Tss);
  task->tss.debug = 0;

  CLI();
  // Insert created task after `currentTask`
  task->next = currentTask->next;
  currentTask->next = task;
  STI();
};
Exemple #9
0
void remove_timer(struct Timer_dec * timer)
{
    // The variables this function changes are used by the
    // Handle_Timers interrupt and so this function
    // must be atomic

    // This basically removes the current timer
    // by linking around it
    //  ----->(n - 1)->Next
    //  |        n        |
    //  Prev<-(n + 1)<-----
    // if it was malloced it will have to be freed manually
    CLI();

    timer->Previous->Next = timer->Next;
    timer->Next->Previous = timer->Previous;

    STI();
}
Exemple #10
0
void* BucketAlloc::malloc(size_t size) {
    CLI();
    lock.lock();

    // try to allocate the memory
    void* mem = mallocOneTry(size);

    // if it is null, lets do a merge step and try again
    if (mem == nullptr) {
        merge();
        mem = mallocOneTry(size);
    }

    // if it is still null, allocate new virtual pages to use.
    if (mem == nullptr) {
        // this is the bucket malloc will start looking in
        size_t bucket = nextHighestPowerOfTwo(size);
        u32 bucketmemsize = 1u << bucket;

        // we want to allocate pages that will fit that bucket or higher
        // so first we round up the bucketmemsize
	    u32 allocsize = bucketmemsize + (bucketmemsize % 0x1000 == 0 ? 0 : (0x1000 - (bucketmemsize % 0x1000)));
        
        // if allocsize without header is in the same bucket, add a page
        if (nextHighestPowerOfTwo(allocsize - 16) == bucket)
            allocsize += 0x1000;

        // then we allocate the virtual memory
        void* page = memory::kernelPageDirectory.bindFirstFreeVirtualPages(KERNEL_END_VIRTUAL, allocsize / 0x1000);
        
        // give it the the allocator, and try to allocate some memory
        if (page != nullptr) {
            init(page, allocsize);
            mem = mallocOneTry(size);
        }
    }

    // and return the allocated memory, this might be null if nothing was found
    lock.release();
    STI();
    return mem;
}
Exemple #11
0
byte I2CSendAddress(void)
{
  // If you call this and don't then send or receive data, the unit will say busy.
   CLI(); 
   IIC1C1_TX = 1; 
   I2C_Status |= CHAN_BUSY; 
   WriteBufferSize = 0;   
   if(IIC1C1_MST) 
   {  
     // If we are already in master mode, the do a repeat start
     IIC1C1_RSTA = 1;        
   }
   else 
   {
     // This also generates a start signal.
     IIC1C1_MST = 1;
   }
   IIC1D = DeviceAddress+1;
   STI();           
   return ERROR_NONE;  
}
Exemple #12
0
void add_timer(struct Timer_dec * timer)
{
    // The variables this function changes are used by the
    // Handle_Timers interrupt and so this function
    // must be atomic
    CLI();

    if(!timer)
        return;
    
    // Link in the new timer
    //         n->|<-base-><-n
    //     n-><-timer-><-base-><-n
    //
    timer->Next = &base;
    timer->Previous = base.Previous;
    base.Previous->Next = timer;
    base.Previous = timer;

    // Reset its ticks
    timer->Ticks = 0;

    STI();
}
Exemple #13
0
int main(void)
{
	RT_TASK *rtask;
	MBX *mbx;
	int maxisr = 0, maxsched = 0, ovrun = 0, semcnt;
	struct { int isr, sched; } latency;
	int timer_period, timer_freq, h_timer_freq;
	int count, perns, pervar, maxpervar = 0;
	RTIME tp, t;

	rt_allow_nonroot_hrt();
	pthread_create(&thread, NULL, endt, NULL);
	iopl(3);

	if (!(rtask = rt_task_init_schmod(nam2num("RTASK"), 0, 0, 0, SCHED_FIFO, ALLOWED_CPUS))) {
		printf("CANNOT CREATE REAL TIME TASK\n");
		return 1;
	}
	if (!(mbx = rt_named_mbx_init("LATMBX", 100*sizeof(latency)))) {
		printf("CANNOT CREATE MAILBOX\n");
		rt_task_delete(rtask);
		return 1;
	}

	rt_make_hard_real_time();
	timer_period = 1;
	timer_freq = 2;
	tmr_get_setup(timer, &timer_period, &timer_freq);
	h_timer_freq = timer_freq/2;
	perns = timer_period*1000000000LL/timer_freq;
 	tmr_start(timer);
#ifdef USE_EXT_WAIT
 	printf("Wait_on_timer returns timer count and cpu time.\n");
#else
 	printf("Wait_on_timer does just that.\n");
#endif
#ifdef DISABLE_INTR
 	printf("Wait_on_timer and times getting with interrupt disabled.\n");
#else
 	printf("Wait_on_timer and times getting with interrupt enabled.\n");
#endif
 	printf("Timer setup completed, running.\n\n");

	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();

	while (wait_on_timer(timer) > 0);
	tp = rt_get_cpu_time_ns();
	while (!end) {
		CLI();
		CHECK_FLAGS();
#ifdef USE_EXT_WAIT
		if ((semcnt = wait_on_timer_ext(timer, &count, &t)) > 0) {
			rt_printk("OVRN: %d, TOT: %d\n", semcnt, ++ovrun);
		}
#else
		if ((semcnt = wait_on_timer(timer)) > 0) {
			rt_printk("OVRN: %d, TOT: %d\n", semcnt, ++ovrun);
		}
		count = tmr_get_count(timer, &t);
#endif
		CHECK_FLAGS();
		STI();
		if ((latency.sched = ((timer_period - count)*1000000 + h_timer_freq)/timer_freq) > maxsched) {
			maxsched = latency.sched;
		}
		if ((latency.isr = ((timer_period - tmr_get_isr_count(timer))*1000000 + h_timer_freq)/timer_freq) > maxisr) {
			maxisr = latency.isr;
		}
		pervar = abs((int)(t - tp));
		tp = t;
		if (pervar > maxpervar) {
			maxpervar = pervar;
		}
		rt_mbx_send_if(mbx, &latency, sizeof(latency));
//		rt_printk("MXI %d, MXS %d\n", maxisr, maxsched);
	}
 	tmr_stop(timer);

	rt_make_soft_real_time();
	rt_task_delete(rtask);
	rt_mbx_delete(mbx);
	printf("*** MAX LATENCIES: ISR %d (us), SCHED %d (us) ***\n", maxisr, maxsched);
	printf("*** MAX PERIOD VARIATION %d (us) ***\n", (maxpervar - perns + 500)/1000);
	return 0;
}
Exemple #14
0
static void
execute(MVM_VirtualMachine *mvm, Function *func,
        MVM_Byte *code, int code_size)
{
    int         base;
    MVM_Executable *exe;
    int         pc;
    //MVM_Value   ret;

    pc = mvm->pc;
    exe = mvm->current_executable;

    while (pc < code_size) {
        /*printf("%s  sp(%d)\t\n",
                mvm_opcode_info[code[pc]].mnemonic,
                                mvm->stack.stack_pointer);*/


        switch (code[pc]) {
        case MVM_PUSH_INT_1BYTE:
            STI_WRITE(mvm, 0, code[pc+1]);
            //printf("int byte %d\n",code[pc+1]);
            mvm->stack.stack_pointer++;
            pc += 2;
            break;
        case MVM_PUSH_INT_2BYTE:
            STI_WRITE(mvm, 0, GET_2BYTE_INT(&code[pc+1]));
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        case MVM_PUSH_INT:
            STI_WRITE(mvm, 0,
                      exe->constant_pool[GET_2BYTE_INT(&code[pc+1])].u.c_integer);
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        case MVM_PUSH_DOUBLE_0:
            STD_WRITE(mvm, 0, 0.0);
            mvm->stack.stack_pointer++;
            pc++;
            break;
        case MVM_PUSH_DOUBLE_1:
            STD_WRITE(mvm, 0, 1.0);
            mvm->stack.stack_pointer++;
            pc++;
            break;
        case MVM_PUSH_DOUBLE:
            STD_WRITE(mvm, 0,
                      exe->constant_pool[GET_2BYTE_INT(&code[pc+1])].u.c_decimal);
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        case MVM_PUSH_STRING:
            STO_WRITE(mvm, 0,
                      mvm_literal_to_mvm_string_i(mvm,
                                                  exe->constant_pool
                                                  [GET_2BYTE_INT(&code
                                                          [pc+1])]
                                                  .u.c_string));
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        case MVM_PUSH_NULL:
            STO_WRITE(mvm, 0, NULL);
            mvm->stack.stack_pointer++;
            pc++;
            break;
        case MVM_PUSH_STACK_INT:
            STI_WRITE(mvm, 0,
                      STI_I(mvm, base + GET_2BYTE_INT(&code[pc+1])));
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        case MVM_PUSH_STACK_DOUBLE:
            STD_WRITE(mvm, 0,
                      STD_I(mvm, base + GET_2BYTE_INT(&code[pc+1])));
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        case MVM_PUSH_STACK_OBJECT:
            STO_WRITE(mvm, 0,
                      STO_I(mvm, base + GET_2BYTE_INT(&code[pc+1])));
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        case MVM_POP_STACK_INT:
            STI_WRITE_I(mvm, base + GET_2BYTE_INT(&code[pc+1]),
                        STI(mvm, -1));
            mvm->stack.stack_pointer--;
            pc += 3;
            break;
        case MVM_POP_STACK_DOUBLE:
            STD_WRITE_I(mvm, base + GET_2BYTE_INT(&code[pc+1]),
                        STD(mvm, -1));
            mvm->stack.stack_pointer--;
            pc += 3;
            break;
        case MVM_POP_STACK_OBJECT:
            STO_WRITE_I(mvm, base + GET_2BYTE_INT(&code[pc+1]),
                        STO(mvm, -1));
            mvm->stack.stack_pointer--;
            pc += 3;
            break;
        case MVM_PUSH_STATIC_INT:
            STI_WRITE(mvm, 0,
                      mvm->static_v.variable[GET_2BYTE_INT(&code[pc+1])]
                      .int_value);
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        case MVM_PUSH_STATIC_DOUBLE:
            STD_WRITE(mvm, 0,
                      mvm->static_v.variable[GET_2BYTE_INT(&code[pc+1])]
                      .double_value);
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        case MVM_PUSH_STATIC_OBJECT:
            STO_WRITE(mvm, 0,mvm->static_v.variable[GET_2BYTE_INT(&code[pc+1])].object);
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        case MVM_POP_STATIC_INT:
            mvm->static_v.variable[GET_2BYTE_INT(&code[pc+1])].int_value
                = STI(mvm, -1);
            mvm->stack.stack_pointer--;
            pc += 3;
            break;
        case MVM_POP_STATIC_DOUBLE:
            mvm->static_v.variable[GET_2BYTE_INT(&code[pc+1])]
            .double_value
                = STD(mvm, -1);
            mvm->stack.stack_pointer--;
            pc += 3;
            break;
        case MVM_POP_STATIC_OBJECT:
            mvm->static_v.variable[GET_2BYTE_INT(&code[pc+1])].object
                = STO(mvm, -1);
            mvm->stack.stack_pointer--;
            pc += 3;
            break;
        case MVM_PUSH_ARRAY_INT:
        {
            MVM_Object *array = STO(mvm, -2);
            int index = STI(mvm, -1);
            int int_value;

            restore_pc(mvm, exe, func, pc);
            int_value = MVM_array_get_int(mvm, array, index);

            STI_WRITE(mvm, -2, int_value);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        }
        case MVM_PUSH_ARRAY_DOUBLE:
        {
            MVM_Object *array = STO(mvm, -2);
            int index = STI(mvm, -1);
            double double_value;

            restore_pc(mvm, exe, func, pc);
            double_value = MVM_array_get_double(mvm, array, index);

            STD_WRITE(mvm, -2, double_value);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        }
        case MVM_PUSH_ARRAY_OBJECT:
        {
            MVM_Object *array = STO(mvm, -2);
            int index = STI(mvm, -1);
            MVM_Object *object;

            restore_pc(mvm, exe, func, pc);
            object = MVM_array_get_object(mvm, array, index);

            STO_WRITE(mvm, -2, object);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        }
        case MVM_POP_ARRAY_INT:
        {
            int value = STI(mvm, -3);
            MVM_Object *array = STO(mvm, -2);
            int index = STI(mvm, -1);

            restore_pc(mvm, exe, func, pc);
            MVM_array_set_int(mvm, array, index, value);
            mvm->stack.stack_pointer -= 3;
            pc++;
            break;
        }
        case MVM_POP_ARRAY_DOUBLE:
        {
            double value = STD(mvm, -3);
            MVM_Object *array = STO(mvm, -2);
            int index = STI(mvm, -1);

            restore_pc(mvm, exe, func, pc);
            MVM_array_set_double(mvm, array, index, value);
            mvm->stack.stack_pointer -= 3;
            pc++;
            break;
        }
        case MVM_POP_ARRAY_OBJECT:
        {
            MVM_Object *value = STO(mvm, -3);
            MVM_Object *array = STO(mvm, -2);
            int index = STI(mvm, -1);

            restore_pc(mvm, exe, func, pc);
            MVM_array_set_object(mvm, array, index, value);
            mvm->stack.stack_pointer -= 3;
            pc++;
            break;
        }
        case MVM_PUSH_FIELD_INT:
        {
            MVM_Object *obj = STO(mvm, -1);
            int index = GET_2BYTE_INT(&code[pc+1]);

            //check_null_pointer(exe, func, pc, obj);
            STI_WRITE(mvm, -1,
                      obj->u.class_object.field[index].int_value);
            pc += 3;
            break;
        }
        case MVM_PUSH_FIELD_DOUBLE:
        {
            MVM_Object *obj = STO(mvm, -1);
            int index = GET_2BYTE_INT(&code[pc+1]);

            //check_null_pointer(exe, func, pc, obj);
            STD_WRITE(mvm, -1,
                      obj->u.class_object.field[index].double_value);
            pc += 3;
            break;
        }
        case MVM_PUSH_FIELD_OBJECT:
        {
            MVM_Object *obj = STO(mvm, -1);
            int index = GET_2BYTE_INT(&code[pc+1]);

            //check_null_pointer(exe, func, pc, obj);
            STO_WRITE(mvm, -1, obj->u.class_object.field[index].object);
            pc += 3;
            break;
        }
        case MVM_POP_FIELD_INT:
        {
            MVM_Object *obj = STO(mvm, -1);
            int index = GET_2BYTE_INT(&code[pc+1]);
            obj->u.class_object.field[index].int_value = STI(mvm, -2);
            mvm->stack.stack_pointer -= 2;
            pc += 3;
            break;
        }
        case MVM_POP_FIELD_DOUBLE:
        {
            MVM_Object *obj = STO(mvm, -1);
            int index = GET_2BYTE_INT(&code[pc+1]);
            obj->u.class_object.field[index].double_value = STD(mvm, -2);
            mvm->stack.stack_pointer -= 2;
            pc += 3;
            break;
        }
        case MVM_POP_FIELD_OBJECT:
        {
            MVM_Object *obj = STO(mvm, -1);
            int index = GET_2BYTE_INT(&code[pc+1]);

            //check_null_pointer(exe, func, pc, obj);
            obj->u.class_object.field[index].object = STO(mvm, -2);
            mvm->stack.stack_pointer -= 2;
            pc += 3;
            break;
        }
        case MVM_ADD_INT:
            STI(mvm, -2) = STI(mvm, -2) + STI(mvm, -1);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_ADD_DOUBLE:
            STD(mvm, -2) = STD(mvm, -2) + STD(mvm, -1);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_ADD_STRING:
            STO(mvm, -2) = chain_string(mvm,
                                        STO(mvm, -2),
                                        STO(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_SUB_INT:
            STI(mvm, -2) = STI(mvm, -2) - STI(mvm, -1);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_SUB_DOUBLE:
            STD(mvm, -2) = STD(mvm, -2) - STD(mvm, -1);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_MUL_INT:
            STI(mvm, -2) = STI(mvm, -2) * STI(mvm, -1);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_MUL_DOUBLE:
            STD(mvm, -2) = STD(mvm, -2) * STD(mvm, -1);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_DIV_INT:
            if (STI(mvm, -1) == 0) {
                //mvm_error(exe, func, pc, DIVISION_BY_ZERO_ERR,
                //          MESSAGE_ARGUMENT_END);
            }
            STI(mvm, -2) = STI(mvm, -2) / STI(mvm, -1);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_DIV_DOUBLE:
            STD(mvm, -2) = STD(mvm, -2) / STD(mvm, -1);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_MOD_INT:
            STI(mvm, -2) = STI(mvm, -2) % STI(mvm, -1);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_MOD_DOUBLE:
            STD(mvm, -2) = fmod(STD(mvm, -2), STD(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_MINUS_INT:
            STI(mvm, -1) = -STI(mvm, -1);
            pc++;
            break;
        case MVM_MINUS_DOUBLE:
            STD(mvm, -1) = -STD(mvm, -1);
            pc++;
            break;
        case MVM_INCREMENT:
            STI(mvm, -1)++;
            pc++;
            break;
        case MVM_DECREMENT:
            STI(mvm, -1)--;
            pc++;
            break;
        case MVM_CAST_INT_TO_DOUBLE:
            STD(mvm, -1) = (double)STI(mvm, -1);
            pc++;
            break;
        case MVM_CAST_DOUBLE_TO_INT:
            STI(mvm, -1) = (int)STD(mvm, -1);
            pc++;
            break;
        case MVM_CAST_BOOLEAN_TO_STRING:
            if (STI(mvm, -1)) {
                STO_WRITE(mvm, -1,
                          mvm_literal_to_mvm_string_i(mvm, TRUE_STRING));
            } else {
                STO_WRITE(mvm, -1,
                          mvm_literal_to_mvm_string_i(mvm, FALSE_STRING));
            }
            pc++;
            break;
        case MVM_CAST_INT_TO_STRING:
        {
            char buf[LINE_BUF_SIZE];
            MVM_Char *str;

            sprintf(buf, "%d", STI(mvm, -1));
            restore_pc(mvm, exe, func, pc);
            str = str_alloc(buf);
            STO_WRITE(mvm, -1,
                      mvm_create_mvm_string_i(mvm, str));
            pc++;
            break;
        }
        case MVM_CAST_DOUBLE_TO_STRING:
        {
            char buf[LINE_BUF_SIZE];
            MVM_Char *str;

            sprintf(buf, "%f", STD(mvm, -1));
            restore_pc(mvm, exe, func, pc);
            str = str_alloc(buf);
            STO_WRITE(mvm, -1,
                      mvm_create_mvm_string_i(mvm, str));
            pc++;
            break;
        }
        case MVM_EQ_INT:
            STI(mvm, -2) = (STI(mvm, -2) == STI(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_EQ_DOUBLE:
            STI(mvm, -2) = (STD(mvm, -2) == STD(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_EQ_OBJECT:
            STI_WRITE(mvm, -2, STO(mvm, -2) == STO(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_EQ_STRING:
            STI_WRITE(mvm, -2,
                      !strcmp(STO(mvm, -2)->u.string.string, STO(mvm, -1)->u.string.string));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_GT_INT:
            STI(mvm, -2) = (STI(mvm, -2) > STI(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_GT_DOUBLE:
            STI(mvm, -2) = (STD(mvm, -2) > STD(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_GT_STRING:
            STI_WRITE(mvm, -2,
                      strcmp(STO(mvm, -2)->u.string.string,
                             STO(mvm, -1)->u.string.string) > 0);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_GE_INT:
            STI(mvm, -2) = (STI(mvm, -2) >= STI(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_GE_DOUBLE:
            STI(mvm, -2) = (STD(mvm, -2) >= STD(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_GE_STRING:
            STI_WRITE(mvm, -2,
                      strcmp(STO(mvm, -2)->u.string.string,
                             STO(mvm, -1)->u.string.string) >= 0);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_LT_INT:
            STI(mvm, -2) = (STI(mvm, -2) < STI(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_LT_DOUBLE:
            STI(mvm, -2) = (STD(mvm, -2) < STD(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_LT_STRING:
            STI_WRITE(mvm, -2,
                      strcmp(STO(mvm, -2)->u.string.string,
                             STO(mvm, -1)->u.string.string) < 0);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_LE_INT:
            STI(mvm, -2) = (STI(mvm, -2) <= STI(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_LE_DOUBLE:
            STI(mvm, -2) = (STD(mvm, -2) <= STD(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_LE_STRING:
            STI_WRITE(mvm, -2,
                      strcmp(STO(mvm, -2)->u.string.string,
                             STO(mvm, -1)->u.string.string) <= 0);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_NE_INT:
            STI(mvm, -2) = (STI(mvm, -2) != STI(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_NE_DOUBLE:
            STI(mvm, -2) = (STD(mvm, -2) != STD(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_NE_OBJECT:
            STI_WRITE(mvm, -2, STO(mvm, -2) != STO(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_NE_STRING:
            STI_WRITE(mvm, -2,
                      strcmp(STO(mvm, -2)->u.string.string,
                             STO(mvm, -1)->u.string.string) != 0);
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_LOGICAL_AND:
            STI(mvm, -2) = (STI(mvm, -2) && STI(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_LOGICAL_OR:
            STI(mvm, -2) = (STI(mvm, -2) || STI(mvm, -1));
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_LOGICAL_NOT:
            STI(mvm, -1) = !STI(mvm, -1);
            pc++;
            break;
        case MVM_POP:
            mvm->stack.stack_pointer--;
            pc++;
            break;
        case MVM_DUPLICATE:
            mvm->stack.stack[mvm->stack.stack_pointer]
                = mvm->stack.stack[mvm->stack.stack_pointer-1];
            mvm->stack.stack_pointer++;
            pc++;
            break;
        case MVM_JUMP:
            pc = GET_2BYTE_INT(&code[pc+1]);
            break;
        case MVM_JUMP_IF_TRUE:
            if (STI(mvm, -1)) {
                pc = GET_2BYTE_INT(&code[pc+1]);
            } else {
                pc += 3;
            }
            mvm->stack.stack_pointer--;
            break;
        case MVM_JUMP_IF_FALSE:
            if (!STI(mvm, -1)) {
                pc = GET_2BYTE_INT(&code[pc+1]);
            } else {
                pc += 3;
            }
            mvm->stack.stack_pointer--;
            break;
        case MVM_PUSH_FUNCTION:
            STI_WRITE(mvm, 0, GET_2BYTE_INT(&code[pc+1]));
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        case MVM_INVOKE:
        {
            int func_idx = STI(mvm, -1);
            if (mvm->function[func_idx].kind == NATIVE_FUNCTION) {
                invoke_native_function(mvm, &mvm->function[func_idx],
                                       &mvm->stack.stack_pointer);
                pc++;
            } else {
                invoke_minic_function(mvm, &func, &mvm->function[func_idx],
                                      &code, &code_size, &pc,
                                      &mvm->stack.stack_pointer, &base,
                                      &exe);
            }
            break;
        }
        case MVM_RETURN:
            return_function(mvm, &func, &code, &code_size, &pc,
                            &mvm->stack.stack_pointer, &base,
                            &exe);
            break;
        case MVM_NEW_ARRAY:
        {
            int dim = code[pc+1];
            MVM_TypeSpecifier *type
                = &exe->type_specifier[GET_2BYTE_INT(&code[pc+2])];
            MVM_Object *array;

            restore_pc(mvm, exe, func, pc);
            array = create_array(mvm, dim, type);
            mvm->stack.stack_pointer -= dim;
            STO_WRITE(mvm, 0, array);
            mvm->stack.stack_pointer++;
            pc += 4;
            break;
        }
        case MVM_NEW_ARRAY_LITERAL_INT: /* FALLTHRU */
        {
            int size = GET_2BYTE_INT(&code[pc+1]);
            MVM_Object *array;

            restore_pc(mvm, exe, func, pc);
            array = create_array_literal_int(mvm, size);
            mvm->stack.stack_pointer -= size;
            STO_WRITE(mvm, 0, array);
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        }
        case MVM_NEW_ARRAY_LITERAL_DOUBLE: /* FALLTHRU */
        {
            int size = GET_2BYTE_INT(&code[pc+1]);
            MVM_Object *array;

            restore_pc(mvm, exe, func, pc);
            array = create_array_literal_double(mvm, size);
            mvm->stack.stack_pointer -= size;
            STO_WRITE(mvm, 0, array);
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        }
        case MVM_NEW_ARRAY_LITERAL_OBJECT: /* FALLTHRU */
        {
            int size = GET_2BYTE_INT(&code[pc+1]);
            MVM_Object *array;

            restore_pc(mvm, exe, func, pc);
            array = create_array_literal_object(mvm, size);
            mvm->stack.stack_pointer -= size;
            STO_WRITE(mvm, 0, array);
            mvm->stack.stack_pointer++;
            pc += 3;
            break;
        }
        default:
            break;
        }
        /* MEM_check_all_blocks(); */
    }

    //return ret;
}
Exemple #15
0
/**
 * sti():
 *
 */
__inline__ void		sti(void)
{
  STI();
}
int main(int argc, char *argv[]) {
	E_RT_init(argc, argv);
JMP(main);
main: MOVI(0, R999);
JMP(ML1);
RL3: MOVI(2, R901);
MOVI(10000, R777);
MOVS("NAVDEEP", R777);
PRTS(R777);
PRTS("a:b\n");
JMP(L4);
RL5: MOVI(2, R904);
MOVI(10000, R777);
MOVS("NAVDEEP", R777);
PRTS(R777);
PRTS("a OR b:c\n");
JMP(L6);
ML1: R900=MUL(128,0);
R900=ADD(10999,R900);
R001=ADD(R900,97);
STI(1, R001);
R001=ADD(R900,98);
STI(-1, R001);
R001=ADD(R900,99);
STI(-1, R001);
R001=ADD(R900,100);
STI(-1, R001);
R900=MUL(128,1);
R900=ADD(10999,R900);
R001=ADD(R900,97);
STI(-1, R001);
R001=ADD(R900,98);
STI(2, R001);
R001=ADD(R900,99);
STI(-1, R001);
R001=ADD(R900,100);
STI(-1, R001);
R900=MUL(128,2);
R900=ADD(10999,R900);
R001=ADD(R900,97);
STI(-1, R001);
R001=ADD(R900,98);
STI(-1, R001);
R001=ADD(R900,99);
STI(-1, R001);
R001=ADD(R900,100);
STI(-1, R001);
MOVI(2, R902);
MOVI(0, R901);
R903=MUL(128,0);
R903=ADD(11383,R903);
R001=ADD(R903,97);
STI(1, R001);
R001=ADD(R903,98);
STI(1, R001);
R001=ADD(R903,99);
STI(-1, R001);
R001=ADD(R903,100);
STI(-1, R001);
R903=MUL(128,1);
R903=ADD(11383,R903);
R001=ADD(R903,97);
STI(-1, R001);
R001=ADD(R903,98);
STI(-1, R001);
R001=ADD(R903,99);
STI(2, R001);
R001=ADD(R903,100);
STI(-1, R001);
R903=MUL(128,2);
R903=ADD(11383,R903);
R001=ADD(R903,97);
STI(-1, R001);
R001=ADD(R903,98);
STI(-1, R001);
R001=ADD(R903,99);
STI(-1, R001);
R001=ADD(R903,100);
STI(-1, R001);
MOVI(2, R905);
MOVI(0, R904);
L2: IN(R000);
JMPC(GT(0, R000), L0);
JMPC(GT(0, R901), L4);
R001=MUL(128,R901);
R001=ADD(10999,R001);
R001=ADD(R000,R001);
LDI(R001, R002);
JMPC(EQ(R002, R902), RL3);
MOVI(R002, R901);
L4: JMPC(GT(0, R904), L6);
R001=MUL(128,R904);
R001=ADD(11383,R001);
R001=ADD(R000,R001);
LDI(R001, R002);
JMPC(EQ(R002, R905), RL5);
MOVI(R002, R904);
L6: JMP(L2);
L0: MOVI(31000, R000);
MOVS("The End", R000);
PRTS(R000);

	E_RT_exit(); return 0;
}
Exemple #17
0
int main(int argc, char *argv[]) {
	E_RT_init(argc, argv);
JMP(begin);
Label0: R005=ADD(R000,2);
STI(R001, R000);
R000=SUB(R000,1);
MOVI(R000, R001);
LDI(R005, R008);
R005=ADD(R005,1);
LDF(R005, F001);
R005=ADD(R005,1);
MOVIF(R008, F003);
MOVIF(R008, F006);
F005=FADD(F006,F001);
MOVF(F005, F008);
R010=ADD(R008,1);
MOVI(R010, R011);
MOVI(R010, R012);
MOVIF(R008, F010);
MOVF(F005, F011);
while_1_start: JMPC(GT(1000, R008), while_1_begin);
JMP(while_1_end);
while_1_begin: MOVIF(R008, F013);
MOVIF(R008, F014);
F008=FADD(F014,F001);
F001=FMUL(F001,2.0);
R008=ADD(R008,100);
JMP(while_1_start);
while_1_end: PRTF(F008);
PRTS(R007);
MOVI(R008, R002);
JMP(Label1);
Label1: MOVI(R001, R000);
R000=ADD(R000,1);
LDI(R000, R001);
R000=ADD(R000,1);
LDI(R000, R004);
R000=ADD(R000,2);
JMPI(R004);
eventLabel_a: INI(R010);
INF(F013);
STI(R010, R000);
R000=SUB(R000,1);
STF(F013, R000);
R000=SUB(R000,1);
STF(F013, R000);
R000=SUB(R000,1);
STI(R010, R000);
R000=SUB(R000,1);
MOVL(Label2, R004);
STI(R004, R000);
R000=SUB(R000,1);
JMP(Label0);
Label2: MOVI(R002, R006);
R000=ADD(R000,1);
LDF(R000, F013);
R000=ADD(R000,1);
LDI(R000, R010);
JMP(EventMStart);
begin: MOVI(10000, R000);
MOVI(0, R006);
MOVS("\n", R007);
IN(R010);
IN(R010);
IN(R010);
EventMStart: IN(R010);
JMPC(GT(64, R010), EventMOut);
JMPC(EQ(97, R010), eventLabel_a);
JMP(EventMStart);
EventMOut: PRTS("\nDone\n");

	E_RT_exit(); return 0;
}