1.1 code block - RawIron/rawiron.github.io GitHub Wiki

code block

  • a block is an aggregate of statements
  • a block can call another block
  • in case many blocks are allowed there must be an address available for each block

execution model

>>>
_>>

arguments

  • closed blocks are not very useful
{ 2 + 3 }
{ 5 + 6 }

{
  a = 5
  b = 4
  a + b
}
  • needed is a way to pass data to the block

  • name those data arguments

  • pass all arguments

(a,b) -> [2,3]
         { a + b }
 c  <- [5]
  • pass arguments one at a time
a     -> [2,_]
b     -> [2,3]
         { a + b }
 c  <- [5]

block statement counters

synchronous

  • caller waits
  • callee returns result after the evaluation of the block was completed
>>>
[]
 {
  a=2
  b=3
  (a,b) -> [2,3]
             { a + b }
   c    <- [5]
 }
[]

asynchronous

  • caller does not wait
  • return result while the block is still active
  • there is only 1 of >>> and each block has 1 of _>> there is more than 1 of >>>
>>>
_>>      
[] {       _>>
  (a,b) -> [2,4] { 
              range(a,b)
   c    <- [2]
              ...
   c    <- [3]
            }
           []
 }
[]

co-routines

  • caller does wait
  • return result while the co-routine is still active
  • there is only 1 of >>> and co-routine has a _>>
>>>      
[] {       _>>
  (a,b) -> [2,4] { 
              range(a,b)
   c    <- [2]
              ...
   c    <- [3]
            }
           []
 }
[]

concurrency, parallelism

  • without concurrency/parallelism always exactly one block is active
  • there is only 1 of >>>
    [a,b]
    block_1
    {
      a+b
    }
[a+b]


   [a]
   block_2
   {
     -a
   }
[-a]

>>>
[]
main_block
{
 (a1,b1) -> [2,4]block_1
   c1    <- [5]
             ...
   a2    -> [3]block_2
   c2    <- [-3]
 }
[]
  • more than 1 active block at a time
  • more than 1 of >>>
    >>>
    [a,b]
    block_1
    {
      range(a,b)
  [a]
     ...
[a+1]
    }
   []


   >>>
   [a]
   block_2
   {
     -a
   }
[-a]


>>>
[]
main_block
{
  (a1,b1) -> [2,4]block_1
    c1    <- [2]block_1
             ...
    a2    -> [3]block_2
    c1    <- [3]block_1
    c2    <- [-3]block_2
    c1    <- []block_1
 }
[]

state

  • a state is an aggregate of data
  • the block has a memory
  • assumption that same arguments create the same result is no longer true
|9, "brave"|
  • attach a state to a block
  |9,"brave"|
  [4]
  {
  }
 []
  • pass a state into a block
  [|9,"brave"|, 4]
  {
  }
 []

shared resources

  • state is the only structure other than block

  • a state is shared by 2 blocks

  <&>|9,"brave"|

  |&|
  [4]
  {
  }
 []

  |&|
  ["buy", 32]
  {
  }
 []