Skip to content

Commit

Permalink
Merge branch 'add-flexpret-docs' of github.com:magnmaeh/lf-lang.githu…
Browse files Browse the repository at this point in the history
…b.io into add-flexpret-docs
  • Loading branch information
magnmaeh committed May 19, 2024
2 parents b5f23b8 + a459fbd commit 16fec8b
Show file tree
Hide file tree
Showing 365 changed files with 26,388 additions and 2,088 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ In our [deployment workflow](https://github.com/lf-lang/lf-lang.github.io/blob/m
$ yarn build
```
This generates static content in the `build` directory, which gets served using GitHub's static contents hosting service, GitHub Pages.

### Versioning
Instructions for "freezing" the current docs and filing them under a version number, can be found [here](https://docusaurus.io/docs/versioning). Normally, the steps are:
```
git switch main
git pull
git checkout -b v<major>.<minor>.<patch>
yarn docusaurus docs:version <major>.<minor>.<patch>
git add versioned_docs/*
git commit -a -m 'Docs v<major>.<minor>.<patch>'
```
2 changes: 1 addition & 1 deletion docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const config: Config = {


clientModules: [
"src/components/ShikijiLFHighlighter/shikijiloader.ts"
"src/components/ShikiLFHighlighter/shikiloader.ts"
],
};

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
"@docusaurus/plugin-ideal-image": "^3.1.1",
"@docusaurus/preset-classic": "^3.1.1",
"@mdx-js/react": "^3.0.0",
"clsx": "^1.2.1",
"clsx": "^2.1.1",
"prism-react-renderer": "^2.1.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-transition-group": "^4.4.5",
"shikiji": "^0.7.4",
"shiki": "^1.5.1",
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
"@docusaurus/eslint-plugin": "^3.1.1",
"@docusaurus/module-type-aliases": "^3.1.1",
"@docusaurus/tsconfig": "^3.1.1",
"@docusaurus/types": "^3.1.1",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"eslint": "^8.55.0",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"eslint": "^9.2.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-regexp": "^2.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/components/LinguaFrancaMultiTargetUtils/LangSpecific.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TabItem from "@theme/TabItem";
import styles from "./styles.module.css";
import CodeBlock from "@theme/CodeBlock";
import { ReactNode, useEffect, useState } from "react";
import { ShikijiLFHighlighter } from "../ShikijiLFHighlighter";
import { ShikiLFHighlighter } from "../ShikiLFHighlighter";

interface WebpackImportedRawModule {
default: Readonly<Record<string, string>>;
Expand Down Expand Up @@ -47,7 +47,7 @@ export const NoSelectorTargetCodeBlock = (
string | Promise<WebpackImportedRawModule | null>
>),
): JSX.Element => {
const Component = props.lf ? ShikijiLFHighlighter : CodeBlock;
const Component = props.lf ? ShikiLFHighlighter : CodeBlock;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { lf, ...targetToCode } = props;
const newProps: Record<TargetsType, ReactNode> = {} as Record<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { HighlighterGeneric, BuiltinLanguage, BuiltinTheme } from "shikiji";
import { loadShikiji } from "./shikijiloader";
import { HighlighterGeneric, BuiltinLanguage, BuiltinTheme } from "shiki";
import { loadShiki } from "./shikiloader";
import { useColorMode } from "@docusaurus/theme-common";
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";

Expand All @@ -12,7 +12,7 @@ declare global {
}
}

export const ShikijiLFHighlighter = ({
export const ShikiLFHighlighter = ({
children,
...props
}: { children: string } & Record<string, unknown>) => {
Expand All @@ -28,7 +28,7 @@ export const ShikijiLFHighlighter = ({
useEffect(() => {
(async () => {
if (!isBrowser) return;
const shiki = await loadShikiji();
const shiki = await loadShiki();
setCode(
shiki.codeToHtml(children, {
lang: "Lingua Franca",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
import { LanguageRegistration, getHighlighter } from "shikiji";
import { LanguageRegistration, getHighlighter } from "shiki";
import { targets } from "@site/src/components/LinguaFrancaMultiTargetUtils";
import LFTextMateLanguageDefinition from "./lflang.tmLanguage.json";
import { HighlighterGeneric, BuiltinLanguage, BuiltinTheme } from "shikiji";
import { HighlighterGeneric, BuiltinLanguage, BuiltinTheme } from "shiki";

declare global {
interface Window {
Expand All @@ -12,11 +12,11 @@ declare global {
}
}

export const loadShikiji = async () => {
export const loadShiki = async () => {
if (window.LFWebsite?.shikijiInstance != null) {
return window.LFWebsite.shikijiInstance;
}
const shikiji = await getHighlighter({
const shiki = await getHighlighter({
themes: ["material-theme-lighter", "material-theme-darker"],
langs: [
...targets,
Expand All @@ -27,19 +27,19 @@ export const loadShikiji = async () => {
if (window.LFWebsite == null) {
window.LFWebsite = {};
}
window.LFWebsite.shikijiInstance = shikiji;
return shikiji;
window.LFWebsite.shikijiInstance = shiki;
return shiki;
};

if (ExecutionEnvironment.canUseDOM) {
// As soon as the site loads in the browser, check if a Shikiji instance is created. If not, create one and save to global.

// Don't catch. Let it throw~ let it throw~
loadShikiji().then((v) => {
loadShiki().then((v) => {
if (v != null) {
console.log("Shikiji is loaded.");
console.log("Shiki loaded.");
} else {
throw Error("Shikiji not loaded correctly.");
throw Error("Shiki did loaded correctly.");
}
});
}
4 changes: 2 additions & 2 deletions src/theme/CodeBlock/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from "react";
import CodeBlock from "@theme-original/CodeBlock";
import { ShikijiLFHighlighter } from "@site/src/components/ShikijiLFHighlighter";
import { ShikiLFHighlighter } from "@site/src/components/ShikiLFHighlighter";

export default function CodeBlockWrapper(props) {
return (
<>
{/* If using <CodeBlock /> then it will contain language="lf-c"; if using ``` it will contain className="language-lf-c". */}
{props.language?.startsWith("lf") ||
props.className?.startsWith("language-lf") ? (
<ShikijiLFHighlighter {...props} />
<ShikiLFHighlighter {...props} />
) : (
<CodeBlock {...props} />
)}
Expand Down
3 changes: 3 additions & 0 deletions versioned_docs/version-0.7.0/assets/code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin
src-gen
include
1 change: 1 addition & 0 deletions versioned_docs/version-0.7.0/assets/code/c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include/
22 changes: 22 additions & 0 deletions versioned_docs/version-0.7.0/assets/code/c/src/Alignment.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
target C {
timeout: 3 secs
}

