1
0
Fork 0
forked from fun/fun

Added ./scripts/play.fun to interactive run thrue all examples in ./examples/. (0.40.6)

This commit is contained in:
Johannes Findeisen 2026-04-21 01:04:39 +02:00
commit 5eb5cd7348
10 changed files with 275 additions and 141 deletions

View file

@ -4,7 +4,7 @@ published: true
noToc: false
noComments: false
noDate: false
title: Fun - VM Configuration Constants
title: VM Configuration Constants
subtitle: Detailed explanation of VM limits and memory management constants.
description: Learn about MAX_FRAMES, MAX_FRAME_LOCALS, MAX_GLOBALS, STACK_SIZE, and OUTPUT_SIZE in the Fun VM.
permalink: /documentation/vm/
@ -19,9 +19,10 @@ The Fun Virtual Machine (VM) uses several fixed-size limits to manage memory and
This document explains what each of these constants does in plain English.
View [../build/](../build/) to see how to set the params at build time.
View [Build](../build/) to see how to set the params at build time.
## `MAX_FRAMES` (Default: 128)
This constant defines the **maximum depth of the call stack**.
When a function is called, the VM creates a "frame" to keep track of that function's execution (where it's at in the code and its local variables). If a function calls another function, a new frame is added on top.
@ -30,6 +31,7 @@ When a function is called, the VM creates a "frame" to keep track of that functi
- **Analogy:** Imagine a stack of dinner plates. `MAX_FRAMES` is the maximum height the stack can reach before it becomes unstable or hits the ceiling.
## `MAX_FRAME_LOCALS` (Default: 64)
This constant limits the **number of local variables** each individual function can have.
Every time a function is called, it gets its own space for variables that only exist within that function.
@ -38,6 +40,7 @@ Every time a function is called, it gets its own space for variables that only e
- **Analogy:** Think of this as the number of pockets in a single person's jacket. You can only carry 64 items in your pockets at once.
## `MAX_GLOBALS` (Default: 128)
This constant defines the **maximum number of global variables** available to the entire program.
Global variables are accessible from anywhere in your code, unlike local variables which belong to a specific function.
@ -46,6 +49,7 @@ Global variables are accessible from anywhere in your code, unlike local variabl
- **Analogy:** This is like a shared community bulletin board. There is only enough room on the board for 128 different notices.
## `STACK_SIZE` (Default: 1024)
This constant sets the size of the **operand stack**.
The VM uses this stack for almost everything it does: adding numbers, comparing values, and passing arguments to functions. Most operations take values from the top of the stack, perform a calculation, and push the result back onto the stack.
@ -54,6 +58,7 @@ The VM uses this stack for almost everything it does: adding numbers, comparing
- **Analogy:** Imagine a workbench where you put tools and materials you are currently working on. `STACK_SIZE` is the area of that workbench. If it's too small, you can't work on complex projects.
## `OUTPUT_SIZE` (Default: 1024)
This constant determines the size of the **output buffer**.
When your program uses commands like `PRINT` or `ECHO`, the results are stored in an internal list before they are displayed or processed further.