summary refs log tree commit diff stats
path: root/bin
Commit message (Expand)AuthorAgeFilesLines
* fixes #21461 (#21463)Arnaud Moura2023-03-032-2/+2
* nim-gdb: remove unnecessary quotes and fix uname (#20739)Xiao-Yong2022-11-031-1/+1
* make choosenim work on windows [backport] (#18993)flywind2021-10-141-1/+0
* get rid of $READLINK variable (#14841)Andrey Makarov2020-06-281-2/+2
* make nim-gdb compatible with BSD systems (#14700)BarrOff2020-06-181-6/+4
* Revert –#13658 for nim-gdb.bat. Fixes #13705 (#13707)Joey2020-03-201-1/+3
* Fix gdb scripts (#13658)Joey2020-03-163-16/+11
* Make gdb script work on mac and linux; add windows gdb script (#13453)Joey2020-02-212-4/+28
* 32 bit fixes (#10608)Arne Döring2019-02-131-0/+3
* fixes #9276 (#9317)Arne Döring2018-10-241-0/+0
* file mode bullshitAraq2018-08-051-0/+0
* Gdb pretty printers (#8263)Arne Döring2018-07-161-0/+18
* empty.txt files: Trim trailing whitespaceAdam Strzelecki2015-09-041-1/+1
* rewrote lambdalifting; fixes deeply nested closuresAraq2014-06-261-1/+1
* Merge pull request #1075 from flaviut/inlinedocsAndreas Rumpf2014-04-091-0/+1
bel */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .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 */
discard """
  file: "tmatrix.nim"
  output: "111"
"""
# Test overloading of [] with multiple indices

type
  TMatrix* = object
    data: seq[float]
    fWidth, fHeight: int

template `|`(x, y: int): expr = y * m.fWidth + x

proc createMatrix*(width, height: int): TMatrix = 
  result.fWidth = width
  result.fHeight = height
  newSeq(result.data, width*height)

proc width*(m: TMatrix): int {.inline.} = return m.fWidth
proc height*(m: TMatrix): int {.inline.} = return m.fHeight

proc `[,]`*(m: TMatrix, x, y: int): float {.inline.} =
  result = m.data[x|y]

proc `[,]=`*(m: var TMatrix, x, y: int, val: float) {.inline.} =
  m.data[x|y] = val
  
proc `[$ .. $, $ .. $]`*(m: TMatrix, a, b, c, d: int): TMatrix =
  result = createMatrix(b-a+1, d-c+1)
  for x in a..b:
    for y in c..d:
      result[x-a, y-c] = m[x, y]

proc `[$ .. $, $ .. $]=`*(m: var TMatrix, a, b, c, d: int, val: float) =
  for x in a..b:
    for y in c..d:
      m[x, y] = val

proc `[$ .. $, $ .. $]=`*(m: var TMatrix, a, b, c, d: int, val: TMatrix) =
  assert val.width == b-a+1
  assert val.height == d-c+1
  for x in a..b:
    for y in c..d:
      m[x, y] = val[x-a, y-c]

proc `-|`*(m: TMatrix): TMatrix =
  ## transposes a matrix
  result = createMatrix(m.height, m.width)
  for x in 0..m.width-1:
    for y in 0..m.height-1: result[y,x] = m[x,y]

#m.row(0, 2) # select row
#m.col(0, 89) # select column

const
  w = 3
  h = 20

var m = createMatrix(w, h)
for i in 0..w-1:
  m[i, i] = 1.0

for i in 0..w-1:
  stdout.write(m[i,i]) #OUT 111