This commit is contained in:
mehbark 2023-04-17 00:26:08 -04:00
parent 465a93c59f
commit 640e3e357d
10 changed files with 794 additions and 2217 deletions

View file

@ -1,46 +0,0 @@
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
If you arent satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).

2266
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,43 +1,44 @@
{ {
"name": "concat", "name": "concat",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"dependencies": { "homepage": "concat",
"@testing-library/jest-dom": "^5.16.5", "dependencies": {
"@testing-library/react": "^13.4.0", "@testing-library/jest-dom": "^5.16.5",
"@testing-library/user-event": "^13.5.0", "@testing-library/react": "^13.4.0",
"@types/jest": "^27.5.2", "@testing-library/user-event": "^13.5.0",
"@types/node": "^16.18.23", "@types/jest": "^27.5.2",
"@types/react": "^18.0.35", "@types/node": "^16.18.23",
"@types/react-dom": "^18.0.11", "@types/react": "^18.0.35",
"react": "^18.2.0", "@types/react-dom": "^18.0.11",
"react-dom": "^18.2.0", "react": "^18.2.0",
"react-scripts": "5.0.1", "react-dom": "^18.2.0",
"typescript": "^4.9.5", "react-scripts": "5.0.1",
"web-vitals": "^2.1.4" "typescript": "^4.9.5",
}, "web-vitals": "^2.1.4"
"scripts": { },
"start": "react-scripts start", "scripts": {
"build": "react-scripts build", "start": "react-scripts start",
"test": "react-scripts test", "build": "react-scripts build",
"eject": "react-scripts eject" "test": "react-scripts test",
}, "eject": "react-scripts eject"
"eslintConfig": { },
"extends": [ "eslintConfig": {
"react-app", "extends": [
"react-app/jest" "react-app",
] "react-app/jest"
}, ]
"browserslist": { },
"production": [ "browserslist": {
">0.2%", "production": [
"not dead", ">0.2%",
"not op_mini all" "not dead",
], "not op_mini all"
"development": [ ],
"last 1 chrome version", "development": [
"last 1 firefox version", "last 1 chrome version",
"last 1 safari version" "last 1 firefox version",
] "last 1 safari version"
} ]
}
} }

View file

@ -1,21 +1,21 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#008282" />
<meta <meta
name="description" name="description"
content="Web site created using create-react-app" content="An (extremely) simple stack-based language with neato interactivity"
/> />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!-- <!--
manifest.json provides metadata used when your web app is installed on a manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
--> -->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!-- <!--
Notice the use of %PUBLIC_URL% in the tags above. Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build. It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML. Only files inside the `public` folder can be referenced from the HTML.
@ -24,12 +24,12 @@
work correctly both with client-side routing and a non-root public URL. work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`. Learn how to configure a non-root public URL by running `npm run build`.
--> -->
<title>React App</title> <title>Concat</title>
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div> <div id="root"></div>
<!-- <!--
This HTML file is a template. This HTML file is a template.
If you open it directly in the browser, you will see an empty page. If you open it directly in the browser, you will see an empty page.
@ -38,6 +38,5 @@
To begin the development, run `npm start` or `yarn start`. To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`. To create a production bundle, use `npm run build` or `yarn build`.
--> --></body>
</body>
</html> </html>

View file

