Last active
November 4, 2018 02:10
-
-
Save frame-lang/47cb1e87715c38861a5b0ebbda5e3bce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------------------// | |
// // | |
// FMN // | |
// // | |
//-------------------------------------------------// | |
#Transition1 | |
-machine- | |
$Begin | |
|start| -> $S1 ^ | |
|enter| print("Never called") ^ | |
|exit| print("The end of the beginning") ^ | |
$S1 | |
|enter| print("Welcome to $S1!") ^ | |
|toggle| -> $S2 ^ | |
|exit| print("Goodbye to $S1!") ^ | |
$S2 | |
|enter| print("Welcome to $S2!") ^ | |
|toggle| -> $S1 ^ | |
|exit| print("Goodbye to $S2!") ^ | |
//-------------------------------------------------// | |
// // | |
// Implementation // | |
// // | |
//-------------------------------------------------// | |
class Transition1 { | |
// -machine- | |
var _state(e:FrameEvent) = Begin | |
/********************************** | |
$Begin | |
|start| -> $S1 | |
***********************************/ | |
func Begin(e:FrameEvent) { | |
if (e._msg == "start") { | |
_transition(S1) | |
return | |
} | |
if (e._msg == "enter") { | |
print("Never called") | |
return | |
} | |
if (e._msg == "exit") { | |
print("The end of the beginning") | |
return | |
} | |
} | |
/********************************** | |
$S1 | |
|enter| print("Welcome to $S1!") ^ | |
|toggle| -> $S2 ^ | |
|exit| print("Goodbye to $S1!") ^ | |
***********************************/ | |
func S1(e:FrameEvent) { | |
if (e._msg == "enter") { | |
print("Welcome to $S1!") | |
return | |
} | |
if (e._msg == "toggle") { | |
_transition(S2) | |
return | |
} | |
if (e._msg == "exit") { | |
print("Goodbye to $S1!") | |
return | |
} | |
} | |
/********************************** | |
$S2 | |
|enter| print("Welcome to $S2!") ^ | |
|toggle| -> $S1 ^ | |
|exit| print("Goodbye to $S2!") ^ | |
***********************************/ | |
func S2(e:FrameEvent) { | |
if (e._msg == "enter") { | |
print("Welcome to $S2!") | |
return | |
} | |
if (e._msg == "toggle") { | |
_transition(S1) | |
return | |
} | |
if (e._msg == "exit") { | |
print("Goodbye to $S2!") | |
return | |
} | |
} | |
// machinery | |
func _transition(newState:FrameState) { | |
_state(new FrameEvent("exit")) | |
_state = newState | |
_state(new FrameEvent("enter")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment