展示 HN:R3forth,一种受 ColorForth 启发的语言,带有微型虚拟机。
Show HN: R3forth, a ColorForth-inspired language with a tiny VM

原始链接: https://github.com/phreda4/r3

## r3forth:极简主义、自托管编程环境 r3forth 是一种轻量级、自包含的编程语言和环境,灵感来自 Forth,兼具极简主义和创造力。其核心虚拟机非常小(约 40kb),可在 Windows 和 Linux 上运行,利用 SDL2 进行图形和游戏开发。 R3 摒弃了大型标准库,专注于核心虚拟机、栈和用户代码。尽管是一个虚拟机,但它构建速度很快,并具有自托管编译器(目前适用于 Windows),为本机执行铺平了道路。 一个基于此核心构建的丰富生态系统提供了 2D 图形、3D 引擎、碰撞检测和即时模式 GUI 的库。用户可以使用集成的 IDE,其中包含代码编辑器和字典浏览器,或者将 r3 用作带有任何文本编辑器的编译器/解释器。 安装很简单——下载预编译的二进制文件或通过 Git 从源代码构建。R3 提供快速开发循环,编译和执行速度几乎是瞬间的,使其非常适合实验和快速原型设计。它是一种适用于游戏开发、演示和通用编程的通用工具。

## R3forth:一种受ColorForth启发的语言 开发者phreda4最近分享了R3forth,一种受ColorForth启发的编程语言,其特点是拥有非常小的虚拟机。该项目在GitHub上可用,展示了利用SDL2的令人印象深刻的图形演示,包括精灵表和其他功能。 Hacker News上的讨论显示,该语言不区分大小写,目前是单线程的,但开发者建议运行多个实例以执行并行任务。一位评论员指出它与Mike Hore的Powermops相似,Powermops是另一个基于Forth的系统,令人惊讶的是它仍然存在,甚至还有ARM版本。总的来说,R3forth似乎是一个为Forth和复古风格编程爱好者精心设计且有趣的項目。
相关文章

原文

A Minimalist, Self-Hosted Stack Machine Environment

r3forth is a programming language and environment inspired by ColorForth and the Forth philosophy. It’s designed to be a complete, self-contained system that balances extreme minimalism with practical creative power.

R3 can load and call procedures from any dynamic library (.DLL in windows) or (.SO in linux) the distro use SDL2 library for make games.

  • Ultra-Minimalist VM: A highly portable, lightweight core (~40kb) written in C. It’s designed for simplicity and speed, currently supporting Windows and Linux: r3evm.
  • Zero Bloat Philosophy: No massive standard libraries or complex toolchains. It’s just the core VM, the stack, and your code.
  • High Performance & Native Ambitions: Despite running on a VM, r3 is architected for speed. It features a self-hosted compiler (currently for Windows) written entirely in r3forth, laying the groundwork for future direct-to-metal implementations.
  • Rich Ecosystem: On top of this minimal core, r3 provides a powerful suite of libraries for:
  • Graphics & 2D: Sprites, tilemaps, fonts, animations, and stack-based sprites.
  • Advanced Logic: 3D engine, collision hash, and TUI/Immediate Mode GUI (immgui).
  • Tooling: Integrated editors and a growing collection of games and demos.

r3 requires SDL2 development libraries.

  1. Install dependencies:
sudo apt install libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev

2a. Run the precompiled binary:

Donwload the latest release(.zip)

or

2b. Build and Run: If you want to build the VM from source (recommended for compatibility):

# Clone the VM core
git clone https://github.com/phreda4/r3evm
cd r3evm && make
# Move the binary back to the main folder
mv r3lin ../ && cd ..
./r3lin
  1. Donwload the latest release(.zip)
  2. Extract and run r3.exe. No installation required.

r3 is flexible. You can use the built-in environment or stay in your favorite terminal/editor.

1. The Integrated Development Environment (IDE)

By default, running the binary without arguments loads the internal system.

  • Execution: Run ./r3lin (Linux) or r3.exe (Windows).
  • Bootstrap: The system automatically loads main.r3. This script acts as the entry point, scanning the /r3 folder to build the internal menu and tools.
  • The Environment: Inside, you have access to the built-in code editor, dictionary browser, and live-coding tools.

2. Standard Text Editor Workflow (CLI)

If you prefer using Emacs, Vim or Notepad++, you can use r3 as a traditional compiler/interpreter.

  • Create your script: Save your code with the .r3 extension (e.g., hello.r3).
  • Run it directly: Pass the filename as an argument:
| linux
./r3lin hello.r3

| windows
r3 hello.r3
  • Development Loop: r3 is designed for instant feedback. The VM starts, compiles, and executes your script in milliseconds.
r3forth1.mp4
r3forth2.mp4

Red box in the corner program

^r3/lib/sdl2gfx.r3

:main
	0 sdlcls
	$ff0000 sdlcolor
	10 10 100 100 sdlfrect
	sdlredraw
	sdlkey
	>esc< =? ( exit )
	drop ;
	
:
	"red box in the corner" 800 600 SDLinit
	'main SDLShow
	SDLquit 
	;
  • main.r3: The core startup script.
  • /r3: Contains all the code, the system libraries, the IDE code, and core tools, etc.. all in .r3 code
  • /asm: Compiler folder, not used if you not invoke it.
  • /dll: In WIN you not install anything, the dll is here.
  • /doc: Documentation.
  • /media: graphics, sounds, models, font..etc
  • /mem: use like static memory (for keep info when exit r3)
  • main.xml: syntax coloring for notepad++

r3 is not just a language; it's a creative suite. Here is what you can find:

develop.mov
games.mov
demo.mov
opengl.mov

In the /doc folder.


联系我们 contact @ memedata.com