35 lines
2.3 KiB
Markdown
35 lines
2.3 KiB
Markdown
# Introduction
|
|
|
|
Welcome to this short book on the basics of FZLang, and thank you for giving this programming language a try.
|
|
|
|
First, let's talk about what FZLang is and how this book is organized.
|
|
|
|
## What is FZLang?
|
|
|
|
FZLang is a programming language with its own toolchain, which includes a compiler and a virtual machine. The compiler checks and compiles source code into a portable file, and the virtual machine runs programs written in FZLang.
|
|
|
|
This project originally began as a way to learn about building compilers. I (Samsonium) wanted to explore a few questions:
|
|
|
|
- Why is there a meaningful difference between a compiler and an interpreter?
|
|
- How does a program called a compiler understand what I want it to do?
|
|
- How does execution of a compiled program work? And how does the process of translating from human-readable code to machine instructions happen?
|
|
|
|
I've been programming for more than ten years, but had never taken the time to find out!
|
|
|
|
So this project became a place to experiment and learn more about the foundations of the tools programmers use every day. Along the way, the language began to take shape and develop a philosophy of its own.
|
|
|
|
Today, I would describe that philosophy as: “Be as convenient as a tool, while always trying to remain predictable.” I imagine every language community wants something similar for its language, but this principle has helped me make choices at important points in the project's development.
|
|
|
|
### How FZLang handles memory
|
|
|
|
The question first came up when I introduced stacks to the virtual machine: “A garbage collector, or something else?” Learning how garbage collection works would certainly have been interesting. However, having chosen Java as my first language, I was familiar with its “weight” and runtime behavior. Of course, its garbage collector deserves some of the credit for that.
|
|
|
|
So instead of a GC, I decided to explore RAII. This led to a simple model for how objects move through a program: when an object is passed as an argument, it is “borrowed” into a nested environment; when returned, it is moved into the parent environment. This approach avoids a GC and, most importantly, gives objects a deterministic lifetime—and therefore more predictable memory use, as far as possible.
|
|
|
|
In short, FZLang uses scope-based RAII.
|
|
|
|
---
|
|
|
|
Next: [Getting started](./01_getting-started.md)
|
|
|