packages feed

fir-0.1.0.0: test/Tests/Control/BreakNested.hs

{-# LANGUAGE BlockArguments   #-}
{-# LANGUAGE DataKinds        #-}
{-# LANGUAGE PolyKinds        #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators    #-}

module Tests.Control.BreakNested where

-- fir
import FIR

------------------------------------------------
-- program

-- Breaking out of two loops at once: the break is a predecessor of the merge block
-- of the outer loop, and must contribute to its ϕ-instructions (here, for "x").

type Defs =
  '[ "out"  ':-> StorageBuffer '[ DescriptorSet 0, Binding 0 ]
                   ( Struct '[ "res" ':-> Float ] )
   , "main" ':-> EntryPoint '[ LocalSize 1 1 1 ] Compute
   ]

program :: Module Defs
program = Module do

  entryPoint @"main" @Compute do

    _ <- def @"x" @RW @Float 0
    loop do
      modify @"x" ( + 1 )
      loop do
        x <- get @"x"
        if x > 10
        then do
          put @"x" 100
          break @2
        else
          if x > 5
          then break @1
          else put @"x" ( x + 2 )

    x <- get @"x"
    assign @( Name "out" :.: Name "res" ) x