From 25f50b1100d9d00403349dd169a72c175c310249 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sun, 24 Dec 2023 19:25:42 -0500 Subject: [PATCH] Stand up basic functioning TCP-based Ludus Repl --- .gitignore | 178 ++++++++++++++++++++++++++++++++++++++++++++++ .ignore | 2 + README.md | 15 ++++ bun.lockb | Bin 0 -> 2031 bytes listener.ts | 35 +++++++++ package-lock.json | 50 +++++++++++++ package.json | 14 ++++ runner.ts | 13 ++++ scratch.ld | 11 +++ sender.ts | 19 +++++ tsconfig.json | 22 ++++++ 11 files changed, 359 insertions(+) create mode 100644 .gitignore create mode 100644 .ignore create mode 100644 README.md create mode 100755 bun.lockb create mode 100644 listener.ts create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 runner.ts create mode 100644 scratch.ld create mode 100644 sender.ts create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dfebb8a --- /dev/null +++ b/.gitignore @@ -0,0 +1,178 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +.*.bun-build +.lrepl + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Caches + +.cache + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/.ignore b/.ignore new file mode 100644 index 0000000..d8b0427 --- /dev/null +++ b/.ignore @@ -0,0 +1,2 @@ +.jj/ +node_modules/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..af3fe62 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# ludus-repl + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.0.20. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000000000000000000000000000000000000..ac05b895ecf5279ea1974900671d5889db494aa4 GIT binary patch literal 2031 zcmY#Z)GsYA(of3F(@)JSQ%EY!;{sycoc!eMw9K4T-L(9o+{6;yG6OCq1_lQ6$=+&R z!c1oS*Ue|x*k^xiqr&#tv7MnIJPdXzJw1DT;@N?UfPe);F>s*K4N!gwOaYkB#lX-Y z0%U>cU?9y2q=9TOU*%bO;22k}jMCgO06^On9sQP_yebGi{ zv85J3N1MUzG(>eYtXzYYUjmGArg{c?1`G_a5)f9>aWLg1mZTP!FfhQ%L|EC!#ApcA zVrap@z`+LcCj)~AltvB7;?&%-)FM6Cijvf#yu_T~lA_GKbUOt@gySsWjw>ln2Ag!? zx5(0>DHB9M6#__%|K4Jocd~`MN{Wk9i-4xZURG!fO7s3P9jKZISYEYQn4V#*;QLnr zbwN0^1^|XVFdPhV1p`A)X-a9aZc%DMPDy1!YH@N=W`grNo446wH$ bUd3Y!!p%T)5FA}oJ!2pQx&<7TgOC6Ka=&N+ literal 0 HcmV?d00001 diff --git a/listener.ts b/listener.ts new file mode 100644 index 0000000..0917e7b --- /dev/null +++ b/listener.ts @@ -0,0 +1,35 @@ +import { run } from "@ludus/ludus-js-pure" + +const port = Math.floor((Math.random() * 1000) + 50000) + +const repl_info = { port } + +const repl_file = Bun.file("./.lrepl") + +await Bun.write(repl_file, JSON.stringify(repl_info)) + +console.log(`Ludus REPL listening on localhost:${port}`) + +Bun.listen({ + hostname: "localhost", + port, + socket: { + data: (socket, data) => { + const source = data.toString("utf-8") + const result = run(source) + const msgs = result.console + for (const msg of msgs) { + console.log(msg) + } + if (!result.errors) console.log(result.result) + else { + console.log("Ludus had some errors:") + console.log(result.errors) + } + }, + error: (socket, error) => { console.log(error); socket.end() } + } +}) + + + diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..4d62bfc --- /dev/null +++ b/package-lock.json @@ -0,0 +1,50 @@ +{ + "name": "ludus-repl", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "ludus-repl", + "dependencies": { + "@ludus/ludus-js-pure": "^0.1.0-alpha.8" + }, + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + } + }, + "node_modules/@ludus/ludus-js-pure": { + "version": "0.1.0-alpha.8", + "resolved": "https://registry.npmjs.org/@ludus/ludus-js-pure/-/ludus-js-pure-0.1.0-alpha.8.tgz", + "integrity": "sha512-r0slrbccrvauaRa8tPZh5hrx5lS9gXyhyI5+cVWyYOqJyHNmh62uMEbi3rNjVSc+FqKdQ8GpiC1ZcrNJP5aWiA==" + }, + "node_modules/@types/bun": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/bun/-/bun-1.0.0.tgz", + "integrity": "sha512-TPI/aImv/fSo0SWlt29wq0tWRqQOWsC4FOXYeUK0Ni6tAS+FqJZ2p7QCGY4hmHaHQeE2KhKJ6Qn9k3kvFfXD3Q==", + "dev": true, + "dependencies": { + "bun-types": "1.0.18" + } + }, + "node_modules/bun-types": { + "version": "1.0.18", + "dev": true, + "license": "MIT" + }, + "node_modules/typescript": { + "version": "5.3.3", + "license": "Apache-2.0", + "peer": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..4f8cd74 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "ludus-repl", + "module": "index.ts", + "type": "module", + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "dependencies": { + "@ludus/ludus-js-pure": "^0.1.0-alpha.8" + } +} diff --git a/runner.ts b/runner.ts new file mode 100644 index 0000000..b9861b1 --- /dev/null +++ b/runner.ts @@ -0,0 +1,13 @@ +import {run} from "@ludus/ludus-js-pure" + +const script = Bun.argv[2] +const file = Bun.file(script) +const source = await file.text() +console.log(`Source to run: +${source}`) + +const result = run(source) + +if (!result.errors) console.log(result.result) +else console.log(result.errors) + diff --git a/scratch.ld b/scratch.ld new file mode 100644 index 0000000..92b010f --- /dev/null +++ b/scratch.ld @@ -0,0 +1,11 @@ +let foo = 42 +let bar = :thing +let baz = #{:a 1, :b 2} + +doc! (add) + +print! ("This is a message from inside Ludus") + +[foo, bar, baz] + +add (1, 2) diff --git a/sender.ts b/sender.ts new file mode 100644 index 0000000..5ef926e --- /dev/null +++ b/sender.ts @@ -0,0 +1,19 @@ +const repl_file = Bun.file("./.lrepl") +const repl_info = await repl_file.json() +const port = repl_info.port + +const socket = await Bun.connect({ + hostname: "localhost", + port, + socket: { + data: (_, data) => process.exit() + } +}) + +for await (const input of Bun.stdin.stream()) { + const chunk = Buffer.from(input).toString("utf-8") + socket.write(chunk) + socket.end() + process.exit() +} + diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..dcd8fc5 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "lib": ["ESNext"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + /* Linting */ + "skipLibCheck": true, + "strict": true, + "noFallthroughCasesInSwitch": true, + "forceConsistentCasingInFileNames": true + } +}