Exemplo n.º 1
0
STATIC mp_obj_t stm_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
    // TODO support slice index to read/write multiple values at once
    stm_mem_obj_t *self = self_in;
    if (value == MP_OBJ_NULL) {
        // delete
        return MP_OBJ_NULL; // op not supported
    } else if (value == MP_OBJ_SENTINEL) {
        // load
        uint32_t addr = get_read_addr(index, self->elem_size);
        uint32_t val;
        switch (self->elem_size) {
            case 1: val = (*(uint8_t*)addr); break;
            case 2: val = (*(uint16_t*)addr); break;
            default: val = (*(uint32_t*)addr); break;
        }
        return mp_obj_new_int(val);
    } else {
        // store
        uint32_t addr = get_write_addr(index, self->elem_size);
        uint32_t val = mp_obj_get_int(value);
        switch (self->elem_size) {
            case 1: (*(uint8_t*)addr) = val; break;
            case 2: (*(uint16_t*)addr) = val; break;
            default: (*(uint32_t*)addr) = val; break;
        }
        return mp_const_none;
    }
}
Exemplo n.º 2
0
void write(symbol_t value) {
	physical_cell_t* write_addr = get_write_addr();
	physical_goto(write_addr);
	physical_write_current(value);
	// The read pointer now points to the cell we just wrote
	*virtual_current = write_addr;
}
Exemplo n.º 3
0
int main() {
	int i; // Counter variable - removes a gcc warning

	init();

	for (i = 0; i < rules_num; i++) {
		#define rule (rules[0])

		// Discard state mismatches
		if (rule.state_in != ANY && rule.state_in != state)
			continue;
		// Discard symbol mismatches
		if (rule.symbol_in != '*' && rule.symbol_in != read())
			continue;

		// State change
		if (rule.state_out != ANY)
			state = rule.state_out;
		// Symbol change
		if (rule.symbol_out != '*') {
			write(rule.symbol_out);
		}

		// Tape movement
		assert(rule.direction == 'r' || rule.direction == 'l' || rule.direction == '*');
		switch (rule.direction) {
			case 'r':
				virtualMove(RIGHT);
				break;
			case 'l':
				virtualMove(LEFT);
				break;
			case '*':
				// Do nothing
				break;
		}
		break;
	}

	printf("Final state: %i\n", state);
	printf("Final position on the (virtual) tape: %i\n", virtual_current - virtual_tape);
	printf("Final symbol on the tape: %i (%c)\n", read(), read());
	printf("-----\nStatistics\n");
	printf("Physical tape length: %i\n", get_write_addr() - physical_tape);
	return 0;
}