1
0
Fork 0
forked from fun/fun

Documentation update and some web fixes. No code changes. (0.41.16)

This commit is contained in:
Johannes Findeisen 2026-05-28 23:44:45 +02:00
commit 2cd6628a71
9 changed files with 236 additions and 75 deletions

View file

@ -8,12 +8,12 @@
<ul style="list-style: none;">
<li><a class="page-link" href="/" style="text-decoration:none;" title="Homepage">/</a></li>
<li><a class="page-link" href="/about/" style="text-decoration:none;" title="About">About</a></li>
<li><a class="page-link" href="/community/" style="text-decoration:none;" title="Community">Community</a></li>
<li><a class="page-link" href="/contact/" style="text-decoration:none;" title="Contact">Contact</a></li>
<li><a class="page-link" href="/features/" style="text-decoration:none;" title="Features">Features</a></li>
<!--<li><a class="page-link" href="/community/" style="text-decoration:none;" title="Community">Community</a></li>-->
<!--<li><a class="page-link" href="/contact/" style="text-decoration:none;" title="Contact">Contact</a></li>-->
<li><a class="page-link" href="/documentation/" style="text-decoration:none;" title="Documentation">Documentation</a></li>
<li><a class="page-link" href="/faq/" style="text-decoration:none;" title="FAQ">FAQ</a></li>
<li><a class="page-link" href="/features/" style="text-decoration:none;" title="FAQ">Features</a></li>
<li><a class="page-link" href="/download/" style="text-decoration:none;" title="Download">Download</a></li>
<li><a class="page-link" href="/faq/" style="text-decoration:none;" title="FAQ">FAQ</a></li>
<!--
https://www.w3schools.com/howto/howto_js_toggle_dark_mode.asp
https://dev.to/warish/how-to-create-a-dark-mode-toggle-with-html-css-and-javascript-378m

View file

@ -4,7 +4,7 @@ layout: default
<div class="post">
<header class="post-header">
<h1 class="post-title" id="terminal">{{ site.title }} {{ page.title }}</h1>
<h1 class="post-title" id="NOterminal">{{ site.title }} {{ page.title }}</h1>
{% if page.noDate != true %}<p class="post-meta" style="padding: 0;">{% if page.date %}{{ page.date | date: "%b %-d, %Y" }} - {% endif %}
Edited: {{ page.path | file_date | date: "%b %-d, %Y" }}{% endif %}{% if page.author %}, <a href="{{ site.git_short }}/{{ page.author }}" target="_blank" class="user">{{ page.author }}</a>{% endif %}</p>
{% if page.subtitle %}<p style="padding: 0px 0px 0px 0px;">{{ page.subtitle }}</p>{% endif %}

View file

@ -4,7 +4,7 @@ layout: default
<div class="post">
<header class="post-header">
<h1 class="post-title" id="terminal">{{ site.title }} {{ page.title }}</h1>
<h1 class="post-title" id="NOterminal">{{ site.title }} {{ page.title }}</h1>
<p class="post-meta" style="padding: 0px 0px 0px 0px;">{% if page.date %}{{ page.date | date: "%b %-d, %Y" }}{% endif %}{% if page.date and page.date_updated %} - {% endif %}{% if page.date_updated %}Edited: {{ page.date_updated | date: "%b %-d, %Y" }}{% endif %}{% if page.author %}, <a href="{{ page.author_url }}" target="_blank" class="user">{{ page.author }}</a>{% endif %}</p>
</header>
<article class="post-content">

View file

