sps.c
State executeProgram(Program *prog, Table *table) {
    State s;
    State (*function)(Context);

    Variables variables;
    variables_ctor(&variables);
    // set context, that doesn't change with each command
    unsigned i;
    Context context = {.table=table, .vars=&variables, .execPtr=&i};

    unsigned realCounter = 0;

    for (i=0; i < prog->len; i++) {
        // set the correct function
        function = prog->cmds[i].fn;
        // set up the context before executing
        context.argStr = prog->cmds[i].argStr;

        s = function(context);
        if (s != SUCCESS)
            break;

        if (realCounter++ >= INF_CYCLE_LIMIT) {
            s = ERR_INF_CYCLE;
            break;
        }
    }
    variables_dtor(&variables);
    return s;
}
// takes in program structure and executes commands in it
takes in program structure and executes commands in it
takes in program structure and executes commands in it
State executeProgram(Program *prog, Table *table) {
    State s;
    State (*function)(Context);
    Variables variables;
    variables_ctor(&variables);
    unsigned i;
    Context context = {.table=table, .vars=&variables, .execPtr=&i};
    unsigned realCounter = 0;
    for (i=0; i < prog->len; i++) {
        function = prog->cmds[i].fn;
        context.argStr = prog->cmds[i].argStr;
        s = function(context);
        if (s != SUCCESS)
            break;
        if (realCounter++ >= INF_CYCLE_LIMIT) {
            s = ERR_INF_CYCLE;
            break;
        }
    }
    variables_dtor(&variables);
    return s;
}
State executeProgram ( Program * prog , Table * table ) { State s ; State ( * function ) ( Context ) ; Variables variables ; variables_ctor ( & variables ) ; unsigned i ; Context context = { . table = table , . vars = & variables , . execPtr = & i } ; unsigned realCounter = 0 ; for ( i = 0 ; i < prog -> len ; i ++ ) { function = prog -> cmds [ i ] . fn ; context . argStr = prog -> cmds [ i ] . argStr ; s = function ( context ) ; if ( s != SUCCESS ) break ; if ( realCounter ++ >= INF_CYCLE_LIMIT ) { s = ERR_INF_CYCLE ; break ; } } variables_dtor ( & variables ) ; return s ; }
takes in program structure and executes commands in it
takes in program structure and executes commands in it
// set context, that doesn't change with each command // set the correct function // set up the context before executing