Exemplo n.º 1
0
enum dylan_type_enum
dylan_type (D instance) {
  if ((DUMINT)instance & 3) {
    if ((DUMINT)instance & 1)
      return(integer_type);
    else if ((DUMINT)instance & 2)
      return(character_type);
    else
      return(unknown_type);
  } else { /* dylan pointer */
    if (float_p(instance))
      return(float_type);
    else if (boolean_p(instance))
      return(dylan_boolean_type);
    else if (string_p(instance))
      return(string_type);
    else if (vector_p(instance))
      return(vector_type);
    else if (pair_p(instance))
      return(pair_type);
    else if (empty_list_p(instance))
      return(empty_list_type);
    else if (symbol_p(instance))
      return(symbol_type);
    else if (simple_condition_p(instance))
      return(simple_condition_type);
    else if (class_p(instance))
      return(class_type);
    else if (function_p(instance))
      return(function_type);
    else
      return(user_defined_type);
  }
}
Exemplo n.º 2
0
cons_t *do_macros(cons_t *rprog, dict_t **scope) {
	dict_t *symbol;
	value_t val;
	cons_t *stack = NULL;

	while (rprog != NULL) {
		val = list_peek(rprog);
		if (symbol_p(val) && macro_p(unwrap_symbol(val))) {
			symbol = unwrap_symbol(val);
			unwrap_native(value(symbol))(&stack, scope);
		} else {
			list_push(&stack, val);
		}
		rprog = list_next(rprog);
	}

	return stack;
}
Exemplo n.º 3
0
Arquivo: eval.c Projeto: fisxoj/glisp
object *eval (object *o)
{
  /* printf("%s: Trying to eval object type: %d\n", __func__, o->type); */

if (is_truthy (atom (o))) {
  if (symbol_p (o)) {
    /* printf("%s: Looking for symbol\n", __func__); */
    return env_find_symbol_value (current_env, o);
  } else {
    /* printf("%s: Not eval-ing\n", __func__); */
    return o;
  }
 } else {
  /* printf("%s: Function call\n", __func__); */
    object *symbol = car (o);
    object *arguments = cdr (o);

    return call_function (symbol, arguments);
  }
}
Exemplo n.º 4
0
/*
 * ~~ a brief interlude about the executor ~~
 *
 * The executor takes a function, which is a list of values, the 
 * current stack, which it may modify, and a scope, which it will not modify.
 *
 * It uses the following algorithm to execute the function:
 * 1. Get the next value. if there are no more values, end.
 *   a. if the value is a number, push it onto the stack
 *   b. if the value is a function, call it with the current stack and scope
 *     1. if the function is a native, call it directly
 *     2. otherwise, call execute() on it
 * 2. Go to 1.
 */
void execute(cons_t *prog, cons_t **stack, dict_t **scope) {
	dict_t *symbol;
	value_t val;

	while (prog != NULL) {
		val = CAR(prog);
		if (number_p(val)) {
			list_push(stack, val);
		} else if (symbol_p(val)) {
			symbol = unwrap_symbol(val);
			val = value(symbol);
			if (null_p(val)) {
				fprintf(stderr, "%s? ", key(symbol));
				break;
			} else {
				unwrap_native(val)(stack, scope);
			}
		} else {
			printf("OH DANG BRO %d:%ld\n", val.storage, val.value.literal);
		}
		prog = list_next(prog);
	}
}