//: Containers contain a fixed number of elements of different types. :(before "End Mu Types Initialization") //: We'll use this container as a running example, with two number elements. type_ordinal point = put(Type_ordinal, "point", Next_type_ordinal++); get_or_insert(Type, point); // initialize get(Type, point).kind = CONTAINER; get(Type, point).name = "point"; get(Type, point).elements.push_back(reagent("x:number")); get(Type, point).elements.push_back(reagent("y:number")); //: Containers can be copied around with a single instruction just like //: numbers, no matter how large they are. //: Tests in this layer often explicitly set up memory before reading it as a //: container. Don't do this in general. I'm tagging exceptions with /raw to //: avoid errors. :(scenario copy_multiple_locations) def main [ 1:number <- copy 34 2:number <- copy 35 3:point <- copy 1:point/unsafe ] +mem: storing 34 in location 3 +mem: storing 35 in location 4 //: trying to copy to a differently-typed destination will fail :(scenario copy_checks_size) % Hide_errors = true; def main [ 2:point <- copy 1:number ] +error: main: can't copy 1:number to 2:point; types don't match :(before "End Mu Types Initialization") // A more complex container, containing another container as one of its // elements. type_ordinal point_number = put(Type_ordinal, "point-number", Next_type_ordinal++); get_or_insert(Type, point_number); // initialize get(Type, point_number).kind = CONTAINER; get(Type, point_number).name = "point-number"; get(Type, point_number).elements.push_back(reagent("xy:point")); get(Type, point_number).elements.push_back(reagent("z:number")); :(scenario copy_handles_nested_container_elements) def main [ 12:number <- copy 34 13:number <- copy 35 14:number <- copy 36 15:point-number <- copy 12:point-number/unsafe ] +mem: storing 36 in location 17 //: products of recipes can include containers :(scenario return_container) def main [ 3:point <- f 2 ] def f [ 12:number <- next-ingredient 13:number <- copy 35 return 12:point/raw ] +run: result 0 is [2, 35] +mem: storing 2 in location 3 +mem: storing 35 in location 4 //: Containers can be checked for equality with a single instruction just like //: numbers, no matter how large they are. :(scenario compare_multiple_locations) def main [ 1:number <- copy 34 # first 2:number <- copy 35 3:number <- copy 36 4:number <- copy 34 # second 5:number <- copy 35 6:number <- copy 36 7:boolean <- equal 1:point-number/raw, 4:point-number/unsafe ] +mem: storing 1 in location 7 :(scenario compare_multiple_locations_2) def main [ 1:number <- copy 34 # first 2:number <- copy 35 3:number <- copy 36 4:number <- copy 34 # second 5:number <- copy 35 6:number <- copy 37 # different 7:boolean <- equal 1:point-number/raw, 4:point-number/unsafe ] +mem: storing 0 in location 7 //: Global data structure for container metadata. //: Can't put this in type_info because later layers will add support for more //: complex type trees where metadata depends on *combinations* of types. :(before "struct reagent") struct container_metadata { int size; vector offset; // End container_metadata Fields container_metadata() :size(0) { // End container_metadata Constructor } }; :(before "End reagent Fields") container_metadata metadata; // can't be a pointer into Container_metadata because we keep changing the base storage when we save/restore snapshots :(before "End reagent Copy Operator") metadata = other.metadata; :(before "End reagent Copy Constructor") metadata = other.metadata; :(before "End Globals") // todo: switch to map after figuring out how to consistently compare type trees vector > Container_metadata, Container_metadata_snapshot; :(before "End save_snapshots") Container_metadata_snapshot = Container_metadata; :(before "End restore_snapshots") restore_container_metadata(); :(before "End One-time Setup") atexit(clear_container_metadata); :(code) // invariant: Container_metadata always contains a superset of Container_metadata_snapshot void restore_container_metadata() { for (int i = 0; i < SIZE(Container_metadata); ++i) { assert(Container_metadata.at(i).first); if (i < SIZE(Container_metadata_snapshot)) { assert(Container_metadata.at(i).first == Container_metadata_snapshot.at(i).first); continue; } delete Container_metadata.at(i).first; Container_metadata.at(i).first = NULL; } Container_metadata.resize(SIZE(Container_metadata_snapshot)); } void clear_container_metadata() { Container_metadata_snapshot.clear(); for (int i = 0; i < SIZE(Container_metadata); ++i) { delete Container_metadata.at(i).first; Container_metadata.at(i).first = NULL; } Container_metadata.clear(); } //: do no work in size_of, simply lookup Container_metadata :(before "End size_of(reagent r) Cases") if (r.metadata.size) return r.metadata.size; :(before "End size_of(type) Cases") if (type->value == -1) return 1; // error value, but we'll raise it e
# gridwm - grid window manager
#   (C)opyright MMVI Anselm R. Garbe

include config.mk

WMSRC = bar.c client.c cmd.c draw.c event.c key.c util.c wm.c
WMOBJ = ${WMSRC:.c=.o}
MENSRC = menu.c draw.c util.c
MENOBJ = ${MENSRC:.c=.o}
SELSRC = gridsel.c util.c
SELOBJ = ${SELSRC:.c=.o}
MAN1 = gridwm.1 gridmenu.1
BIN = gridwm gridmenu gridsel 

all: config gridwm gridmenu gridsel
	@echo finished

config:
	@echo gridwm build options:
	@echo "LIBS     = ${LIBS}"
	@echo "CFLAGS   = ${CFLAGS}"
	@echo "LDFLAGS  = ${LDFLAGS}"
	@echo "CC       = ${CC}"

.c.o:
	@echo CC $<
	@${CC} -c ${CFLAGS} $<

${WMOBJ}: wm.h draw.h config.h util.h

gridmenu: ${MENOBJ}
	@echo LD $@
	@${CC} -o $@ ${MENOBJ} ${LDFLAGS}

gridwm: ${WMOBJ}
	@echo LD $@
	@${CC} -o $@ ${WMOBJ} ${LDFLAGS}

gridsel: ${SELOBJ}
	@echo LD $@
	@${CC} -o $@ ${SELOBJ} ${LDFLAGS}

clean:
	rm -f gridwm gridmenu *.o core

dist: clean
	mkdir -p gridwm-${VERSION}
	cp -R Makefile README LICENSE config.mk *.h *.c ${MAN} gridwm-${VERSION}
	tar -cf gridwm-${VERSION}.tar gridwm-${VERSION}
	gzip gridwm-${VERSION}.tar
	rm -rf gridwm-${VERSION}

install: all
	@mkdir -p ${DESTDIR}${PREFIX}/bin
	@cp -f ${BIN} ${DESTDIR}${PREFIX}/bin
	@echo installed executable files to ${DESTDIR}${PREFIX}/bin
	@mkdir -p ${DESTDIR}${MANPREFIX}/man1
	@cp -f ${MAN1} ${DESTDIR}${MANPREFIX}/man1
	@echo installed manual pages to ${DESTDIR}${MANPREFIX}/man1

uninstall:
	for i in ${BIN}; do \
		rm -f ${DESTDIR}${PREFIX}/bin/`basename $$i`; \
	done
	for i in ${MAN1}; do \
		rm -f ${DESTDIR}${MANPREFIX}/man1/`basename $$i`; \
	done
" a:number\n" "]\n"); // try to extend the container after transform transform_all(); CHECK_TRACE_DOESNT_CONTAIN_ERROR(); Hide_errors = true; run("container foo [\n" " b:number\n" "]\n"); CHECK_TRACE_CONTAINS_ERROR(); } //:: Allow container definitions anywhere in the codebase, but complain if you //:: can't find a definition at the end. :(scenario run_complains_on_unknown_types) % Hide_errors = true; def main [ # integer is not a type 1:integer <- copy 0 ] +error: main: unknown type integer in '1:integer <- copy 0' :(scenario run_allows_type_definition_after_use) def main [ 1:bar <- copy 0/unsafe ] container bar [ x:number ] $error: 0 :(after "Begin Instruction Modifying Transforms") // Begin Type Modifying Transforms Transform.push_back(check_or_set_invalid_types); // idempotent // End Type Modifying Transforms :(code) void check_or_set_invalid_types(const recipe_ordinal r) { recipe& caller = get(Recipe, r); trace(9991, "transform") << "--- check for invalid types in recipe " << caller.name << end(); for (int index = 0; index < SIZE(caller.steps); ++index) { instruction& inst = caller.steps.at(index); for (int i = 0; i < SIZE(inst.ingredients); ++i) check_or_set_invalid_types(inst.ingredients.at(i).type, maybe(caller.name), "'"+to_original_string(inst)+"'"); for (int i = 0; i < SIZE(inst.products); ++i) check_or_set_invalid_types(inst.products.at(i).type, maybe(caller.name), "'"+to_original_string(inst)+"'"); } // End check_or_set_invalid_types } void check_or_set_invalid_types(type_tree* type, const string& block, const string& name) { if (!type) return; // will throw a more precise error elsewhere // End Container Type Checks if (type->value == 0) return; if (!contains_key(Type, type->value)) { assert(!type->name.empty()); if (contains_key(Type_ordinal, type->name)) type->value = get(Type_ordinal, type->name); else raise << block << "unknown type " << type->name << " in " << name << '\n' << end(); } check_or_set_invalid_types(type->left, block, name); check_or_set_invalid_types(type->right, block, name); } :(scenario container_unknown_field) % Hide_errors = true; container foo [ x:number y:bar ] +error: foo: unknown type in y :(scenario read_container_with_bracket_in_comment) container foo [ x:number # ']' in comment y:number ] +parse: --- defining container foo +parse: element: {x: "number"} +parse: element: {y: "number"} :(before "End transform_all") check_container_field_types(); :(code) void check_container_field_types() { for (map::iterator p = Type.begin(); p != Type.end(); ++p) { const type_info& info = p->second; // Check Container Field Types(info) for (int i = 0; i < SIZE(info.elements); ++i) check_invalid_types(info.elements.at(i).type, maybe(info.name), info.elements.at(i).name); } } void check_invalid_types(const type_tree* type, const string& block, const string& name) { if (!type) return; // will throw a more precise error elsewhere if (type->value == 0) { assert(!type->left && !type->right); return; } if (!contains_key(Type, type->value)) raise << block << "unknown type in " << name << '\n' << end(); check_invalid_types(type->left, block, name); check_invalid_types(type->right, block, name); }