コード例 #1
0
ファイル: evaluator.c プロジェクト: mishraritvik/personal
Value * bind_names_values(Environment *env, Value *names, Value *values) {

    assert(env != NULL);
    assert(names != NULL);
    assert(values != NULL);

    /* Bind each value under its specified name. */
    while (is_cons_pair(names)) {
        Value *argname = get_car(names);

        if (is_nil(values))
            return make_error("not enough values to complete bindings!");

        assert(is_cons_pair(values));

        create_binding(env, argname->string_val, get_car(values));

        names = get_cdr(names);
        values = get_cdr(values);
    }

    assert(is_nil(names));
    if (!is_nil(values))
        return make_error("too many values for the specified bindings!");

    return NULL;
}
コード例 #2
0
ファイル: ShaderModuleBase.cpp プロジェクト: gan74/Yave
static auto create_bindings(const spirv_cross::Compiler& compiler, const std::vector<spirv_cross::Resource>& resources, ShaderType shader_type, vk::DescriptorType type) {
	auto bindings = std::unordered_map<u32, core::Vector<vk::DescriptorSetLayoutBinding>>();
	for(const auto& r : resources) {
		auto id = r.id;
		bindings[compiler.get_decoration(id, spv::DecorationDescriptorSet)] << create_binding(compiler.get_decoration(id, spv::DecorationBinding), shader_type, type);
	}
	return bindings;
}
コード例 #3
0
ファイル: evaluator.c プロジェクト: mishraritvik/personal
/*!
 * Creates and initializes a new environment struct for the global environment.
 * The global environment is the root of all other environments, and has a
 * couple of unique characteristics.  First, it has no parent environment
 * (obvious, since it's the root of all environments).  Second, all built-in
 * functions are bound into this environment.
 */
Environment * init_global_environment(void) {
    NativeLambdaBinding *binding;

    assert(global_env == NULL);
    global_env = make_environment(NULL);

    binding = native_lambdas;
    while (binding->name != NULL) {
        create_binding(global_env, binding->name,
                       make_native_lambda(global_env, binding->func));

        binding++;
    }

    return global_env;
}
コード例 #4
0
ファイル: obs-hotkey.c プロジェクト: Bl00drav3n/obs-studio
void obs_hotkey_load_bindings(obs_hotkey_id id,
		obs_key_combination_t *combinations, size_t num)
{
	size_t idx;

	if (!lock())
		return;

	if (find_id(id, &idx)) {
		obs_hotkey_t *hotkey = &obs->hotkeys.hotkeys.array[idx];
		remove_bindings(id);
		for (size_t i = 0; i < num; i++)
			create_binding(hotkey, combinations[i]);

		hotkey_signal("hotkey_bindings_changed", hotkey);
	}
	unlock();
}
コード例 #5
0
ファイル: obs-hotkey.c プロジェクト: Bl00drav3n/obs-studio
static inline void load_binding(obs_hotkey_t *hotkey, obs_data_t *data)
{
	if (!hotkey || !data)
		return;

	obs_key_combination_t combo = {0};
	uint32_t *modifiers = &combo.modifiers;
	load_modifier(modifiers, data, "shift", INTERACT_SHIFT_KEY);
	load_modifier(modifiers, data, "control", INTERACT_CONTROL_KEY);
	load_modifier(modifiers, data, "alt", INTERACT_ALT_KEY);
	load_modifier(modifiers, data, "command", INTERACT_COMMAND_KEY);

	combo.key = obs_key_from_name(obs_data_get_string(data, "key"));
	if (!modifiers && (combo.key == OBS_KEY_NONE ||
			   combo.key >= OBS_KEY_LAST_VALUE))
		return;

	create_binding(hotkey, combo);
}
コード例 #6
0
ファイル: evaluator.c プロジェクト: mishraritvik/personal
/*!
 * This helper function takes an interpreted lambda expression, a list of
 * evaluated operands for the lambda, and the environment that the lambda will
 * be run in, and binds each operand into the environment with the argument name
 * specified in the lambda's argument list.
 *
 * The function returns NULL on success, or a Value* of type T_Error if
 * something horrible happens along the way.  For example, the function may
 * receive too many or too few arguments, or the interpreter may not have enough
 * memory to construct a specific binding.
 */
Value * bind_arguments(Environment *child_env, Lambda *lambda, Value *operands) {
    Value *argname_iter, *argval_iter;

    assert(child_env != NULL);
    assert(lambda != NULL);
    assert(!lambda->native_impl);
    assert(operands != NULL);

    /* Populate the child environment with values based on the lambda's
     * argument-specification, and the input operands.
     */
    argname_iter = lambda->arg_spec;
    argval_iter = operands;
    if (is_atom(argname_iter)) {
        /* Entire operand list gets bound under a single name. */
        create_binding(child_env, argname_iter->string_val, operands);
    }
    else {
        /* Bind each operand under its specified name.
         *
         * TODO:  Find a way to use bind_names_values(), one day...
         */
        assert(is_cons_pair(argname_iter));
        do {
            Value *argname = get_car(argname_iter);

            if (is_nil(argval_iter))
                return make_error("not enough arguments for lambda!");

            assert(is_cons_pair(operands));

            create_binding(child_env, argname->string_val,
                           get_car(argval_iter));

            argname_iter = get_cdr(argname_iter);
            argval_iter = get_cdr(argval_iter);
        }
        while (is_cons_pair(argname_iter));

        if (is_nil(argname_iter) && !is_nil(argval_iter))
            return make_error("too many arguments for lambda!");

        /* If argname_iter is an atom then the argument-list was an improper
         * list, and the remainder of the operands get bound under this name.
         */
        if (is_atom(argname_iter)) {
            create_binding(child_env, argname_iter->string_val, argval_iter);
        }
        else {
            /* The lambda special-form should have constructed the argument
             * specification properly, so this assertion should never fail.
             */
            assert(is_nil(argname_iter));
        }
    }

    /* NULL just means "success" here.  The only other thing this function might
     * return is a Value of type T_Error, if something awful happened...
     */
    return NULL;
}