about summary refs log tree commit diff stats
path: root/000organization.cc
Commit message (Expand)AuthorAgeFilesLines
* 5704Kartik Agaram2019-10-191-0/+2
* 5485 - promote SubX to top-levelKartik Agaram2019-07-271-4/+30
* 4252Kartik Agaram2018-06-061-2/+2
* 4061Kartik K. Agaram2017-10-131-4/+4
* 4010Kartik K. Agaram2017-10-041-16/+16
* 3966Kartik K. Agaram2017-07-091-1/+1
* 3965 - get rid of the teardown() functionKartik K. Agaram2017-07-091-6/+2
* 3557Kartik K. Agaram2016-10-221-4/+4
* 3414Kartik K. Agaram2016-09-241-1/+1
* 3297 - run unit tests before scenariosKartik K. Agaram2016-09-051-0/+3
* 3273Kartik K. Agaram2016-08-281-7/+9
* 3272Kartik K. Agaram2016-08-281-0/+3
* 3270Kartik K. Agaram2016-08-281-0/+5
* 3027Kartik K. Agaram2016-06-021-1/+1
* 2935Kartik K. Agaram2016-05-071-2/+2
* 2609 - run $browse-trace on old runsKartik K. Agaram2015-11-291-0/+1
* 1342Kartik K. Agaram2015-05-111-8/+8
* 1330Kartik K. Agaram2015-05-101-0/+5
* 1294Kartik K. Agaram2015-05-061-5/+5
* 1276 - make C++ version the defaultKartik K. Agaram2015-05-051-0/+121
vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# new type to help incrementally scan arrays
container stream:_elem [
  index:num
  data:&:@:_elem
]

def new-stream s:&:@:_elem -> result:&:stream:_elem [
  local-scope
  load-ingredients
  result <- new {(stream _elem): type}
  *result <- put *result, index:offset, 0
  *result <- put *result, data:offset, s
]

def rewind in:&:stream:_elem -> in:&:stream:_elem [
  local-scope
  load-ingredients
  *in <- put *in, index:offset, 0
]

def read in:&:stream:_elem -> result:_elem, empty?:bool, in:&:stream:_elem [
  local-scope
  load-ingredients
  empty? <- copy 0/false
  idx:num <- get *in, index:offset
  s:&:@:_elem <- get *in, data:offset
  len:num <- length *s
  at-end?:bool <- greater-or-equal idx len
  {
    break-unless at-end?
    empty-result:&:_elem <- new _elem:type
    return *empty-result, 1/true
  }
  result <- index *s, idx
  idx <- add idx, 1
  *in <- put *in, index:offset, idx
]

def peek in:&:stream:_elem -> result:_elem, empty?:bool [
  local-scope
  load-ingredients
  empty?:bool <- copy 0/false
  idx:num <- get *in, index:offset
  s:&:@:_elem <- get *in, data:offset
  len:num <- length *s
  at-end?:bool <- greater-or-equal idx len
  {
    break-unless at-end?
    empty-result:&:_elem <- new _elem:type
    return *empty-result, 1/true
  }
  result <- index *s, idx
]

def read-line in:&:stream:char -> result:text, in:&:stream:char [
  local-scope
  load-ingredients
  idx:num <- get *in, index:offset
  s:text <- get *in, data:offset
  next-idx:num <- find-next s, 10/newline, idx
  result <- copy-range s, idx, next-idx
  idx <- add next-idx, 1  # skip newline
  # write back
  *in <- put *in, index:offset, idx
]

def end-of-stream? in:&:stream:_elem -> result:bool [
  local-scope
  load-ingredients
  idx:num <- get *in, index:offset
  s:&:@:_elem <- get *in, data:offset
  len:num <- length *s
  result <- greater-or-equal idx, len
]