[Cuis-dev] A small experiment with OMeta as intepreter for push-pull streams (e.g. network)

Michał Olszewski miolszewski at outlook.com
Thu Jun 20 07:17:54 PDT 2024


Hi all,

While working on a parser (uses text emphasis as part of the grammar 
btw.) for my bachelor's streaming language, I've strayed a bit and made 
a really small and fun experiment with OMeta2 serving as interpreter for 
simple message format being received from a SocketStream, showing 
versatility of OMeta in not just "local", finite pattern matching but 
also from push-pull streams, like network sockets.

To enable it, I had to add small change to defer fetching next element 
from the stream.

I attached necessary package and workspace contents. You can git clone 
OMeta with above fix from my repo: https://github.com/michalo1334/OMeta-Cuis

Tested in Cuis7.0.

Have fun!

Cheers,
Michał

Possible TODO: implement parser/msg constructor for simple binary format 
like MessagePack and do message passing between objects across network. 
Implement everything in OMeta :).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MoTest.pck.st
Type: application/vnd.sailingtracker.track
Size: 6751 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240620/ef4f168b/attachment-0001.st>
-------------- next part --------------
"Receiver"
socket1 := Socket newTCP. 
socket1 listenOn: 5566.

socket1.
socket2.

"Sender"
socket2 := Socket newTCP.
socket2 connectToHostNamed: 'localhost' port: 5566.

ss1 := SocketStream on: socket1 :: binary.
ss1 timeout: 0.
ss2 := SocketStream on: socket2 :: binary.
ss1 timeout: 0.

"Queue to put all parsed messages"
q := SharedQueue new.

"Start process interpreting incoming messages - we assume there will be no desync in message stream nor wrong message format nor lost connection"
"Interpreter will deserialize messages in infinite manner and each one will put into passed SharedQueue then display the msg"
p := [MoMsgInterpreter matchAll: ss1 with: #messageStream withArgs: {q}] newProcess.
p priority: Processor userBackgroundPriority :: resume.

"^^^^ You can do-it all at once"

"handy to terminate interpreting process"
p terminate.

"Structured message - editable"
mTest := {#msg. {#version -> 1. #contentType -> #string} asDictionary. 'ssddsdsdsĘĘĘĘĘĘĘĘĘĘĘĘĘĘĘE'}.

"Convert to binary representation"
binary := MoMsgConstructor match: mTest with: #message.

"Put onto stream and send to receiver"
"See Transcript for received message"
ss2 nextPutAll: binary; flush.

"Quick look at deserialized message - should be the same as the original one"
MoMsgInterpreter matchAll: binary with: #message


More information about the Cuis-dev mailing list