summary refs log tree commit diff stats
BranchCommit messageAuthorAge
masterMerge branch 'victorbnl-viewnior-config'toonn2 years
 
TagDownloadAuthorAge
v1.9.3ranger-1.9.3.tar.gz  toonn5 years
v1.9.2ranger-1.9.2.tar.gz  toonn6 years
v1.9.1ranger-1.9.1.tar.gz  Wojciech Siewierski7 years
v1.9.0ranger-1.9.0.tar.gz  hut7 years
v1.9.0b6ranger-1.9.0b6.tar.gz  Wojciech Siewierski7 years
v1.9.0b5ranger-1.9.0b5.tar.gz  nfnty8 years
v1.9.0b4ranger-1.9.0b4.tar.gz  nfnty8 years
v1.9.0b3ranger-1.9.0b3.tar.gz  nfnty8 years
v1.9.0b2ranger-1.9.0b2.tar.gz  nfnty8 years
v1.9.0b1ranger-1.9.0b1.tar.gz  nfnty8 years
v1.8.1ranger-1.8.1.tar.gz  nfnty8 years
v1.8.0ranger-1.8.0.tar.gz  hut8 years
v1.7.2ranger-1.7.2.tar.gz  hut9 years
v1.7.1ranger-1.7.1.tar.gz  hut10 years
v1.7.0-emacsranger-1.7.0-emacs.tar.gz  hut10 years
v1.7.0ranger-1.7.0.tar.gz  hut10 years
v1.6.1ranger-1.6.1.tar.gz  hut12 years
v1.6.0ranger-1.6.0.tar.gz  hut12 years
v1.5.5ranger-1.5.5.tar.gz  hut12 years
v1.5.4ranger-1.5.4.tar.gz  hut13 years
v1.5.3ranger-1.5.3.tar.gz  hut13 years
v1.5.2ranger-1.5.2.tar.gz  hut13 years
v1.5.1ranger-1.5.1.tar.gz  hut13 years
v1.5.0ranger-1.5.0.tar.gz  hut13 years
v1.4.4ranger-1.4.4.tar.gz  hut13 years
v1.4.3ranger-1.4.3.tar.gz  hut14 years
v1.4.2ranger-1.4.2.tar.gz  hut14 years
v1.4.1ranger-1.4.1.tar.gz  hut14 years
v1.4.0ranger-1.4.0.tar.gz  hut14 years
v1.2.3ranger-1.2.3.tar.gz  hut14 years
v1.2.2ranger-1.2.2.tar.gz  hut14 years
v1.2.1ranger-1.2.1.tar.gz  hut14 years
v1.2.0ranger-1.2.0.tar.gz  hut14 years
v1.1.2ranger-1.1.2.tar.gz  hut14 years
v1.1.1ranger-1.1.1.tar.gz  hut14 years
v1.1.0ranger-1.1.0.tar.gz  hut14 years
v1.0.4ranger-1.0.4.tar.gz  hut15 years
v1.0.3ranger-1.0.3.tar.gz  hut15 years
v1.0.2ranger-1.0.2.tar.gz  hut15 years
v0.2.6ranger-0.2.6.tar.gz  hut15 years
v1.0.1ranger-1.0.1.tar.gz  hut15 years
v0.2.5ranger-0.2.5.tar.gz  hut15 years
v0.2.4ranger-0.2.4.tar.gz  hut15 years
v0.2.3ranger-0.2.3.tar.gz  hut15 years
v0.2.2ranger-0.2.2.tar.gz  hut15 years
v0.2.1ranger-0.2.1.tar.gz  hut16 years
v0.2.0ranger-0.2.0.tar.gz  hut16 years
v0.1.0ranger-0.1.0.tar.gz  hut16 years
ighlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .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 */
# A list links up multiple objects together to make them easier to manage.
#
# The objects must be of the same type. If you want to store multiple types in
# a single list, use an exclusive-container.

container list:_elem [
  value:_elem
  next:address:list:_elem
]

def push x:_elem, in:address:list:_elem -> result:address:list:_elem [
  local-scope
  load-ingredients
  result <- new {(list _elem): type}
  *result <- merge x, in
]

def first in:address:list:_elem -> result:_elem [
  local-scope
  load-ingredients
  result <- get *in, value:offset
]

def rest in:address:list:_elem -> result:address:list:_elem/contained-in:in [
  local-scope
  load-ingredients
  result <- get *in, next:offset
]

scenario list-handling [
  run [
    local-scope
    x:address:list:number <- push 3, 0
    x <- push 4, x
    x <- push 5, x
    10:number/raw <- first x
    x <- rest x
    11:number/raw <- first x
    x <- rest x
    12:number/raw <- first x
    20:address:list:number/raw <- rest x
  ]
  memory-should-contain [
    10 <- 5
    11 <- 4
    12 <- 3
    20 <- 0  # nothing left
  ]
]

def length l:address:list:_elem -> result:number [
  local-scope
  load-ingredients
  return-unless l, 0
  rest:address:list:_elem <- rest l
  length-of-rest:number <- length rest
  result <- add length-of-rest, 1
]

# insert 'x' after 'in'
def insert x:_elem, in:address:list:_elem -> in:address:list:_elem [
  local-scope
  load-ingredients
  new-node:address:list:_elem <- new {(list _elem): type}
  *new-node <- put *new-node, value:offset, x
  next-node:address:list:_elem <- get *in, next:offset
  *in <- put *in, next:offset, new-node
  *new-node <- put *new-node, next:offset, next-node
]

scenario inserting-into-list [
  run [
    local-scope
    list:address:list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    list2:address:list:character <- rest list  # inside list
    list2 <- insert 6, list2
    # check structure
    list2 <- copy list
    10:character/raw <- first list2
    list2 <- rest list2
    11:character/raw <- first list2
    list2 <- rest list2
    12:character/raw <- first list2
    list2 <- rest list2
    13:character/raw <- first list2
  ]
  memory-should-contain [
    10 <- 5  # scanning next
    11 <- 4
    12 <- 6  # inserted element
    13 <- 3
  ]
]

scenario inserting-at-end-of-list [
  run [
    local-scope
    list:address:list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    list2:address:list:character <- rest list  # inside list
    list2 <- rest list2  # now at end of list
    list2 <- insert 6, list2
    # check structure like before
    list2 <- copy list
    10:character/raw <- first list2
    list2 <- rest list2
    11:character/raw <- first list2
    list2 <- rest list2
    12:character/raw <- first list2
    list2 <- rest list2
    13:character/raw <- first list2
  ]
  memory-should-contain [
    10 <- 5  # scanning next
    11 <- 4
    12 <- 3
    13 <- 6  # inserted element
  ]
]

scenario inserting-after-start-of-list [
  run [
    local-scope
    list:address:list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    list <- insert 6, list
    # check structure like before
    list2:address:list:character <- copy list
    10:character/raw <- first list2
    list2 <- rest list2
    11:character/raw <- first list2
    list2 <- rest list2
    12:character/raw <- first list2
    list2 <- rest list2
    13:character/raw <- first list2
  ]
  memory-should-contain [
    10 <- 5  # scanning next
    11 <- 6  # inserted element
    12 <- 4
    13 <- 3
  ]
]

# remove 'x' from its surrounding list 'in'
#
# Returns null if and only if list is empty. Beware: in that case any other
# pointers to the head are now invalid.
def remove x:address:list:_elem/contained-in:in, in:address:list:_elem -> in:address:list:_elem [
  local-scope
  load-ingredients
  # if 'x' is null, return
  return-unless x
  next-node:address:list:_elem <- rest x
  # clear next pointer of 'x'
  *x <- put *x, next:offset, 0
  # if 'x' is at the head of 'in', return the new head
  at-head?:boolean <- equal x, in
  return-if at-head?, next-node
  # compute prev-node
  prev-node:address:list:_elem <- copy in
  curr:address:list:_elem <- rest prev-node
  {
    return-unless curr
    found?:boolean <- equal curr, x
    break-if found?
    prev-node <- copy curr
    curr <- rest curr
  }
  # set its next pointer to skip 'x'
  *prev-node <- put *prev-node, next:offset, next-node
]

