Exemple #1
0
void
eval_draw(void)
{
	F = cadr(p1);
	T = caddr(p1);

	if (T == symbol(NIL)) {
		push(F);
		rewrite();
		guess();
		T = pop();
		F = pop();
	}

	push(get_binding(T));
	push(get_arglist(T));

	draw_main();

	p2 = pop();
	p1 = pop();
	set_binding_and_arglist(T, p1, p2);

	// return value

	push(symbol(NIL));
}
Exemple #2
0
int get_custom_key_handler_state() {
  U* tmp = usr_symbol("prizmUIhandleKeys");
  if (!issymbol(tmp)) return 0;
  tmp = get_binding(tmp);
  if(isnonnegativeinteger(tmp)) {
    return !iszero(tmp);
  } else return 0;
}
Exemple #3
0
int main(int argc, char **argv) {
	const char *path;
	gel_file_t *file;
	int opt;
	gel_sym_iter_t iter;
	gel_sym_t *sym;

	/* Check arguments */
	opterr = 1;
	while((opt = getopt(argc, argv, "h")) != EOF)
		switch(opt) {
		case 'h':
			help();
		default:
			assert(0);
		}
	if(optind >= argc)
		help();
	path = argv[optind];

	/* open the file */
	file = gel_open(path, "", 0);
	if(file == NULL) {
    	fprintf(stderr, "ERROR: %s\n", gel_strerror());
    	return 2;
  	}

	/* display header */
	printf("st_value st_size  binding type    st_shndx         name\n");

	/* iterate on symboles */
	for(sym = gel_sym_first(&iter, file); sym; sym = gel_sym_next(&iter)) {

		/* get information */
		gel_sym_info_t infos;
		gel_sym_infos(sym, &infos);
		if(strcmp(infos.name, "") == 0)
			continue;

		/* display information */
		printf("%08x %8x %-7s %-7s %-16s %s\n",
			infos.vaddr,
			infos.size,
			get_binding(&infos),
			get_type(&infos),
			get_section_index(file, &infos),
			infos.name);
	}

	/* cleanup */
	gel_close(file);
	return 0;
}
Exemple #4
0
const Value *lookup(const wchar_t * name, Env * env)
{
	const Binding *bnd = UNBOUND;
	const Value   *val = 0;

	if ((bnd = get_binding(env, name)) != UNBOUND) {
		val = bnd->value;
	}

	assert(val != 0);

	return val;
}
Exemple #5
0
/**
 * Bind content of @vectors over /proc/{@ptracee->pid}/auxv.  This
 * function returns -1 if an error occurred, otherwise 0.
 */
static int bind_proc_pid_auxv(const Tracee *ptracee)
{
	word_t vectors_address;
	ElfAuxVector *vectors;

	const char *guest_path;
	const char *host_path;
	Binding *binding;
	int status;

	vectors_address = get_elf_aux_vectors_address(ptracee);
	if (vectors_address == 0)
		return -1;

	vectors = fetch_elf_aux_vectors(ptracee, vectors_address);
	if (vectors == NULL)
		return -1;

	/* Path to these ELF auxiliary vectors.  */
	guest_path = talloc_asprintf(ptracee->ctx, "/proc/%d/auxv", ptracee->pid);
	if (guest_path == NULL)
		return -1;

	/* Remove binding to this path, if any.  It contains ELF
	 * auxiliary vectors of the previous execve(2).  */
	binding = get_binding(ptracee, GUEST, guest_path);
	if (binding != NULL && compare_paths(binding->guest.path, guest_path) == PATHS_ARE_EQUAL) {
		remove_binding_from_all_lists(ptracee, binding);
		TALLOC_FREE(binding);
	}

	host_path = create_temp_file(ptracee->ctx, "auxv");
	if (host_path == NULL)
		return -1;

	status = fill_file_with_auxv(ptracee, host_path, vectors);
	if (status < 0)
		return -1;

	/* Note: this binding will be removed once ptracee gets freed.  */
	binding = insort_binding3(ptracee, ptracee->life_context, host_path, guest_path);
	if (binding == NULL)
		return -1;

	/* This temporary file (host_path) will be removed once the
	 * binding is freed.  */
	talloc_reparent(ptracee->ctx, binding, host_path);

	return 0;
}
Exemple #6
0
void
eval_product(void)
{
	int i, j, k;

	// 1st arg (quoted)

	X = cadr(p1);
	if (!issymbol(X))
		stop("product: 1st arg?");

	// 2nd arg

	push(caddr(p1));
	eval();
	j = pop_integer();
	if (j == (int) 0x80000000)
		stop("product: 2nd arg?");

	// 3rd arg

	push(cadddr(p1));
	eval();
	k = pop_integer();
	if (k == (int) 0x80000000)
		stop("product: 3rd arg?");

	// 4th arg
	// fix

	p1 = cddddr(p1);
	p1 = car(p1);

	B = get_binding(X);
	A = get_arglist(X);

	push_integer(1);

	for (i = j; i <= k; i++) {
		push_integer(i);
		I = pop();
		set_binding(X, I);
		push(p1);
		eval();
		multiply();
	}

	set_binding_and_arglist(X, B, A);
}
Exemple #7
0
int get_custom_fkey_label(int fkey) {
  U* tmp;
  if(fkey==2) {
    tmp = usr_symbol("prizmUIfkey3label");
  } else if (fkey==3) {
    tmp = usr_symbol("prizmUIfkey4label");
  } else if (fkey==5) {
    tmp = usr_symbol("prizmUIfkey6label");
  } else return 0;
  if (issymbol(tmp)) {
    tmp = get_binding(tmp);
    if(isnonnegativeinteger(tmp)) {
      return *tmp->u.q.a;
    }
  }
  return 0;
}
Exemple #8
0
void
setup_yrange_f(void)
{
	// default range is (-10,10)

	ymin = -10.0;

	ymax = 10.0;

	p1 = usr_symbol("yrange");

	if (!issymbol(p1))
		return;

	p1 = get_binding(p1);

	// must be two element vector

	if (!istensor(p1) || p1->u.tensor->ndim != 1 || p1->u.tensor->nelem != 2)
		return;

	push(p1->u.tensor->elem[0]);
	eval();
	yyfloat();
	eval();
	p2 = pop();

	push(p1->u.tensor->elem[1]);
	eval();
	yyfloat();
	eval();
	p3 = pop();

	if (!isnum(p2) || !isnum(p3))
		return;

	push(p2);
	ymin = pop_double();

	push(p3);
	ymax = pop_double();

	if (ymin == ymax)
		stop("draw: yrange is zero");
}
Exemple #9
0
void
setup_trange_f(void)
{
	// default range is (-pi, pi)

	tmin = -M_PI;

	tmax = M_PI;

	p1 = usr_symbol("trange");

	if (!issymbol(p1))
		return;

	p1 = get_binding(p1);

	// must be two element vector

	if (!istensor(p1) || p1->u.tensor->ndim != 1 || p1->u.tensor->nelem != 2)
		return;

	push(p1->u.tensor->elem[0]);
	eval();
	yyfloat();
	eval();
	p2 = pop();

	push(p1->u.tensor->elem[1]);
	eval();
	yyfloat();
	eval();
	p3 = pop();

	if (!isnum(p2) || !isnum(p3))
		return;

	push(p2);
	tmin = pop_double();

	push(p3);
	tmax = pop_double();

	if (tmin == tmax)
		stop("draw: trange is zero");
}
Exemple #10
0
 bool is_declared_special(Value name)
 {
   Binding * binding = get_binding(name);
   return binding ? binding->specialp() : false;
 }
