コード例 #1
0
ファイル: compile.c プロジェクト: 1085164753/hopeless
/*
 * Generate the nodes of the matching tree given a path and a pattern.
 */
local void
gen_matches(int level, Path here, Expr *pattern)
{
	int	i;

	switch (pattern->e_class) {
	case E_CHAR:
		gen_char_match(level, here, pattern->e_char);
	when E_NUM:
		gen_num_match(level, here, pattern->e_num);
	when E_CONS:
		ASSERT( pattern->e_const->c_nargs == 0 );
		add_match(level, here, num_cases(pattern->e_const),
			pattern->e_const->c_index);
	when E_APPLY:
		gen_match_constr(level, &here, 0, pattern);
	when E_PLUS:
		for (i = 0; i < pattern->e_incr; i++) {
			add_match(level, here, NUMCASE, GREATER);
			here = p_push(P_PRED, here);
		}
		gen_matches(level, here, pattern->e_arg);
	when E_PAIR:
		gen_matches(level, p_push(P_LEFT, here), pattern->e_left);
		gen_matches(level, p_push(P_RIGHT, here), pattern->e_right);
	when E_VAR:
		;
	otherwise:
		NOT_REACHED;
	}
}
コード例 #2
0
ファイル: compile.c プロジェクト: 1085164753/hopeless
local void
gen_num_match(int level, Path here, Num n)
{
	if (n > Zero) {
		add_match(level, here, NUMCASE, GREATER);
		gen_num_match(level, p_push(P_PRED, here), n-1);
	} else
		add_match(level, here, NUMCASE, EQUAL);
}
コード例 #3
0
ファイル: compile.c プロジェクト: 1085164753/hopeless
/*
 * Similar wierd recursion to nv_constructor() (qv)
 */
local void
gen_match_constr(int level, Path *here_ptr, int arity, Expr *pattern)
{
	if (pattern->e_class == E_CONS) {
		if (pattern->e_const == succ) {
			add_match(level, *here_ptr, NUMCASE, GREATER);
			*here_ptr = p_push(P_PRED, *here_ptr);
		} else {
			add_match(level, *here_ptr,
				num_cases(pattern->e_const),
				pattern->e_const->c_index);
			*here_ptr = p_push(P_STRIP, *here_ptr);
		}
	} else {
		ASSERT( pattern->e_class == E_APPLY );
		gen_match_constr(level, here_ptr, arity+1, pattern->e_func);
		if (arity > 0) {
			gen_matches(level, p_push(P_LEFT, *here_ptr),
				pattern->e_arg);
			*here_ptr = p_push(P_RIGHT, *here_ptr);
		} else	/* last argument */
			gen_matches(level, *here_ptr, pattern->e_arg);
	}
}
コード例 #4
0
ファイル: exe_mkfile.c プロジェクト: carriercomm/FileSystem-2
void exe_mkfile(t_dir* lroot, char* name){
	char* fullname;
	t_metafile *f;

//	printf("Dir fullname: %s \n", lroot->fullname);	
	fullname = (char*)xmalloc(sizeof(char)* 1);
	fullname[0] = '\0';
	fullname = my_strconcat(fullname, lroot->fullname);
	fullname = my_strconcat(fullname, name);

	f = (t_metafile*)xmalloc(sizeof(t_metafile)*1);

	f->fullname = (char*)xmalloc(sizeof(char)*my_strlen(fullname)*1);
	my_strcpy(f->fullname, fullname);
	f->fullname[my_strlen(fullname)] = '\0';	
	
	f->path = (char*)xmalloc(sizeof(char)*(my_strlen(lroot->path)+1));
	my_strcpy(f->path,lroot->path); 
	f->path[my_strlen(lroot->path)] = '\0';

	f->filesize = 0;
	
	f->tv = time_stamp();
	
	f->LFile = create_Lfile(f->filesize);
	

	f->filename = (char*)xmalloc(sizeof(char)*(my_strlen(name)+1));
	my_strcpy(f->filename, name);
	f->path[my_strlen(lroot->path)] = '\0';

/*	printf("1: %s\n", f->filename);
	printf("2: %s\n", f->fullname);
	printf("3: %s\n", f->path);
	printf("4: %i\n", f->filesize);
	printf("5: %d\n", (int)f->tv);
	print_Ldisk();
*/
	p_push(lroot->GFiles, f, 0);
	gl_filecount++;

}