Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brainf**k project #25

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/lib/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function isKey<T extends object>(x: T, k: PropertyKey): k is keyof T {
return k in x;
}

type Projects = "WEBHOOK_DESTROYER" | "STILL_ALIVE";
type Projects = "WEBHOOK_DESTROYER" | "STILL_ALIVE" | "BRAINFUCK";
type Project = {
title: string;
description: string;
Expand All @@ -23,6 +23,12 @@ const Projects: Record<Projects, Project> = {
needsJS: true,
slug: "still-alive",
},
BRAINFUCK: {
title: "brainf**k interpreter",
description: "a interpreter for the brainf**k language",
needsJS: true,
slug: "brainfuck"
}
} as const;

const keys = Object.keys(Projects);
Expand Down
9 changes: 9 additions & 0 deletions src/pages/projects/brainfuck.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
import ProjectLayout from "~/layouts/ProjectLayout.astro";
import { Projects } from "~/lib/projects";
import { Brainfuck as Brainfk } from "~/projects/brainfuck/brainfuck.tsx";
---

<ProjectLayout project={Projects.BRAINFUCK}>
<Brainfk client:only />
</ProjectLayout>
23 changes: 23 additions & 0 deletions src/projects/brainfuck/brainfuck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createSignal } from "solid-js";

function useBrainfuck() {
const [output, setOutput] = createSignal("none");

const interpret = (program: string) => {
console.log(program);
alert("test to see if this runs");
setOutput("this interpreter is not done, this output is just a placeholder");
}

const reset = () => {
setOutput("none");
}

return {
output,
interpret,
reset
};
}

export { useBrainfuck };
32 changes: 32 additions & 0 deletions src/projects/brainfuck/brainfuck.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Input } from "~/components/ui/input";
import type { JSX } from "solid-js";
import { useBrainfuck } from "./brainfuck.ts";

export function Brainfuck() {
const { output, interpret } = useBrainfuck();
return (
<>
<span>output: {output()} </span>
<form onSubmit={(e) => {
e.preventDefault();
const formData = new FormData(e.target);
const program = formData.get("program").toString();
interpret(program);
}}>
<Input
id="program"
placeholder="the brainfuck program to execute"
class={`w-[90%]`}
style={{ "font-family": "inherit" }}
required
/>
<button
class="mt-2 w-fit rounded-md bg-red-500 px-4 py-2 text-[1.2rem]"
style={{ "font-family": "inherit" }}
>
run
</button>
</form>
</>
)
}