scenario removing-from-list [
  run [
    local-scope
    list:address:list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    list2:address:list:character <- rest list  # second element
    list <- remove list2, list
    10:boolean/raw <- equal list2, 0
    # check structure like before
    list2 <- copy list
    11:character/raw <- first list2
    list2 <- rest list2
    12:character/raw <- first list2
    20:address:list:character/raw <- rest list2
  ]
  memory-should-contain [
    10 <- 0  # remove returned non-null
    11 <- 5  # scanning next, skipping deleted element
    12 <- 3
    20 <- 0  # no more elements
  ]
]

scenario removing-from-start-of-list [
  run [
    local-scope
    list:address:list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    list <- remove list, list
    # check structure like before
    list2:address:list:character <- copy list
    10:character/raw <- first list2
    list2 <- rest list2
    11:character/raw <- first list2
    20:address:list:character/raw <- rest list2
  ]
  memory-should-contain [
    10 <- 4  # scanning next, skipping deleted element
    11 <- 3
    20 <- 0  # no more elements
  ]
]

scenario removing-from-end-of-list [
  run [
    local-scope
    list:address:list:character <- push 3, 0
    list <- push 4, list
    list <- push 5, list
    # delete last element
    list2:address:list:character <- rest list
    list2 <- rest list2
    list <- remove list2, list
    10:boolean/raw <- equal list2, 0
    # check structure like before
    list2 <- copy list
    11:character/raw <- first list2
    list2 <- rest list2
    12:character/raw <- first list2
    20:address:list:character/raw <- rest list2
  ]
  memory-should-contain [
    10 <- 0  # remove returned non-null
    11 <- 5  # scanning next, skipping deleted element
    12 <- 4
    20 <- 0  # no more elements
  ]
]

scenario removing-from-singleton-list [
  run [
    local-scope
    list:address:list:character <- push 3, 0
    list <- remove list, list
    1:number/raw <- copy list
  ]
  memory-should-contain [
    1 <- 0  # back to an empty list
  ]
]

def to-text in:address:list:_elem -> result:text [
  local-scope
  load-ingredients
  buf:address:buffer <- new-buffer 80
  buf <- to-buffer in, buf
  result <- buffer-to-array buf
]

# variant of 'to-text' which stops printing after a few elements (and so is robust to cycles)
def to-text-line in:address:list:_elem -> result:text [
  local-scope
  load-ingredients
  buf:address:buffer <- new-buffer 80
  buf <- to-buffer in, buf, 6  # max elements to display
  result <- buffer-to-array buf
]

def to-buffer in:address:list:_elem, buf:address:buffer -> buf:address:buffer [
  local-scope
  load-ingredients
  {
    break-if in
    buf <- append buf, 48/0
    return
  }
  # append in.value to buf
  val:_elem <- get *in, value:offset
  buf <- append buf, val
  # now prepare next
  next:address:list:_elem <- rest in
  nextn:number <- copy next
  return-unless next
  buf <- append buf, [ -> ]
  # and recurse
  remaining:number, optional-ingredient-found?:boolean <- next-ingredient
  {
    break-if optional-ingredient-found?
    # unlimited recursion
    buf <- to-buffer next, buf
    return
  }
  {
    break-unless remaining
    # limited recursion
    remaining <- subtract remaining, 1
    buf <- to-buffer next, buf, remaining
    return
  }
  # past recursion depth; insert ellipses and stop
  append buf, [...]
]