Exemple #1
0
//填充数组
void fill_vector(Cell* vec, Cell* fill_obj) {
	int num = long_value(vec) / 2 + long_value(vec) % 2;
	Cell* p = NULL;
	int i;
	for (i = 0; i < num; i++) {
		p = vec + 1 + i;
		p->_flag = T_PAIR;
		set_immutable(p);		//不可变的
		p->_pair._car = fill_obj;		//填充数组的内容
		p->_pair._cdr = fill_obj;		//填充数组的内容
	}
}
Exemple #2
0
// (error x y z ...)
Cell* op_err(Scheme *sc) {
	Cell *x;

	if (!is_string(car(sc->args))) {
		sc->args = cons(sc, make_string(sc, " -- "), sc->args);
		set_immutable(sc->args);
	}
	fprintf(stderr, "Error: ");
	fprintf(stderr, car(sc->args)->_string);
	sc->args = cdr(sc->args);

	for (x = sc->args; x != &g_nil; x = cdr(x)) {
		fprintf(stderr, cell2str(sc, car(x)));
	}
	fprintf(stderr, "\n");

	return s_return_helper(sc, &g_true);
}
Exemple #3
0
Cell* op_read_sexpr(Scheme *sc) {
	Cell* x;
	char *temp;

	switch (sc->token) {
	case TOK_EOF:
		return s_return_helper(sc, &g_eof);
	case TOK_VECTOR:
		s_save(sc, op_read_vec, &g_nil, &g_nil); //压入 数组 处理过程
		break;
		/* no break */
		/* fall through */
	case TOK_LPAREN:
		sc->token = token(sc);
		if (sc->token == TOK_RPAREN) {
			return s_return_helper(sc, &g_nil);
		} else if (sc->token == TOK_DOT) {
			return error_helper(sc, "syntax error: illegal dot expression",
			NULL);
		} else {
			//sc->nesting_stack[sc->top_file_index]++;
			s_save(sc, op_read_list, &g_nil, &g_nil); //压入读取列表的函数
			//读取S表达式
			sc->op = op_read_sexpr;
			return &g_true;
		}
	case TOK_QUOTE: //引用
		s_save(sc, op_read_quote, &g_nil, &g_nil); //压入 引用 处理函数
		sc->token = token(sc);
		//读取S表达式
		sc->op = op_read_sexpr;
		return &g_true;
	case TOK_ATOM: //原子
		temp = readstr_upto(sc, DELIMITERS);
		// printf("%s\n", temp);

		return s_return_helper(sc,
				make_atom_from_string(sc, temp));
	case TOK_DQUOTE: //双引号 (字符串类型的原子)
		x = readstrexp(sc);
		if (x == &g_false)
			return error_helper(sc, "Error reading string", NULL);
		set_immutable(x);
		return s_return_helper(sc, x);
	case TOK_SHARP: { //#是eval的简写吗?
		Cell* f = find_slot_in_env(sc, sc->env, sc->sym_sharp_hook, TRUE); //f的类型symbol_kv ,f是一段处理#的代码
		if (f == &g_nil)
			return error_helper(sc, "undefined sharp expression", NULL);
		sc->code = cons(sc, slot_value_in_env(f), &g_nil);
		sc->op = op_eval;
		return &g_true;
	}
		/* no break */
	case TOK_SHARP_CONST: //常量
		x = make_sharp_const(sc, readstr_upto(sc, DELIMITERS));
		if (x == &g_nil)
			return error_helper(sc, "undefined const sharp expression", NULL);
		return s_return_helper(sc, x);
	default:
		return error_helper(sc, "syntax error: illegal token", NULL);
	}

	return NULL;
}
Exemple #4
0
int main(int argc, char **argv)
{
	const char *path;
	char buf[5];
	int fd, rc;

	if (argc < 2) {
		fprintf(stderr, "usage: %s <path>\n", argv[0]);
		return EXIT_FAILURE;
	}

	path = argv[1];

	/* attributes: EFI_VARIABLE_NON_VOLATILE |
	 *		EFI_VARIABLE_BOOTSERVICE_ACCESS |
	 *		EFI_VARIABLE_RUNTIME_ACCESS
	 */
	*(uint32_t *)buf = 0x7;
	buf[4] = 0;

	/* create a test variable */
	fd = open(path, O_WRONLY | O_CREAT, 0600);
	if (fd < 0) {
		perror("open(O_WRONLY)");
		return EXIT_FAILURE;
	}

	rc = write(fd, buf, sizeof(buf));
	if (rc != sizeof(buf)) {
		perror("write");
		return EXIT_FAILURE;
	}

	close(fd);

	rc = get_immutable(path);
	if (rc < 0) {
		perror("ioctl(FS_IOC_GETFLAGS)");
		return EXIT_FAILURE;
	} else if (rc) {
		rc = set_immutable(path, 0);
		if (rc < 0) {
			perror("ioctl(FS_IOC_SETFLAGS)");
			return EXIT_FAILURE;
		}
	}

	fd = open(path, O_RDONLY);
	if (fd < 0) {
		perror("open");
		return EXIT_FAILURE;
	}

	if (unlink(path) < 0) {
		perror("unlink");
		return EXIT_FAILURE;
	}

	rc = read(fd, buf, sizeof(buf));
	if (rc > 0) {
		fprintf(stderr, "reading from an unlinked variable "
				"shouldn't be possible\n");
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}