# # # The Nim Compiler # (c) Copyright 2017 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. # import ast, renderer, msgs, options, lineinfos, idents, treetab import std/[intsets, tables, sequtils, strutils, sets, strformat, hashes] when defined(nimPreviewSlimSystem): import std/assertions # IMPORTANT: notes not up to date, i'll update this comment again # # notes: # # Env: int => nilability # a = b # nilability a <- nilability b # deref a # if Nil error is nil # if MaybeNil error might be nil, hint add if isNil # if Safe fine # fun(arg: A) # nilability arg <- for ref MaybeNil, for not nil or others Safe # map is env? # a or b # each one forks a different env # result = union(envL, envR) # a and b # b forks a's env # if a: code # result = union(previousEnv after not a, env after code) # if a: b else: c # result = union(env after b, env after c) # result = b # nilability result <- nilability b, if return type is not nil and result not safe, error # return b # as result = b # try: a except: b finally: c # in b and c env is union of all possible try first n lines, after union of a and b and c # keep in mind canRaise and finally # case a: of b: c # similar to if # call(arg) # if it returns ref, assume it's MaybeNil: hint that one can add not nil to the return type # call(var arg) # zahary comment # if arg is ref, assume it's MaybeNil after call # loop # union of env for 0, 1, 2 iterations as Herb Sutter's paper # why 2? # return # if something: stop (break return etc) # is equivalent to if something: .. else: remain # new(ref) # ref becomes Safe # objConstr(a: b) # returns safe # each check returns its nilability and map type SeqOfDistinct[T, U] = distinct seq[U] # TODO use distinct base type instead of int? func `[]`[T, U](a: SeqOfDistinct[T, U], index: T): U = (seq[U])(a)[index.int] proc `[]=`[T, U](a: var SeqOfDistinct[T, U], index: T, value: U) = ((seq[U])(a))[index.int] = value func `[]`[T, U](a: var SeqOfDistinct[T, U], index: T): var U = (seq[U])(a)[index.int] func len[T, U](a: SeqOfDistinct[T, U]): T = (seq[U])(a).len.T func low[T, U](a: SeqOfDistinct[T, U]): T = (seq[U])(a).low.T func high[T, U](a: SeqOfDistinct[T, U]): T = (seq[U])(a).high.T proc setLen[T, U](a: var SeqOfDistinct[T, U], length: T) = ((seq[U])(a)).setLen(length.Natural) proc newSeqOfDistinct[T, U](length: T = 0.T): SeqOfDistinct[T, U] = (SeqOfDistinct[T, U])(newSeq[U](length.int)) func newSeqOfDistinct[T, U](length: int = 0): SeqOfDistinct[T, U] = # newSeqOfDistinct(length.T) # ? newSeqOfDistinct[T, U](length.T) (SeqOfDistinct[T, U])(newSeq[U](length)) iterator items[T, U](a: SeqOfDistinct[T, U]): U = for element in (seq[U])(a): yield element iterator pairs[T, U](a: SeqOfDistinct[T, U]): (T, U) = for i, element in (seq[U])(a): yield (i.T, element) func `$`[T, U](a: SeqOfDistinct[T, U]): string = $((seq[U])(a)) proc add*[T, U](a: var SeqOfDistinct[T, U], value: U) = ((seq[U])(a)).add(value) type ## a hashed representation of a node: should be equal for structurally equal nodes Symbol = distinct int ## the index of an expression in the pre-indexed sequence of those ExprIndex = distinct int16 ## the set index SetIndex = distinct int ## transition kind: ## what was the reason for changing the nilability of an expression ## useful for error messages and showing why an expression is being detected as nil / maybe nil TransitionKind = enum TArg, TAssign, TType, TNil, TVarArg, TResult, TSafe, TPotentialAlias, TDependant ## keep history for each transition History = object info: TLineInfo ## the location nilability: Nilability ## the nilability kind: TransitionKind ## what kind of transition was that node: PNode ## the node of the expression ## the context for the checker: an instance for each procedure NilCheckerContext = ref object # abstractTime: AbstractTime # partitions: Partitions # symbolGraphs: Table[Symbol, ] symbolIndices: Table[Symbol, ExprIndex] ## index for each symbol expressions: SeqOfDistinct[ExprIndex, PNode] ## a sequence of pre-indexed expressions dependants: SeqOfDistinct[ExprIndex, IntSet] ## expr indices for expressions which are compound and based on others warningLocations: HashSet[TLineInfo] ## warning locations to check we don't warn twice for stuff like warnings in for loops idgen: IdGenerator ## id generator config: ConfigRef ## the config of the compiler ## a map that is containing the current nilability for usually a branch ## and is pointing optionally to a parent map: they make a stack of maps NilMap = ref object expressions: SeqOfDistinct[ExprIndex, Nilability] ## the expressions with the same order as in NilCheckerContext history: SeqOfDistinct[Expr
# dwm - dynamic window manager
# © 2006-2007 Anselm R. Garbe, Sander van Dijk
include config.mk
SRC = client.c draw.c event.c layout.c main.c tag.c util.c
OBJ = ${SRC:.c=.o}
all: options dwm
options:
@echo dwm build options:
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "CC = ${CC}"
.c.o:
@echo CC $<
@${CC} -c ${CFLAGS} $<
${OBJ}: dwm.h config.h config.mk
config.h:
@echo creating $@ from config.default.h
@cp config.default.h $@
dwm: ${OBJ}
@echo CC -o $@
@${CC} -o $@ ${OBJ} ${LDFLAGS}
@strip $@
clean:
@echo cleaning
@rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz
dist: clean
@echo creating dist tarball
@mkdir -p dwm-${VERSION}
@cp -R LICENSE Makefile README config.*.h config.mk \
dwm.1 dwm.h ${SRC} dwm-${VERSION}
@tar -cf dwm-${VERSION}.tar dwm-${VERSION}
@gzip dwm-${VERSION}.tar
@rm -rf dwm-${VERSION}
install: all
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
@mkdir -p ${DESTDIR}${PREFIX}/bin
@cp -f dwm ${DESTDIR}${PREFIX}/bin
@chmod 755 ${DESTDIR}${PREFIX}/bin/dwm
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
@sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1
uninstall:
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
@rm -f ${DESTDIR}${PREFIX}/bin/dwm
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
@rm -f ${DESTDIR}${MANPREFIX}/man1/dwm.1
.PHONY: all options clean dist install uninstall