)}
diff --git a/site/src/lib/javaRuntime.ts b/site/src/lib/javaRuntime.ts
deleted file mode 100644
index 1bfe579..0000000
--- a/site/src/lib/javaRuntime.ts
+++ /dev/null
@@ -1,196 +0,0 @@
-// Runs real Java client-side via CheerpJ (a JVM compiled to WebAssembly),
-// loaded lazily from Leaning Tech's CDN on first use under their free
-// Community License. This is the only file that knows CheerpJ exists -
-// everything else just calls runJava().
-//
-// Each run is a real compile-then-execute: the snippet is written into
-// CheerpJ's virtual filesystem, compiled with javac (from the OpenJDK 8
-// tools.jar vendored in public/), and the resulting class is executed. javac
-// itself is a Java program running inside the same in-browser JVM.
-const CHEERPJ_LOADER_URL = 'https://cjrtnc.leaningtech.com/4.3/loader.js'
-
-// CheerpJ mounts the site's HTTP origin at /app/, so the vendored compiler
-// lives under the Vite base path (/ in production).
-const TOOLS_JAR = `/app${import.meta.env.BASE_URL}tools.jar`
-// FRC2713/maze-solver-java, built into a jar and vendored the same way. Gives
-// lesson snippets the com.frc2713.mazesolver API — the Direction enum, the
-// Maze/Cell/Robot interfaces, the concrete GridMaze students build with
-// `new GridMaze(grid)`, and MazeSolver — so they write solving algorithms
-// against it instead of raw bitmasks. The jar is produced by CI on deploy and
-// by scripts/vendor-maze-solver.sh locally.
-const SOLVER_JAR = `/app${import.meta.env.BASE_URL}maze-solver.jar`
-const CLASS_PATH = `${TOOLS_JAR}:${SOLVER_JAR}:/files/`
-
-// Globals installed by loader.js (a classic script, not an ES module).
-declare global {
- function cheerpjInit(options?: object): Promise
- function cheerpjRunMain(className: string, classPath: string, ...args: string[]): Promise
- function cheerpOSAddStringFile(path: string, data: Uint8Array): void
-}
-
-let cheerpjPromise: Promise | null = null
-let status: 'idle' | 'loading' | 'ready' = 'idle'
-
-// Lets the UI show "loading the Java runtime" (a multi-MB download plus a
-// slow first compile) only the first time, instead of on every Run click.
-export function getJavaRuntimeStatus() {
- return status
-}
-
-function injectScriptOnce(src: string): Promise {
- return new Promise((resolve, reject) => {
- const script = document.createElement('script')
- script.src = src
- script.onload = () => resolve()
- script.onerror = () => reject(new Error(`Failed to load ${src}`))
- document.head.appendChild(script)
- })
-}
-
-// CheerpJ writes System.out and System.err as text into whatever element has
-// id="console". We keep a hidden one and read/clear it around each run, which
-// is safe because runs are queued (see runQueue below).
-let consoleElement: HTMLPreElement | null = null
-
-function loadCheerpjOnce(): Promise {
- if (!cheerpjPromise) {
- status = 'loading'
- cheerpjPromise = (async () => {
- consoleElement = document.createElement('pre')
- consoleElement.id = 'console'
- consoleElement.style.display = 'none'
- document.body.appendChild(consoleElement)
- await injectScriptOnce(CHEERPJ_LOADER_URL)
- await cheerpjInit({ status: 'none' })
- // Warm-up: the first javac invocation inside the browser JVM is several
- // times slower than the ones after it, so absorb that cost here while
- // the UI still says "loading" instead of on the student's first Run.
- await compileAndRun('class Warmup { public static void main(String[] a) {} }')
- status = 'ready'
- })()
- }
- return cheerpjPromise
-}
-
-export interface RunOutcome {
- ok: boolean
- output: string
-}
-
-// Bare statements are wrapped in a main-method shell so early lessons can run
-// `System.out.println("hi");` without meeting class boilerplate (lesson 11
-// reveals the shell). Snippets that declare their own class/enum run as-is.
-// The blanket java.util import lets ArrayList/HashMap snippets work before
-// imports are taught.
-const WRAP_PREFIX = 'import java.util.*;\npublic class Main {\npublic static void main(String[] args) {\n'
-const WRAP_SUFFIX = '\n}\n}'
-const WRAP_LINE_OFFSET = 3
-
-interface PreparedSource {
- source: string
- mainClass: string
- lineOffset: number
-}
-
-function prepareSource(code: string): PreparedSource {
- // Ignore `class`/`interface`/`enum` mentions inside line comments when
- // deciding whether the snippet is already a full compilation unit. An
- // interface-only snippet (lesson 29) must not fall through to the wrap
- // path below — a top-level `interface` inside a method body is illegal.
- const withoutComments = code.replace(/\/\/[^\n]*/g, '')
- const declarations = [...withoutComments.matchAll(/\b(?:class|enum|interface)\s+(\w+)/g)]
- if (declarations.length > 0) {
- // Run the class that owns main(): the last type declared before the main
- // method (snippets can hold several classes, e.g. lesson 21). The public
- // class must also match the filename, and in our lessons that is always
- // the class with main. A snippet with no main still compiles for feedback.
- const mainIndex = withoutComments.search(/\bstatic\s+void\s+main\b/)
- const before = declarations.filter((d) => d.index! < mainIndex)
- const mainClass = (before.length > 0 ? before[before.length - 1] : declarations[0])[1]
- return { source: code, mainClass, lineOffset: 0 }
- }
- return {
- source: WRAP_PREFIX + code + WRAP_SUFFIX,
- mainClass: 'Main',
- lineOffset: WRAP_LINE_OFFSET,
- }
-}
-
-// javac diagnostics point at the wrapped file (/str/Main.java:12); rewrite
-// them to the student's own line numbers and drop the trailing "N errors"
-// count, keeping the code line + caret which genuinely help.
-function simplifyCompileErrors(text: string, lineOffset: number, mainClass: string): string {
- const kept: string[] = []
- for (const line of text.split('\n')) {
- const diag = new RegExp(`^/str/${mainClass}\\.java:(\\d+):\\s*(.*)$`).exec(line)
- if (diag) {
- kept.push(`line ${Number(diag[1]) - lineOffset}: ${diag[2]}`)
- continue
- }
- if (/^\d+ errors?$/.test(line.trim())) continue
- kept.push(line)
- }
- return kept.join('\n').trim()
-}
-
-// CheerpJ reports runtime stack frames as "Unknown Source" (no line numbers),
-// so the best we can do is keep the exception itself plus the frames in the
-// student's own classes and drop JVM-internal ones.
-function simplifyRuntimeError(text: string): string {
- const kept: string[] = []
- for (const line of text.split('\n')) {
- if (/^\s+at\s/.test(line) && !/\(Unknown Source\)|\(\w+\.java/.test(line)) continue
- kept.push(line.replace(/\(Unknown Source\)/, '').trimEnd())
- }
- return kept.join('\n').trim()
-}
-
-async function compileAndRun(code: string): Promise {
- const { source, mainClass, lineOffset } = prepareSource(code)
- const out = consoleElement!
- out.textContent = ''
- cheerpOSAddStringFile(`/str/${mainClass}.java`, new TextEncoder().encode(source))
- const exitCode = await cheerpjRunMain(
- 'com.sun.tools.javac.Main',
- CLASS_PATH,
- `/str/${mainClass}.java`,
- '-d',
- '/files/',
- )
- if (exitCode !== 0) {
- return { ok: false, output: simplifyCompileErrors(out.textContent ?? '', lineOffset, mainClass) }
- }
- out.textContent = ''
- await cheerpjRunMain(mainClass, CLASS_PATH)
- // Console writes land asynchronously; give the DOM a beat to settle.
- await new Promise((resolve) => setTimeout(resolve, 150))
- const output = out.textContent ?? ''
- // CheerpJ exits 0 even on an uncaught exception, so detect failure from the
- // output itself. "Error:" covers JVM launcher failures (e.g. a snippet whose
- // class has no main method).
- if (/^Exception in thread |^Error: /m.test(output)) {
- return { ok: false, output: simplifyRuntimeError(output) }
- }
- return { ok: true, output: output.replace(/\n$/, '') }
-}
-
-// The CheerpJ runtime is a single shared instance (loading it twice would mean
-// downloading tens of MB again), so concurrent Run clicks across different
-// code blocks are queued rather than racing each other's console capture.
-let runQueue: Promise = Promise.resolve()
-
-export function runJava(code: string): Promise {
- const run = async (): Promise => {
- await loadCheerpjOnce()
- return compileAndRun(code)
- }
-
- const result = runQueue.then(run, run)
- runQueue = result.catch(() => {})
- return result
-}
-
-// Dev-only hook so lesson snippets can be batch-tested from the console.
-if (import.meta.env.DEV && typeof window !== 'undefined') {
- ;(window as unknown as { __runJava: typeof runJava }).__runJava = runJava
-}
diff --git a/site/src/lib/lessons.ts b/site/src/lib/lessons.ts
index 28e0316..3c0a47b 100644
--- a/site/src/lib/lessons.ts
+++ b/site/src/lib/lessons.ts
@@ -121,30 +121,25 @@ export function nextLesson(slug: string): Lesson | undefined {
return index === -1 ? undefined : lessons[index + 1]
}
-export type RunnableLanguage = 'python' | 'java'
+export type RunnableLanguage = 'python'
export interface RunnableSnippet {
language: RunnableLanguage
code: string
}
-// Drives the playground panel: a page's first ```python or ```java fence is
-// what gets loaded into it. Pages can still show other code samples in prose;
-// only this one is treated as "the" runnable snippet for the page.
+// Drives the playground panel: a page's first ```python fence is what gets
+// loaded into it. Pages can still show other code samples in prose; only this
+// one is treated as "the" runnable snippet for the page.
export function firstRunnableSnippet(markdown: string): RunnableSnippet | null {
- const match = /```(python|java)\r?\n([\s\S]*?)```/.exec(markdown)
+ const match = /```python\r?\n([\s\S]*?)```/.exec(markdown)
if (!match) return null
return {
- language: match[1] as RunnableLanguage,
- code: match[2].trimEnd(),
+ language: 'python',
+ code: match[1].trimEnd(),
}
}
-export function firstJavaSnippet(markdown: string): string | null {
- const match = /```java\r?\n([\s\S]*?)```/.exec(markdown)
- return match ? match[1].trimEnd() : null
-}
-
// A page can swap the Java playground for the visual block editor with a
// ```blocks fence whose body names a preset (see lib/blockPresets.ts). The
// fence is a directive, not content, so it never renders in the prose column.
@@ -183,11 +178,11 @@ export function hasMaze(markdown: string): boolean {
// writes their own reactive solver in real Java, run through the maze round-trip.
// The fifth, `astar`, is the same editor but its harness also hands the student
// the whole Maze so they can plan a global shortest path (the A* lesson).
-export type SolverMode = 'random' | 'naive' | 'wall' | 'java' | 'astar' | 'python' | 'python-astar'
+export type SolverMode = 'random' | 'naive' | 'wall' | 'python' | 'python-astar'
export function mazeSolver(markdown: string): SolverMode | null {
const match = MAZE_FENCE.exec(markdown)
if (!match) return null
- const m = /solver:\s*(python-astar|python|random|naive|wall|java|astar)/.exec(match[1])
+ const m = /solver:\s*(python-astar|python|random|naive|wall)/.exec(match[1])
return m ? (m[1] as SolverMode) : null
}
diff --git a/site/src/lib/mazeHarness.ts b/site/src/lib/mazeHarness.ts
deleted file mode 100644
index b8db150..0000000
--- a/site/src/lib/mazeHarness.ts
+++ /dev/null
@@ -1,112 +0,0 @@
-// The JS → Java → animated-steps maze round-trip (see docs/maze-roundtrip.md).
-//
-// A student writes a `solve(Robot)` algorithm in the maze playground. To run it
-// we build a full Java compilation unit here: the current maze is interpolated
-// in as an `int[][]` literal, the student's method is spliced into the class
-// body, and a `main` drives the robot then prints the Maze Trail as a single
-// sentinel-tagged line for the JS side to parse and animate back.
-//
-// `new GridMaze(grid)` resolves against the maze-solver library on the
-// classpath (see lib/javaRuntime.ts). Nothing maze-specific is bundled into
-// the harness source itself.
-
-// The maze as a ready-to-embed Java `int[][]` literal body (just the rows, no
-// surrounding `int[][] x = {...}`). Each cell is the same N/S/E/W bitmask the JS
-// grid uses — a set bit means that side is OPEN — so Java reads it with the
-// identical constants. This is the one source of truth for the literal format;
-// both the harness and "Copy for Java" build on it.
-export function mazeGridLiteral(grid: number[][]): string {
- return grid.map((row) => ' {' + row.join(', ') + '}').join(',\n')
-}
-
-// Everything the harness puts *above* the student's spliced-in code. Kept as its
-// own string so we can measure its line count and translate compile-error line
-// numbers back to what the student sees in their editor.
-//
-// The `wall` harness hands the student just a `Robot` (a reactive, sense-as-you-go
-// algorithm like the wall follower). The `astar` harness also hands them the whole
-// `Maze` — random access to every cell via `maze.cellAt(...)` — and imports
-// `java.util.*`, because a global planner like A* needs the full map plus
-// PriorityQueue/HashMap up front. The trail emission is identical either way.
-export type HarnessMode = 'wall' | 'astar'
-
-function harnessPrefix(grid: number[][], mode: HarnessMode): string {
- const imports =
- mode === 'astar'
- ? 'import java.util.*;\nimport com.frc2713.mazesolver.*;'
- : 'import com.frc2713.mazesolver.*;'
- const call = mode === 'astar' ? 'new MazeRun().solve(maze, robot);' : 'new MazeRun().solve(robot);'
- return `${imports}
-
-public class MazeRun {
- static final int[][] GRID = {
-${mazeGridLiteral(grid)}
- };
-
- public static void main(String[] args) {
- Maze maze = new GridMaze(GRID);
- Robot robot = maze.robot();
-
- ${call}
-
- // Emit the Maze Trail as one sentinel-tagged JSON line of [row,col] pairs.
- int[][] trail = robot.trail();
- StringBuilder sb = new StringBuilder("__TRAIL__ [");
- for (int i = 0; i < trail.length; i++) {
- if (i > 0) sb.append(',');
- sb.append('[').append(trail[i][0]).append(',').append(trail[i][1]).append(']');
- }
- System.out.println(sb.append(']'));
- }
-
- // ===== your algorithm =====
-`
-}
-
-// The harness closes the class after the student's spliced-in code.
-const HARNESS_SUFFIX = '\n}\n'
-
-// How many lines the harness inserts above the student's first line. Compile
-// errors come back as "line N: ..." counted in the assembled file; subtracting
-// this maps them to the line the student actually typed. The offset depends on
-// the mode (the astar prefix has one extra import line), so pass the same mode
-// used to build the harness.
-export function studentLineOffset(grid: number[][], mode: HarnessMode = 'wall'): number {
- return harnessPrefix(grid, mode).split('\n').length - 1
-}
-
-// Assemble the full compilation unit: harness prefix + student code + close.
-export function buildMazeHarness(
- grid: number[][],
- studentCode: string,
- mode: HarnessMode = 'wall',
-): string {
- return harnessPrefix(grid, mode) + studentCode.trimEnd() + HARNESS_SUFFIX
-}
-
-// Rewrite the "line N:" prefixes in a compile-error message so they point at the
-// student's editor lines instead of the assembled harness. Runtime errors have
-// no line numbers under CheerpJ, so they pass through untouched.
-export function retargetErrorLines(output: string, offset: number): string {
- return output.replace(/^line (\d+):/gm, (_m, n) => `line ${Math.max(1, Number(n) - offset)}:`)
-}
-
-export interface TrailResult {
- // Cells in [x, y] = [col, row] order (the swap from Java-native [row, col]
- // happens here and nowhere else), including the Start cell first.
- cells: [number, number][]
-}
-
-// Find the __TRAIL__ sentinel line in captured stdout and parse it. Returns null
-// if no sentinel line is present (treat as "algorithm produced no trail").
-export function parseTrail(output: string): TrailResult | null {
- const line = output.split('\n').find((l) => l.startsWith('__TRAIL__ '))
- if (!line) return null
- try {
- const rowCol = JSON.parse(line.slice('__TRAIL__ '.length)) as [number, number][]
- // The one conversion point: Java is [row, col]; the robot state is [x, y].
- return { cells: rowCol.map(([row, col]) => [col, row]) }
- } catch {
- return null
- }
-}
diff --git a/site/src/lib/pythonRuntime.ts b/site/src/lib/pythonRuntime.ts
index 992cf3b..0ebfa00 100644
--- a/site/src/lib/pythonRuntime.ts
+++ b/site/src/lib/pythonRuntime.ts
@@ -1,4 +1,7 @@
-import type { RunOutcome } from './javaRuntime'
+export interface RunOutcome {
+ ok: boolean
+ output: string
+}
export interface RunnerResponse {
ok: boolean
diff --git a/site/src/routes/LessonView.tsx b/site/src/routes/LessonView.tsx
index ba81418..f2bf3a0 100644
--- a/site/src/routes/LessonView.tsx
+++ b/site/src/routes/LessonView.tsx
@@ -142,7 +142,6 @@ export function LessonView() {
>