diff --git a/CLAUDE.md b/CLAUDE.md index e658270..ee664ec 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,119 +1,149 @@ ---- -description: Use Bun instead of Node.js, npm, pnpm, or vite. -globs: "*.ts, *.tsx, *.html, *.css, *.js, *.jsx, package.json" -alwaysApply: false ---- +# CLAUDE.md -## Overview +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. -This is a stack based VM for a simple dyanmic language called Shrimp. +## Project Overview -Please read README.md, SPEC.md, src/vm.ts, and the examples/ to understand the VM. +ReefVM is a stack-based bytecode virtual machine for the Shrimp programming language. It implements a complete VM with closures, tail call optimization, exception handling, variadic functions, named parameters, and Ruby-style iterators with break/continue. -## Bun +**Essential reading**: Before making changes, read README.md, SPEC.md, and GUIDE.md to understand the VM architecture, instruction set, and compiler patterns. -Default to using Bun instead of Node.js. +## Development Commands -- Use `bun ` instead of `node ` or `ts-node ` -- Use `bun test` instead of `jest` or `vitest` -- Use `bun build ` instead of `webpack` or `esbuild` -- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install` -- Use `bun run - - +### Label Usage (Preferred) +Use labels instead of numeric offsets for readability: +``` +JUMP .skip +PUSH 42 +HALT +.skip: + PUSH 99 + HALT ``` -With the following `frontend.tsx`: +## TypeScript Configuration -```tsx#frontend.tsx -import React from "react"; +- Import alias: `#reef` maps to `./src/index.ts` +- Module system: ES modules (`"type": "module"` in package.json) +- Bun automatically handles TypeScript compilation -// import .css files directly and it works -import './index.css'; +## Bun-Specific Notes -import { createRoot } from "react-dom/client"; +- Use `bun` instead of `node`, `npm`, `pnpm`, or `vite` +- No need for dotenv - Bun loads .env automatically +- Prefer Bun APIs over Node.js equivalents when available +- See .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc for detailed Bun usage -const root = createRoot(document.body); +## Common Gotchas -export default function Frontend() { - return

Hello, world!

; -} +**Jump offsets**: JUMP/JUMP_IF_FALSE/JUMP_IF_TRUE use relative offsets from the next instruction (PC + 1). PUSH_TRY/PUSH_FINALLY use absolute instruction indices. -root.render(); -``` +**Stack operations**: Most binary operations pop in reverse order (second operand is popped first, then first operand). -Then, run index.ts +**MAKE_ARRAY operand**: Specifies count, not a stack index. `MAKE_ARRAY #3` pops 3 items. -```sh -bun --hot ./index.ts -``` +**CALL_NATIVE stack behavior**: Unlike CALL, it consumes all stack values as arguments and clears the stack. -For more information, read the Bun API docs in `node_modules/bun-types/docs/**.md`. +**Finally blocks**: The compiler must generate explicit JUMPs to finally blocks for successful try/catch completion. The VM only auto-jumps to finally on THROW. + +**Variable scoping**: STORE updates existing variables in parent scopes or creates in current scope. It does NOT shadow by default.