@ -19,14 +19,18 @@ permalink: /about/
## What is Fun?
Fun is an experiment, just for fun, but Fun works!
Fun is a small, strict, and simple programming language that runs on a compact stack-based virtual machine. The C core is intentionally minimal; most functionality and standard libraries are implemented in Fun itself.
Fun is a highly strict programming language, but also highly simple. It looks like Python (My favorite language), but there are differences.
Fun is dynamically typed with optional static type annotations, <a href="/features/">featuring first-class functions</a>, classes with inheritance, pattern matching, and a rich standard library. It supports everything from basic scripting to TCP sockets, serial communication, threading, cryptography (MD5, SHA-1/256/384/512, CRC-32, AES-256), and a built-in debugger.
Influenced by **[Bash](https://www.gnu.org/software/bash/){:class="ext"}**, **[C](https://en.wikipedia.org/wiki/The_C_Programming_Language){:class="ext"}**, **[Lua](https://www.lua.org/){:class="ext"}**, PHP, **[Python](https://www.python.org/){:class="ext"}**, and a little Rust (Most influences came from linked languages).
Influenced by: **[Bash](https://www.gnu.org/software/bash/){:class="ext"}**, **[C](https://en.wikipedia.org/wiki/The_C_Programming_Language){:class="ext"}**, **[Lua](https://www.lua.org/){:class="ext"}**, **[PHP](https://www.php.net/){:class="ext"}**, **[Python](https://www.python.org/){:class="ext"}**, and **[Rust](https://www.rust-lang.org/){:class="ext"}**.
Fun is an experiment - just for fun - but Fun works!
Fun is and will ever be 100% free under the terms of the [Apache-2.0 License](https://opensource.org/license/apache-2-0){:class="ext"}.
---
## Idea
- Simplicity
@ -38,11 +42,19 @@ Fun is and will ever be 100% free under the terms of the [Apache-2.0 License](ht
## Characteristics
- Dynamic and optionally statically typed
- Type safety
- Written in C (C99) and Fun
- Internal libs are written with no_camel_case even when written in Fun, except class names
- Only a minimal function set is written in C, and most other core functions and libraries are implemented in Fun
- **Dynamic typing** with optional **static type annotations** (`number`, `string`, `boolean`, `float`, `byte`, `uint8`&ndash;`uint64`, `int8`&ndash;`int64`)
- **Stack-based bytecode VM** written in C99 with ~220 opcodes
- **First-class functions**, anonymous functions (`fn`), and higher-order operations (`map`, `filter`, `reduce`)
- **Classes** with constructors, methods, and single inheritance
- **Exception handling** with `try`/`catch`/`finally`
- **Built-in data structures**: arrays (with slicing), maps/objects, strings
- **Concurrency**: threads (`thread_spawn`, `thread_join`) and cooperative async scheduler
- **Networking**: TCP and Unix domain sockets with non-blocking I/O polling
- **Serial communication**: full termios-based serial port control
- **Cryptography**: pure-Fun implementations of MD5, SHA-1/256/384/512, CRC-32/CRC-32C, AES-256 ECB
- **Built-in debugger** with breakpoints, step/next/finish, and stack inspection
- **Minimal C core** &mdash; most standard libraries are implemented in Fun itself
- **Internal style**: `snake_case` for functions and variables, `CamelCase` for class names
## The Fun Manifesto
@ -60,13 +72,13 @@ Coding should be enjoyable, elegant, and consistent.
- **One Way to Do It**<br>
No clutter, no 15 ways of writing the same thing. Simplicity means clarity.
- **Hackable by Nature**<br>
Fun should be small and embeddable, like Lua. Easy to understand, extend, and tinker with true to the hacker spirit.
Fun should be small and embeddable, like Lua. Easy to understand, extend, and tinker with &mdash; true to the hacker spirit.
- **Beautiful Defaults**<br>
A language that doesnt need linters, formatters, or style guides. Beauty is built in.
A language that doesn't need linters, formatters, or style guides. Beauty is built in.
## The Community
Fun is not about being the fastest or the most feature-rich. Its about sharing joy in coding. The community should be:
Fun is not about being the fastest or the most feature-rich. It's about sharing joy in coding. The community should be:
- Respectful
- Curious
@ -84,41 +96,151 @@ A language that feels like home for developers who:
- Believe consistency is freedom
- Want to write code that looks good and feels good
Fun may not change the world but it will make programming a little more fun.
Fun may not change the world &mdash; but it will make programming a little more fun.
## Features
## Language Features
### Core
### Core Syntax & Types
- Indentation-based blocks (2-space)
- Line and block comments
- Static type annotations with automatic runtime range clamping for fixed-width integers
- `typeof()`, `to_string()`, `to_number()`, `cast()` &mdash; type introspection and conversion
- `exit` statement with optional exit code
- Source file includes: `#include "path"` and `#include <path>`
- functions/classes/objects
- if/else if/else
- try/catch/finally
### Operators
- Arithmetic: `+`, `-`, `*`, `/`, `%`
- Comparison: `<`, `<=`, `>`, `>=`, `==`, `!=`
- Logical: `&&`, `||`, `!` (short-circuit)
- Bitwise: `band()`, `bor()`, `bxor()`, `bnot()`, `shl()`, `shr()`, `rol()`, `ror()`
- Ternary: `condition ? true_expr : false_expr`
and much more...
### Control Flow
- `if` / `else if` / `else`
- `while` with `break` and `continue`
- `for var in array` &mdash; iteration
- `for var in range(start, end)` &mdash; numeric range
- `for (key, value) in map` &mdash; map destructuring
- `match` expression (stdlib)
- `try` / `catch` / `finally`
Look at the examples here: [https://git.xw3.org/fun/fun/src/branch/main/examples](https://git.xw3.org/fun/fun/src/branch/main/examples){:class="ext"}
### Functions
- `fun name(params) body` &mdash; named functions
- `fn(params) body` &mdash; anonymous function literals
- First-class: pass as arguments, store in variables
- Recursion support
- `return` with optional value (implicit nil)
### Lib
### Object-Oriented Programming
- `class Name(typed params) body` &mdash; class definition
- `_construct(this, ...)` &mdash; auto-invoked constructor
- `this` keyword for instance access
- `obj.method(args)` &mdash; method call sugar (auto-binds this)
- `obj.field` &mdash; dot property access
- `class Child(...) extends Parent` &mdash; inheritance with method overriding
See [https://git.xw3.org/fun/fun/src/branch/main/lib](https://git.xw3.org/fun/fun/src/branch/main/lib) for what the standard library provides.
### Data Structures
- **Arrays**: literal `[1, 2, 3]`, index access `arr[0]`, slice `arr[1:3]`, negative indices, `len()`, `push()`, `pop()`, `insert()`, `remove()`, `contains()`, `indexOf()`, `clear()`, `enumerate()`, `zip()`, `join()`, `map()`, `filter()`, `reduce()`
- **Maps**: literal `{"key": value}`, bracket access `map["key"]`, dot access `map.key`, `has()`, `keys()`, `values()`
- **Strings**: concatenation with `+`, `len()`, `substr()`, `find()`, `split()`, `join()`
### Extensions (only Linux actually)
### Pattern Matching & Regex
- POSIX regex: `regex_match()`, `regex_search()`, `regex_replace()`
- [CGI](https://en.wikipedia.org/wiki/Common_Gateway_Interface){:class="ext"} support builtin using [kcgi](https://kristaps.bsd.lv/kcgi/){:class="ext"} (optional) <span style="color:red;font-weight:bold;">&#9744;</span>
- [cURL](https://curl.se/){:class="ext"} support builtin using [libcurl](https://curl.se/libcurl/){:class="ext"} (optional) <span style="color:green;font-weight:bold;">&#9745;</span>
- [INI](https://en.wikipedia.org/wiki/INI_file){:class="ext"} support builtin using [iniparser](https://gitlab.com/iniparser/iniparser/){:class="ext"} (optional) <span style="color:green;font-weight:bold;">&#9745;</span>
- [JSON](https://www.json.org/){:class="ext"} support builtin using [json-c](https://github.com/json-c/json-c){:class="ext"} (optional) <span style="color:green;font-weight:bold;">&#9745;</span>
- [PCRE2](https://pcre2project.github.io/pcre2/){:class="ext"} support builtin for Perl-Compatible Regular Expressions (optional) <span style="color:green;font-weight:bold;">&#9745;</span>
- [PCSC](https://pcscworkgroup.com/){:class="ext"} smart card support builtin using [PCSC lite](https://pcsclite.apdu.fr/){:class="ext"} (optional) <span style="color:green;font-weight:bold;">&#9745;</span>
- [SQLite](https://sqlite.org/){:class="ext"} support builtin (optional) <span style="color:green;font-weight:bold;">&#9745;</span>
- [XML](https://www.w3.org/XML/){:class="ext"} support builtin using [libxml2](https://gitlab.gnome.org/GNOME/libxml2/-/wikis/home){:class="ext"} (optional) <span style="color:green;font-weight:bold;">&#9745;</span>
### Mathematics
- Built-in: `abs`, `min`, `max`, `fmin`, `fmax`, `clamp`, `pow`, `sqrt`, `floor`, `ceil`, `trunc`, `round`, `sin`, `cos`, `tan`, `exp`, `log`, `log10`, `gcd`, `lcm`, `isqrt`, `sign`
- Random: `random_seed()`, `random_int()`, `random_number()` (cryptographic)
- Integer clamping: `sclamp()`, `uclamp()`
<span style="color:green;font-weight:bold;">&#9745;</span> = Done / <span style="color:red;font-weight:bold;">&#9744;</span> = Planned or in progress.
### I/O & Platform
- `print()`, `echo()` &mdash; output
- `read_file()`, `write_file()` &mdash; file I/O
- `input_line()` &mdash; stdin with optional prompt
- `env()`, `env_all()` &mdash; environment variables
- `proc_run()`, `system()` &mdash; process execution
- `os_list_dir()` &mdash; directory listing
Note: Not all of the above features will be implemented. Those who are marked "Done" will probably remain in Fun, but I don't know actually... ;)
### Date, Time & Sleep
- `time_now_ms()`, `clock_mono_ms()`, `date_format()`, `sleep()`
There are some libs written in Fun available in the [https://git.xw3.org/fun/fun/src/branch/main/lib/](https://git.xw3.org/fun/fun/src/branch/main/lib){:class="git"} diretory. In the future most Fun enhancements should be written in Fun itself.
### Networking (Built-in, Unix)
- **TCP**: listen, accept, connect, send, recv, close
- **Unix domain sockets**: listen, connect
- **Non-blocking I/O**: `fd_set_nonblock()`, `fd_poll_read()`, `fd_poll_write()`
### Serial Communication (Unix)
- `serial_open()`, `serial_config()`, `serial_send()`, `serial_recv()`, `serial_close()`
### Concurrency
- `thread_spawn(fn, args)` &mdash; spawn thread, returns ID
- `thread_join(id)` &mdash; join, returns result
- Cooperative async scheduler in stdlib
### Debugging
- Built-in debugger with 64 breakpoints
- Step, next, finish, continue modes
- `--trace` / `-t` for opcode-level execution tracing
- `--repl-on-error`: enter REPL on runtime error with stack preserved
## Standard Library (stdlib)
Written primarily in Fun itself (lib/):
- **String utilities**: trim, starts/ends-with, split, replace-all, case conversion, repeat
- **Array utilities**: slice, reverse, concat, unique, flatten
- **Math helpers**: `abs`, `clamp`, `gcd`, `lcm`, `powi`, min3, max3, array min/max
- **Hex encoding**: hex-to-bytes, bytes-to-hex, dec-to-hex, hex-to-dec
- **Base64 encoding**: encode/decode
- **Cryptography** (pure Fun): MD5, SHA-1, SHA-256, SHA-384, SHA-512, CRC-32, CRC-32C, AES-256 ECB
- **Functional utilities**: Option type (Some/None), Result type (Ok/Err), pattern matching
- **Range utilities**: `range(n)`, `range2(start, end)`, `range3(start, end, step)`
- **Date/Time**: `DateTime` class with formatting, timers, sleep
- **CLI**: `argv()`, `parse_args()` with flag support
- **Console**: `Console` class with prompt, ask, hidden input, progress bar
- **Process**: `Process` class wrapping proc_run/system
- **Thread**: `Thread` class wrapping spawn/join
- **Socket classes**: `TcpClient`, `TcpServer`, `UnixClient`
- **Serial**: `Serial` class
- **Async scheduler**: cooperative multitasking with I/O polling
- **HTTP Servers**: static file server, CGI-capable server
- **IRC**: `IRCClient` with full protocol support
- **CGI**: `CGI` class for web applications
## Optional Extensions (Build-time)
Enabled via CMake flags, each wrapping a mature C library:
- **JSON** (`FUN_WITH_JSON` / json-c) &mdash; parse, stringify, file I/O <span style="color:green;font-weight:bold;">&#9745;</span>
- **cURL** (`FUN_WITH_CURL` / libcurl) &mdash; HTTP GET, POST, download <span style="color:green;font-weight:bold;">&#9745;</span>
- **SQLite** (`FUN_WITH_SQLITE` / libsqlite3) &mdash; open, query, exec, close <span style="color:green;font-weight:bold;">&#9745;</span>
- **PCRE2** (`FUN_WITH_PCRE2` / libpcre2) &mdash; Perl-compatible regex with flags <span style="color:green;font-weight:bold;">&#9745;</span>
- **OpenSSL** (`FUN_WITH_OPENSSL` / libcrypto) &mdash; MD5, SHA-256, SHA-512, RIPEMD-160 hashing <span style="color:green;font-weight:bold;">&#9745;</span>
- **INI** (`FUN_WITH_INI` / iniparser 4.2.6) &mdash; load, get/set, save config files <span style="color:green;font-weight:bold;">&#9745;</span>
- **XML** (`FUN_WITH_XML2` / libxml2) &mdash; parse, navigate, query XML documents <span style="color:green;font-weight:bold;">&#9745;</span>
- **PC/SC** (`FUN_WITH_PCSC` / libpcsclite) &mdash; smart card communication <span style="color:green;font-weight:bold;">&#9745;</span>
- **KCGI** (`FUN_WITH_KCGI` / libkcgi) &mdash; CGI web applications <span style="color:green;font-weight:bold;">&#9745;</span>
<span style="color:green;font-weight:bold;">&#9745;</span> = Done
Each extension also has a corresponding stdlib wrapper class (e.g., `JSON`, `INI`, `XML`, `PCSC`, `PCRE2`, `KCGI`).
## Tooling
- **`fun`** &mdash; Interpreter/REPL: runs `.fun` scripts or starts interactive REPL
- **`funstx`** &mdash; Syntax checker with optional `--fix` mode
- **REPL** &mdash; Full-featured interactive shell with history, tab completion, multi-line input, and commands (`:help`, `:load`, `:edit`, `:save`, `:debug`, `:trace`, `:type`, and more)
- **Built-in debugger** &mdash; breakpoints, step/next/finish, stack traces
- **Formatting** &mdash; `clang-format` target for consistent C source
## Build System
- **CMake** 3.10+ with C99 standard
- Build toggles for debug mode, musl, REPL, C++ FFI, Rust FFI, Doxygen docs
- Per-extension toggles for all optional libraries
- Release builds with LTO, section GC, and symbol stripping
- CTest integration &mdash; example scripts run as automated tests
- Doxygen API reference generation
## Code
- [https://git.xw3.org/fun/fun/](https://git.xw3.org/fun/fun/){:class="git"}
- [https://git.xw3.org/fun/fun/](https://git.xw3.org/fun/fun/){:class="git"}

View file

@ -1,6 +1,6 @@
---
layout: page
published: true
published: false
noToc: false
noDate: false
title: Community

View file

@ -1,6 +1,6 @@
---
layout: page
published: true
published: false
noToc: true
noDate: false
noPermalink: true

View file

@ -1,20 +1,21 @@
---
layout: page
published: true
noToc: false
noComments: false
noDate: false
title: Documentation
subtitle: Detailed documentation for the Fun programming language.<br><br><span style="color:red;">The documentation is always a work in progress! It will always be behind the development of the code. It will be 100% aligned with a 1.0 release... ;)</span>
subtitle: Detailed documentation for the Fun programming language.
description: The Fun Documentation Index
permalink: /documentation/
lang: en
tags:
- documentation
- index
- fun
- language
- programming
- api
---
> **Note:** The documentation is always a work in progress and may lag behind the code. It will be fully aligned with a 1.0 release.
This file serves as an index of the documents in this directory. Links are relative and can be opened directly on Git hosting or locally.
## Basics

View file

@ -4,7 +4,7 @@ published: true
noToc: false
noComments: false
noDate: false
title: Fun — Feature Overview
title: Feature Overview
subtitle: A high-level list of language, VM/runtime, tooling, and ecosystem features in Fun.
description: Comprehensive feature list of the Fun programming language, its VM/runtime, tooling, build options, and optional extensions.
permalink: /features/
@ -31,6 +31,7 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
## Language
### Syntax & Structure
- Indentation-based block structure (strict 2-space indent)
- Line comments (`//`) and block comments (`/* */`)
- Optional shebang (`#!`) line for script execution
@ -38,6 +39,7 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
- `exit` statement with optional exit code
### Type System
- **Dynamic typing** with optional **static type annotations**
- **Value types:** Integer (signed 64-bit), Float (double), Boolean, String, Array, Map, Function, Nil
- **Type annotations:** `number`, `string`, `boolean`, `float`, `nil`, `array`, `map`, `class`
@ -48,6 +50,7 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
- `cast(value, typeName)` explicit type casting
### Variables & Scope
- Global and local (per-function) variable scoping
- Auto-declaration on first assignment
- Typed variable declarations: `string name = "Fun"`
@ -55,37 +58,37 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
### Operators
**Arithmetic:** `+`, `-`, `*`, `/`, `%` (addition also concatenates strings)
**Comparison:** `<`, `<=`, `>`, `>=`, `==`, `!=`
**Logical:** `&&` (and), `||` (or), `!` (not) — short-circuit evaluation
**Bitwise (32-bit):** `band()`, `bor()`, `bxor()`, `bnot()`, `shl()`, `shr()`, `rol()`, `ror()`
**Ternary:** `condition ? true_expr : false_expr`
- **Arithmetic:** `+`, `-`, `*`, `/`, `%` (addition also concatenates strings)
- **Comparison:** `<`, `<=`, `>`, `>=`, `==`, `!=`
- **Logical:** `&&` (and), `||` (or), `!` (not) — short-circuit evaluation
- **Bitwise (32-bit):** `band()`, `bor()`, `bxor()`, `bnot()`, `shl()`, `shr()`, `rol()`, `ror()`
- **Ternary:** `condition ? true_expr : false_expr`
### Data Structures
**Arrays:**
#### **Arrays**
- Literal syntax: `[1, 2, 3]`
- Index get/set: `arr[0]`, `arr[0] = value`
- Slice syntax: `arr[start:end]`
- Negative indices for end-relative access
- Built-in operations: `len()`, `push()`, `pop()`, `insert()`, `remove()`, `slice()`, `contains()`, `indexOf()`, `clear()`, `enumerate()`, `zip()`, `join()`, `map()`, `filter()`, `reduce()`
**Maps (dictionaries):**
#### **Maps (dictionaries)**
- Literal syntax: `{"key": value, ...}`
- Bracket access/assignment: `map["key"]`, `map["key"] = value`
- Dot property access: `map.key`
- Built-in operations: `has()`, `keys()`, `values()`
### Strings
- Double and single-quoted string literals
- Concatenation with `+`
- Built-in operations: `len()`, `substr()`, `find()`, `split()`, `join()`
### Control Flow
- `if` / `else if` / `else` conditional chains
- `while` loops with `break` and `continue`
- `for var in array` — array iteration
@ -94,6 +97,7 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
- `match` expression (stdlib `lib/utils/match.fun`)
### Functions
- Named function definitions: `fun name(params) body`
- Anonymous function literals: `fn(params) body`
- First-class functions (pass as arguments, store in variables)
@ -101,6 +105,7 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
- Return with `return expr` (or implicit nil)
### Object-Oriented Programming
- Class definitions: `class Name(typed params) body`
- Constructor method: `_construct(this, ...)` — auto-invoked on instantiation
- Methods: `fun method(this, ...)` inside class body
@ -111,17 +116,20 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
- Method overriding in subclasses
### Error Handling
- `try` / `catch` / `finally` blocks
- Error variable binding: `catch err`
- `throw` opcode for raising exceptions
- Per-frame try-stack for nested exception handlers
### Pattern Matching & Regex (Built-in POSIX)
- `regex_match(str, pattern)` — full match test (returns 1/0)
- `regex_search(str, pattern)` — first match with groups (returns map)
- `regex_replace(str, pattern, replacement)` — global search and replace
### Functional Programming
- First-class and anonymous functions
- `map(array, fn)` — transform each element
- `filter(array, fn)` — keep matching elements
@ -130,6 +138,7 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
- `enumerate()` and `zip()` iteration helpers
### Concurrency
- `thread_spawn(fn, args)` — spawn a thread, returns thread ID
- `thread_join(id)` — join a thread, returns its result
- Cooperative async scheduler (stdlib `lib/async/scheduler.fun`)
@ -139,6 +148,7 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
## Virtual Machine & Runtime
### Architecture
- Compact stack-based bytecode VM written in **C99**
- Tagged union value type supporting 8 runtime types
- ~220 opcodes covering all language features
@ -146,12 +156,14 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
- Each frame has 64 local slots and a 16-entry try/catch stack
### Memory & Performance
- Deterministic execution model
- Reference-counted arrays and maps
- Function/data sectioning with linker GC for small binaries
- LTO (Link-Time Optimization) support for Release builds
### Debugging & Tracing
- Built-in debugger with breakpoints (up to 64)
- Step, next, finish, and continue commands
- `--trace` / `-t` flag for opcode-level execution tracing
@ -161,6 +173,7 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
- Source line mapping in error messages (includes include-file resolution)
### I/O & Platform
- `print()` — output with newline
- `echo()` — output without newline (immediate flush)
- `read_file(path)` — read entire file into string
@ -172,6 +185,7 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
- `os_list_dir(path)` — list directory entries
### Date, Time & Random
- `time_now_ms()` — wall clock in milliseconds since Unix epoch
- `clock_mono_ms()` — monotonic clock for interval measurement
- `date_format(ms, fmt)` — format timestamps via strftime
@ -181,6 +195,7 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
- `random_number(len)` — cryptographically random hex string
### Networking (Built-in, Unix)
- `sock_tcp_listen(port, backlog)` — TCP server socket
- `sock_tcp_accept(listen_fd)` — accept client connection
- `sock_tcp_connect(host, port)` — TCP client connection
@ -191,12 +206,14 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
- `fd_poll_read(fd, timeout_ms)` / `fd_poll_write(fd, timeout_ms)` — I/O readiness polling
### Serial Communication (Unix)
- `serial_open(path, baud_rate)` — open serial port
- `serial_config(fd, data_bits, parity, stop_bits, flow_control)` — configure
- `serial_send(fd, data)` / `serial_recv(fd, maxlen)` — send/receive
- `serial_close(fd)` — close
### Integer Utilities
- `sclamp(value, bits)` / `uclamp(value, bits)` — signed/unsigned bit-width clamping
- Integer type declarations (`byte`, `uint8``uint64`, `int8``int64`) with automatic range clamping
- `gcd(a, b)`, `lcm(a, b)` — greatest common divisor, least common multiple
@ -210,6 +227,7 @@ This page summarizes the core capabilities of Fun: the language, its virtual mac
The standard library is written primarily in **Fun itself** and lives in `lib/`:
### Strings (`lib/strings.fun`)
- `str_ltrim`, `str_rtrim`, `str_trim` — whitespace trimming
- `str_starts_with`, `str_ends_with` — prefix/suffix checking
- `str_split` — single-character delimiter splitting
@ -219,22 +237,27 @@ The standard library is written primarily in **Fun itself** and lives in `lib/`:
- `string_to_bytes_ascii` — ASCII string to byte array
### Arrays (`lib/arrays.fun`)
- `array_slice`, `array_reverse`, `array_concat` — slicing and combining
- `array_index_of`, `array_contains` — searching
- `array_unique` — deduplication
- `array_flatten1` — flatten one level of nesting
### Math (`lib/math.fun`)
- `abs`, `clamp`, `gcd`, `lcm`, `powi` (integer exponentiation)
- `min3`, `max3`, `array_min`, `array_max`
### Hex (`lib/hex.fun`)
- `hex_to_dec`, `dec_to_hex`, `hex_to_bytes`, `bytes_to_hex`
### Encoding (`lib/encoding/base64.fun`)
- `b64_encode_bytes`, `b64_decode_to_bytes` — Base64 encoding/decoding
### Cryptography (Pure Fun implementations in `lib/crypt/`)
- **MD5**`MD5` class (`lib/crypt/md5.fun`)
- **SHA-1**`SHA1` class (`lib/crypt/sha1.fun`)
- **SHA-256**`SHA256` class (`lib/crypt/sha256.fun`)
@ -245,44 +268,55 @@ The standard library is written primarily in **Fun itself** and lives in `lib/`:
- **AES-256**`AES256` class (ECB mode)
### Functional Utilities
- **Option type** (`lib/utils/option.fun`): `some()`, `none()`, `is_some`, `is_none`, `unwrap`, `unwrap_or`, `option_map`, `and_then`, `or_else`, `try_get`
- **Result type** (`lib/utils/result.fun`): `ok()`, `err()`, `is_ok`, `is_err`, `unwrap`, `unwrap_or`, `result_map`, `map_err`, `and_then`, `or_else`, `to_option`
- **Pattern matching** (`lib/utils/match.fun`): `match(value, cases)` with `is`, `when`, `else` patterns
### Range Utilities (`lib/utils/range.fun`)
- `range(n)``[0, n)`
- `range2(start, end)``[start, end)`
- `range3(start, end, step)` — stepped range
### Date/Time (`lib/utils/datetime.fun`)
- `DateTime` class with `now_ms`, `mono_ms`, `format`, `iso_now`, `iso_from`, `date_str`, `time_str`, `today_str`, `start_timer`, `elapsed_ms`, `sleep_ms`, `sleep_s`
### CLI (`lib/cli.fun`)
- `argv()` — retrieve command-line arguments
- `parse_args(args)` — parse flags and positional arguments
### Console (`lib/io/console.fun`)
- `Console` class with `prompt`, `ask`, `ask_hidden`, `ask_yes_no`, `term_cols`, `progress` (progress bar)
### Process (`lib/io/process.fun`)
- `Process` class wrapping `proc_run` and `system`
### Thread (`lib/io/thread.fun`)
- `Thread` class wrapping `thread_spawn` / `thread_join`
### Socket Classes (`lib/io/socket.fun`)
- `TcpClient` — TCP client with connect/send/recv/close/recv_all
- `TcpServer` — TCP server with listen/accept/close
- `UnixClient` — Unix domain socket client
### Serial (`lib/io/serial.fun`)
- `Serial` class wrapping serial port operations
### Async Scheduler (`lib/async/scheduler.fun`)
- Cooperative multitasking with `task_spawn`, `co_yield`, `run_once`, `run_until_done`
- I/O readiness polling: `await_read`, `await_write`
### Networking / Web
- **CGI** (`lib/net/cgi.fun`): full CGI request parsing, response generation, URL encoding/decoding
- **HTTP Server** (`lib/net/http_server.fun`): static file serving with `.fun` script execution
- **HTTP CGI Server** (`lib/net/http_cgi_server.fun`): CGI-based HTTP server
@ -307,6 +341,7 @@ Enabled via CMake flags; each wraps a mature C library:
| **KCGI** | `FUN_WITH_KCGI` | libkcgi | `kcgi_parse()`, `kcgi_reply_start()`, `kcgi_write()`, `kcgi_end()` |
Each extension also has a corresponding **stdlib wrapper class** in `lib/io/` or `lib/net/`:
- `JSON` class (`lib/io/json.fun`)
- `INI` class (`lib/io/ini.fun`)
- `XML` class (`lib/io/xml.fun`)
@ -319,11 +354,13 @@ Each extension also has a corresponding **stdlib wrapper class** in `lib/io/` or
## FFI / Interop (Experimental)
### Rust FFI (`FUN_WITH_RUST`)
- Cargo-based Rust static library linked into the VM
- Demo opcodes: `rust_hello()`, `rust_hello_args()`, `rust_hello_args_return()`, `rust_get_sp()`, `rust_set_exit()`
- Rust has unsafe access to VM internals via raw pointer and struct offset APIs
### C++ FFI (`FUN_WITH_CPP`)
- C++ static library linked into the VM
- Demo opcode: `cpp_add(a, b)`

View file

@ -19,11 +19,13 @@ permalink: /
<h2>What is Fun?</h2>
<p>Fun is an experiment, just for fun, but Fun works!</p>
<p>Fun is a small, strict, and simple programming language that runs on a compact stack-based virtual machine. The C core is intentionally minimal; most functionality and standard libraries are implemented in Fun itself.</p>
<p>Fun is a highly strict programming language, but also highly simple. It looks like Python (My favorite language), but there are differences.</p>
<p>Fun is dynamically typed with optional static type annotations, <a href="/features/">featuring first-class functions</a>, classes with inheritance, pattern matching, and a rich standard library. It supports everything from basic scripting to TCP sockets, serial communication, threading, cryptography (MD5, SHA-1/256/384/512, CRC-32, AES-256), and a built-in debugger.</p>
<p>Influenced by <a href="https://www.gnu.org/software/bash/" class="ext">Bash</a>, <a href="https://en.wikipedia.org/wiki/The_C_Programming_Language" class="ext">C</a>, <a href="https://www.lua.org/" class="ext">Lua</a>, PHP, <a href="https://www.python.org/" class="ext">Python</a>, and a little Rust (Most influences came from linked languages).</p>
<p>Influenced by: <a href="https://www.gnu.org/software/bash/" class="ext">Bash</a>, <a href="https://en.wikipedia.org/wiki/The_C_Programming_Language" class="ext">C</a>, <a href="https://www.lua.org/" class="ext">Lua</a>, <a href="https://www.php.net/" class="ext">PHP</a>, <a href="https://www.python.org/" class="ext">Python</a>, and <a href="https://www.rust-lang.org/" class="ext">Rust</a>.</p>
<p>Fun is an experiment - just for fun - but Fun works!</p>
<p>Fun is and will ever be 100% free under the terms of the <a href="https://opensource.org/license/apache-2-0" class="ext">Apache-2.0 License</a>.</p>
@ -61,4 +63,3 @@ permalink: /
{% if count == paginator.page %}<a href="/{{ count }}/" class="active" title="Page {{ count }}">{{ count }}</a>{% else %}<a href="/{{ count }}/" title="Page {{ count }}">{{ count }}</a>{% endif %}
{% endfor %}
</div><br>