Example #1
0
void l_eval(const char *source, const char *source_file, LClosure *closure) {
  LAst ast = l_parse(source, source_file);
  list_iter_p iter = list_iterator(ast, FRONT);
  while(list_next(iter) != NULL) {
    l_eval_node((LNode*)list_current(iter), closure);
  }
}
Example #2
0
static int repl()
{
	l_vm *vm = l_vm_create("repl");
	vm_map_increfs(vm->root);
	while (1)
	{
		char *str = l_plat_readline("> ");
		if (str == NULL)
			return 1;

		l_scanner *stream = l_scanner_create_str(str);
		vm_var *v = l_vm_run(vm, l_parse(stream));

		char *s = vm_var_tostring(v);
		if (v->type == VAR_TYPE_ARRAY && v->var.array->type == VAR_TYPE_CHAR)
			printf("\"%s\"\n", s);
		else if (v->type == VAR_TYPE_CHAR)
			printf("'%s'\n", s);
		else
			printf("%s\n", s);

		free(str);

		l_vm_cleanup(vm);
	}
	vm_map_decrefs(vm->root);

	return 0;
}
Example #3
0
static int pretty(FILE *f)
{
	l_scanner *stream = l_scanner_create(f);
	l_p_expr_list *list = l_parse(stream);

	l_pretty_expr_list(list, 0, stdout);

	return 0;
}
Example #4
0
static int exec(FILE *f, char *fname)
{
	l_scanner *stream = l_scanner_create(f);
	l_p_expr_list *list = l_parse(stream);

	l_vm *vm = l_vm_create(fname);
	l_vm_run(vm, list);

	return 0;
}