Ejemplo n.º 1
0
static bool simulator_view(WINDOW *out, WINDOW *state, struct program *program,
                           enum STATE *current_state)
{
        int input;
        static int timeout = 0;

        set_state(current_state);

        while (1) {
                wtimeout(state, timeout);
                input = wgetch(status);

                if (program->simulator.memory[program->simulator.PC].isBreakpoint) {
                        popup_window("Breakpoint hit!", 0, true);
                        program->simulator.isPaused = true;
                        program->simulator.memory[program->simulator.PC]
                                .isBreakpoint = false;
                }

                if (QUIT == input) {
                        return false;
                } else if (GOBACK == input) {
                        *current_state = MAIN;
                        program->simulator.isPaused = true;
                        return true;
                } else if (PAUSE == input) {
                        program->simulator.isPaused = !program->simulator.isPaused;
                } else if (START == input || RUN == input) {
                        program->simulator.isPaused = program->simulator.isHalted;
                } else if (RESTART == input) {
                        memPopulated = -1;
                        init_machine(program);
                        wclear(out);
                        wrefresh(out);
                } else if (STEP_NEXT == input) {
                        executeNext(&(program->simulator), output);
                        program->simulator.isPaused = true;
                        printState(&(program->simulator), state);
                } else if (CONTINUE == input) {
                        memPopulated = -1;
                        init_machine(program);
                } else if (CONTINUE_RUN == input) {
                        memPopulated = -1;
                        init_machine(program);
                        program->simulator.isPaused = false;
                }

                if (!program->simulator.isPaused && !program->simulator.isHalted) {
                        executeNext(&(program->simulator), out);
                        timeout = 0;
                } else {
                        set_state(current_state);
                        printState(&(program->simulator), state);
                        timeout = -1;
                        generateContext(context, program, 0, program->simulator.PC);
                }
        }
}
Ejemplo n.º 2
0
void ConvertIntegerBool::calculate()
{
	Component::calculate();

	if (!m_recursionLocked)
	{
		m_recursionLocked = true;

		bool state, oldState;
		state = oldState = getOutput()->getOutput();
		int input = getInput()->getInput();

		if (getFalseThreshold().value() <= getTrueThreshold().value())
		{
			if(input >= getTrueThreshold().value())
			{
				state = true;
			}
			else if(input <= getFalseThreshold().value())
			{
				state = false;
			}
		}
		else
		{
			if(input <= getTrueThreshold().value())
			{
				state = true;
			}
			else if(input >= getFalseThreshold().value())
			{
				state = false;
			}
		}
		if (state != oldState)
		{
			getOutput()->setOutput(state, false);
			if (getOutput()->getWireProperty())
			{
				getOutput()->getWireProperty()->execute();
			}
		}
		m_recursionLocked = false;
	}
	else
	{
		executeNext();
	}
}
Ejemplo n.º 3
0
/** Executes the simulation of this component */
void ConvertBoolFloat::calculate()
{
	Component::calculate();
	
	if (!m_recursionLocked)
	{
		m_recursionLocked = true;
	
		double d = getInput()->getInput() ? getTrueValue() : getFalseValue();
		getOutput()->setOutput(d, false);
		if (getOutput()->getWireProperty())
		{
			getOutput()->getWireProperty()->execute();
		}
		m_recursionLocked = false;
	}
	else
	{
		executeNext();
	}
}
Ejemplo n.º 4
0
void ExtConnIntegerIn::calculate()
{
	// Protect against infinite recursion
	if (!isRecursionLocked())
	{
		setRecursionLocked(true);
		ExternalConnector::calculate();
	
		ConnectorIntegerOut * out = (ConnectorIntegerOut *)getInternalConn();
		ConnectorIntegerIn * in = (ConnectorIntegerIn *)getUsedExternalConn();
	
		out->setOutput(in->getInput(), false);
		if (out->getWireProperty())
		{
			out->getWireProperty()->execute();
		}
		setRecursionLocked(false);
	}
	else
	{
		executeNext();
	}
}
Ejemplo n.º 5
0
int main(int argc, char** argv) {
    if (argc == 1) {
        return 0;
    }

    // Check input for validity.
    if (!validateInput(argc - 1, &argv[1])) {
        return -1;
    }

    // Count number of processes on the pipeline.
    for (int i = 0; argv[i] != 0; ++i) {
        if (!strcmp(argv[i], "|")) {
            ++numProcesses;
        }
    }

    // Open files as needed for I/O redirection.
    int bound = argc - 1;
    for (int i = 0; i < bound; ++i) {
        int erase_redirect = 0;
        // Find output redirect if it exists and open the pipe.
        if (!strcmp(argv[i], ">")) {
            write_fd = open(argv[i+1], O_CREAT | O_WRONLY);
            if (write_fd < 0) {
                perror(argv[i+1]);
                exit(-1);
            }
            dup2(write_fd, 1);
            close(write_fd);
            erase_redirect = 1;
        }
        // Find input redirect if it exists and get the file descriptor for it.
        if (!strcmp(argv[i], "<")) {
            read_fd = open(argv[i+1], O_RDONLY);
            if (read_fd < 0) {
                perror(argv[i+1]);
                exit(-1);
            }
            erase_redirect = 1;
        }

        // If a redirect is detected, eliminate the arguments and continue
        // processing.
        if (erase_redirect) {
            for (int j = i; j < bound - 1; ++j) {
                argv[j] = argv[j+2];
            }
            argc -= 2;
            bound -= 2;
            erase_redirect = 0;
            --i;
        }
    }

    // Get first command to execute.
    curIndex = argc - 1;
    prevIndex = curIndex;
    curIndex = nextSpecial(curIndex, argv);
    if (curIndex == -1) curIndex = 0;
    getNextCommand(curIndex + 1, prevIndex, argv);

    // If there are multiple processes, enter function to execute all processes.
    if (numProcesses > 1) {
        executeNext(argc, argv);
    }
    // Otherwise, redirect stdin if needed and execute the command.
    else {
        if (read_fd != -1) {
            dup2(read_fd, 0);
            close(read_fd);
        }
        execvp(command[0], command);
    }

    freeCommand();
}