Ejemplo n.º 1
0
void interpretator(Function *main)
{
    Interpretator *interpretator=new(Interpretator);

    interpretator->stack=malloc(10000);
    interpretator->stack_head=interpretator->stack;

    run_function(interpretator, main, 0);
}
Ejemplo n.º 2
0
void interpretator(Function *main)
{
    undefined=new(Variable);
    undefined->name=str_init("undefined");
    undefined->type=UNDEFINED;

    Interpretator *interpretator=new(Interpretator);

    interpretator->stack=malloc(1000);
    interpretator->stack_head=interpretator->stack;

    run_function(interpretator, main, 0);
}
Ejemplo n.º 3
0
void run_repl(Module *state, const char *in_file) {
    printf("EaRing.  Copyright 2008 Zed A. Shaw.\n");
    printf("Done compiling %s.  Enter ? to get the function list.\n", in_file);
    char *cmd = NULL;
    current_module = state;
    repl_init(NULL);

    while((cmd = repl_prompt())) {
        if(cmd[0] == '?') {
            tst_traverse(state->functions, (tst_traverse_cb)query_functions, NULL);
        } else {
            run_function(state, cmd);
        }
    }
}
static WasmResult run_start_function(WasmInterpreterModule* module,
                                     WasmInterpreterThread* thread) {
  WasmResult result = WASM_OK;
  if (module->start_func_offset != WASM_INVALID_OFFSET) {
    if (s_trace)
      printf(">>> running start function:\n");
    WasmInterpreterResult iresult =
        run_function(module, thread, module->start_func_offset);
    if (iresult != WASM_INTERPRETER_RETURNED) {
      /* trap */
      fprintf(stderr, "error: %s\n", s_trap_strings[iresult]);
      result = WASM_ERROR;
    }
  }
  return result;
}
Ejemplo n.º 5
0
/* run a function with no args that returns an object */
jsobjtype run_function_object(jsobjtype obj, const char *name)
{
	run_function(obj, name, 0, NULL);
	if (!propval)
		return NULL;
	if (head.proptype == EJ_PROP_OBJECT || head.proptype == EJ_PROP_ARRAY) {
		jsobjtype p;
		sscanf(propval, "%p", &p);
		nzFree(propval);
		propval = 0;
		return p;
	}
/* wrong type, just return NULL */
	nzFree(propval);
	propval = 0;
	return NULL;
}				/* run_function_object */
Ejemplo n.º 6
0
int main(int argc, char* argv[]) {
	printf("sizeof(double) = %d\n", sizeof(double));
	
	set_thread_affinity(4, 4);

	run_function(pi_serial, "serial");
	run_function(pi_par_atomic, "parallel atomic");
	run_function(pi_par_reduction, "parallel reduction");
	run_function(pi_par_false_sharing, "parallel false sharing");

	set_thread_affinity(4, 1);
	run_function(pi_par_false_sharing, "parallel false sharing");

	set_thread_affinity(2, 4);

	for (int start_position = 0; start_position < 20; start_position++) {
		run_function(pi_par_false_sharing, "parallel false sharing", &start_position);
	}

	set_thread_affinity(4, 4);
	for (int i=0; i<3; i++) {		
		run_function(pi_par_reduction, "parallel reduction 4x4");		
		
	}
	set_thread_affinity(4, 2);
	for (int i=0; i<3; i++) {
		run_function(pi_par_reduction, "parallel reduction 4x2");
	}
	clear_thread_affinity(4, 4);
	for (int i=0; i<3; i++) {
		run_function(pi_par_reduction, "parallel reduction randx4");
	}

	system("pause");
	return 0;
}
Ejemplo n.º 7
0
/* run a function with no args that returns a boolean */
bool run_function_bool(jsobjtype obj, const char *name)
{
	run_function(obj, name, 0, NULL);
	if (!propval)
		return true;
	if (head.proptype == EJ_PROP_BOOL) {
		bool rc = (propval[0] == '1');
		nzFree(propval);
		propval = 0;
		return rc;
	}
	if (head.proptype == EJ_PROP_INT) {
		int n = atoi(propval);
		nzFree(propval);
		propval = 0;
		return (n != 0);
	}
/* wrong type, but at least it's something, just return true */
	nzFree(propval);
	propval = 0;
	return true;
}				/* run_function_bool */
Ejemplo n.º 8
0
void run_function_objargs(jsobjtype obj, const char *name, int nargs, ...)
{
/* lazy, limit of 20 args */
	jsobjtype argv[20];
	int i;
	va_list p;

	if (nargs > 20) {
		puts("more than 20 args to a javascript function");
		return;
	}

	va_start(p, nargs);
	for (i = 0; i < nargs; ++i)
		argv[i] = va_arg(p, jsobjtype);
	va_end(p);

	run_function(obj, name, nargs, argv);

/* return is thrown away; this is a void function */
	nzFree(propval);
	propval = 0;
}				/* run_function_objargs */
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
    CORD input = NULL;
    const char *in_file_name = NULL;
    FILE *in_file = NULL;
    Module *state = NULL;
    int opt;
    int disassemble = 0;
    const char *func = "main";
    int interactive = 0;
    int listing = 0;

    while((opt = getopt(argc, argv, "lhdf:i")) != -1) {
        switch(opt) {
            case 'd': disassemble = 1; break;
            case 'f': func = optarg; break;
            case 'i': interactive = 1; break;
            case 'l': listing = 1; break;
            case 'h': /// fall through!
            default:
                die(NULL, "USAGE: earing [-d | -i] [-f function] <file.asm>\n");
                return 1;
        }
    }

    if(optind >= argc) {
        die(NULL, "You have to give a file.  Use -h to see the usage.");
        return 1;
    }

    GC_INIT();

    in_file_name = argv[optind];
    in_file = fopen(in_file_name, "r");

    if(!in_file) {
        die(NULL, "Failed to open the input file %s", in_file_name);
    }

    input = CORD_from_file(in_file);

    state = Module_create(in_file_name, 1024);
    Module_register_default_directives(state);

    if(!Module_compile(state, CORD_to_const_char_star(input), CORD_len(input))) {
        die(state, "Parsing failed with %d errors.\n", state->errors);
        return 1;
    } else {
        if(listing) {
            tst_traverse(state->functions, (tst_traverse_cb)query_functions, NULL);
        } else if(disassemble) {
            dis_functions(state);
        } else if(interactive) {
            // go into interactive mode with the repl
            run_repl(state, in_file_name);
        } else {
            // run the given function or the "main" default
            run_function(state, func);
        }
    }

    return 0;
}
Ejemplo n.º 10
0
string Eval  (const string& o_operation)
{

    string operation = OperatorsToFunctionCalls (o_operation); //really redundant
    operation = StripWhitespaceBE (operation);
    operation = StripParens (operation);
    //auto operands = SeparateOperands (operation); operand count has to be one at this point

	list <string> operands = SeparateOperands (operation);
	
	
	
	if (operands.size() == 1)
	{		

        // literal value
        if (IsNumericValue (operation))
		    return tostr (NumEval (operation)); //maybe return operation  directly
		
	    function_t fcode;
        string function_name = GetFunctionName(operation);
        
         //function
        if (IsFunctionCall (operation))
        { 
            SeparateArguments (StripB (function_name, operation));
    		return run_function (function_name, SeparateArguments (StripB (function_name, operation)));
     	} // if 
     	
	 	
        // only one operand at this point, which is a variable
        if (IsVariable (operation))
			return GetVariable (operands.front())-> Value ();

		// check for Literals
		// TODO: OperationType does so many unncessasry checks (for variables, waveforms, etc) 
		//       its better to figure out some way to skip those checks
		type_t optype = OperationType (operation);
		if (optype == TYPE_TEXT or optype == TYPE_NUM)
			return operation;
			
		// NaV: Not a value
		if (operation == "NaV")
			error ("operation did not return a valid value");
			
		// Unknown object
		error ("object `" + operation + "' is unsupported.");        	
		
	} // if 
	
	else
	{
		
		string result = "";
		
		for (list<string>::iterator o = operands.begin(); o != operands.end(); o++)
		{
			
			if (IsOperator (*o))
			{
				result += *o;	
				
			} /* if */
			
			else
			{
				result += Eval (*o);	
			
			} /* else */
			
			
		} /* for */
		
		
		return StripE (" ", result);
	} /* else */	 
				
} /* eval */