Beispiel #1
0
NValue
n_symbol_pool_get_symbol(const char* contents, NError* error) {
    n_error_clear(error);
    if (contents != NULL) {
        int32_t index = _find_symbol(contents);
        if (index < 0) {
            const char* dup_contents = duplicate_string(contents);
            if (dup_contents == NULL) {
                n_error_set(error, N_E_BAD_ALLOCATION);
                n_error_set_msg(error, "contents");
                return N_UNDEFINED;
            }
            index = n_symbol_array_append(&_pool, dup_contents);
            if (index < 0) {
                n_error_set(error, N_E_BAD_ALLOCATION);
                n_error_set_msg(error, "inner-pool");
                return N_UNDEFINED;
            }
        }
        return n_wrap_symbol(index);
    }
    else {
        n_error_set(error, N_E_INVALID_ARGUMENT);
        n_error_set_msg(error, "contents");
        return N_UNDEFINED;
    }
}
var_info Symbol_Table::insert_symbol(std::string s, oper_type o){
	//find variable 
	int level;
	var_info result = _find_symbol(s, &level);

	if (result.type != EMP && level == 0){
		return{ USD, result.name };
	}
	else{
		std::stringstream var_name;
		var_name << "var" << var_count++;
		scopes.back().insert(std::pair<std::string, var_info>(s, { o, var_name.str() }));
		return{ o, var_name.str() };
	}

}
var_info Symbol_Table::find_symbol(std::string s){
	int level;
	return _find_symbol(s, &level);

}