From 1c1efc0fe6d306556c1f9fee1444fbf617c7a120 Mon Sep 17 00:00:00 2001 From: Simon From Jakobsen Date: Thu, 18 Jul 2024 12:44:39 +0000 Subject: [PATCH] init, benchmark, vim syntax --- benchmark.stela | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ stela.vim | 50 ++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 benchmark.stela create mode 100644 stela.vim diff --git a/benchmark.stela b/benchmark.stela new file mode 100644 index 0000000..38fd2ba --- /dev/null +++ b/benchmark.stela @@ -0,0 +1,101 @@ + +class HouseSettings { + public attribute Settings: [int; 10]; + + operation get(id: int) -> int { return 0; } + operation set(id: int, value: int) {} +} + +enumeration DoorState { + Closed, + Open, +} + +derivable class GenericDoorControl { + attribute Runtime: int; + attribute SensorState: DoorState; + + operation Close() {} + operation Open() {} + + operation SetRuntime(time: int) {} + operation State() -> DoorState { return DoorState::Closed; } +} + +class DoorControl derives GenericDoorControl { + associate itsHouseSettings: HouseSettings; + + attribute State: DoorState; + attribute locked: bool; + + operation SetState(state: DoorState) {} + operation GetState() -> DoorState { return DoorState::Closed; } + + operation Lock() { this.locked = true; } + operation Unlock() { this.locked = false; } + + state_machine { + entry { + transition DoorControl; + } + DoorControl { + state_machine "Door operation" { + initial { + transition Closing { + SetState(DoorState::Closed); + } + } + Closing { + entry { + Lock(); + } + exit { + Unlock(); + } + transition Opening { + SetState(DoorState::Open); + }; + } + Opening { + state_machine { + initial { + transition Unlocked; + } + Unlocked { + ThreadSleepSeconds(1); + if this.locked + transition Unlocked + else + transition final { + SetState(DoorState::Open); + }; + } + } + } + } + state_machine "Check sensor" { + initial { + transition Check; + } + Check { + ThreadSleepSeconds(1); + transition Check; + } + } + } + } +} + +class WinterGardenControl { + associate itsHouseSettings: HouseSettings; + associate itsDoorControl: &[HouseSettings]; + + public attribute NofDoors: int; + + operation SetState(amount: int) {} + operation SetDoors(amount: int) {} + + operation GetState() -> DoorState; + operation GetState(door: int) -> DoorState; +} + diff --git a/stela.vim b/stela.vim new file mode 100644 index 0000000..20b8351 --- /dev/null +++ b/stela.vim @@ -0,0 +1,50 @@ +" Vim syntax file +" Language: STate machine Event LAnguage +" Maintainer: Simon +" Latest Revision: 17 July 2024 + +if exists("b:current_syntax") + finish +endif + +syn keyword Keyword return if else +syn keyword Keyword enumeration derivable derives class public private +syn keyword Keyword operation attribute associate state_machine +syn keyword Keyword transition +syn keyword Special initial final entry exit +syn keyword Type void int float bool +syn keyword Boolean true false +syn keyword Identifier this + +syn match Operator '-' +syn match Operator '->' +syn match Operator ':' +syn match Operator '::' +syn match Operator '=' +syn match Operator '+' +syn match Operator '\*' +syn match Operator ';' +syn match Operator '\.' +syn match Operator ',' + +syn match Number '\d\+' +syn match Number '[-+]\d\+' + +syn match Float '[-+]\d\+\.\d*' +syn match Float '[-+]\=\d[[:digit:]]*[eE][\-+]\=\d\+' +syn match Float '\d[[:digit:]]*[eE][\-+]\=\d\+' +syn match Float '[-+]\=\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+' +syn match Float '\d[[:digit:]]*\.\d*[eE][\-+]\=\d\+' + +syn region String start=+"+ skip=+\\"+ end=+"+ + +syn keyword Todo contained TODO FIXME XXX NOTE +syn match Comment "#.*$" contains=Todo +syn match Comment "//.*$" contains=Todo + +syn match Function '[a-zA-Z_]\w*\ze(' + +syn region stelaBlock start="{" end="}" transparent fold + +let b:current_syntax = "stela" +