站内导读
中文 Toy v2-beta 是用 C 写的可嵌入脚本语言参考实现,以字节码解释执行,作为宿主程序的一部分运行,通过外部脚本暴露程序逻辑。它采用类 C 语法,带中间 AST 与字节码表示、可选强类型、一等函数与闭包,并支持 C 原生绑定和重定向输出与错误信息。适合需要在自有程序中加入可定制脚本层的开发者。
日本語 Toy v2-beta は C で書かれた組み込み向けスクリプト言語の参照実装で、バイトコード解釈方式を採り、単体ではなくホストプログラムの一部として動作します。C 風の構文、中間 AST とバイトコード、省略可能な強い型付け、第一級関数とクロージャ、C ネイティブバインディングを備え、出力やエラーのリダイレクトも可能です。自前のアプリに拡張可能なスクリプト層を組み込みたい開発者向けです。
한국어 Toy v2-beta는 C로 작성된 임베디드용 스크립트 언어 참조 구현으로, 바이트코드로 해석되며 독립 실행이 아니라 호스트 프로그램의 일부로 동작합니다. C와 유사한 문법, 중간 AST와 바이트코드 표현, 선택적 강타입, 일급 함수와 클로저, C 네이티브 바인딩을 지원하고 출력과 오류 메시지를 재지정할 수 있습니다. 자체 프로그램에 확장 가능한 스크립트 계층을 넣으려는 개발자에게 적합합니다.
English Toy v2-beta is a C reference implementation of an embeddable, bytecode-interpreted scripting language that runs as part of a host program rather than standalone. It offers C-like syntax, intermediate AST and bytecode forms, an optional strong type system, first-class functions and closures, native C bindings, and redirectable output and error messages. It suits developers adding a customizable script layer to their own applications.
README · 详细文档
来源 · 查看原文
<p align="center"> <image src="toylogo.png" alt="The Toy Logo" /> </p>
Toy v2-beta
The Toy Scripting Language is an imperative, bytecode-interpreted, embeddable scripting language. Rather than functioning independently, it serves as part of another program, the "host". This design allows for straightforward customization by both the host's developers and end users, achieved by exposing program logic through external scripts.
This repository holds the reference implementation for Toy version 2, written in C - open beta is currently underway.
Nifty Features
- Simple C-like syntax
- Intermediate AST and bytecode representations
- Strong, but optional type system
- First-class functions and closures
- Extensible with native C-bindings
- Can re-direct output, error and assertion messages
- Open-Source under the zlib license
Syntax
fn makeCounter() {
var counter: Int = 0;
fn increment() {
return ++counter;
}
return increment;
}
//'tally' holds internal state
var tally = makeCounter();
for (var result = 0; result < 10; result = tally()) {
print result;
}
Building
This project requires gcc and make by default, but should also work in other environments. Officially supported platforms include linux, windows and macOS, see source/toy_common.h for implementation details.
Run make in the root directory to build the shared library named libToy.so and a useable REPL named repl.out.
Documentation
The contents of docs/ is also available on the official website toylang.com.
License
This source code is covered by the zlib license (see LICENSE for details).
Contributors and Special Thanks
<p align="center"> <image src="noai.png" alt="No AI" width="200px" /> </p>
Contributions via the GitHub mirror are welcome, but absolutely no AI contributions will be accepted.
@Jenny-hso - Syntax highlighting for multiple text editors Suyash Dwivedi - "No AI" logo via wikimedia, CC BY-SA 4.0 @NishiOwO - Unofficial NetBSD support @Gipson62 - v1 docs spell checking @8051Enthusiast - fixAlignment() trick @hiperiondev - v1 Disassembler, v1 porting support and feedback @add00 - v1 Library support @gruelingpine185 - Unofficial v1 MacOS support @solar-mist - v1 Minor bugfixes Various Anons - Feedback @munificent - For writing the book that sparked my interest in langdev
Financial Supporters
You can show your support and be listed here by joining my Patreon, or buying me a coffee at ko-fi.