Examples (WIP)

Examples in this page are to understand concepts of Karuta language quickly (I hope everything is within your familiar concepts and paradigms).

Just a module

module {
  reg r int
  ram a int[16]

  process p() {
    a[r]++
  }
}

module keyword specifies an object and allows to define members inside it.

Communication

module {
  channel ch int

  process p1() {
    ch.write(1)
  }

  process p2() {
    ch.read()
  }
}

channels, regs, rams and most of member objects are accessible from multiple threads.

Module hierarchy

module {
  shared m module = new()

  process p() {
    m.ch.write(1)
  }
}

module m {
  channel ch int
  process p() {
    p.ch.read()
  }
}

Matrix multiplication

module m {
  ram a int[4][4]
  ram b int[4][4]
  ram x int[4][4]

  func mult() {
    for var i int = 0; i < 4; ++i {
      for var j int = 0; j < 4; ++j {
        var t int = 0
        for var k int = 0; k < 4; ++k {
          t += a[i][k] * b[k][j]
        }
        x[i][j] = t
      }
    }
  }
  process p() {
    mult()
  }
}