Last active
March 25, 2021 17:59
-
-
Save deech/b964125a4bd30a85d569863d55da4288 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Most remember Pieter Hintjens for his messaging protocols. I don't know anything about that, | |
but I credit him with rekindling my love of programming in general, Lisp and functional programming | |
in one fell swoop about 17 years ago. | |
He did this by writing 'Libero', a mid-90's C program that took an ASCII diagram of a state machine | |
and produced code that ran that machine in a remarkable number of languages including 'sh', 'python', | |
'C' and many more. Some of them are listed on the original page (https://imatix-legacy.github.io/libero/). | |
I discovered in the early 00's and it fascinated me because was a unique combination of code generation | |
and what is now called purely functional programming. | |
Here, for example, is a snippet of a state machine that models an old school landline phone and would be | |
compiled into any of those languages using Libero: | |
Idle: | |
(--) Offhook -> Dialing-First | |
+ Start-Dial-Tone | |
+ Reset-Dialed-Number | |
+ Wait-For-Incoming-Message | |
(--) Request -> Ringing | |
+ Start-Ringing-Local | |
+ Wait-For-Incoming-Message | |
All the download and example links in the legacy page (https://imatix-legacy.github.io/libero/) are | |
non-working but fortunately the tool's sources itself have been rolled into 'openamq' (https://github.com/imatix/openamq/tree/master/tooling/base1/libero). The original examples, however, are lost to time. I distinctly | |
remember installing from source being an interesting process because the shell script that did the | |
work was itself written in Libero and had to be generated! | |
In any case what follows below is a set of instructions for building the tool from the 'openamq' repo | |
so that you too can play with it: | |
1. Clone the repo: 'git clone https://github.com/imatix/openamq' | |
2. Navigate to: './openamq/tooling/base1/libero' | |
3. Copy the 'Makefile' below into that directory. It's mostly a copy of 'Makefile.unix' but with the C compiler and linker updated. | |
4. 'make lr'. Hopefully there is an executable called 'lr' in your current directory. | |
5. Notice that there are a number of 'lrschema.*' files in the current directory. These are the backend definitions that you pass to 'lr' to get it to generate code in those languages. So for example, if you want to generate ASM from 'state-machine.l', you would do 'lr -schema=lrschema.asm' state-machine.l'. | |
Now you too can follow along with the tutorial (https://imatix-legacy.github.io/libero/lrintr1.htm#TOC6). | |
I remember having a lot of fun with it back in the day. | |
Enjoy :) | |
This file contains hidden or 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
# | |
# Makefile for Libero | |
# | |
# Generated by iMatix Boom | |
# | |
# Copyright (c) 1996-2009 iMatix Corporation | |
# All rights reserved. | |
# | |
# This file is licensed under the BSD license as follows: | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions | |
# are met: | |
# | |
# * Redistributions of source code must retain the above copyright | |
# notice, this list of conditions and the following disclaimer. | |
# * Redistributions in binary form must reproduce the above copyright | |
# notice, this list of conditions and the following disclaimer in | |
# the documentation and/or other materials provided with the | |
# distribution. | |
# * Neither the name of iMatix Corporation nor the names of its | |
# contributors may be used to endorse or promote products derived | |
# from this software without specific prior written permission. | |
# | |
# THIS SOFTWARE IS PROVIDED BY IMATIX CORPORATION "AS IS" AND ANY | |
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IMATIX CORPORATION BE | |
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | |
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
# | |
# Default values for object, library, and executable extensions. | |
# | |
OBJ = .o | |
LIB = .a | |
EXE = | |
CC = cc | |
# Reset the suffixes that will be considered to just our own list. | |
# | |
# Make programs use the .SUFFIXES psuedo rule for this | |
.SUFFIXES: | |
.SUFFIXES: $(EXE) $(LIB) $(OBJ) .c .d .i .l | |
# Objects depend on source files with the same name; and are compiled | |
# with the iMatix c script without any arguments. | |
# | |
.c$(OBJ): | |
$(CC) -c $< | |
# And .c files _do_not_ depend on .l files (.l files are Libero files, | |
# not lex input files as the default rules think). | |
# | |
# The semicolon forces make to accept the rule as an override. | |
# | |
.l.c: ; | |
# | |
# Default rule -- all depends on everything. | |
# We do this so that we can define the rule at the end. | |
# | |
all: everything | |
# | |
# The following targets are not files. Mark them as such. | |
# | |
.PHONY: all generate everything install regen clean | |
# | |
# Dependencies | |
# | |
liblr$(LIB): lrcalc$(OBJ) lreval$(OBJ) lrcode$(OBJ) lrload$(OBJ) lrdump$(OBJ) lrfree$(OBJ) lrsort$(OBJ) lrglib$(OBJ) lrlibr$(OBJ) lroptn$(OBJ) lrsymb$(OBJ) | |
ar rc liblr$(LIB) lrcalc$(OBJ) lreval$(OBJ) lrcode$(OBJ) lrload$(OBJ) lrdump$(OBJ) lrfree$(OBJ) lrsort$(OBJ) lrglib$(OBJ) lrlibr$(OBJ) lroptn$(OBJ) lrsymb$(OBJ) | |
lr$(OBJ): lr.c prelude.h lrpriv.h lrlibr.h lrglib.h lroptn.h version.h | |
lr$(EXE): lr$(OBJ) liblr$(LIB) | |
$(CC) lr.o -L. -llr -o lr | |
lrcalc$(OBJ): lrcalc.c | |
lreval$(OBJ): lreval.c | |
lrcode$(OBJ): lrcode.c lrsymb.h | |
lrload$(OBJ): lrload.c | |
lrdump$(OBJ): lrdump.c | |
lrfree$(OBJ): lrfree.c | |
lrsort$(OBJ): lrsort.c | |
lrglib$(OBJ): lrglib.c | |
lrlibr$(OBJ): lrlibr.c | |
lroptn$(OBJ): lroptn.c | |
lrsymb$(OBJ): lrsymb.c | |
lrcalc.i: lrcalc.l | |
lr -quiet lrcalc.l | |
lrcalc.d: lrcalc.l | |
lr -quiet lrcalc.l | |
lreval.i: lreval.l | |
lr -quiet lreval.l | |
lreval.d: lreval.l | |
lr -quiet lreval.l | |
lrcode.i: lrcode.l | |
lr -quiet lrcode.l | |
lrcode.d: lrcode.l | |
lr -quiet lrcode.l | |
lrload.i: lrload.l | |
lr -quiet lrload.l | |
lrload.d: lrload.l | |
lr -quiet lrload.l | |
everything: generate liblr$(LIB) lr$(EXE) | |
install: | |
sh boomake install | |
generate: stamp_generate | |
stamp_generate: | |
sh boomake regen | |
regen: | |
sh boomake regen | |
clean: | |
sh boomake clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment