//: Arrays contain a variable number of elements of the same type. Their value //: starts with the length of the array. //: //: You can create arrays of containers, but containers can only contain //: elements of a fixed size, so you can't create containers containing arrays. //: Create containers containing addresses to arrays instead. //: You can create arrays using 'create-array'. :(scenario create_array) def main [ # create an array occupying locations 1 (for the size) and 2-4 (for the elements) 1:array:num:3 <- create-array ] +run: creating array from 4 locations :(before "End Primitive Recipe Declarations") CREATE_ARRAY, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "create-array", CREATE_ARRAY); :(before "End Primitive Recipe Checks") case CREATE_ARRAY: { if (inst.products.empty()) { raise << maybe(get(Recipe, r).name) << "'create-array' needs one product and no ingredients but got '" << to_original_string(inst) << '\n' << end(); break; } reagent/*copy*/ product = inst.products.at(0); // Update CREATE_ARRAY product in Check if (!is_mu_array(product)) { raise << maybe(get(Recipe, r).name) << "'create-array' cannot create non-array '" << product.original_string << "'\n" << end(); break; } if (!product.type->right) { raise << maybe(get(Recipe, r).name) << "create array of what? '" << to_original_string(inst) << "'\n" << end(); break; } // 'create-array' will need to check properties rather than types type_tree* array_length_from_type = product.type->right->right; if (!array_length_from_type) { raise << maybe(get(Recipe, r).name) << "create array of what size? '" << to_original_string(inst) << "'\n" << end(); break; } if (!product.type->right->right->atom) array_length_from_type = array_length_from_type->left; if (!is_integer(array_length_from_type->name)) { raise << maybe(get(Recipe, r).name) << "'create-array' product should specify size of array after its element type, but got '" << product.type->right->right->name << "'\n" << end(); break; } break; } :(before "End Primitive Recipe Implementations") case CREATE_ARRAY: { reagent/*copy*/ product = current_instruction().products.at(0); // Update CREATE_ARRAY product in Run int base_address = product.value; type_tree* array_length_from_type = product.type->right->right; if (!product.type->right->right->atom) array_length_from_type = array_length_from_type->left; int array_length = to_integer(array_length_from_type->name); // initialize array length, so that size_of will work trace("mem") << "storing " << array_length << " in location " << base_address << end(); put(Memory, base_address, array_length); // in array elements int size = size_of(product); // in locations trace(9998, "run") << "creating array from " << size << " locations" << end(); // initialize array for (int i = 1; i <= size_of(product); ++i) put(Memory, base_address+i, 0); // no need to update product write_products = false; break; } :(scenario copy_array) # Arrays can be copied around with a single instruction just like numbers, # no matter how large they are. # You don't need to pass the size around, since each array variable stores its # size in memory at run-time. We'll call a variable with an explicit size a # 'static' array, and one without a 'dynamic' array since it can contain # arrays of many different sizes. def main [ 1:array:num:3 <- create-array 2:num <- copy 14 3:num <- copy 15 4:num <- copy 16 5:array:num <- copy 1:array:num:3 ] +mem: storing 3 in location 5 +mem: storing 14 in location 6 +mem: storing 15 in location 7 +mem: storing 16 in location 8 :(scenario stash_array) def main [ 1:array:num:3 <- create-array 2:num <- copy 14 3:num <- copy 15 4:num <- copy 16 stash [foo:], 1:array:num:3 ] +app: foo: 3 14 15 16 :(before "End types_coercible Special-cases") if (is_mu_array(from) && is_mu_array(to)) return types_strictly_match(array_element(from.type), array_element(to.type)); :(before "End size_of(reagent r) Special-cases") if (!r.type->atom && r.type->left->atom && r.type->left->value == Array_type_ordinal) { if (!r.type->right) { raise << maybe(current_recipe_name()) << "'" << r.original_string << "' is an array of what?\n" << end(); return 1; } return /*space for length*/1 + array_length(r)*size_of(array_element(r.type)); } :(before "End size_of(type) Non-atom Special-cases") if (type->left->value == Array_type_ordinal) return static_array_length(type); :(code) int static_array_length(const type_tree* type) { if (!type->atom && type->right && !type->right->atom && type->right->right && !type->right->right->atom && !type->right->right->right // exactly 3 types && type->right->right->left && type->right->right->left->atom && is_integer(type->right->right->left->name)) { // third 'type' is a number // get size from type return to_integer(type->right->right->left->name); } cerr << to_string(type) << '\n'; assert(false); } //: disable the size mismatch check for arrays since the destination array //: need not be initialized :(before "End size_mismatch(x) Special-cases") if (x.type && !x.type->atom && x.type->left->value == Array_type_ordinal) return false; //:: arrays inside containers //: arrays are disallowed inside containers unless their length is fixed in //: advance :(scenario container_permits_static_array_element) container foo [ x:array:num:3 ] $error: 0 :(before "End insert_container Special-cases") else if (is_integer(type->name)) { // sometimes types will contain non-type tags, like numbers for the size of an array type->value = 0; } :(scenario container_disallows_dynamic_array_element) % Hide_errors = true; container foo [ x:array:num ] +error: container 'foo' cannot determine size of element 'x' :(before "End Load Container Element Definition") { const type_tree* type = info.elements.back().type; if (type && type->atom && type->name == "array") { raise << "container '" << name << "' doesn't specify type of array elements for '" << info.elements.back().name << "'\n" << end(); continue; } if (type && !type->atom && type->left->atom && type->left->name == "array") { if (!type->right) { raise << "container '" << name << "' doesn't specify type of array elements for '" << info.elements.back().name << "'\n" << end(); continue; } if (!type->right->right || !is_integer(type->right->right->left->name)) { // array has no length raise << "container '" << name << "' cannot determine size of element '" << info.elements.back().name << "'\n" << end(); continue; } } } //: disable the size mismatch check for 'merge' instructions since containers //: can contain arrays, and since we already do plenty of checking for them :(before "End size_mismatch(x) Special-cases") if (current_call().running_step_index < SIZE(get(Recipe, current_call().running_recipe).steps) && current_instruction().operation == MERGE) { return false; } :(scenario merge_static_array_into_container) container foo [ x:num y:array:num:3 ] def main [ 1:array:num:3 <- create-array 10:foo <- merge 34, 1:array:num:3 ] # no errors :(scenario code_inside_container) % Hide_errors = true; container card [ rank:num <- next-ingredient ] def foo [ 1:card <- merge 3 2:num <- get 1:card rank:offset ] # shouldn't die //:: To access elements of an array, use 'index' :(scenario index) def main [ 1:array:num:3 <- create-array 2:num <- copy 14 3:num <- copy 15 4:num <- copy 16 10:num <- index 1:array:num:3, 0/index # the index must be a non-negative whole number ] +mem: storing 14 in location 10 :(scenario index_compound_element) def main [ {1: (array (address number) 3)} <- create-array # skip alloc id 3:num <- copy 14 # skip alloc id 5:num <- copy 15 # skip alloc id 7:num <- copy 16 10:address:num <- index {1: (array (address number) 3)}, 0 ] # skip alloc id +mem: storing 14 in location 11 :(scenario index_direct_offset) def main [ 1:array:num:3 <- create-array 2:num <- copy 14 3:num <- copy 15 4:num <- copy 16 10:num <- copy 0 20:num <- index 1:array:num, 10:num ] +mem: storing 14 in location 20 :(before "End Primitive Recipe Declarations") INDEX, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "index", INDEX); :(before "End Primitive Recipe Checks") case INDEX: { if (SIZE(inst.ingredients) != 2) { raise << maybe(get(Recipe, r).name) << "'index' expects exactly 2 ingredients in '" << to_original_string(inst) << "'\n" << end(); break; } reagent/*copy*/ base = inst.ingredients.at(0); // Update INDEX base in Check if (!is_mu_array(base)) { raise << maybe(get(Recipe, r).name) << "'index' on a non-array '" << base.original_string << "'\n" << end(); break; } reagent/*copy*/ index = inst.ingredients.at(1); // Update INDEX index in Check if (!is_mu_number(index)) { raise << maybe(get(Recipe, r).name) << "second ingredient of 'index' should be a number, but got '" << index.original_string << "'\n" << end(); break; } if (inst.products.empty()) break; reagent/*copy*/ product = inst.products.at(0); // Update INDEX product in Check reagent/*local*/ element(copy_array_element(base.type)); if (!types_coercible(product, element)) { raise << maybe(get(Recipe, r).name) << "'index' on '" << base.original_string << "' can't be saved in '" << product.original_string << "'; type should be '" << names_to_string_without_quotes(element.type) << "'\n" << end(); break; } break; } :(before "End Primitive Recipe Implementations") case INDEX: { reagent/*copy*/ base = current_instruction().ingredients.at(0); // Update INDEX base in Run int base_address = base.value; trace(9998, "run") << "base address is " << base_address << end(); if (base_address == 0) { raise << maybe(current_recipe_name()) << "tried to access location 0 in
Name:		profanity
Version:	0.5.0
Release:	2%{?dist}
Summary:	A console based XMPP client

Group:		Application/System
License:	GPL
URL:		http://www.profanity.im/
Source0:	%{name}-%{version}.tar.gz

BuildRequires:	libstrophe-devel
BuildRequires:	libcurl-devel
BuildRequires:	ncurses-devel
BuildRequires:	openssl-devel
BuildRequires:	glib2-devel
BuildRequires:	expat-devel
BuildRequires:	libotr-devel
BuildRequires:	gnutls-devel
Requires:	libstrophe
Requires:	libcurl
Requires:	ncurses-libs
Requires:	openssl
Requires:	glib2
Requires:	expat
Requires:	libotr
Requires:	gnutls

%description
Profanity is a console based XMPP client written in C using ncurses and libstrophe, inspired by Irssi.

%prep
%setup -q

%build
%configure
make %{?_smp_mflags}

%install
make install DESTDIR=%{buildroot}

%files
%{_bindir}/profanity
%doc %{_datadir}/man/man1/profanity.1.gz

%changelog
k; } //: optimization: none of the instructions in this layer use 'ingredients' so //: stop copying potentially huge arrays into it. :(before "End should_copy_ingredients Special-cases") recipe_ordinal r = current_instruction().operation; if (r == CREATE_ARRAY || r == INDEX || r == PUT_INDEX || r == LENGTH) return false;