예제 #1
0
void populate_reduce_function(
  struct Value * accumulator_key,
  struct Value * current_key,
  struct Tree * ast,
  struct Value * item,
  struct Value * accumulator){
    if(!ast->size && ast->type == 'k'){
        if(string_matches(&current_key->data.str, &ast->content.data.str)){
            if(item->type == 's'){
              ast->type = item->type;
            } else {
              ast->type = 'n';
            }
            ast->content = copy_value_stack(item);
        }
        else if(string_matches(&accumulator_key->data.str, &ast->content.data.str)){
            if(accumulator->type == 's'){
              ast->type = accumulator->type;
            } else {
              ast->type = 'n';
            }
            ast->content = copy_value_stack(accumulator);
        }
    } else if(ast->size > 0){
        for(int i = 0; i < ast->size; i++){
            populate_reduce_function(accumulator_key, current_key, ast->children[i], item, accumulator);
        }
    }
}
예제 #2
0
void populate_each_function(
  struct Value * item_key,
  struct Value * index_key,
  struct Tree * ast,
  struct Value * item,
  struct Value * index){
    if(!ast->size && ast->type == 'k'){
        if(string_matches(item_key->data.str, ast->content.data.str)){
            if(item->type == 's'){
              ast->type = item->type;
            } else {
              ast->type = 'n';
            }
            copy_value(&ast->content, item);
        }
        else if(string_matches(index_key->data.str, ast->content.data.str)){
            ast->type = 'n';
            copy_value(&ast->content, index);
        }
    } else if(ast->size > 0){
        for(int i = 0; i < ast->size; i++){
            populate_each_function(item_key, index_key, ast->children[i], item, index);
        }
    }
}
예제 #3
0
void
piglit_init(int argc, char *argv[])
{
	int i;

	piglit_require_extension("GL_ARB_vertex_buffer_object");

	for (i = 1; i < argc; i++) {
		if (string_matches(argv[i], "drawarrays"))
			mode = DRAWARRAYS;
		else if (string_matches(argv[i], "drawelements"))
			mode = DRAWELEMENTS;
		else if (string_matches(argv[i], "drawrangeelements"))
			mode = DRAWRANGEELEMENTS;
		else
			piglit_report_result(PIGLIT_FAIL);
	}
}
예제 #4
0
파일: execute.c 프로젝트: Delejnr/huo
struct Value execute (struct Tree * ast, struct Tree_map * defined, struct Map * let_map){
    struct Value result;
    // first check for special kinds of execution
    if(ast->type == 'k' && string_matches(&ast->content.data.str, &if_const)){
        return if_block(ast, defined, let_map);
    }
    else if(ast->type == 'k' && string_matches(&let_const, &ast->content.data.str)){
        store_let_binding(ast, defined, let_map);
        result.type = 'u';
    }
    else if(ast->type == 'k' && string_matches(&each_const, &ast->content.data.str)){
        for_each(ast, defined, let_map);
        result.type = 'u';
    }
    else if(ast->type == 'k' && string_matches(&map_const, &ast->content.data.str)){
        return map_array(ast, defined, let_map);
    }
    else if(ast->type == 'k' && string_matches(&reduce_const, &ast->content.data.str)){
        return reduce_array(ast, defined, let_map);
    }
    else if(ast->type == 'k' && string_matches(&set_const, &ast->content.data.str)){
        struct Value index = execute(ast->children[0], defined, let_map);
        struct Value item = execute(ast->children[1], defined, let_map);
        struct Value array = execute(ast->children[2], defined, let_map);
        result = array_set(index, item, array);
        return result;
    }
    else if(ast->type == 'k' && string_matches(&for_const, &ast->content.data.str)){
        for_loop(ast, defined, let_map);
        result.type = 'u'; //return undefined
    }
    else if(ast->type == 'k' && string_matches(&do_const, &ast->content.data.str)){
        for(int i = 0; i < ast->size; i++){
            if(i == ast->size-1){
                result = execute(ast->children[i], defined, let_map);
            } else {
                execute(ast->children[i], defined, let_map);
            }
        }
    }
    else if(ast->type == 'k' && string_matches(&read_const, &ast->content.data.str)){
        return read_file(ast->children[0]->content.data.str);
    }
    else if(ast->type == 'k' && string_matches(&substring_const, &ast->content.data.str)){
        struct Value string = execute(ast->children[2], defined, let_map);
        struct Value start = execute(ast->children[0], defined, let_map);
        struct Value end = execute(ast->children[1], defined, let_map);
        if(string.type != 's'){
            ERROR("Non-string value passed into substring: %c.", string.type);
            result.type = 'u';
            return result;
        } else {
            return substring(start.data.ln, end.data.ln, string);
        }
    }
    else if(ast->type == 'k' && string_matches(&switch_const, &ast->content.data.str)){
        return switch_case(ast, defined, let_map);
    }
    else if(ast->type == 'k' && string_matches(&parallel_const, &ast->content.data.str)){
        parallel_execution(ast, defined, let_map);
        result.type = 'u';
    } else {
        // no special execution types found, check for more basic conditions
        int idx;
        if(!ast->size){
            // ast with no children is either a value or a variable
            if(ast->type == 'k'){
                for(int i = 0; i < let_map->size; i++){
                    if(string_matches(&let_map->members[i]->key->data.str, &ast->content.data.str)){
                        return *let_map->members[i]->val;
                    }
                }
                ERROR("Undefined variable: %s", ast->content.data.str.body);
            } else {
                return ast->content;
            }
        }
        else if(ast->type == 'k' && (idx = is_defined_func(defined, ast->content.data.str)) > -1){
            return execute_defined_func(ast, defined, let_map, idx);
        }
        else if(ast->size == 1){
            struct Value a = execute(ast->children[0], defined, let_map);
            if(ast->type == 'k'){
                if(string_matches(&ast->content.data.str, &print_const)){
                    print(a);
                    printf("\n");
                    result.type = 'u';
                }
                else if(string_matches(&ast->content.data.str, &length_const)){
                    return length(a);
                }
                else if(string_matches(&ast->content.data.str, &return_const)){
                    return execute(ast->children[0], defined, let_map);
                }
            }
        }
        else if(ast->size == 2) {
            struct Value a = execute(ast->children[0], defined, let_map);
            struct Value b = execute(ast->children[1], defined, let_map);
            result = apply_core_function(ast, a, b);
        } else {
            result = reduce_ast(ast, defined, let_map);
        }
    }

    return result;
}