main reactor Alignment {
state s: int = 0
timer t1(100 msec, 100 msec)
timer t2(200 msec, 200 msec)
timer t4(400 msec, 400 msec)

reaction(t1) {=
self->s += 1;
=}

reaction(t2) {=
self->s -= 2;
=}

reaction(t4) {=
printf("s = %d\n", self->s);
=}
}
31 changes: 31 additions & 0 deletions versioned_docs/version-0.7.0/assets/code/c/src/Asynchronous.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
target C {
keepalive: true // Do not exit when event queue is empty.
}

preamble {=
#include "platform.h" // Defines lf_sleep() and thread functions.
=}

main reactor {
preamble {=
// Schedule an event roughly every 200 msec.
void* external(void* a) {
while (true) {
lf_sleep(MSEC(200));
lf_schedule(a, 0);
}
}
=}
state thread_id: lf_thread_t = 0
physical action a(100 msec): int

reaction(startup) -> a {=
// Start a thread to schedule physical actions.
lf_thread_create(&self->thread_id, &external, a);
=}

reaction(a) {=
interval_t elapsed_time = lf_time_logical_elapsed();
printf("Action triggered at logical time %lld nsec after start.\n", elapsed_time);
=}
}
12 changes: 12 additions & 0 deletions versioned_docs/version-0.7.0/assets/code/c/src/BankIndex.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
target C;
preamble {=
int table[] = {4, 3, 2, 1};
=}
reactor A(bank_index:int = 0, value:int = 0) {
reaction (startup) {=
printf("bank_index: %d, value: %d\n", self->bank_index, self->value);
=}
}
main reactor {
a = new[4] A(value = {= table[bank_index] =});
}
21 changes: 21 additions & 0 deletions versioned_docs/version-0.7.0/assets/code/c/src/CheckDeadline.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
target C;

