Stand up basic functioning TCP-based Ludus Repl

This commit is contained in:
Scott Richmond 2023-12-24 19:25:42 -05:00
commit 25f50b1100
11 changed files with 359 additions and 0 deletions

178
.gitignore vendored Normal file
View File

@ -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

2
.ignore Normal file
View File

@ -0,0 +1,2 @@
.jj/
node_modules/

15
README.md Normal file
View File

@ -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.

BIN
bun.lockb Executable file

Binary file not shown.

35
listener.ts Normal file
View File

@ -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() }
}
})

50
package-lock.json generated Normal file
View File

@ -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"
}
}
}
}

14
package.json Normal file
View File

@ -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"
}
}

13
runner.ts Normal file
View File

@ -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)

11
scratch.ld Normal file
View File

@ -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)

19
sender.ts Normal file
View File

@ -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()
}

22
tsconfig.json Normal file
View File

@ -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
}
}