hclang

中文文档
0.42.0发布于 2026/11/04MIT构建来源已验证

Homoiconic C command-line interpreter and REPL

原始使用文档
文档目录17 节
  1. Introduction
  2. Quick Start
  3. Try it Online
  4. Use as a Library
  5. Run the CLI
  6. Run Tests
  7. Usage
  8. Available Tasks
  9. BitScheme
  10. Debug Mode
  11. Development
  12. Setup
  13. Project Structure
  14. VS Code Extension
  15. Publishing
  16. Links
  17. License

Homoiconic C

JSR JSR Score

A universal language for code and data.

Introduction

Homoiconic C (HC) is a single universal language for code and data. This monorepo contains the first implementation of HC as an interpreter written in TypeScript running on Deno.

The repository includes several packages:

  • @swanfactory/hclang - Core library published to JSR
  • CLI - Interactive REPL and command-line tools
  • MAML - Multipurpose Abstract Markup Language, a radically simple proposal for replacing web technologies (HTML, CSS, JavaScript, SVG) with a single format based on HC
  • Web - Web components and Fresh framework integration

HC can also be used to define easily-parseable variants of other common file formats (e.g., HCSV, HCSON).

Quick Start

Try it Online

Visit The Swan Factory HC playground to try HC directly in your browser with no installation required. For offline use, download hcweb.html from the latest release and open it in your browser.

Use as a Library

# Deno
deno add jsr:@swanfactory/hclang

# Node.js/npm
npx jsr add @swanfactory/hclang

Then in your code:

import { execute } from "@swanfactory/hclang";

const result = execute("1 + 1");
console.log(result); // Output: '2'

See the library documentation for more details.

Run the CLI

With Node.js 24 or newer, run the current CLI directly from npm. Deno is not required:

# Interactive REPL
npx hclang@latest

# Evaluate a file
npx hclang@latest path/to/program.hc

# Verify executable examples in an HC document
npx hclang@latest path/to/examples.hc --testdoc

From source:

git clone https://github.com/TheSwanFactory/hclang.git
cd hclang
deno task hc

This will launch the interactive HC interpreter.

Run Tests

deno task test

Usage

Available Tasks

The root deno.json provides several tasks:

TaskDescription
deno task hcLaunch the HC REPL
deno task setupInstall pre-commit hooks
deno task testCheck formatting and lint, then run all tests
deno task fixFormat sources and apply lint fixes
deno task test:cliTest CLI package
deno task test:libTest library package
deno task test:mamlTest MAML package
deno task test:webTest web package
deno task test:bsTest BitScheme documentation
deno task test:docTest HC documentation examples
deno task buildBuild native, npm, and web artifacts
deno task build:npmGenerate the Node.js CLI package in dist/npm
deno task test:npmPack and smoke-test the CLI package through npx

BitScheme

BitScheme is a specialized scripting language for declaratively parsing, manipulating, and generating binary data. It includes executable documentation that can be tested:

deno task test:bs

This runs the BitScheme interpreter on its own documentation, executing embedded code examples and verifying outputs.

Debug Mode

Enable verbose debugging output:

export DEBUG=true
deno task hc

Development

Setup

  1. Clone the GitHub repository:

    git clone https://github.com/TheSwanFactory/hclang.git
    cd hclang
    
  2. Install Deno:

    # macOS
    brew install deno
    
    # Other platforms: see https://deno.land/
    
  3. (Optional) Install pre-commit for automatic code quality checks:

    # macOS
    brew install pre-commit
    
    # Other platforms: pip install pre-commit
    

    Install pre-commit hooks explicitly with deno task setup.

  4. Run tests:

    deno task test
    

    This checks formatting and lint without fixing sources, then runs the test suite. Use deno task fix to format and apply lint fixes.

    deno task bundle:check checks bundled HC sources without rewriting them; after editing hc/*.hc, regenerate them with deno task bundle:embed.

Project Structure

This is a Deno workspace (monorepo) with the following packages:

hclang/
├── cli/          # HC command-line interface & REPL
├── lib/          # Core library (published to JSR)
├── maml/         # MAML markup language
├── web/          # Web components
├── doc/          # Documentation and papers
└── deno.json     # Workspace root configuration

VS Code Extension

The VS Code extension for HC is now included in this repository at vscode-extension/. It provides comprehensive syntax highlighting for all HC language features based on the complete grammar specification.

Installation:

# Install from source
deno task vscode:install

# Or package for distribution
deno task vscode:package

# Or publish to marketplace
deno task vscode:publish

The extension recognizes .hc files and provides:

  • Syntax highlighting for all HC elements (numbers, strings, identifiers, operators, etc.)
  • Smart bracket matching for {}, [], ()
  • Auto-closing pairs
  • Comment toggling with #

Note: The old standalone language-hclang repository is now deprecated in favor of this integrated extension.

Publishing

For maintainers publishing new versions:

  1. Ensure all tests pass:

    deno task test
    
  2. Update version everywhere:

    deno task bump
    

    This updates deno.json, lib/version.ts, and all workspace package versions, then commits the changes.

  3. Merge the PR to the master branch.

    GitHub Actions compares the version in deno.json with the version before the merge. When the version changed, it publishes the libraries to JSR, publishes the exact hclang tarball exercised through npx, and creates a GitHub Release tagged v<version> with generated notes. Each registry is checked independently, so a rerun resumes a partial release instead of retrying versions that are already immutable. Merges without a version bump do not publish or create a release; no manual tag is required.

    The tested web release also deploys to GitHub Pages. CI verifies the live version and evaluates HC in a browser after deployment; a daily availability workflow checks the public demo between releases. See the web publishing setup.

    npm publishing runs in the protected npm-publish GitHub environment using a trusted publisher for the public hclang package. Its npm settings must authorize the TheSwanFactory/hclang repository, .github/workflows/deno.js.yml, the npm-publish environment, and direct npm publish before merging a release bump. The build/PR job has no OIDC token permission.

License

MIT

版本与发布记录

hclang 共发布 63 个版本,首次发布于 2017/03/05;过去 12 个月发布了 47 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.42.0latest2026/11/04今天
0.41.12026/11/03今天
0.41.02026/11/03今天
0.40.02026/11/031 天前
0.39.02026/11/021 天前
0.38.22026/11/021 天前

关于 hclang 的常见问题

hclang 是什么?

同源的C命令行解释器和REPL

如何安装 hclang?

在项目目录运行 npm install hclang,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 hc,可以用 npx hc 直接运行。

hclang 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/hclang 是否存在。

hclang 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

hclang 可以商用吗?

hclang 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

hclang 还在维护吗?

最新版本 0.42.0 发布于 2026/11/04(今天);至今共发布 63 个版本,其中过去 12 个月发布了 47 个;首次发布于 2017/03/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。