reactor Count {
output out:int;
reaction(startup) -> out {=
int count = 0;
while (!lf_check_deadline(self, true)) {
count++;
}
lf_set(out, count);
=} deadline (3 msec) {=
printf("Stopped counting.\n");
=}
}

main reactor {
c = new Count();
reaction(c.out) {=
printf("Counted to %d\n", c.out->value);
=}
}
16 changes: 16 additions & 0 deletions versioned_docs/version-0.7.0/assets/code/c/src/ChildBank.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
target C;
reactor Child (
bank_index:int = 0
) {
reaction(startup) {=
printf("My bank index: %d.\n", self->bank_index);
=}
}
reactor Parent (
bank_index:int = 0
) {
c = new[2] Child();
}
main reactor {
p = new[2] Parent();
}
18 changes: 18 additions & 0 deletions versioned_docs/version-0.7.0/assets/code/c/src/ChildParentBank.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
target C

reactor Child(bank_index: int = 0, parent_bank_index: int = 0) {
reaction(startup) {=
printf(
"My bank index: %d. My parent's bank index: %d.\n",
self->bank_index, self->parent_bank_index
);
=}
}

reactor Parent(bank_index: int = 0) {
c = new[2] Child(parent_bank_index=bank_index)
}

main reactor {
p = new[2] Parent()
}
23 changes: 23 additions & 0 deletions versioned_docs/version-0.7.0/assets/code/c/src/ChildParentBank2.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
target C

reactor Child(bank_index: int = 0, parent_bank_index: int = 0) {
output out: int

reaction(startup) -> out {=
lf_set(out, self->parent_bank_index * 2 + self->bank_index);
=}
}

reactor Parent(bank_index: int = 0) {
c = new[2] Child(parent_bank_index=bank_index)

reaction(c.out) {=
for (int i=0; i < c_width; i++) {
printf("Received %d from child %d.\n", c[i].out->value, i);
}
=}
}

main reactor {
p = new[2] Parent()
}
13 changes: 13 additions & 0 deletions versioned_docs/version-0.7.0/assets/code/c/src/Contained.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
target C

import Overwriting from "Overwriting.lf"

main reactor {
s = new Overwriting()

reaction(s.y) {=
if (s.y->value != 0 && s.y->value != 1) {
lf_print_error_and_exit("Outputs should only be 0 or 1!");
}
=}
}
11 changes: 11 additions & 0 deletions versioned_docs/version-0.7.0/assets/code/c/src/Count.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target C

reactor Count {
state count: int = 0
output y: int
timer t(0, 100 msec)

reaction(t) -> y {=
lf_set(y, self->count++);
=}
}
24 changes: 24 additions & 0 deletions versioned_docs/version-0.7.0/assets/code/c/src/Cycle.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
target C;
reactor A {
input x:int;
output y:int;
reaction(x) -> y {=
// ... something here ...
=}
}
reactor B {
input x:int;
output y:int;
reaction(x) {=
// ... something here ...
=}
reaction(startup) -> y {=
// ... something here ...
=}
}
main reactor {
a = new A();
b = new B();
a.y -> b.x;
b.y -> a.x;
}
24 changes: 24 additions & 0 deletions versioned_docs/version-0.7.0/assets/code/c/src/CycleReordered.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
target C;
reactor A {
input x:int;
output y:int;
reaction(x) -> y {=
// ... something here ...
=}
}
reactor B {
input x:int;
output y:int;
reaction(startup) -> y {=
// ... something here ...
=}
reaction(x) {=
// ... something here ...
=}
}
main reactor {
a = new A();
b = new B();
a.y -> b.x;
b.y -> a.x;
}
Loading

0 comments on commit 16fec8b

Please sign in to comment.