Exemple #11
0
 void rebind(Value name, Value value)
 {
   Binding * binding = get_binding(name);
   binding->set_value(value);
 }
Exemple #12
0
void
run(char *s)
{
	int i, n;

	/*if (strncmp(s, "selftest", 8) == 0) {
		selftest();
		return;
	}*/

	if (setjmp(stop_return))
		return;

	init();

	while (1) {

		n = scan(s);

		p1 = pop();
		check_stack();

		if (n == 0)
			break;

		// if debug mode then print the source text

		if (equaln(get_binding(symbol(TRACE)), 1)) {
			for (i = 0; i < n; i++)
				if (s[i] != '\r')
					printchar(s[i]);
			if (s[n - 1] != '\n') // n is not zero, see above
				printchar('\n');
		}

		s += n;

		push(p1);
		top_level_eval();

		p2 = pop();
		check_stack();

		if (p2 == symbol(NIL))
			continue;

		// print string w/o quotes

		if (isstr(p2)) {
			printstr(p2->u.str);
			printstr("\n");
			continue;
		}

		if (equaln(get_binding(symbol(TTY)), 1) || test_flag) // tty mode?
			printline(p2);
		else {
//#ifdef LINUX
			display(p2);
/*#else
			push(p2);
			cmdisplay();
#endif*/
		}
	}
}
Exemple #13
0
void
top_level_eval(void)
{
	save();

	trigmode = 0;

	p1 = symbol(AUTOEXPAND);

	if (iszero(get_binding(p1)))
		expanding = 0;
	else
		expanding = 1;

	p1 = pop();
	push(p1);
	eval();
	p2 = pop();

	// "draw", "for" and "setq" return "nil", there is no result to print

	if (p2 == symbol(NIL)) {
		push(p2);
		restore();
		return;
	}

	// update "last"

	set_binding(symbol(LAST), p2);

	if (!iszero(get_binding(symbol(BAKE)))) {
		push(p2);
		bake();
		p2 = pop();
	}

	// If we evaluated the symbol "i" or "j" and the result was sqrt(-1)

	// then don't do anything.

	// Otherwise if "j" is an imaginary unit then subst.

	// Otherwise if "i" is an imaginary unit then subst.

	if ((p1 == symbol(SYMBOL_I) || p1 == symbol(SYMBOL_J))
	&& isimaginaryunit(p2))
		;
	else if (isimaginaryunit(get_binding(symbol(SYMBOL_J)))) {
		push(p2);
		push(imaginaryunit);
		push_symbol(SYMBOL_J);
		subst();
		p2 = pop();
	} else if (isimaginaryunit(get_binding(symbol(SYMBOL_I)))) {
		push(p2);
		push(imaginaryunit);
		push_symbol(SYMBOL_I);
		subst();
		p2 = pop();
	}

#ifndef LINUX

	// if we evaluated the symbol "a" and got "b" then print "a=b"

	// do not print "a=a"

	if (issymbol(p1) && !iskeyword(p1) && p1 != p2 && test_flag == 0) {
		push_symbol(SETQ);
		push(p1);
		push(p2);
		list(3);
		p2 = pop();
	}
#endif
	push(p2);

	restore();
}