Esempio n. 1
0
void uiloop(data_t a, data_t b, int nsteps, char *s)
{
	int done = 0;
	struct input inp;
	struct parse_options po;
	struct expr_environ *env = new_env();
	struct expr_var ans;
	data_t ans_data = 45;
	
	Genv = env;
	
	/* setup global vars */
	ans.name = "ans";
	ans.location = &ans_data;
	var_load(env, &ans);
	
	/*setup C funcions & constants*/
	load_builtins(env);
	func_multiload(env, local_funcs, ARSIZE(local_funcs));

	/*Parser options*/
	po.auto_clear = 0;
	po.n_args = (nsteps != 0);
	po.n_rets = CALC_N_RETS;
	
	if (s == NULL) {
		mk_lineinput(&inp, stdin);
		
		while(!done && !linput_done(inp) && !Gdone) {
			fputs("> ", stderr);
			if (linput_prefetch(inp)) {
				eval_print(a, b, nsteps, po, env, inp, &ans_data);
			}
		}
		
		destroy_lineinput(&inp);
	} else {
		mk_strinput(&inp, s, STRINP_NOCOPY);
		eval_print(a, b, nsteps, po, env, inp, &ans_data);
		destroy_strinput(&inp);
	}
	
	destroy_env(env);
}
Esempio n. 2
0
int
main(int argc, char **argv)
{
	char line[256];
	js_State *J;
	int i;

	J = js_newstate(NULL, NULL, JS_STRICT);

	js_newcfunction(J, jsB_gc, "gc", 0);
	js_setglobal(J, "gc");

	js_newcfunction(J, jsB_load, "load", 1);
	js_setglobal(J, "load");

	js_newcfunction(J, jsB_print, "print", 0);
	js_setglobal(J, "print");

	js_newcfunction(J, jsB_write, "write", 0);
	js_setglobal(J, "write");

	js_newcfunction(J, jsB_read, "read", 1);
	js_setglobal(J, "read");

	js_newcfunction(J, jsB_readline, "readline", 0);
	js_setglobal(J, "readline");

	js_newcfunction(J, jsB_quit, "quit", 1);
	js_setglobal(J, "quit");

	js_dostring(J, require_js);

	if (argc > 1) {
		for (i = 1; i < argc; ++i) {
			if (js_dofile(J, argv[i]))
				return 1;
			js_gc(J, 0);
		}
	} else {
		fputs(PS1, stdout);
		while (fgets(line, sizeof line, stdin)) {
			eval_print(J, line);
			fputs(PS1, stdout);
		}
		putchar('\n');
		js_gc(J, 1);
	}

	js_freestate(J);

	return 0;
}
//======================================================================================================================
//======================================================================================================================
//======================================================================================================================
STKUNIT_UNIT_TEST(perceptMesh, open_new_close_PerceptMesh_2)
{
    EXCEPTWATCH;

    double x=0.123, y=0.234, z=0.345, time=0.0;

    // start_demo_open_new_close_PerceptMesh_2
    PerceptMesh eMesh(3u);
    // open the file we previously saved with the new fields
    eMesh.open_read_only(input_files_loc+"cube_with_pressure.e");

    eMesh.print_info("Info after reading mesh");

    //eMesh.print_fields();
    mesh::FieldBase *f_coords = eMesh.get_field("coordinates");

    // create a field function from the existing coordinates field
    FieldFunction ff_coords("ff_coords", f_coords, eMesh, 3, 3);

    // here we could evaluate this field function
    eval_vec3_print(x, y, z, time, ff_coords);

    // get the pressure field
    mesh::FieldBase* pressure_field = eMesh.get_field("pressure");

    // FIXME
    std::vector< const mesh::FieldBase * > sync_fields( 1 , pressure_field );
    mesh::communicate_field_data( eMesh.get_bulk_data()->shared_aura() , sync_fields );
    // FIXME

    //double * pdata = eMesh.node_field_data(pressure_field, 1);

    FieldFunction ff_pressure("ff_pressure", pressure_field, eMesh, 3, 1);
    ff_pressure.add_alias("P");
    StringFunction sf_pressure("P");

    // a point-source at the origin
#define EXACT_SOL log(sqrt( x*x + y*y + z*z) + 1.e-10)

    StringFunction sf_exact_solution(EXPAND_AND_QUOTE(EXACT_SOL), Name("sf_exact_solution"), 3, 1);
    StringFunction sf_error = sf_exact_solution - sf_pressure;

    eval_print(x,y,z,time, sf_error);
    double val_cpp = EXACT_SOL - pressure_value;
    double val_sf  = eval(x,y,z,time, sf_error);
    EXPECT_DOUBLE_EQ(val_sf, val_cpp);
    // end_demo

}
STKUNIT_UNIT_TEST(function, stringFunction_test_alias)
{
  EXCEPTWATCH;
  StringFunction sfx("x", Name("sfx"), Dimensions(3), Dimensions(1));
  StringFunction sfy("y", Name("sfy"), Dimensions(3), Dimensions(1));
  StringFunction sfxy("x-y", Name("sfxy"), Dimensions(3), Dimensions(1));
  StringFunction sfembedded("sfxy", Name("sfembedded"), Dimensions(3), Dimensions(1));
  double x = 1.234;
  double y = 5.678;
  double z = 0;
  double t = 0;
  double xy = x-y;
  //StringFunction sfxy1== sfx-sfy;
  eval_print(1,2,3,0, sfxy);
  double vx = eval(x, y, z, t, sfx);
  std::cout << "x = " << x << " vx= " << vx << std::endl;
  STKUNIT_EXPECT_DOUBLE_EQ(vx, x);
  double vy = eval(x, y, z, t, sfy);
  STKUNIT_EXPECT_DOUBLE_EQ(vy, y);
  double vxy = eval(x, y, z, t, sfxy);
  STKUNIT_EXPECT_DOUBLE_EQ(vxy, xy);

  // embedded function
  std::cout << "sfembedded = ..." << sfembedded << std::endl;
  eval_print(1,2,3,0, sfembedded);
  std::cout << "sfembedded = " << eval(x, y, z, t, sfembedded) << std::endl;

  double vxy1 = eval(x, y, z, t, sfembedded);
  STKUNIT_EXPECT_DOUBLE_EQ(vxy1, xy);

  sfembedded.add_alias("sfalias");
  StringFunction sftestalias("sfalias", Name("sftestalias"));
  double vxy2 = eval(x, y, z, t, sftestalias);
  std::cout << "sftestalias = " << eval(x, y, z, t, sftestalias) << std::endl;
  STKUNIT_EXPECT_DOUBLE_EQ(vxy2, xy);
}
Esempio n. 5
0
File: clamb.c Progetto: irori/clamb
int main(int argc, char *argv[])
{
    Cell root;
    clock_t start;
    char *prog_file = NULL;
    int i;
    int print_stats = 0;
    int parse_only = 0;
    
    for (i = 1; i < argc && argv[i][0] == '-'; i++) {
	if (strcmp(argv[i], "-g") == 0)
	    gc_notify = 1;
	else if (strcmp(argv[i], "-s") == 0)
	    print_stats = 1;
	else if (strcmp(argv[i], "-p") == 0)
	    parse_only = 1;
        else if (strcmp(argv[i], "-u") == 0)
	    setbuf(stdout, NULL);
	else
	    errexit("unknown option %s\n", argv[i]);
    }

    input_init(argv + i);
    storage_init(INITIAL_HEAP_SIZE);
    rs_init();

    root = load_program();
    if (parse_only) {
	unparse(root);
	return 0;
    }

    start = clock();
    eval_print(root);

    if (print_stats) {
	double evaltime = (clock() - start) / (double)CLOCKS_PER_SEC;

	printf("\n%d reductions\n", reductions);
	printf("  total eval time --- %5.2f sec.\n", evaltime - total_gc_time);
	printf("  total gc time   --- %5.2f sec.\n", total_gc_time);
	printf("  max stack depth --- %d\n", rs_max_depth());
    }
    return 0;
}
Esempio n. 6
0
// Compute the multi-step evaluation of the term t. 
Term*
eval(Term* t) {
  switch (t->kind) {
  case if_term: return eval_if(as<If>(t));
  case succ_term: return eval_succ(as<Succ>(t));
  case pred_term: return eval_pred(as<Pred>(t));
  case iszero_term: return eval_iszero(as<Iszero>(t));
  case app_term: return eval_app(as<App>(t));
  case call_term: return eval_call(as<Call>(t));
  case ref_term: return eval_ref(as<Ref>(t));
  case print_term: return eval_print(as<Print>(t));
  case def_term: return eval_def(as<Def>(t));
  case prog_term: return eval_prog(as<Prog>(t));
  case comma_term: return eval_comma(as<Comma>(t));
  default: break;
  }
  return t;
}
Esempio n. 7
0
void
main(void)
{
  struct eval_state_t *es;

  /* set up test variables */
  an_int.type = et_int; an_int.value.as_int = 1;
  a_uint.type = et_uint; a_uint.value.as_uint = 2;
  a_float.type = et_float; a_float.value.as_float = 3.0f;
  a_double.type = et_double; a_double.value.as_double = 4.0;
  a_symbol.type = et_symbol; a_symbol.value.as_symbol = "testing 1 2 3...";

  /* instantiate an evaluator */
  es = eval_new(my_eval_ident, NULL);

  while (1)
    {
      struct eval_value_t val;
      char expr_buf[1024];

      fgets(expr_buf, 1024, stdin);

      /* chop */
      if (expr_buf[strlen(expr_buf)-1] == '\n')
	expr_buf[strlen(expr_buf)-1] = '\0';

      if (expr_buf[0] == '\0')
	exit(0);

      val = eval_expr(es, expr_buf, NULL);
      if (eval_error)
	fprintf(stdout, "eval error: %s\n", eval_err_str[eval_error]);
      else
	{
	  fprintf(stdout, "%s == ", expr_buf);
	  eval_print(stdout, val);
	  fprintf(stdout, "\n");
	}
    }
}
Esempio n. 8
0
void
eval_display(void)
{
  eval_print();
}
Esempio n. 9
0
File: main.c Progetto: ccxvii/mujs
int
main(int argc, char **argv)
{
	char *input;
	js_State *J;
	int status = 0;
	int strict = 0;
	int interactive = 0;
	int i, c;

	while ((c = xgetopt(argc, argv, "is")) != -1) {
		switch (c) {
		default: usage(); break;
		case 'i': interactive = 1; break;
		case 's': strict = 1; break;
		}
	}

	J = js_newstate(NULL, NULL, strict ? JS_STRICT : 0);

	js_newcfunction(J, jsB_gc, "gc", 0);
	js_setglobal(J, "gc");

	js_newcfunction(J, jsB_load, "load", 1);
	js_setglobal(J, "load");

	js_newcfunction(J, jsB_compile, "compile", 2);
	js_setglobal(J, "compile");

	js_newcfunction(J, jsB_print, "print", 0);
	js_setglobal(J, "print");

	js_newcfunction(J, jsB_write, "write", 0);
	js_setglobal(J, "write");

	js_newcfunction(J, jsB_read, "read", 1);
	js_setglobal(J, "read");

	js_newcfunction(J, jsB_readline, "readline", 0);
	js_setglobal(J, "readline");

	js_newcfunction(J, jsB_repr, "repr", 0);
	js_setglobal(J, "repr");

	js_newcfunction(J, jsB_quit, "quit", 1);
	js_setglobal(J, "quit");

	js_dostring(J, require_js);
	js_dostring(J, stacktrace_js);

	if (xoptind == argc) {
		interactive = 1;
	} else {
		c = xoptind++;

		js_newarray(J);
		i = 0;
		while (xoptind < argc) {
			js_pushstring(J, argv[xoptind++]);
			js_setindex(J, -2, i++);
		}
		js_setglobal(J, "scriptArgs");

		if (js_dofile(J, argv[c]))
			status = 1;
	}

	if (interactive) {
		if (isatty(0)) {
			using_history();
			rl_bind_key('\t', rl_insert);
			input = readline(PS1);
			while (input) {
				eval_print(J, input);
				if (*input)
					add_history(input);
				free(input);
				input = readline(PS1);
			}
			putchar('\n');
		} else {
			input = read_stdin();
			if (!input || !js_dostring(J, input))
				status = 1;
			free(input);
		}
	}

	js_gc(J, 0);
	js_freestate(J);

	return status;
}