Skip to content

Commit

Permalink
Merge pull request #85 from lf-lang/docker-fix
Browse files Browse the repository at this point in the history
Updated formatting and Docker example
  • Loading branch information
lhstrh authored Sep 14, 2023
2 parents 94a9e68 + 6bb7ddf commit 2a1493a
Show file tree
Hide file tree
Showing 54 changed files with 283 additions and 95 deletions.
12 changes: 9 additions & 3 deletions examples/C/src/ChatApplication/SimpleChat.lf
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ reactor InputHandler {
reactor Printer {
input in: string

reaction(in) {= printf("Received: %s\n", in->value); =}
reaction(in) {=
printf("Received: %s\n", in->value);
=}
}

reactor ChatHandler {
Expand All @@ -81,9 +83,13 @@ reactor ChatHandler {
u = new InputHandler()
r = new Printer()

reaction(u.out) -> send {= lf_set(send, u.out->value); =}
reaction(u.out) -> send {=
lf_set(send, u.out->value);
=}

reaction(receive) -> r.in {= lf_set(r.in, receive->value); =}
reaction(receive) -> r.in {=
lf_set(r.in, receive->value);
=}
}

federated reactor SimpleChat {
Expand Down
8 changes: 6 additions & 2 deletions examples/C/src/Delay.lf
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ reactor Delay2 {
input x: int
output y: int

reaction(a) -> y {= lf_set(y, a->value); =}
reaction(a) -> y {=
lf_set(y, a->value);
=}

reaction(x) -> a {= lf_schedule_int(a, 0, x->value); =}
reaction(x) -> a {=
lf_schedule_int(a, 0, x->value);
=}
}

/** Print the (elapsed) logical and physical times at which inputs are received. */
Expand Down
9 changes: 6 additions & 3 deletions examples/C/src/DistributedDatabase/ReplicatedDatabase.lf
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ reactor Server(
self->queries_outstanding++;
=}

reaction(update_trigger) -> update {= lf_set(update, self->update_amount); =} deadline(
update_deadline) {=
reaction(update_trigger) -> update {=
lf_set(update, self->update_amount);
=} deadline(update_deadline) {=
tag_t tag = lf_tag();
lf_print_error("At tag (%lld, %u), deadline missed at database \"%s\". Rejecting update.\n"
" Elapsed physical time is %lld.",
Expand Down Expand Up @@ -186,7 +187,9 @@ reactor Database(name: char* = "unnamed database", num_remote_inputs: int = 1) {
#endif
=}

reaction(query) -> balance {= lf_set(balance, self->record); =}
reaction(query) -> balance {=
lf_set(balance, self->record);
=}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ reactor ResourceManager(
}
=}

reaction(shutdown) {= free(self->queue.queue); =}
reaction(shutdown) {=
free(self->queue.queue);
=}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion examples/C/src/ReflexGame/ReflexGame.lf
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ reactor GetUserInput {
lf_thread_create(&thread_id, &read_input, user_response);
=}

reaction(prompt) {= self->prompt_time = lf_time_logical(); =}
reaction(prompt) {=
self->prompt_time = lf_time_logical();
=}

reaction(user_response) -> another {=
if (user_response->value == EOF) {
Expand Down
8 changes: 6 additions & 2 deletions examples/C/src/RockPaperScissors.lf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/
target C

preamble {= typedef enum {paper=0, rock=1, scissors=2} symbol_t; =}
preamble {=
typedef enum {paper=0, rock=1, scissors=2} symbol_t;
=}

main reactor RockPaperScissors {
player1 = new Player(id=1)
Expand All @@ -19,7 +21,9 @@ main reactor RockPaperScissors {
}

reactor Player(id: char = 0) {
preamble {= const char* symbol_names[] = {"paper", "rock", "scissors"}; =}
preamble {=
const char* symbol_names[] = {"paper", "rock", "scissors"};
=}

input observe: symbol_t
output reveal: symbol_t
Expand Down
4 changes: 3 additions & 1 deletion examples/C/src/browser-ui/BrowserUI.lf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ main reactor {
state count: int = 0
s = new ServerUI()

reaction(s.initialized) {= self->count = 0; =}
reaction(s.initialized) {=
self->count = 0;
=}

reaction(s.request) -> s.response {=
char* response;
Expand Down
4 changes: 3 additions & 1 deletion examples/C/src/car-brake/CarBrake.lf
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ reactor Braking {

state thread: lf_thread_t

reaction(startup) -> pedal {= lf_thread_create(&self->thread, &press_pedal, pedal); =}
reaction(startup) -> pedal {=
lf_thread_create(&self->thread, &press_pedal, pedal);
=}

reaction(shutdown) {=
stop_thread = true;
Expand Down
2 changes: 1 addition & 1 deletion examples/C/src/containerized/HelloWorldContainerized.lf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ target C {
import MessageGenerator from "../distributed/HelloWorld.lf"
import PrintMessage from "../distributed/HelloWorld.lf"

federated reactor HelloWorldContainerized at rti {
federated reactor HelloWorldContainerized {
source = new MessageGenerator(prefix = "Hello World")
print = new PrintMessage()
source.message -> print.message
Expand Down
8 changes: 6 additions & 2 deletions examples/C/src/deadlines/AnytimePrime.lf
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ reactor Prime {

// Output the largest prime found.
lf_set(out, (long long)primes.start[num_primes - 1]);
=} deadline(3 sec) {= lf_print("Deadline handler called!"); =}
=} deadline(3 sec) {=
lf_print("Deadline handler called!");
=}
}

reactor Print {
input in: {= long long =}

reaction(in) {= printf("Largest prime found within the deadline: %lld\n", in->value); =}
reaction(in) {=
printf("Largest prime found within the deadline: %lld\n", in->value);
=}
}

main reactor AnytimePrime {
Expand Down
4 changes: 3 additions & 1 deletion examples/C/src/deadlines/PeriodicDeadline.lf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ reactor OffsetSensor(offset: time = 0) extends Sensor {
lf_sleep(SEC(2));
=}

reaction(t) -> y {= lf_set(y, self->count++); =}
reaction(t) -> y {=
lf_set(y, self->count++);
=}
}

reactor StartupSensor extends Sensor {
Expand Down
8 changes: 6 additions & 2 deletions examples/C/src/keyboard/Keyboard.lf
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ reactor KeyboardInput(exit_key: int = 0) {
lf_thread_create(&thread_id, &read_input, &keyboard_input);
=}

reaction(keypress) -> key {= lf_set(key, keypress->value); =}
reaction(keypress) -> key {=
lf_set(key, keypress->value);
=}

reaction(shutdown) {=
endwin();
Expand All @@ -98,5 +100,7 @@ reactor KeyboardInput(exit_key: int = 0) {
main reactor {
k = new KeyboardInput(exit_key=120)

reaction(k.key) {= lf_print("You typed %c (keycode %d).", k.key->value, k.key->value); =}
reaction(k.key) {=
lf_print("You typed %c (keycode %d).", k.key->value, k.key->value);
=}
}
8 changes: 6 additions & 2 deletions examples/C/src/leader-election/Election.lf
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ reactor Node(id: int = 0) {
logical action a: int

initial mode NotElected {
reaction(startup) -> out {= lf_set(out, self->id); =}
reaction(startup) -> out {=
lf_set(out, self->id);
=}

reaction(a) -> out {= lf_set(out, a->value); =}
reaction(a) -> out {=
lf_set(out, a->value);
=}

reaction(in) -> a, reset(Elected) {=
if (in->value > self->id) {
Expand Down
4 changes: 3 additions & 1 deletion examples/C/src/lib/PrintToFile.lf
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ reactor PrintToFile(filename: string = "output.data") {
fprintf(self->file, "%f %f\n", t, y->value);
=}

reaction(shutdown) {= fclose(self->file); =}
reaction(shutdown) {=
fclose(self->file);
=}
}
4 changes: 3 additions & 1 deletion examples/C/src/lib/Random.lf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ reactor Random(seed: {= unsigned int =} = 0) {
}
=}

method random(): int {= return rand_r(&self->seed); =}
method random(): int {=
return rand_r(&self->seed);
=}

method exponential(lambda: double): double {=
double u = random() / (RAND_MAX + 1.0);
Expand Down
4 changes: 3 additions & 1 deletion examples/C/src/lib/RandomDelay.lf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ reactor RandomDelay(average: time = 1 sec) extends Random {
output out: time
logical action a: time

reaction(a) -> out {= lf_set(out, a->value); =}
reaction(a) -> out {=
lf_set(out, a->value);
=}

reaction(in) -> a {=
double lambda = SEC(1) / ((double)self->average);
Expand Down
4 changes: 3 additions & 1 deletion examples/C/src/lib/ServerUI.lf
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ reactor ServerUI(initial_file: string = "page.html", hostport: uint16_t = 8080)
* with its contents. The caller is responsible for freeing the pointer returned.
* @param path File path relative to the source .lf file.
*/
method read_file(path: {= const char* =}): char* {=
method read_file(path: {=
const char*
=}): char* {=
// Construct the path to the file to be read
char* file_path = (char *) malloc(strlen(LF_SOURCE_DIRECTORY) + strlen(path) + 2);
if (file_path == NULL) lf_print_error_and_exit("Out of memory.");
Expand Down
12 changes: 9 additions & 3 deletions examples/C/src/lib/WebSocketServer.lf
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ reactor WebSocketServer(hostport: int = 8000, max_clients: int = 0) {
self->status.running = true;
=}

reaction(received_action) -> received {= lf_set_token(received, received_action->token); =}
reaction(received_action) -> received {=
lf_set_token(received, received_action->token);
=}

reaction(send) {=
// NOTE: This send must be before the reaction to connected_action
Expand All @@ -290,7 +292,11 @@ reactor WebSocketServer(hostport: int = 8000, max_clients: int = 0) {
}
=}

reaction(connected_action) -> connected {= lf_set(connected, connected_action->value); =}
reaction(connected_action) -> connected {=
lf_set(connected, connected_action->value);
=}

reaction(shutdown) {= self->status.running = false; =}
reaction(shutdown) {=
self->status.running = false;
=}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ main reactor {
s.theta -> p.theta
s.phi -> p.phi

reaction(disturb) -> s.d {= lf_set(s.d, 0.5); =}
reaction(disturb) -> s.d {=
lf_set(s.d, 0.5);
=}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,7 @@ reactor PendulumSimulation(
self->x[1] += d->value;
=}

reaction(u) {= self->latest_u = u->value; =}
reaction(u) {=
self->latest_u = u->value;
=}
}
4 changes: 3 additions & 1 deletion examples/C/src/modal_models/FurutaPendulum/Print.lf
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ reactor Print(filename: string = "pendulum.csv") {
);
=}

reaction(shutdown) {= fclose(self->file); =}
reaction(shutdown) {=
fclose(self->file);
=}
}
4 changes: 3 additions & 1 deletion examples/C/src/patterns/Simultaneity.lf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ reactor Source(period: time = 100 ms) {
output out: int
state count: int = 0

reaction(t) -> out {= lf_set(out, self->count++); =}
reaction(t) -> out {=
lf_set(out, self->count++);
=}
}

reactor Sink {
Expand Down
24 changes: 18 additions & 6 deletions examples/C/src/patterns/lib/SendersAndReceivers.lf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ target C
reactor SendOnce {
output out: int

reaction(startup) -> out {= lf_set(out, 42); =}
reaction(startup) -> out {=
lf_set(out, 42);
=}
}

/**
Expand Down Expand Up @@ -47,14 +49,18 @@ reactor ReceiveAndSend {
input in: int
output out: int

reaction(in) -> out {= lf_set(out, in->value); =}
reaction(in) -> out {=
lf_set(out, in->value);
=}
}

reactor SendOnceAndReceive {
input in: int
output out: int

reaction(startup) -> out {= lf_set(out, 42); =}
reaction(startup) -> out {=
lf_set(out, 42);
=}

reaction(in) {=
lf_print("At tag (%lld, %d), received %d.",
Expand Down Expand Up @@ -164,7 +170,9 @@ reactor SendAndReceiveWithLocalQuery(query_offset: time = 0, query_period: time
extends LocalRemoteUpdates {
local_query = new SendPeriodicallyAndReceive(offset=query_offset, period=query_period)

reaction(local_query.out) -> local_query.in {= lf_set(local_query.in, self->count); =}
reaction(local_query.out) -> local_query.in {=
lf_set(local_query.in, self->count);
=}
}

// @label Accumulate local/remote increments, delayed query.
Expand All @@ -175,7 +183,11 @@ reactor SendAndReceiveWithDelayedQuery(
local_query = new SendPeriodicallyAndReceive(offset=query_offset, period=query_period)
logical action a(query_delay)

reaction(local_query.out) -> a {= lf_schedule(a, 0); =}
reaction(local_query.out) -> a {=
lf_schedule(a, 0);
=}

reaction(a) -> local_query.in {= lf_set(local_query.in, self->count); =}
reaction(a) -> local_query.in {=
lf_set(local_query.in, self->count);
=}
}
8 changes: 6 additions & 2 deletions examples/C/src/rhythm/PlayWaveform.lf
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ reactor PlayWaveform(
lf_start_audio_loop(lf_time_logical());
=}

reaction(waveform) {= self->waveform_id = waveform->value; =}
reaction(waveform) {=
self->waveform_id = waveform->value;
=}

reaction(note) {=
if (self->waveform_id < 0 || self->waveform_id > NUM_WAVEFORMS) {
Expand All @@ -96,5 +98,7 @@ reactor PlayWaveform(
}
=}

reaction(shutdown) {= lf_stop_audio_loop(); =}
reaction(shutdown) {=
lf_stop_audio_loop();
=}
}
Loading

0 comments on commit 2a1493a

Please sign in to comment.