BRiX
Advanced Computing Environment
Hosted by SourceForge
brix-os project page

Previous: Shadow Extensions ----- Up: Contents ----- Next: Environments

Histories

show notes
Features that need to be added to the page or ideas that haven't been thought out.
  • histories will need some sort of pre-scanning and variable monitoring.
    	defx sum(var:Symbol) {
    	  prescan {
    	    // need extension to create unique non-accessible variables like var_sum
    	    `do-after monitorDeclaration var { compile mutable var_sum = var }
    	    `do-after monitorWrites var { compile var_sum += var }
    	  }
    	  push_value var_sum
    	  return typeOf var_sum
    	}
  • reference variables
    	foo := def (`ref a:Int){
    	  orig(a); // store value
    	  orig(`ref a); // store pointer
    	}

The names of these extensions will be changed or prefixed to avoid root namespace pollution.

Histories are only maintained if they are used in the function and the hidden variables such as orig_value_of_a have no name and can't be directly accessed. The bold black code in the examples below is injected by the history extensions.

Original Value
Get original value of variable, parameters are stored at top of function and local variables are stored when they are first declared.

ORIG ( variable )
  • variable -- name of variable
	foo := def (a:int) { // a = 1
	  `const orig_value_of_a := a
	  a++ // a = 2
	  b := orig(a) // b = 1
	}

	// orig in post-condition
	foo := def (a:int) {
	  post (result > orig(a))
	  ...
	  return a
	}

Previous Value
Get value of variable before it was last modified. Only maintained for the previous modification before the OLD extension is used.

OLD ( variable )
  • variable -- name of variable
	foo := def () {
	  a := 1
	  a = 2
	  old_value_of_a := a
	  a = 3
	  b := old(a) // b = 2
	  old_value_of_a = a
	  a = 4
	  b = old(a) // b = 3
	}

Sum of Values
Maintain the sum of all values assigned to a variable. The sum is not maintained after the last SUM in the function. Variable type must support the addition_interface.

SUM ( variable:addition_interface )
  • variable -- name of variable
	foo := def () {
	  sum_of_a := (a := 10)
	  sum_of_a += (a = 20)
	  b := sum(a) // b = 30
	  sum_of_a += (a = 30)
	  b = sum(a) // b = 60
	}

Number of Assignments
Count the number of times a variable is modified. The count is not maintained after the last COUNT in the function.

COUNT ( variable )
  • variable -- name of variable
	foo := def () {
	  count_of_a := 0
	  a := 10
	  count_of_a++
	  a = 20
	  b := count(a) // b = 1
	  count_of_a++
	  a = 30
	  b = count(a) // b = 2
	}

Value Bounds
Maintain minimum and maximum values of variable. Bounds are not maintained after the last MIN or MAX in the function. Variable type must support less than and greater than operators.

MIN ( variable )
  • variable -- name of variable

MAX ( variable )
  • variable -- name of variable
	// minimum value
	foo := def () {
	  min_a := (a := 1)
	  a = 2
	  if (a < min_a) min_a = a
	  b = min(a); // b = 1
	}

	// maximum value
	foo := def () {
	  max_a := (a := 1)
	  a = 2
	  if (a > max_a) max_a = a
	  b = max(a) // b = 2
	}

	// minimum and maximum values
	foo := def () {
	  min_a := (max_a := (a := 1)
	  a = 2
	  if (a < min_a) min_a = a
	  else if (a > max_a) max_a = a
	  b := min(a) // b = 1
	  c := max(a) // c = 2
	}

Previous: Shadow Extensions ----- Up: Contents ----- Next: Environments