@ -1,38 +1,153 @@
.App { html {
text-align: center; --fg: #dcfdfd;
--bg: #021111;
--accent-hue: 180;
--accent-sat: 100%;
--accent-lig: 10%;
--accent: hsl(var(--accent-hue), var(--accent-sat), var(--accent-lig));
color: var(--fg);
background-color: var(--bg);
} }
.App-logo { #root {
height: 40vmin; display: flex;
pointer-events: none; height: 100%;
width: 100%;
overflow: hidden;
} }
@media (prefers-reduced-motion: no-preference) { .program {
.App-logo { height: 100%;
animation: App-logo-spin infinite 20s linear; width: 50%;
} color: var(--fg);
background-color: var(--bg);
resize: none;
outline: 1px solid var(--fg);
border: none;
} }
.App-header { .info {
background-color: #282c34; z-index: -413;
min-height: 100vh; display: grid;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
} }
.App-link { .ops,
color: #61dafb; .states {
width: 50vw;
} }
@keyframes App-logo-spin { .ops {
from { /* position: fixed; */
transform: rotate(0deg); /* top: 0;
} left: 50%; */
to { background-color: var(--bg);
transform: rotate(360deg); border: 1px solid var(--fg);
} }
.states {
overflow: scroll;
}
.state {
border-right: 1px solid var(--fg);
border-bottom: 1px solid var(--fg);
/* margin: 5px; */
}
.state > * {
margin-left: 5px;
}
.stack {
display: block;
}
/* later i can do .op.active and .state.active if necessary */
.active {
/* outline: 1px solid var(--accent);
border: none;
border-left: 1px solid var(--accent); */
/* border-left: 1px solid var(--fg); */
background-color: var(--accent);
}
.op {
display: flex;
white-space: pre;
}
/* https://www.joshwcomeau.com/css/custom-css-reset/ */
/*
1. Use a more-intuitive box-sizing model.
*/
*,
*::before,
*::after {
box-sizing: border-box;
}
/*
2. Remove default margin
*/
* {
margin: 0;
font-family: "Courier New", Courier, monospace;
font-weight: bold;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-size: 14px;
}
/*
3. Allow percentage-based heights in the application
*/
html,
body {
height: 100%;
}
/*
Typographic tweaks!
4. Add accessible line-height
5. Improve text rendering
*/
body {
line-height: 1.5;
-webkit-font-smoothing: antialiased;
}
/*
6. Improve media defaults
*/
img,
picture,
video,
canvas,
svg {
display: block;
max-width: 100%;
}
/*
7. Remove built-in form typography styles
*/
input,
button,
textarea,
select {
font: inherit;
}
/*
8. Avoid text overflows
*/
p,
h1,
h2,
h3,
h4,
h5,
h6 {
overflow-wrap: break-word;
}
/*
9. Create a root stacking context
*/
#root,
#__next {
isolation: isolate;
} }

View file

@ -1,9 +0,0 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

View file

@ -1,26 +1,340 @@
import React from 'react'; /* eslint-disable eqeqeq */
import logo from './logo.svg'; import React, { useState } from "react";
import './App.css'; import "./App.css";
function App() { export default function App() {
return ( let [input, setInput] = useState("");
<div className="App"> let [activeStateIdx, setActiveStateIdx] = useState(0);
<header className="App-header"> let parsed = somes(input.split(/[^a-z0-9-]+/).map(parse_op));
<img src={logo} className="App-logo" alt="logo" /> let states = steps(INITIAL_STATE, parsed);
<p> return (
Edit <code>src/App.tsx</code> and save to reload. <>
</p> <textarea
<a onChange={e => setInput(e.target.value)}
className="App-link" value={input}
href="https://reactjs.org" className="program"
target="_blank" title={`\
rel="noopener noreferrer" type Op =
> | number
Learn React | "add"
</a> | "sub"
</header> | "mul"
</div> | "div"
); | "put"
| "jmp"
| "dup"
| "del"
| "cmp"
| "swp";`}
></textarea>
<div className="info">
<Ops
parsed={parsed}
ip={(states[activeStateIdx] ?? INITIAL_STATE).ip}
// // hack
// top={document.getElementById("input")?.clientHeight ?? 0}
/>
<States
states={states}
activeStateIdx={activeStateIdx}
setActiveStateIdx={n => setActiveStateIdx(n)}
/>
</div>
</>
);
} }
export default App; function Ops({
parsed,
ip,
}: // top,
{
parsed: Op[];
ip: number;
// top: number;
}): JSX.Element {
return (
<div
className="ops"
children={parsed.map((op, i) => (
<Op op={op} highlighted={i == ip} num={i} key={i} />
))}
// style={{
// top: `${top + 5}px`,
// }}
/>
);
}
function Op({
op,
highlighted,
num,
...props
}: {
op: Op;
num: number;
highlighted: boolean;
}): JSX.Element {
return (
<div
className={`op ${highlighted ? "active" : ""}`}
key={num}
{...props}
>
<div className="op-num">{num}: </div>
{op}
</div>
);
}
function States({
states,
activeStateIdx,
setActiveStateIdx,
}: {
states: State[];
activeStateIdx: number;
setActiveStateIdx: (_: number) => any;
}): JSX.Element {
return (
<div
className="states"
children={states.map((state, i) => (
<State
state={state}
key={i}
active={activeStateIdx == i}
onMouseEnter={() => setActiveStateIdx(i)}
/>
))}
/>
);
}
function State({
state,
active,
onMouseEnter,
...props
}: {
state: State;
active: boolean;
onMouseEnter: () => any;
}): JSX.Element {
return (
<div
className={`state ${active ? "active" : ""}`}
onMouseEnter={onMouseEnter}
{...props}
>
<div className="ip">Ip: {state.ip}</div>
<span>Stack:</span> <Stack stack={state.stack} />
<span>Output:</span> <Output output={state.output} />
</div>
);
}
function Stack({ stack }: { stack: number[] }): JSX.Element {
let ns = [...stack];
ns.reverse();
return (
<div
className="stack"
children={ns.map((item, i) => (
<StackItem item={item} key={i} />
))}
/>
);
}
function StackItem({ item, ...props }: { item: number }): JSX.Element {
return (
<div className="stack-item" {...props}>
{item}
</div>
);
}
// bad
function Output({ output }: { output: number[] }): JSX.Element {
return (
<div
className="output"
children={output.map((item, i) => (
<StackItem item={item} key={i} />
))}
></div>
);
}
type Option<T> = T | undefined;
function is_some<T>(a: Option<T>): a is T {
return typeof a != "undefined";
}
function is_none<T>(a: Option<T>): a is undefined {
return typeof a == "undefined";
}
function cons<T>(x: T, xs: T[]): T[] {
return [x, ...xs];
}
function somes<T>(os: Option<T>[]): T[] {
if (os.length == 0) {
return [];
} else {
let first = os[0];
if (is_some(first)) {
return cons(first, somes(os.slice(1)));
} else {
return somes(os.slice(1));
}
}
}
type Op =
| number
| "add"
| "sub"
| "mul"
| "div"
| "put"
| "jmp"
| "dup"
| "del"
| "cmp"
| "swp";
function parse_int(n: string, radix?: number): Option<number> {
let maybe_int = parseInt(n, radix);
// eslint-disable-next-line no-self-compare
if (maybe_int == maybe_int) {
return maybe_int;
}
}
function parse_op(op: string): Option<Op> {
if (parse_int(op)) {
return parse_int(op);
}
switch (op) {
case "add":
case "sub":
case "mul":
case "div":
case "put":
case "jmp":
case "dup":
case "del":
case "cmp":
case "swp":
return op;
}
}
type State = {
ip: number;
stack: number[];
output: number[];
};
const INITIAL_STATE: State = {
ip: 0,
stack: [],
output: [],
};
function steps(state: State, ops: Op[], limit = 100, num_steps = 0): State[] {
if (!ops[state.ip] || num_steps > limit) {
return [state];
}
return cons(
state,
steps(step(state, ops[state.ip]), ops, limit, num_steps + 1)
);
}
// all but jmp advance the ip by one
// cmp: lt => -1, eq => 0, gt => 1
function step(state: State, op: Op): State {
let ns = JSON.parse(JSON.stringify(state));
ns.ip++;
function binary_op(
default_a: number,
default_b: number,
f: (a: number, b: number) => number
) {
let [b, a] = [ns.stack.pop() ?? default_b, ns.stack.pop() ?? default_a];
ns.stack.push(f(a, b));
}
if (typeof op == "number") {
ns.stack.push(op);
} else {
switch (op) {
case "add":
binary_op(0, 0, (a, b) => a + b);
break;
case "sub":
binary_op(0, 0, (a, b) => a - b);
break;
case "mul":
binary_op(0, 1, (a, b) => a * b);
break;
case "div":
binary_op(0, 1, (a, b) => a / b);
break;
case "put": {
let popped = ns.stack.pop();
if (typeof popped != "undefined") {
ns.output.push(popped);
}
break;
}
case "jmp":
ns.ip--;
ns.ip += ns.stack.pop() ?? 1;
break;
case "dup": {
let popped = ns.stack.pop();
if (typeof popped != "undefined") {
ns.stack.push(popped, popped);
}
break;
}
case "del":
ns.stack.pop();
break;
case "cmp": {
let [a, b] = [ns.stack.pop() ?? 0, ns.stack.pop() ?? 0];
// matter of taste
ns.stack.push(cmp(b, a));
break;
}
case "swp": {
let [a, b] = [ns.stack.pop(), ns.stack.pop()];
if (typeof a == "undefined" || typeof b == "undefined") {
break;
}
ns.stack.push(a, b);
break;
}
}
}
return ns;
}
function cmp(a: number, b: number): number {
if (a < b) {
return -1;
} else if (a == b) {
return 0;
} else {
return 1;
}
}

View file

@ -1,19 +1,12 @@
import React from 'react'; import React from "react";
import ReactDOM from 'react-dom/client'; import ReactDOM from "react-dom/client";
import './index.css'; import App from "./App";
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement document.getElementById("root") as HTMLElement
); );
root.render( root.render(
<React.StrictMode> <React.StrictMode>
<App /> <App />
</React.StrictMode> </React.StrictMode>
); );
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

View file

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

View file

@ -1,15 +0,0 @@
import { ReportHandler } from 'web-vitals';
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;