Documentation update and some web fixes. No code changes. (0.41.16)
This commit is contained in:
parent
c61329124b
commit
2cd6628a71
9 changed files with 236 additions and 75 deletions
|
|
@ -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`–`uint64`, `int8`–`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** — 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 — true to the hacker spirit.
|
||||
- **Beautiful Defaults**<br>
|
||||
A language that doesn’t 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. It’s 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 — 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()` — 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` — iteration
|
||||
- `for var in range(start, end)` — numeric range
|
||||
- `for (key, value) in map` — 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` — named functions
|
||||
- `fn(params) body` — 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` — class definition
|
||||
- `_construct(this, ...)` — auto-invoked constructor
|
||||
- `this` keyword for instance access
|
||||
- `obj.method(args)` — method call sugar (auto-binds this)
|
||||
- `obj.field` — dot property access
|
||||
- `class Child(...) extends Parent` — 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;">☐</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;">☑</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;">☑</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;">☑</span>
|
||||
- [PCRE2](https://pcre2project.github.io/pcre2/){:class="ext"} support builtin for Perl-Compatible Regular Expressions (optional) <span style="color:green;font-weight:bold;">☑</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;">☑</span>
|
||||
- [SQLite](https://sqlite.org/){:class="ext"} support builtin (optional) <span style="color:green;font-weight:bold;">☑</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;">☑</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;">☑</span> = Done / <span style="color:red;font-weight:bold;">☐</span> = Planned or in progress.
|
||||
### I/O & Platform
|
||||
- `print()`, `echo()` — output
|
||||
- `read_file()`, `write_file()` — file I/O
|
||||
- `input_line()` — stdin with optional prompt
|
||||
- `env()`, `env_all()` — environment variables
|
||||
- `proc_run()`, `system()` — process execution
|
||||
- `os_list_dir()` — 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)` — spawn thread, returns ID
|
||||
- `thread_join(id)` — 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) — parse, stringify, file I/O <span style="color:green;font-weight:bold;">☑</span>
|
||||
- **cURL** (`FUN_WITH_CURL` / libcurl) — HTTP GET, POST, download <span style="color:green;font-weight:bold;">☑</span>
|
||||
- **SQLite** (`FUN_WITH_SQLITE` / libsqlite3) — open, query, exec, close <span style="color:green;font-weight:bold;">☑</span>
|
||||
- **PCRE2** (`FUN_WITH_PCRE2` / libpcre2) — Perl-compatible regex with flags <span style="color:green;font-weight:bold;">☑</span>
|
||||
- **OpenSSL** (`FUN_WITH_OPENSSL` / libcrypto) — MD5, SHA-256, SHA-512, RIPEMD-160 hashing <span style="color:green;font-weight:bold;">☑</span>
|
||||
- **INI** (`FUN_WITH_INI` / iniparser 4.2.6) — load, get/set, save config files <span style="color:green;font-weight:bold;">☑</span>
|
||||
- **XML** (`FUN_WITH_XML2` / libxml2) — parse, navigate, query XML documents <span style="color:green;font-weight:bold;">☑</span>
|
||||
- **PC/SC** (`FUN_WITH_PCSC` / libpcsclite) — smart card communication <span style="color:green;font-weight:bold;">☑</span>
|
||||
- **KCGI** (`FUN_WITH_KCGI` / libkcgi) — CGI web applications <span style="color:green;font-weight:bold;">☑</span>
|
||||
|
||||
<span style="color:green;font-weight:bold;">☑</span> = Done
|
||||
|
||||
Each extension also has a corresponding stdlib wrapper class (e.g., `JSON`, `INI`, `XML`, `PCSC`, `PCRE2`, `KCGI`).
|
||||
|
||||
## Tooling
|
||||
|
||||
- **`fun`** — Interpreter/REPL: runs `.fun` scripts or starts interactive REPL
|
||||
- **`funstx`** — Syntax checker with optional `--fix` mode
|
||||
- **REPL** — 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** — breakpoints, step/next/finish, stack traces
|
||||
- **Formatting** — `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 — 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"}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue