The Blech language

Documentation Download News

Embedded real-time programming

Look and feel


struct Display
var hundredth: int32
var seconds: int32
var minutes: int32
end

@[CFunction(binding = "showConsole", header = "runtimeLAPFAST.h")]
extern function show (this: Display)

function writeTicksToDisplay (ticks: int32) (display: Display)
let seconds = ticks / 100
display.minutes = seconds / 60
display.seconds = seconds - 60 * display.minutes
display.hundredth = ticks - 100 * seconds
end

activity Measurement (isPressedResetLap: bool)
(totalTime: int32, lastLap: int32, display: Display)
cobegin // run
repeat
await true
totalTime = totalTime + 1
end
with // lap
repeat
// show total time every tick
repeat
writeTicksToDisplay(totalTime)(display)
await true
until isPressedResetLap end

// calculate lap and update display once
let lapTime = totalTime - lastLap
lastLap = totalTime
writeTicksToDisplay(lapTime)(display)
await isPressedResetLap
// back to total time
end
end
end


activity StopWatchController (isPressedStartStop: bool,
isPressedResetLap: bool)
(display: Display)
var totalTime: int32
var lastLap: int32
repeat
// init
totalTime = 0
lastLap = 0
writeTicksToDisplay(totalTime)(display)
await isPressedStartStop // transition init -> run
repeat
when isPressedStartStop abort
run Measurement(isPressedResetLap)
(totalTime, lastLap, display)
end
// stop, show total time and wait
writeTicksToDisplay(totalTime)(display)
await isPressedStartStop or isPressedResetLap
until isPressedResetLap end // repeat if StartStop was pressed
// back to init if ResetLap was pressed
end
end

@[EntryPoint]
activity Main (isPressedStartStop: bool, isPressedReset: bool)
var display: Display
cobegin
run StopWatchController(isPressedStartStop, isPressedReset)
(display)
with
// render display in every tick
repeat
show(display)
await true
end
end
end

Get an overview …

Blech is a synchronous programming language for embedded, reactive, realtime-critical software. It allows writing reactive subprograms and combining them both sequentially and concurrently.

Blech compiles to clean C, which may be integrated into existing projects or simulation frameworks.

The name Blech ironically describes embedded hardware. It expresses that Blech programs can run directly on the Blech of pretty much any embedded device.

Read our introductory blog post to learn more on the purpose of Blech .

Contributions welcome!

We do a Pull Request contributions workflow on GitHub. New contributors are always welcome!

Read more …

Discuss with the Blech developers!

Exchange ideas on the development and evolution of Blech; its compiler, tools and documentation.

Read more …

Follow us on Twitter!

For announcement of latest features, releases, posts, and social events.

Read more …