Compare commits
No commits in common. "10144d273731fbbaee8d3e037a65712265ee9ba4" and "33001a7ad25e35979f166bf381771b483312fa53" have entirely different histories.
10144d2737
...
33001a7ad2
423 changed files with 13957 additions and 24469 deletions
|
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
project(fun VERSION 0.39.15 LANGUAGES C)
|
||||
project(fun VERSION 0.38.16 LANGUAGES C)
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
|
@ -46,16 +46,7 @@ message(STATUS "===========================")
|
|||
|
||||
# Convenience aggregate target (like 'build' in Makefile)
|
||||
add_custom_target(build
|
||||
DEPENDS fun funstx fun_test test_opcodes
|
||||
)
|
||||
|
||||
# Formatting helper target: run clang-format over C/C++ sources using .clang-format
|
||||
add_custom_target(format
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Running clang-format on sources..."
|
||||
COMMAND /bin/sh -c "command -v clang-format >/dev/null 2>&1 || { echo 'clang-format not found in PATH' >&2; exit 1; }"
|
||||
COMMAND /bin/sh -c "set -e; for pat in '*.c' '*.h' '*.cpp' '*.hpp'; do find ${CMAKE_SOURCE_DIR}/src -type f -name \"\$pat\" -print0; done | xargs -0 -n 50 clang-format -i"
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMENT "Apply .clang-format (IndentWidth=2) to all source files"
|
||||
DEPENDS fun fun_test test_opcodes
|
||||
)
|
||||
|
||||
# --- Rust (Cargo) integration: optionally build and link a staticlib with opcode examples ---
|
||||
|
|
@ -401,28 +392,6 @@ if(BUILD_TESTING)
|
|||
fun_add_example_test(crypto_crc32 examples/crypto/crc32_example.fun)
|
||||
fun_add_example_test(crypto_crc32c examples/crypto/crc32c_example.fun)
|
||||
fun_add_example_test(crypto_aes256 examples/crypto/aes256.fun)
|
||||
|
||||
# Include-line mapping regression test:
|
||||
# This script intentionally triggers a runtime error inside an included file.
|
||||
# The VM augments the error with a precise (file:line) from the included file.
|
||||
# We assert that stderr/stdout contain the correct mapped location and that the
|
||||
# program exits with a non-zero status (WILL_FAIL).
|
||||
set(_inc_map_script "${CMAKE_SOURCE_DIR}/examples/error/include_line_mapping_test.fun")
|
||||
if(EXISTS "${_inc_map_script}")
|
||||
add_test(NAME include_line_mapping
|
||||
COMMAND $<TARGET_FILE:fun> "${_inc_map_script}"
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
)
|
||||
# Ensure the interpreter resolves <...> includes to the repo lib/
|
||||
set_tests_properties(include_line_mapping PROPERTIES
|
||||
ENVIRONMENT "FUN_LIB_DIR=${CMAKE_SOURCE_DIR}/lib"
|
||||
# The runtime error message should contain the mapped file path and line 7
|
||||
PASS_REGULAR_EXPRESSION "lib/test/include_divzero.fun:7"
|
||||
WILL_FAIL TRUE
|
||||
)
|
||||
else()
|
||||
message(WARNING "include_line_mapping_test.fun not found; skipping include_line_mapping CTest")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Install rules
|
||||
|
|
@ -431,11 +400,6 @@ install(TARGETS fun
|
|||
RUNTIME DESTINATION /usr/bin
|
||||
)
|
||||
|
||||
# Also install the syntax-checker CLI by default
|
||||
install(TARGETS funstx
|
||||
RUNTIME DESTINATION /usr/bin
|
||||
)
|
||||
|
||||
# Libs
|
||||
install(DIRECTORY lib/
|
||||
DESTINATION /usr/share/fun/lib
|
||||
|
|
@ -455,11 +419,3 @@ endif()
|
|||
install(FILES README.md LICENSE
|
||||
DESTINATION /usr/share/doc/fun
|
||||
)
|
||||
|
||||
# - Manpages
|
||||
# Install section 1 manpages for the CLI tools
|
||||
install(FILES
|
||||
man/fun.1
|
||||
man/funstx.1
|
||||
DESTINATION /usr/share/man/man1
|
||||
)
|
||||
|
|
|
|||
|
|
@ -139,12 +139,6 @@ if(FUN_WITH_REPL)
|
|||
endif()
|
||||
target_link_libraries(fun PRIVATE fun_core)
|
||||
|
||||
# Executable: funstx (syntax checker CLI)
|
||||
add_executable(funstx
|
||||
${CMAKE_SOURCE_DIR}/src/funstx.c
|
||||
)
|
||||
target_link_libraries(funstx PRIVATE fun_core)
|
||||
|
||||
# Internal test programs
|
||||
add_executable(fun_test
|
||||
${CMAKE_SOURCE_DIR}/src/fun_test.c)
|
||||
|
|
|
|||
|
|
@ -23,9 +23,6 @@ This file serves as an index of the documents in this directory. Links are relat
|
|||
|
||||
- [build.md](./build.md) - How to build Fun with CMake, available targets, and build options (FUN_DEBUG, FUN_USE_MUSL, FUN_WITH_CPP, FUN_WITH_RUST, FUN_WITH_OPENSSL, FUN_WITH_LIBRESSL).
|
||||
- [cli.md](./cli.md) - Command-line usage of the `fun` executable: synopsis, options, exit codes, includes and library paths.
|
||||
- [fun.md](./fun.md) - Full usage guide for the `fun` executable: invocation patterns, REPL, env vars, include paths, examples, and install locations.
|
||||
- [asyncio.md](./asyncio.md) - Async I/O primitives and patterns: non-blocking sockets, fd polling, examples, and best practices.
|
||||
- [funstx.md](./funstx.md) - Syntax checker for .fun files with optional --fix auto-corrections; usage, exit codes, and limitations.
|
||||
- [contributing.md](./contributing.md) - How to contribute: project structure, coding style, running tests, and PR guidelines.
|
||||
- [style-guide.md](./style-guide.md) - Coding conventions for C and Fun (indentation, naming, idioms).
|
||||
- [stdlib.md](./stdlib.md) - Overview of the standard library modules under ./lib with one-line summaries.
|
||||
|
|
@ -38,10 +35,6 @@ This file serves as an index of the documents in this directory. Links are relat
|
|||
- [bytecode-format.md](./bytecode-format.md) - Reference for the bytecode format (split out from internals for convenience).
|
||||
- [roadmap.md](./roadmap.md) - High-level direction, planned features, and pointers to issues.
|
||||
|
||||
## Examples
|
||||
|
||||
- [examples/README.md](./examples/README.md) - Catalog of all example scripts under ./examples/: what each area contains, how to run them, required env vars, and extension requirements.
|
||||
|
||||
## External extensions
|
||||
|
||||
Documentation for optional, build-time selectable integrations lives in [external/](./external/):
|
||||
|
|
|
|||
210
docs/asyncio.md
210
docs/asyncio.md
|
|
@ -1,210 +0,0 @@
|
|||
# Async I/O ("asyncio") in Fun
|
||||
|
||||
This guide explains the new asynchronous I/O primitives in Fun and how to use them to build non-blocking network and file descriptor workflows. It covers the core concepts, available helpers, common patterns, and runnable examples from the repository.
|
||||
|
||||
## What is asyncio in Fun?
|
||||
|
||||
In Fun, "asyncio" refers to event-driven, non-blocking I/O built around file descriptor readiness. Instead of blocking on reads/writes, you:
|
||||
- Put descriptors (sockets, pipes, etc.) into non-blocking mode
|
||||
- Wait for them to become readable/writable using polling helpers
|
||||
- Perform small, incremental reads/writes when the OS signals readiness
|
||||
|
||||
This lets a single Fun script handle many concurrent connections efficiently without threads, and keeps UIs or other work responsive while I/O is in flight.
|
||||
|
||||
There is no special syntax (like async/await) — you compose ordinary control flow with a few focused opcodes and stdlib functions.
|
||||
|
||||
However, for more ergonomic, "await-like" workflows without changing the VM, a tiny cooperative scheduler is provided in the stdlib at lib/async/scheduler.fun. It lets you write small step functions that advance per tick and use await_read/await_write wrappers for readability.
|
||||
|
||||
## Building blocks
|
||||
|
||||
Core helpers wired into the VM (see src/vm/os/*):
|
||||
- fd_set_nonblock(fd, on) → 1/0: enable or disable O_NONBLOCK on a file descriptor
|
||||
- fd_poll_read(fd, timeout_ms) → int: >0 if fd is readable; 0 on timeout; <0 on error
|
||||
- fd_poll_write(fd, timeout_ms) → int: >0 if fd is writable; 0 on timeout; <0 on error
|
||||
|
||||
Common networking helpers from the stdlib:
|
||||
- tcp_connect(host, port) → fd: open a TCP connection; returns 0 on failure
|
||||
- sock_send(fd, data) → int: send bytes (may write only part in non-blocking mode)
|
||||
- sock_recv(fd, max_bytes) → string: receive up to max_bytes; empty string on EOF
|
||||
- sock_close(fd): close the descriptor
|
||||
|
||||
Tip: Always check return values. In non-blocking mode, partial writes and short reads are normal.
|
||||
|
||||
## Typical patterns
|
||||
|
||||
1) Connect and switch to non-blocking
|
||||
```
|
||||
fd = tcp_connect(host, port)
|
||||
if (fd == 0)
|
||||
// handle connect error
|
||||
ok = fd_set_nonblock(fd, 1)
|
||||
if (ok == 0)
|
||||
// handle mode switch error
|
||||
```
|
||||
|
||||
2) Non-blocking write loop with readiness polling
|
||||
```
|
||||
remaining = req
|
||||
while (len(remaining) > 0)
|
||||
wr = fd_poll_write(fd, 1000) // wait up to 1s
|
||||
if (wr < 0)
|
||||
// poll error; abort
|
||||
if (wr == 0)
|
||||
continue // timeout; try again
|
||||
n = sock_send(fd, remaining)
|
||||
if (n < 0)
|
||||
// send error; abort
|
||||
remaining = substr(remaining, n, len(remaining) - n)
|
||||
```
|
||||
|
||||
3) Non-blocking read-until-close
|
||||
```
|
||||
buf = ""
|
||||
while (true)
|
||||
rd = fd_poll_read(fd, 2000) // wait up to 2s
|
||||
if (rd < 0)
|
||||
// poll error; break
|
||||
if (rd == 0)
|
||||
// timeout: try a read to detect EOF
|
||||
data = sock_recv(fd, 4096)
|
||||
if (len(data) == 0)
|
||||
break // likely closed
|
||||
buf = buf + data
|
||||
continue
|
||||
data = sock_recv(fd, 4096)
|
||||
if (len(data) == 0)
|
||||
break // closed
|
||||
buf = buf + data
|
||||
```
|
||||
|
||||
## Timeouts and responsiveness
|
||||
|
||||
- timeout_ms controls how long poll waits. Use small timeouts inside loops to interleave work across multiple sockets or tasks.
|
||||
- A timeout result (0) is not an error — treat it as an opportunity to perform other duties and try again later.
|
||||
- Negative results (<0) indicate OS-level errors from poll/select; handle or abort as appropriate.
|
||||
|
||||
## Working with multiple connections
|
||||
|
||||
To multiplex several sockets:
|
||||
- Keep per-connection state (outgoing buffer, accumulate incoming, progress markers)
|
||||
- Round-robin over connections, polling each for read/write readiness with short timeouts
|
||||
- Advance each state machine a little per iteration
|
||||
|
||||
Because Fun keeps the primitives low-level and explicit, you can build simple cooperative schedulers, connection pools, or protocol handlers directly in Fun code.
|
||||
|
||||
## Examples in the repository
|
||||
|
||||
- examples/io/async_http_client.fun — Minimal HTTP GET over non-blocking TCP using fd_poll_* helpers
|
||||
- examples/io/await_http_client.fun — Same goal, but written using lib/async/scheduler.fun with await_* helpers
|
||||
- examples/net/http_mt_server.fun — Multi-tenant HTTP server scaffold (compare patterns for concurrency)
|
||||
- examples/net/http_mt_server_cgi.fun — Server variant that dispatches CGI-like handlers
|
||||
- lib/net/http_cgi_server.fun — Library helpers used by the server examples
|
||||
|
||||
Run client example from a build tree:
|
||||
```
|
||||
FUN_LIB_DIR=./lib ./build/fun examples/io/async_http_client.fun
|
||||
```
|
||||
|
||||
If installed system-wide, just:
|
||||
```
|
||||
fun /usr/share/fun/examples/io/async_http_client.fun
|
||||
```
|
||||
|
||||
Or to try the await-style client using the cooperative scheduler:
|
||||
```
|
||||
FUN_LIB_DIR=./lib ./build/fun examples/io/await_http_client.fun
|
||||
```
|
||||
|
||||
## Cooperative scheduler helpers (library-level)
|
||||
|
||||
The file lib/async/scheduler.fun provides a minimal cooperative scheduler built on the existing primitives. There is no VM-level suspension: each task is a small state machine advanced one step per tick. API summary:
|
||||
|
||||
- task_spawn(step_fn, state_map) → task_handle
|
||||
- Registers a task. step_fn is a function that takes a Map state; mutate state and set state.done = 1 when complete.
|
||||
- run_once() → 1
|
||||
- Performs one scheduling tick over all runnable tasks.
|
||||
- run_until_done() → 1
|
||||
- Repeats run_once() with a tiny sleep_ms(1) until all tasks finish.
|
||||
- await_read(fd, timeout_ms) → int
|
||||
- Wrapper over fd_poll_read; returns 1 if readable, 0 on timeout/EOF, -1 on error.
|
||||
- await_write(fd, timeout_ms) → int
|
||||
- Wrapper over fd_poll_write; returns 1 if writable, 0 on timeout, -1 on error.
|
||||
- yield() → 1
|
||||
- No-op helper to make intent explicit in step functions.
|
||||
- async_sleep_mark(state, ms) → 1
|
||||
- Mark the task to be skipped for roughly ms milliseconds; cleared automatically when it wakes.
|
||||
|
||||
Example skeleton using the scheduler:
|
||||
```
|
||||
#include <async/scheduler.fun>
|
||||
|
||||
fun my_task_step(t)
|
||||
if (t.phase == nil)
|
||||
t.phase = 0
|
||||
|
||||
if (t.phase == 0)
|
||||
t.fd = tcp_connect("example.org", 80)
|
||||
if (t.fd == 0)
|
||||
t.done = 1
|
||||
return
|
||||
fd_set_nonblock(t.fd, 1)
|
||||
t.phase = 1
|
||||
return
|
||||
|
||||
if (t.phase == 1)
|
||||
if (await_write(t.fd, 50) == 1)
|
||||
sock_send(t.fd, "GET / HTTP/1.1\r\nHost: example.org\r\n\r\n")
|
||||
t.buf = ""
|
||||
t.phase = 2
|
||||
return
|
||||
|
||||
if (t.phase == 2)
|
||||
rd = await_read(t.fd, 100)
|
||||
if (rd < 0)
|
||||
t.done = 1
|
||||
return
|
||||
if (rd == 0)
|
||||
// try a small read to detect EOF
|
||||
data = sock_recv(t.fd, 4096)
|
||||
if (len(data) == 0)
|
||||
t.done = 1
|
||||
else
|
||||
t.buf = t.buf + data
|
||||
return
|
||||
// readable
|
||||
data = sock_recv(t.fd, 4096)
|
||||
if (len(data) == 0)
|
||||
t.done = 1
|
||||
else
|
||||
t.buf = t.buf + data
|
||||
return
|
||||
|
||||
task = task_spawn(my_task_step, {})
|
||||
run_until_done()
|
||||
```
|
||||
|
||||
This approach is 100% compatible with current runtimes and serves as a stepping stone towards potential future VM-level async/await opcodes.
|
||||
|
||||
## Error handling and cleanup
|
||||
|
||||
- Always close descriptors with sock_close(fd) when finished or on error paths.
|
||||
- Distinguish between timeout (wr/rd == 0), EOF (len(recv) == 0), and errors (wr/rd < 0 or send < 0).
|
||||
- For large payloads, design your loops to tolerate partial progress and resume cleanly.
|
||||
|
||||
## FAQ
|
||||
|
||||
Q: Is there an async/await syntax?
|
||||
A: Not at this time. The model is explicit non-blocking I/O with polling helpers. You can build lightweight schedulers on top if desired.
|
||||
|
||||
Q: Does this work on all platforms?
|
||||
A: The helpers map to portable OS facilities exposed by the VM. Details may vary by platform; see docs/troubleshooting.md and open an issue if you hit differences.
|
||||
|
||||
Q: How do I integrate with the REPL?
|
||||
A: You can prototype small non-blocking fragments in the REPL, but full networking examples are easier to run as scripts.
|
||||
|
||||
## See also
|
||||
|
||||
- [examples.md](./examples.md) — Running bundled examples
|
||||
- [includes.md](./includes.md) — Include paths and library discovery
|
||||
- [opcodes.md](./opcodes.md) — VM opcodes overview
|
||||
- [troubleshooting.md](./troubleshooting.md) — Common issues and quick fixes
|
||||
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
Reference for the `fun` command-line interface.
|
||||
|
||||
For a complete usage guide (including REPL details, environment variables, include paths, examples, and install locations), see [fun.md](./fun.md).
|
||||
|
||||
## Synopsis
|
||||
```
|
||||
fun [options] <script.fun> [-- args...]
|
||||
|
|
|
|||
|
|
@ -1,218 +0,0 @@
|
|||
# Examples catalog and how to run them
|
||||
|
||||
This page is a practical catalog of the example areas that ship with the Fun language. It explains what you’ll find in each folder under ./examples/, how to run the scripts, and where deeper walkthroughs live.
|
||||
|
||||
If you’re building/running from the repository without installing, set FUN_LIB_DIR to the local ./lib directory so examples can locate the stdlib:
|
||||
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- Then run an example: ./build_debug/fun examples/basics/hello_world.fun
|
||||
- Or, if installed: fun examples/basics/hello_world.fun
|
||||
|
||||
Notes
|
||||
- Most scripts are self‑documented with a short header comment at the top. Open them to see exact behavior and expected output.
|
||||
- Some examples depend on optional extensions (cURL, PCRE2, SQLite, Notcurses, Tk, PC/SC, OpenSSL/LibreSSL). See docs/external/ for enablement and availability.
|
||||
- Networking examples often bind to 127.0.0.1 on high ports; read the file header for the exact port.
|
||||
|
||||
Deep‑dives
|
||||
|
||||
## Top‑level examples (./examples)
|
||||
|
||||
Quick micro demos covering language features and tiny utilities.
|
||||
|
||||
Run pattern:
|
||||
- fun examples/<file>.fun
|
||||
|
||||
Highlights (selection):
|
||||
|
||||
- [builtins_extended.fun](./builtins_extended.md) — tour of core built‑ins beyond the basics
|
||||
- [byte_for_demo.fun](./byte_for_demo.md) — iterating bytes with for
|
||||
- [byte_overflow_try_catch.fun](./byte_overflow_try_catch.md) — error handling on overflow
|
||||
- [cast_demo.fun](./cast_demo.md) — conversions and casting helpers
|
||||
- [class_constructor.fun](./class_constructor.md) — basic constructor usage and init patterns
|
||||
- [class_test.fun](./class_test.md) — small class feature checks
|
||||
- [classes_demo.fun](classes_demo.md) — class basics and usage
|
||||
- [class_without_object.fun](./class_without_object.md) — class features without an instance helper
|
||||
- [cli_argv_dump.fun](./cli_argv_dump.md) — prints argv/argc handling
|
||||
- [conversions_showcase.fun](./conversions_showcase.md) — numbers, strings, bytes conversions
|
||||
- [cpp_add.fun](./cpp_add.md) — calling into the optional C++ extension (if enabled)
|
||||
- [datetime_basic.fun](./datetime_basic.md) — minimal date/time helpers
|
||||
- [datetime_extended.fun](./datetime_extended.md) — richer date/time operations
|
||||
- [datetime_timer.fun](datetime_timer.md) — time/date helpers
|
||||
- [echo_example.fun](./echo_example.md) — simple echo of input/args
|
||||
- [env_all.fun](./env_all.md) — enumerate environment variables
|
||||
- [os_env.fun](./os_env.md) — reading environment variables
|
||||
- [error_handling.fun](./error_handling.md) — try/catch and error objects
|
||||
- [try_catch_finally.fun](try_catch_finally.md) — error patterns
|
||||
- [expressions_test.fun](./expressions_test.md) — precedence and grouping
|
||||
- [features.fun](./features.md) — grab bag of language features
|
||||
- [file_print_for_file_line_by_line.fun](./file_print_for_file_line_by_line.md) — iterate file content
|
||||
- [floats.fun](./floats.md) — float ops and formatting
|
||||
- [for_range_test.fun](./for_range_test.md) — ranges and loops
|
||||
- [functions_test.fun](./functions_test.md) — functions, closures, returns
|
||||
- [have_fun.fun](./have_fun.md) — playful starter demo
|
||||
- [have_fun_function.fun](have_fun_function.md) — playful demos
|
||||
- [hex_example.fun](./hex_example.md) — hex encode/decode
|
||||
- [if_else_test.fun](./if_else_test.md) — conditional branching examples
|
||||
- [nested_loops.fun](./nested_loops.md) — loops inside loops
|
||||
- [loops_break_continue.fun](loops_break_continue.md) — control flow
|
||||
- [include_local.fun](./include_local.md) — include a local file/module
|
||||
- [include_lib.fun](./include_lib.md) — include from the stdlib path
|
||||
- [include_local_util.fun](include_local_util.md) — include mechanics
|
||||
- [inheritance_demo.fun](./inheritance_demo.md) — simple class inheritance
|
||||
- [maps.fun](./maps.md), [match.fun](match.md) — data structures and pattern matching
|
||||
- [namespaced_mod.fun](./namespaced_mod.md) — namespaced includes with as
|
||||
- [objects_basic.fun](./objects_basic.md) — simple objects and methods
|
||||
- [objects_more.fun](./objects_more.md) — OO basics
|
||||
- [process_example.fun](./process_example.md) — spawn and capture subprocess output
|
||||
- [progress.fun](./progress.md) — progress bar helper
|
||||
- [progress_inline.fun](./progress_inline.md) — simple progress displays
|
||||
- [random_demo.fun](./random_demo.md) — random helpers overview
|
||||
- [random_number_example.fun](random_number_example.md) — RNG usage
|
||||
- [regex_demo.fun](./regex_demo.md) — regex basics (PCRE2 when enabled)
|
||||
- [regex_procedural.fun](./regex_procedural.md) — regex helpers (PCRE2 when enabled)
|
||||
- [rust_hello.fun](./rust_hello.md), rust_hello_args*.fun — Rust opcodes (if FUN_WITH_RUST)
|
||||
- [serial_demo.fun](./serial_demo.md) — serial port usage
|
||||
- [test_serial.fun](./test_serial.md) — serial port (when available)
|
||||
- [short_circuit_test.fun](./short_circuit_test.md) — boolean evaluation order
|
||||
- [signed_ints.fun](./signed_ints.md) — signed integers overview
|
||||
- [uint_types.fun](./uint_types.md) — unsigned integers overview
|
||||
- [types_integers.fun](./types_integers.md) — integer families
|
||||
- [stdlib_showcase.fun](./stdlib_showcase.md) — sampler of common stdlib modules
|
||||
- [strings_test.fun](./strings_test.md) — string helpers and edge cases
|
||||
- [tcp_http_get.fun](./tcp_http_get.md) — simple HTTP GET over raw TCP
|
||||
- [tcp_http_get_class.fun](./tcp_http_get_class.md) — manual HTTP client over sockets
|
||||
- [test_bits.fun](./test_bits.md) — /rol/shl/xor/dec_to_hex/hex_to_dec bitwise utilities
|
||||
- [thread_class_example.fun](./thread_class_example.md) — define and run a thread class
|
||||
- [threads_demo.fun](./threads_demo.md) — threading building blocks
|
||||
- [typeof.fun](./typeof.md) — type inspection
|
||||
- [typeof_features.fun](./typeof_features.md) — type inspection of declared integer subtypes and runtime categories
|
||||
- [type_safety.fun](./type_safety.md) — static/dynamic type checks
|
||||
- [type_safety_fails.fun](./type_safety_fails.md) — static/dynamic type checks
|
||||
- [types_overview.fun](./types_overview.md) — language types tour
|
||||
- [unix_socket_echo.fun](./unix_socket_echo.md) — local domain socket echo demo
|
||||
- [version.fun](./version.md) — print VM/version info
|
||||
- [while_test.fun](./while_test.md) — simple while loop example
|
||||
|
||||
Tip: If a file name is listed above but not present on your build, it may depend on an extension you did not enable.
|
||||
|
||||
|
||||
## Algorithms (./examples/algos)
|
||||
- deduplicate.fun — removing duplicates from arrays/maps
|
||||
- sort_and_search.fun — sorting and lookup patterns
|
||||
- stack_queue.fun — basic stack and queue implementation
|
||||
|
||||
## Arrays (./examples/arrays)
|
||||
- arrays.fun — create, index, slice; typical idioms
|
||||
- arrays_iter.fun — iteration and enumeration
|
||||
- arrays_advanced.fun — copying, filtering, transformations
|
||||
|
||||
## Basics (./examples/basics)
|
||||
- boolean_decl.fun, booleans.fun — boolean values and operators
|
||||
- builtins_conversions.fun — core built‑ins, type conversions
|
||||
- collections.fun — arrays, maps, nested structures
|
||||
- fibonacci.fun, fizzbuzz.fun — classic exercises
|
||||
- hello_world.fun — the canonical first program
|
||||
|
||||
## CLI (./examples/cli)
|
||||
- args_parse.fun — arguments parsing patterns for small CLIs
|
||||
|
||||
## Compose (./examples/compose)
|
||||
Compositional patterns, small abstractions to combine behavior.
|
||||
|
||||
## Crypto (./examples/crypto)
|
||||
Hashing and cryptographic helpers. Availability depends on whether OpenSSL/LibreSSL is enabled.
|
||||
- openssl_md5.fun — MD5 via OpenSSL (if -DFUN_WITH_OPENSSL)
|
||||
- libressl_md5.fun — MD5 via LibreSSL (if -DFUN_WITH_LIBRESSL)
|
||||
- aes256.fun and hash samples if present on your build
|
||||
|
||||
## Data (./examples/data)
|
||||
Static assets for example servers; not meant to be run directly.
|
||||
- htdocs/ — files used by HTTP server examples (index.html, hello.fun, info.fun, form_post.fun, counter.fun, redirect.fun, json_like_api.fun)
|
||||
|
||||
## Error handling and diagnostics (./examples/error)
|
||||
- debug_reporting.fun — enabling debug output and reading traces
|
||||
- exit_example.fun — exit codes
|
||||
- fail.fun — triggering and observing failures
|
||||
- repl_on_error.fun — dropping into REPL on error
|
||||
- rust_vm_access.fun — Rust opcode errors (if enabled)
|
||||
- test_indent.fun — parser/indentation corner cases
|
||||
- try_catch_with_error.fun — capturing error objects
|
||||
|
||||
## Extra integrations (./examples/extra)
|
||||
These require optional external libraries. See docs/external/.
|
||||
- curl_* — cURL HTTP client examples (download, GET JSON, POST)
|
||||
- ini_* — parsing INI files (simple to complex)
|
||||
- json_showcase.fun — JSON helpers
|
||||
- libsql_example.fun — libSQL client usage
|
||||
- notcurses_* — rich TUI demos (if Notcurses enabled)
|
||||
- pcre2_* — PCRE2 regex engine demos
|
||||
- pcsc*.fun — smart card access via PC/SC
|
||||
- sqlite_example.fun — SQLite usage
|
||||
- tcp_echo_server*.fun — basic TCP echo server
|
||||
- tk_* — Tcl/Tk GUI examples
|
||||
- xml_* — XML parsing with libxml2
|
||||
|
||||
## Interactive (./examples/interactive)
|
||||
- console_prompt.fun — simple prompt loop
|
||||
- input_example.fun — reading user input
|
||||
- input_hidden_example.fun, input_hidden_pam_auth.fun — hidden input/passwords
|
||||
|
||||
## IO (./examples/io)
|
||||
- async_http_client.fun — non‑blocking HTTP client
|
||||
- await_http_client.fun — non‑blocking HTTP client using lib/async/scheduler.fun (await-style helpers)
|
||||
- csv_reader.fun — parse CSV files
|
||||
- file_io.fun, read_write_file.fun — file operations
|
||||
- word_count.fun — classic WC example
|
||||
|
||||
## Math (./examples/math)
|
||||
Small, focused math helpers and demonstrations:
|
||||
- math_ceil, math_floor, math_round, math_trunc, math_sign
|
||||
- math_cos, math_sin, math_tan
|
||||
- math_sqrt, math_isqrt
|
||||
- math_exp_log
|
||||
- math_fmin_fmax
|
||||
- math_gcd_lcm
|
||||
|
||||
## Networking (./examples/net)
|
||||
Servers and socket utilities. See docs/examples/net/httpserver.md for the HTTP family.
|
||||
- HTTP servers: [httpserver.md](./net/httpserver.md) — end‑to‑end walkthrough of all HTTP server variants in examples/net/
|
||||
- http_static_server.fun — minimal static server over sockets
|
||||
- http_server.fun — blocking static/CGI dispatcher using lib/net/http_server.fun
|
||||
- http_server_cgi.fun — blocking server with CGI via lib/net/http_cgi_server.fun
|
||||
- http_server_cgi_lib.fun — blocking server leveraging net/cgi.fun helpers
|
||||
- http_mt_server.fun — thread‑per‑connection static server
|
||||
- http_mt_server_cgi.fun — thread‑per‑connection with CGI support
|
||||
|
||||
## Patterns (./examples/patterns)
|
||||
Small idioms and reusable patterns.
|
||||
- assert_like.fun — assert‑style checks via language constructs
|
||||
|
||||
## Snippets (./examples/snippets)
|
||||
Miscellaneous one‑off code snippets demonstrating particular opcodes or tricks.
|
||||
|
||||
## SQLite daemon (./examples/sqlited)
|
||||
- Files related to running a small SQLite‑backed service (see source for details)
|
||||
|
||||
## Strings (./examples/strings)
|
||||
- base64_demo.fun — base64 encode/decode using encoding/base64
|
||||
- split_join_trim.fun — string splitting and trimming
|
||||
- templating_min.fun — bare‑bones templating
|
||||
- urlencode_decode.fun — percent‑encoding helpers
|
||||
|
||||
## Broken (./examples/broken)
|
||||
Historical or intentionally broken examples kept for reference/regression.
|
||||
- notcurses_* — experiments around Notcurses
|
||||
- ripemd160* — legacy or experimental hash routines
|
||||
|
||||
### Running examples reliably
|
||||
|
||||
Prefer the local build when running from the repository root:
|
||||
- ./build_debug/fun <path/to/example.fun>
|
||||
- or: ./build_release/fun <path/to/example.fun>
|
||||
|
||||
Set up env if needed:
|
||||
- export FUN_LIB_DIR="./lib" # to find stdlib
|
||||
- export FUN_EXEC="./build_debug/fun" # used by CGI examples
|
||||
- export FUN_HTDOCS="./examples/data/htdocs" # override docroot
|
||||
|
||||
When optional extensions are not enabled, their examples will not run; reconfigure the build with the required -D flags shown in docs/external/.
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
# builtins_extended.fun — overview
|
||||
|
||||
What it shows
|
||||
- A tour of core built‑ins beyond the basics: printing, typing, math helpers, conversions, and utility functions commonly used in small scripts.
|
||||
|
||||
How to run
|
||||
- From repo root with local build:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/builtins_extended.fun
|
||||
- Or, if installed: fun examples/builtins_extended.fun
|
||||
|
||||
Notes
|
||||
- Exact behavior and outputs are documented inline at the top of the script; open the .fun file for details.
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# builtins_maps_and_more.fun — overview
|
||||
|
||||
What it shows
|
||||
- Exploring built‑ins while working with maps and related data structures.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/builtins_maps_and_more.fun
|
||||
- Or: fun examples/builtins_maps_and_more.fun
|
||||
|
||||
Notes
|
||||
- Open the .fun file to see the exact behaviors and printed output.
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# byte_for_demo.fun — overview
|
||||
|
||||
What it shows
|
||||
- Iterating bytes with a for-loop; indexing and printing byte values.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/byte_for_demo.fun
|
||||
- Or: fun examples/byte_for_demo.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# byte_overflow_try_catch.fun — overview
|
||||
|
||||
What it shows
|
||||
- Error handling around byte/integer overflow using try/catch.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/byte_overflow_try_catch.fun
|
||||
- Or: fun examples/byte_overflow_try_catch.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# cast_demo.fun — overview
|
||||
|
||||
What it shows
|
||||
- Conversions and casting helpers; demonstrates changing between numeric and string types safely.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/cast_demo.fun
|
||||
- Or: fun examples/cast_demo.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# class_constructor.fun — overview
|
||||
|
||||
What it shows
|
||||
- Class basics and constructor behavior; initializing fields and using methods.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/class_constructor.fun
|
||||
- Or: fun examples/class_constructor.fun
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# class_test.fun — overview
|
||||
|
||||
What it shows
|
||||
- Simple class usage and method invocation; small sanity checks around classes.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/class_test.fun
|
||||
- Or: fun examples/class_test.fun
|
||||
|
||||
Notes
|
||||
- Open the script to see the exact behavior and outputs.
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# class_without_object.fun — overview
|
||||
|
||||
What it shows
|
||||
- Class features that can be used without creating an instance (static-like usage patterns).
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/class_without_object.fun
|
||||
- Or: fun examples/class_without_object.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# classes_demo.fun — overview
|
||||
|
||||
What it shows
|
||||
- Class basics and usage: defining classes, instantiating objects, calling methods.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/classes_demo.fun
|
||||
- Or: fun examples/classes_demo.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# cli_argv_dump.fun — overview
|
||||
|
||||
What it shows
|
||||
- Prints argv/argc handling to demonstrate CLI arguments parsing at a low level.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/cli_argv_dump.fun --foo bar 123
|
||||
- Or: fun examples/cli_argv_dump.fun --foo bar 123
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# conversions_showcase.fun — overview
|
||||
|
||||
What it shows
|
||||
- Numbers, strings, and bytes conversions; typical idioms and edge cases.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/conversions_showcase.fun
|
||||
- Or: fun examples/conversions_showcase.fun
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# cpp_add.fun — overview
|
||||
|
||||
What it shows
|
||||
- Calling into the optional C++ extension from Fun.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/cpp_add.fun
|
||||
- Or: fun examples/cpp_add.fun
|
||||
|
||||
Notes
|
||||
- Requires the optional C++ extension to be enabled in your build; otherwise this example may be unavailable.
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# counter.fun (CGI)
|
||||
|
||||
- Location: examples/data/htdocs/counter.fun
|
||||
- Category: CGI script used by HTTP server examples
|
||||
|
||||
Description
|
||||
- Simple stateful counter example for CGI; demonstrates reading and updating a value across requests (implementation details in script).
|
||||
|
||||
How to run
|
||||
- Through one of the HTTP server examples, e.g.:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- export FUN_EXEC="./build_debug/fun"
|
||||
- ./build_debug/fun examples/net/http_server_cgi.fun
|
||||
- Open: http://127.0.0.1:8080/counter.fun
|
||||
|
||||
See also
|
||||
- docs/examples/httpserver.md (deep-dive)
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# form_post.fun (CGI)
|
||||
|
||||
- Location: examples/data/htdocs/form_post.fun
|
||||
- Category: CGI script used by HTTP server examples
|
||||
|
||||
Description
|
||||
- Demonstrates handling of POST form data via the CGI interface.
|
||||
|
||||
How to run
|
||||
- Through one of the HTTP server examples, e.g.:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- export FUN_EXEC="./build_debug/fun"
|
||||
- ./build_debug/fun examples/net/http_server_cgi.fun
|
||||
- Submit a form to: http://127.0.0.1:8080/form_post.fun
|
||||
|
||||
See also
|
||||
- docs/examples/httpserver.md (deep-dive)
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# hello.fun (CGI)
|
||||
|
||||
- Location: examples/data/htdocs/hello.fun
|
||||
- Category: CGI script used by HTTP server examples
|
||||
|
||||
Description
|
||||
- Simple CGI .fun script that prints a greeting, optionally using query parameters (e.g., ?name=Fun).
|
||||
|
||||
How to run
|
||||
- Through one of the HTTP server examples, e.g.:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- export FUN_EXEC="./build_debug/fun"
|
||||
- ./build_debug/fun examples/net/http_server_cgi.fun
|
||||
- Open: http://127.0.0.1:8080/hello.fun?name=Fun
|
||||
|
||||
See also
|
||||
- docs/examples/httpserver.md (deep-dive)
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# info.fun (CGI)
|
||||
|
||||
- Location: examples/data/htdocs/info.fun
|
||||
- Category: CGI script used by HTTP server examples
|
||||
|
||||
Description
|
||||
- CGI script that prints request/environment information, useful for debugging CGI variables.
|
||||
|
||||
How to run
|
||||
- Through one of the HTTP server examples, e.g.:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- export FUN_EXEC="./build_debug/fun"
|
||||
- ./build_debug/fun examples/net/http_server_cgi.fun
|
||||
- Open: http://127.0.0.1:8080/info.fun
|
||||
|
||||
See also
|
||||
- docs/examples/httpserver.md (deep-dive)
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# json_like_api.fun (CGI)
|
||||
|
||||
- Location: examples/data/htdocs/json_like_api.fun
|
||||
- Category: CGI script used by HTTP server examples
|
||||
|
||||
Description
|
||||
- Demonstrates returning JSON-like output from a CGI endpoint.
|
||||
|
||||
How to run
|
||||
- Through one of the HTTP server examples, e.g.:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- export FUN_EXEC="./build_debug/fun"
|
||||
- ./build_debug/fun examples/net/http_server_cgi.fun
|
||||
- Open: http://127.0.0.1:8080/json_like_api.fun
|
||||
|
||||
See also
|
||||
- docs/examples/httpserver.md (deep-dive)
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# redirect.fun (CGI)
|
||||
|
||||
- Location: examples/data/htdocs/redirect.fun
|
||||
- Category: CGI script used by HTTP server examples
|
||||
|
||||
Description
|
||||
- Demonstrates issuing HTTP redirects from a CGI script (setting Status and Location headers).
|
||||
|
||||
How to run
|
||||
- Through one of the HTTP server examples, e.g.:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- export FUN_EXEC="./build_debug/fun"
|
||||
- ./build_debug/fun examples/net/http_server_cgi.fun
|
||||
- Open: http://127.0.0.1:8080/redirect.fun
|
||||
|
||||
See also
|
||||
- docs/examples/httpserver.md (deep-dive)
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# datetime_basic.fun — overview
|
||||
|
||||
What it shows
|
||||
- Basic time/date helpers and formatting.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/datetime_basic.fun
|
||||
- Or: fun examples/datetime_basic.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# datetime_extended.fun — overview
|
||||
|
||||
What it shows
|
||||
- Extended datetime helpers: parsing, arithmetic, timers, and formatting variants.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/datetime_extended.fun
|
||||
- Or: fun examples/datetime_extended.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# datetime_timer.fun — overview
|
||||
|
||||
What it shows
|
||||
- Measuring elapsed time and simple timers using datetime helpers.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/datetime_timer.fun
|
||||
- Or: fun examples/datetime_timer.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# echo_example.fun — overview
|
||||
|
||||
What it shows
|
||||
- Simple echo of input/args; prints back what you type or pass as arguments.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/echo_example.fun hello world
|
||||
- Or: fun examples/echo_example.fun hello world
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# env_all.fun — overview
|
||||
|
||||
What it shows
|
||||
- Reading and listing environment variables.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/env_all.fun
|
||||
- Or: fun examples/env_all.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# error_handling.fun — overview
|
||||
|
||||
What it shows
|
||||
- Error patterns and handling strategies using try/catch/finally.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/error_handling.fun
|
||||
- Or: fun examples/error_handling.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# expressions_test.fun — overview
|
||||
|
||||
What it shows
|
||||
- Operator precedence and expression grouping tests/demonstrations.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/expressions_test.fun
|
||||
- Or: fun examples/expressions_test.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# features.fun — overview
|
||||
|
||||
What it shows
|
||||
- Grab bag of language features in a single script.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/features.fun
|
||||
- Or: fun examples/features.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# file_print_for_file_line_by_line.fun — overview
|
||||
|
||||
What it shows
|
||||
- Iterate a file line-by-line and print each line; basic file IO idioms.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/file_print_for_file_line_by_line.fun path/to/file.txt
|
||||
- Or: fun examples/file_print_for_file_line_by_line.fun path/to/file.txt
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# floats.fun — overview
|
||||
|
||||
What it shows
|
||||
- Floating point operations and formatting details.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/floats.fun
|
||||
- Or: fun examples/floats.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# for_range_test.fun — overview
|
||||
|
||||
What it shows
|
||||
- Ranges and loops; iterating numeric ranges and verifying bounds.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/for_range_test.fun
|
||||
- Or: fun examples/for_range_test.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# functions_test.fun — overview
|
||||
|
||||
What it shows
|
||||
- Functions, closures, and return behavior; call semantics basics.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/functions_test.fun
|
||||
- Or: fun examples/functions_test.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# have_fun.fun — overview
|
||||
|
||||
What it shows
|
||||
- Playful demo showing off small language tricks.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/have_fun.fun
|
||||
- Or: fun examples/have_fun.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# have_fun_function.fun — overview
|
||||
|
||||
What it shows
|
||||
- A playful function-centric demo; small utility behaviors.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/have_fun_function.fun
|
||||
- Or: fun examples/have_fun_function.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# hex_example.fun — overview
|
||||
|
||||
What it shows
|
||||
- Hex encode/decode helpers; working with hexadecimal representations.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/hex_example.fun
|
||||
- Or: fun examples/hex_example.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# if_else_test.fun — overview
|
||||
|
||||
What it shows
|
||||
- Control flow with if/else; branching and comparisons.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/if_else_test.fun
|
||||
- Or: fun examples/if_else_test.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# include_lib.fun — overview
|
||||
|
||||
What it shows
|
||||
- Including modules from the standard library path using #include <...>.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib" # ensure stdlib is discoverable
|
||||
- ./build_debug/fun examples/include_lib.fun
|
||||
- Or: fun examples/include_lib.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# include_local.fun — overview
|
||||
|
||||
What it shows
|
||||
- Including local files relative to the script and reusing helpers.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/include_local.fun
|
||||
- Or: fun examples/include_local.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# include_local_util.fun — overview
|
||||
|
||||
What it shows
|
||||
- Local include mechanics with a small utility module.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/include_local_util.fun
|
||||
- Or: fun examples/include_local_util.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# inheritance_demo.fun — overview
|
||||
|
||||
What it shows
|
||||
- Simple class inheritance and method overriding examples.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/inheritance_demo.fun
|
||||
- Or: fun examples/inheritance_demo.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# loops_break_continue.fun — overview
|
||||
|
||||
What it shows
|
||||
- Loop control: break and continue; demonstrating control flow within loops.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/loops_break_continue.fun
|
||||
- Or: fun examples/loops_break_continue.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# maps.fun — overview
|
||||
|
||||
What it shows
|
||||
- Working with maps: creation, indexing, iteration, and typical idioms.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/maps.fun
|
||||
- Or: fun examples/maps.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# match.fun — overview
|
||||
|
||||
What it shows
|
||||
- Pattern matching constructs and examples of branching by value/shape.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/match.fun
|
||||
- Or: fun examples/match.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# namespaced_mod.fun — overview
|
||||
|
||||
What it shows
|
||||
- Namespaced includes and using the "as" aliasing pattern for modules.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/namespaced_mod.fun
|
||||
- Or: fun examples/namespaced_mod.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# nested_loops.fun — overview
|
||||
|
||||
What it shows
|
||||
- Control flow with nested loops; inner/outer loop coordination.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/nested_loops.fun
|
||||
- Or: fun examples/nested_loops.fun
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
# http_mt_server.fun
|
||||
|
||||
- Location: examples/net/http_mt_server.fun
|
||||
- Category: Networking / HTTP (multi-threaded)
|
||||
|
||||
Description
|
||||
- Thread-per-connection HTTP server built on io/socket.fun and io/thread.fun. For each accepted client, spawns a thread and returns a small HTML page.
|
||||
|
||||
How to run
|
||||
- From the repository root:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/net/http_mt_server.fun
|
||||
- Then open http://127.0.0.1:8080/ (or the port printed on start)
|
||||
|
||||
Requirements
|
||||
- Uses stdlib io/socket.fun and io/thread.fun. No external extensions required.
|
||||
|
||||
See also
|
||||
- docs/examples/README.md
|
||||
- docs/examples/httpserver.md (deep-dive)
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
# http_mt_server_cgi.fun
|
||||
|
||||
- Location: examples/net/http_mt_server_cgi.fun
|
||||
- Category: Networking / HTTP with CGI (multi-threaded)
|
||||
|
||||
Description
|
||||
- Multi-threaded HTTP server (thread-per-connection) with CGI support. Serves static files from htdocs and executes .fun scripts as CGI using net/cgi.fun helpers.
|
||||
|
||||
How to run
|
||||
- From the repository root:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- export FUN_EXEC="./build_debug/fun" # optional; auto-detected if omitted
|
||||
- export FUN_HTDOCS="./examples/data/htdocs" # optional
|
||||
- ./build_debug/fun examples/net/http_mt_server_cgi.fun
|
||||
- Try: http://127.0.0.1:8080/ and /hello.fun?name=Fun, /info.fun
|
||||
|
||||
Requirements
|
||||
- Uses stdlib io/socket.fun, io/thread.fun, and net/cgi.fun. No external extensions required.
|
||||
|
||||
See also
|
||||
- docs/examples/README.md
|
||||
- docs/examples/httpserver.md (deep-dive)
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
# http_server.fun
|
||||
|
||||
- Location: examples/net/http_server.fun
|
||||
- Category: Networking / HTTP (blocking)
|
||||
|
||||
Description
|
||||
- Blocking HTTP server that serves static files and executes .fun CGI scripts via lib/net/http_server.fun.
|
||||
|
||||
How to run
|
||||
- From the repository root:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/net/http_server.fun
|
||||
- Default docroot: ./examples/data/htdocs
|
||||
- Visit: http://127.0.0.1:8080/
|
||||
|
||||
Notes
|
||||
- For CGI .fun under htdocs, the server uses the Fun interpreter to execute them and forwards output as HTTP.
|
||||
|
||||
Requirements
|
||||
- Uses io/socket.fun and strings.fun; no external extensions required.
|
||||
|
||||
See also
|
||||
- docs/examples/README.md
|
||||
- docs/examples/httpserver.md (deep-dive)
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
# http_server_cgi.fun
|
||||
|
||||
- Location: examples/net/http_server_cgi.fun
|
||||
- Category: Networking / HTTP with CGI (blocking)
|
||||
|
||||
Description
|
||||
- Minimal CGI-capable HTTP server (blocking) using lib/net/http_cgi_server.fun. Serves static files and executes .fun scripts as CGI.
|
||||
|
||||
How to run
|
||||
- From the repository root:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- export FUN_EXEC="./build_debug/fun" # optional; auto-detected if omitted
|
||||
- export FUN_HTDOCS="./examples/data/htdocs" # optional
|
||||
- ./build_debug/fun examples/net/http_server_cgi.fun
|
||||
- Try: http://127.0.0.1:8080/ and /hello.fun, /info.fun
|
||||
|
||||
Requirements
|
||||
- Uses stdlib io/socket.fun, strings.fun, and net/cgi.fun. No external extensions required.
|
||||
|
||||
See also
|
||||
- docs/examples/README.md
|
||||
- docs/examples/httpserver.md (deep-dive)
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
# http_server_cgi_lib.fun
|
||||
|
||||
- Location: examples/net/http_server_cgi_lib.fun
|
||||
- Category: Networking / HTTP with CGI (blocking, stdlib helpers)
|
||||
|
||||
Description
|
||||
- Blocking HTTP server that serves static files and runs .fun as CGI using helpers from lib/net/http_cgi_lib_server.fun and net/cgi.fun.
|
||||
|
||||
How to run
|
||||
- From the repository root:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- export FUN_EXEC="./build_debug/fun" # optional; auto-detected if omitted
|
||||
- export FUN_HTDOCS="./examples/data/htdocs" # optional
|
||||
- ./build_debug/fun examples/net/http_server_cgi_lib.fun
|
||||
- Try: http://127.0.0.1:8080/ and /hello.fun, /info.fun
|
||||
|
||||
Requirements
|
||||
- Uses stdlib io/socket.fun, strings.fun, net/cgi.fun. No external extensions required.
|
||||
|
||||
See also
|
||||
- docs/examples/README.md
|
||||
- docs/examples/httpserver.md (deep-dive)
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
# http_static_server.fun
|
||||
|
||||
- Location: examples/net/http_static_server.fun
|
||||
- Category: Networking / Sockets
|
||||
|
||||
Description
|
||||
- Minimal static HTTP server implemented directly on sockets. Accepts connections and always returns a small HTML page.
|
||||
|
||||
How to run
|
||||
- From the repository root:
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/net/http_static_server.fun
|
||||
- Then open http://127.0.0.1:8088/
|
||||
|
||||
Requirements
|
||||
- Uses core IO/socket stdlib (io/socket.fun). No optional extensions required.
|
||||
|
||||
See also
|
||||
- docs/examples/README.md
|
||||
- docs/examples/httpserver.md (deep-dive over HTTP servers)
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
# HTTP server examples: architecture and how they work
|
||||
|
||||
This guide explains the HTTP server examples under `./examples/net/http_*` and the supporting standard library modules under `./lib/net/`.
|
||||
|
||||
It covers what each example does, how to run it, and how the request handling/CGI pieces are implemented.
|
||||
|
||||
## Prerequisites
|
||||
- Build the project so you have a `fun` executable, or ensure `fun` is on your PATH.
|
||||
- Typical local builds: `./build_debug/fun` or `./build_release/fun`.
|
||||
- For examples that serve files/CGI scripts, content is read from `./examples/data/htdocs` by default.
|
||||
- Helpful env vars used by some examples:
|
||||
- `FUN_LIB_DIR` — path to the stdlib (`./lib` when running from the repo).
|
||||
- `FUN_EXEC` — override path to the `fun` interpreter used to run CGI children.
|
||||
- `FUN_HTDOCS` — override htdocs directory for some examples (not all).
|
||||
- `FUN_PORT` — override port for some examples (mainly the MT CGI one).
|
||||
|
||||
## Supporting stdlib modules (lib/net)
|
||||
|
||||
- `net/http_server.fun` — Simple blocking HTTP server class serving static files, with a very small built-in “CGI for .fun files” (spawns `fun` with `QUERY_STRING`/`POST_DATA`).
|
||||
- `net/http_cgi_server.fun` — Blocking server with fuller CGI support using `net/cgi.fun` to translate CGI output into proper HTTP responses and richer request/header parsing.
|
||||
- `net/http_cgi_lib_server.fun` — Variant of the CGI server with the same core behavior, explicitly wiring the Fun interpreter path and using `CGI().cgi_to_http_response()` from `net/cgi.fun`.
|
||||
- `net/cgi.fun` — Helpers to work with CGI-style programs and to translate CGI output (headers + body) into full HTTP/1.1 responses.
|
||||
|
||||
See docs/stdlib.md → net/ for a quick index of these modules.
|
||||
|
||||
## Example: http_static_server.fun
|
||||
- File: `examples/net/http_static_server.fun`
|
||||
- Purpose: Minimal, hand-written HTTP server that ignores the request path and always responds with a fixed HTML page.
|
||||
- Key includes: `io/socket.fun`
|
||||
- Port/backlog: hard-coded `8088`, backlog 10.
|
||||
- Flow:
|
||||
- Creates `TcpServer(port, backlog)` → `listen()` → loop on `accept()`
|
||||
- `sock_recv()` reads and discards request
|
||||
- Constructs a literal HTTP/1.1 200 response with `Content-Length` and `Connection: close`
|
||||
- Sends the response with `sock_send()` and closes the client
|
||||
- Run:
|
||||
- `./examples/net/http_static_server.fun`
|
||||
- Open http://127.0.0.1:8080/
|
||||
|
||||
## Example: http_server.fun (static + simple .fun CGI)
|
||||
- File: `examples/net/http_server.fun`
|
||||
- Uses: `#include <net/http_server.fun>` (class `HTTPServer`)
|
||||
- Purpose: Blocking server that serves static files from an htdocs directory; if the requested path ends with `.fun`, it spawns `fun` to run the script and returns its output.
|
||||
- Defaults in example:
|
||||
- Port: `8080`
|
||||
- Htdocs: `./examples/data/htdocs`
|
||||
- Implementation highlights (see `lib/net/http_server.fun`):
|
||||
- Parses request line to get `method` and `path`; `/` maps to `/index.html`.
|
||||
- When path ends with `.fun`, builds a small environment:
|
||||
- `QUERY_STRING` (for `?a=b`), `POST_DATA` (raw body when `POST`).
|
||||
- Runs `proc_run("<env> fun <script>")` and uses `out` as response body.
|
||||
- Otherwise reads the file from `htdocs` and serves it as-is.
|
||||
- Sends basic HTTP/1.1 headers: 200/404, `Content-Type: text/html`, `Content-Length`, `Connection: close`.
|
||||
- Run:
|
||||
- `./examples/net/http_server.fun`
|
||||
- Open http://127.0.0.1:8080/ and the sample CGI endpoints like `/hello.fun?name=Fun`.
|
||||
|
||||
## Example: http_server_cgi.fun (CGI via external interpreter)
|
||||
- File: `examples/net/http_server_cgi.fun`
|
||||
- Uses: `#include <net/http_cgi_server.fun>` (class `HTTPCGIServer`)
|
||||
- Purpose: Blocking server that serves static files and executes `.fun` scripts under htdocs via a child Fun interpreter, with fuller CGI environment and header handling.
|
||||
- Defaults in example:
|
||||
- Port: `8080`
|
||||
- Htdocs: `./examples/data/htdocs`
|
||||
- Implementation highlights (see `lib/net/http_cgi_server.fun`):
|
||||
- Robust request-line extraction and header parsing (case-normalized to uppercase).
|
||||
- Path routing: `/` → `/index.html`; `.fun` → treat as CGI script.
|
||||
- Builds CGI env including: `FUN_LIB_DIR`, `REQUEST_METHOD`, `QUERY_STRING`, `SCRIPT_NAME`, `PATH_INFO`, `SERVER_NAME`, `SERVER_PORT`, `SERVER_PROTOCOL`, `HTTP_HOST`, `HTTP_USER_AGENT`, `HTTP_COOKIE`, `CONTENT_TYPE`, `CONTENT_LENGTH`, and `POST_DATA` (if any).
|
||||
- Interpreter selection priority: `$FUN_EXEC` → `./build_debug/fun` → `./build_release/fun` → `fun` from PATH.
|
||||
- Uses `net/cgi.fun` to convert CGI output (headers + body) into a proper HTTP/1.1 response before sending.
|
||||
- Run:
|
||||
- `./examples/net/http_server_cgi.fun`
|
||||
- Try: `/`, `/hello.fun?name=Fun`, `/info.fun` under http://127.0.0.1:8080/
|
||||
|
||||
## Example: http_server_cgi_lib.fun (CGI via stdlib wrapper)
|
||||
- File: `examples/net/http_server_cgi_lib.fun`
|
||||
- Uses: `#include <net/http_cgi_lib_server.fun>` (class `HTTPCGILibServer`)
|
||||
- Purpose: Same goal as the previous example but split into a slightly different stdlib class; also uses `CGI().cgi_to_http_response()` for translating CGI output.
|
||||
- Defaults and behavior mirror `HTTPCGIServer`: static files from htdocs, `.fun` as CGI with the same env block and interpreter selection logic.
|
||||
- Run:
|
||||
- `./examples/net/http_server_cgi_lib.fun`
|
||||
- Try: `/`, `/hello.fun?name=Fun`, `/info.fun` under http://127.0.0.1:8080/
|
||||
|
||||
## Example: http_mt_server.fun (thread-per-connection)
|
||||
- File: `examples/net/http_mt_server.fun`
|
||||
- Uses: `io/socket.fun`, `io/thread.fun`
|
||||
- Purpose: Hand-written multi-threaded server; main thread blocks in `accept()`, each connection handled in a new Fun thread.
|
||||
- Behavior: Reads request, replies with a fixed HTML 200 response, then closes the connection.
|
||||
- Defaults: `PORT = 8080`, `BACKLOG = 128` (note the comment mentions 8089 in a usage line; the code uses 8080).
|
||||
- Run: `./examples/net/http_mt_server.fun` then open http://127.0.0.1:8080/
|
||||
|
||||
## Example: http_mt_server_cgi.fun (thread-per-connection + CGI)
|
||||
- File: `examples/net/http_mt_server_cgi.fun`
|
||||
- Uses: `io/socket.fun`, `io/thread.fun`, `net/cgi.fun`
|
||||
- Purpose: Multi-threaded server that serves static files from htdocs and executes `.fun` scripts as CGI, implemented without higher-level string helpers to keep per-thread globals minimal.
|
||||
- Defaults: `PORT = 8080`, `BACKLOG = 128`, `HTDOCS = ./examples/data/htdocs`.
|
||||
- Request handling flow:
|
||||
- Reads request bytes, extracts the request line, splits out `method` and `target`.
|
||||
- Splits `path` and `query` on `?`; `/` becomes `/index.html`.
|
||||
- Parses headers into a map (uppercase keys) and optionally reads a request body.
|
||||
- Routing:
|
||||
- If `path` ends with `.fun`: build CGI env; spawn a child `fun` to execute the script; capture stdout; translate to HTTP via `_cgi_to_http_response()`; send back.
|
||||
- Else: attempt to read the static file from `HTDOCS + path`; send 200 or 404.
|
||||
- CGI environment variables set (subset):
|
||||
- `FUN_LIB_DIR`, `REQUEST_METHOD`, `QUERY_STRING`, `SCRIPT_NAME`, `PATH_INFO`, `SERVER_NAME`, `SERVER_PORT`, `SERVER_PROTOCOL`, `HTTP_HOST`, `HTTP_USER_AGENT`, `HTTP_COOKIE`, `CONTENT_TYPE`, `CONTENT_LENGTH`, `POST_DATA` (when present).
|
||||
- Interpreter selection (similar to CGI examples): `$FUN_EXEC` → `./build_debug/fun` → `./build_release/fun` → `fun` from PATH.
|
||||
- Notes:
|
||||
- Allows overriding `HTDOCS` & port via `FUN_HTDOCS` and `FUN_PORT` environment variables.
|
||||
- Implements its own small helpers (`_trim`, `_ends_with`, `_split_*`) to avoid heavy string utilities inside threads.
|
||||
- Run: `./examples/net/http_mt_server_cgi.fun` then open http://127.0.0.1:8080/
|
||||
|
||||
## Example: http_server_test.fun
|
||||
- File: `examples/net/http_server_test.fun`
|
||||
- Purpose: Small test harness to exercise/verify server pieces (implementation details may change). Check the source for exact behavior.
|
||||
|
||||
## Common behaviors and notes
|
||||
- Index handling: most servers map `/` to `/index.html` under the configured `htdocs` directory.
|
||||
- Static files: served by reading from `<htdocs><path>`; a missing file returns `404 Not Found`.
|
||||
- CGI scripts:
|
||||
- Any path ending in `.fun` under `htdocs` is executed with the Fun interpreter as a child process.
|
||||
- CGI output is expected to be a mix of optional headers and a body; the servers convert this to a valid HTTP/1.1 response (via `net/cgi.fun` or a local helper).
|
||||
- To ensure the child can `#include` stdlib modules, `FUN_LIB_DIR` is populated (defaults to `./lib` when run from repo root).
|
||||
- Content types: examples return `Content-Type: text/html; charset=utf-8` by default for dynamic responses; static file content types are not auto-detected in these examples.
|
||||
- Connection handling: responses include `Connection: close`; examples do not implement keep-alive or HTTP/1.1 request pipelining.
|
||||
- Security: these are demo servers. Do not expose them to untrusted networks. They lack path normalization, MIME sniffing, directory traversal protection, rate limiting, and TLS.
|
||||
|
||||
## How to point htdocs somewhere else
|
||||
- For class-based servers: call `set_htdocs("/path/to/site")` on the server instance before `start()`.
|
||||
- For the MT CGI example: set `FUN_HTDOCS=/path/to/site` in the environment before launch.
|
||||
|
||||
## Troubleshooting
|
||||
- If a CGI request yields a 500 and you see “CGI produced no output”, run the target `.fun` directly with your `fun` interpreter and fix any errors.
|
||||
- Confirm `FUN_LIB_DIR` points to the stdlib (especially when running CGI scripts that `#include` modules).
|
||||
- If the server cannot start, another process might be using the chosen port.
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# objects_basic.fun — overview
|
||||
|
||||
What it shows
|
||||
- OO basics: defining objects, fields, and invoking methods.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/objects_basic.fun
|
||||
- Or: fun examples/objects_basic.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# objects_more.fun — overview
|
||||
|
||||
What it shows
|
||||
- Additional object patterns: composition, methods, and utilities.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/objects_more.fun
|
||||
- Or: fun examples/objects_more.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# os_env.fun — overview
|
||||
|
||||
What it shows
|
||||
- Reading and writing environment variables from the operating system.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/os_env.fun
|
||||
- Or: fun examples/os_env.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# process_example.fun — overview
|
||||
|
||||
What it shows
|
||||
- Spawning and capturing subprocess output; simple process management.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/process_example.fun
|
||||
- Or: fun examples/process_example.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# progress.fun — overview
|
||||
|
||||
What it shows
|
||||
- Simple progress display in the terminal.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/progress.fun
|
||||
- Or: fun examples/progress.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# progress_inline.fun — overview
|
||||
|
||||
What it shows
|
||||
- Inline progress updates (same line updates) for simple terminal UIs.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/progress_inline.fun
|
||||
- Or: fun examples/progress_inline.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# random_demo.fun — overview
|
||||
|
||||
What it shows
|
||||
- Random number generator usage and seeding basics.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/random_demo.fun
|
||||
- Or: fun examples/random_demo.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# random_number_example.fun — overview
|
||||
|
||||
What it shows
|
||||
- Generating random numbers and printing them; small utility demo.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/random_number_example.fun
|
||||
- Or: fun examples/random_number_example.fun
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# regex_demo.fun — overview
|
||||
|
||||
What it shows
|
||||
- Regex helpers usage; simple matching and replacement tasks.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/regex_demo.fun
|
||||
- Or: fun examples/regex_demo.fun
|
||||
|
||||
Notes
|
||||
- Some regex examples depend on the optional PCRE2 extension; enable it in your build to run.
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# regex_procedural.fun — overview
|
||||
|
||||
What it shows
|
||||
- Procedural approach to regex work: compiling patterns and iterating matches.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/regex_procedural.fun
|
||||
- Or: fun examples/regex_procedural.fun
|
||||
|
||||
Notes
|
||||
- May require the optional PCRE2 extension in your build.
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# rust_hello.fun — overview
|
||||
|
||||
What it shows
|
||||
- Using Rust opcodes from Fun (when built with Rust support).
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/rust_hello.fun
|
||||
- Or: fun examples/rust_hello.fun
|
||||
|
||||
Notes
|
||||
- Requires building with FUN_WITH_RUST; otherwise this example will be unavailable.
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# rust_hello_args.fun — overview
|
||||
|
||||
What it shows
|
||||
- Passing arguments into Rust-backed opcodes and handling returns.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/rust_hello_args.fun
|
||||
- Or: fun examples/rust_hello_args.fun
|
||||
|
||||
Notes
|
||||
- Requires building with FUN_WITH_RUST.
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# rust_hello_args_return.fun — overview
|
||||
|
||||
What it shows
|
||||
- Demonstrates returning values from Rust-backed opcodes with arguments.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/rust_hello_args_return.fun
|
||||
- Or: fun examples/rust_hello_args_return.fun
|
||||
|
||||
Notes
|
||||
- Requires building with FUN_WITH_RUST.
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# serial_demo.fun — overview
|
||||
|
||||
What it shows
|
||||
- Serial port access and basic read/write (when available on your system).
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/serial_demo.fun
|
||||
- Or: fun examples/serial_demo.fun
|
||||
|
||||
Notes
|
||||
- Requires serial device access; may depend on platform support and permissions.
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# short_circuit_test.fun — overview
|
||||
|
||||
What it shows
|
||||
- Boolean evaluation order and short-circuit behavior with && and ||.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/short_circuit_test.fun
|
||||
- Or: fun examples/short_circuit_test.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# signed_ints.fun — overview
|
||||
|
||||
What it shows
|
||||
- Signed integer types and operations; ranges and conversions.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/signed_ints.fun
|
||||
- Or: fun examples/signed_ints.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# stdlib_showcase.fun — overview
|
||||
|
||||
What it shows
|
||||
- Sampler of common standard library modules and utilities.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/stdlib_showcase.fun
|
||||
- Or: fun examples/stdlib_showcase.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# strings_test.fun — overview
|
||||
|
||||
What it shows
|
||||
- String helpers and edge cases; splitting, joining, trimming, and formatting.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/strings_test.fun
|
||||
- Or: fun examples/strings_test.fun
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# tcp_http_get.fun — overview
|
||||
|
||||
What it shows
|
||||
- Manual HTTP client over raw TCP sockets: connect, write request, read response.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/tcp_http_get.fun
|
||||
- Or: fun examples/tcp_http_get.fun
|
||||
|
||||
Notes
|
||||
- Requires network access to the target host used in the script.
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# tcp_http_get_class.fun — overview
|
||||
|
||||
What it shows
|
||||
- Manual HTTP client implemented with a small helper class over sockets.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/tcp_http_get_class.fun
|
||||
- Or: fun examples/tcp_http_get_class.fun
|
||||
|
||||
Notes
|
||||
- Requires network access to the target host used in the script.
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# test_bits.fun — overview
|
||||
|
||||
What it shows
|
||||
- Bitwise utilities demonstration (and/or/xor/shifts) and small tests.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/test_bits.fun
|
||||
- Or: fun examples/test_bits.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# test_dec_to_hex.fun — overview
|
||||
|
||||
What it shows
|
||||
- Decimal to hexadecimal conversion helper/tests.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/test_dec_to_hex.fun
|
||||
- Or: fun examples/test_dec_to_hex.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# test_hex_to_dec.fun — overview
|
||||
|
||||
What it shows
|
||||
- Hexadecimal to decimal conversion helper/tests.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/test_hex_to_dec.fun
|
||||
- Or: fun examples/test_hex_to_dec.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# test_include.fun — overview
|
||||
|
||||
What it shows
|
||||
- Small include mechanics test; ensures local and stdlib includes work.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/test_include.fun
|
||||
- Or: fun examples/test_include.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# test_rol.fun — overview
|
||||
|
||||
What it shows
|
||||
- Bit rotation (ROL) helper/tests.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/test_rol.fun
|
||||
- Or: fun examples/test_rol.fun
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# test_serial.fun — overview
|
||||
|
||||
What it shows
|
||||
- Serial port test; opens a port and exchanges a few bytes (when available).
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/test_serial.fun
|
||||
- Or: fun examples/test_serial.fun
|
||||
|
||||
Notes
|
||||
- Requires serial device access; may depend on platform support and permissions.
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# test_shl.fun — overview
|
||||
|
||||
What it shows
|
||||
- Bit shift left (SHL) helper/tests.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/test_shl.fun
|
||||
- Or: fun examples/test_shl.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# test_types.fun — overview
|
||||
|
||||
What it shows
|
||||
- Type checks and simple assertions around type behavior.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/test_types.fun
|
||||
- Or: fun examples/test_types.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# test_xor.fun — overview
|
||||
|
||||
What it shows
|
||||
- Bitwise XOR helper/tests.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/test_xor.fun
|
||||
- Or: fun examples/test_xor.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# thread_class_example.fun — overview
|
||||
|
||||
What it shows
|
||||
- Threading building blocks using a small thread class; start/join patterns.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/thread_class_example.fun
|
||||
- Or: fun examples/thread_class_example.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# threads_demo.fun — overview
|
||||
|
||||
What it shows
|
||||
- Threading building blocks and concurrent execution demo.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/threads_demo.fun
|
||||
- Or: fun examples/threads_demo.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# try_catch_finally.fun — overview
|
||||
|
||||
What it shows
|
||||
- Structured error handling with try/catch/finally blocks.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/try_catch_finally.fun
|
||||
- Or: fun examples/try_catch_finally.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# type_safety.fun — overview
|
||||
|
||||
What it shows
|
||||
- Static/dynamic type checks and enforcing type safety in small examples.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/type_safety.fun
|
||||
- Or: fun examples/type_safety.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# type_safety_fails.fun — overview
|
||||
|
||||
What it shows
|
||||
- Examples that intentionally violate type expectations to illustrate safety checks.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/type_safety_fails.fun
|
||||
- Or: fun examples/type_safety_fails.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# typeof.fun — overview
|
||||
|
||||
What it shows
|
||||
- Type inspection using typeof and related helpers.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/typeof.fun
|
||||
- Or: fun examples/typeof.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# typeof_features.fun — overview
|
||||
|
||||
What it shows
|
||||
- A tour of typeof-related features and type introspection helpers.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/typeof_features.fun
|
||||
- Or: fun examples/typeof_features.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# types_integers.fun — overview
|
||||
|
||||
What it shows
|
||||
- Integer type families, ranges, and basic operations.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/types_integers.fun
|
||||
- Or: fun examples/types_integers.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# types_overview.fun — overview
|
||||
|
||||
What it shows
|
||||
- Overview of language types with small examples.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/types_overview.fun
|
||||
- Or: fun examples/types_overview.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# uint_types.fun — overview
|
||||
|
||||
What it shows
|
||||
- Unsigned integer types and operations; ranges and conversions.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/uint_types.fun
|
||||
- Or: fun examples/uint_types.fun
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# unix_socket_echo.fun — overview
|
||||
|
||||
What it shows
|
||||
- Local domain (UNIX) socket echo server/client demonstration.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/unix_socket_echo.fun
|
||||
- Or: fun examples/unix_socket_echo.fun
|
||||
|
||||
Notes
|
||||
- Uses a UNIX domain socket path on the local filesystem; ensure you have permissions to create it.
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# version.fun — overview
|
||||
|
||||
What it shows
|
||||
- Prints VM and version info for the Fun interpreter/runtime.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/version.fun
|
||||
- Or: fun examples/version.fun
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# while_test.fun — overview
|
||||
|
||||
What it shows
|
||||
- Simple while loop example; loop conditions and counters.
|
||||
|
||||
How to run
|
||||
- export FUN_LIB_DIR="./lib"
|
||||
- ./build_debug/fun examples/while_test.fun
|
||||
- Or: fun examples/while_test.fun
|
||||
9
docs/external/notcurses.md
vendored
9
docs/external/notcurses.md
vendored
|
|
@ -11,17 +11,8 @@
|
|||
- OP_NC_CLEAR: clear screen/plane; returns 0
|
||||
- OP_NC_DRAW_TEXT: pops text, x, y; draws; returns 0
|
||||
- OP_NC_GETCH: pops timeout_ms; returns codepoint or -1 on timeout/error
|
||||
- OP_NC_GET_SIZE: push [rows, cols] of the stdplane, or -1 if unavailable
|
||||
- OP_NC_SET_STYLE: pops style, bg_rgb, fg_rgb; sets colors/styles for stdplane; returns 0/-1
|
||||
- OP_NC_DRAW_CHAR: pops ch, x, y; draws a single Unicode codepoint; returns 0/-1
|
||||
- OP_NC_DRAW_HLINE: pops len, x, y, ch; draws a horizontal line; returns 0/-1
|
||||
- OP_NC_DRAW_VLINE: pops len, x, y, ch; draws a vertical line; returns 0/-1
|
||||
- OP_NC_BOX: pops x, y, w, h, style; draws a rectangle using ASCII/Unicode box glyphs; returns 0/-1
|
||||
- OP_NC_FILL: pops x, y, w, h, ch; fills an area with a codepoint; returns 0/-1
|
||||
- OP_NC_RENDER: forces a render; returns 0/-1
|
||||
|
||||
## Notes:
|
||||
|
||||
- Requires Notcurses development headers/libs.
|
||||
- Behavior may vary across terminals; see the implementation for details.
|
||||
- When Fun is built without Notcurses (FUN_WITH_NOTCURSES=OFF), these opcodes still exist but perform no-ops and return -1/0 as documented, allowing scripts to degrade gracefully.
|
||||
|
|
|
|||
76
docs/fun.md
76
docs/fun.md
|
|
@ -1,76 +0,0 @@
|
|||
# Fun executable: full usage guide
|
||||
|
||||
This document explains how to use the `fun` binary after building or installing it: invocation patterns, options, environment variables, include/search paths, REPL, and examples.
|
||||
|
||||
## Synopsis
|
||||
```
|
||||
fun [options] [<script.fun>] [-- args...]
|
||||
```
|
||||
|
||||
- If `<script.fun>` is provided, `fun` runs the script.
|
||||
- If omitted and the build enables the REPL, `fun` starts an interactive session.
|
||||
|
||||
## Options
|
||||
- `-i`, `--repl` — start the interactive REPL explicitly (if built with REPL support)
|
||||
- `-v`, `--version` — print version and exit
|
||||
- `-h`, `--help` — show usage info and exit
|
||||
|
||||
Notes:
|
||||
- Available options may vary by build configuration. Always check `fun --help` for your binary.
|
||||
|
||||
## Exit codes
|
||||
- `0` — success
|
||||
- non‑zero — error during parse, compile, or runtime
|
||||
|
||||
## Standard library and includes
|
||||
`fun` searches for modules included from `.fun` code in these locations:
|
||||
|
||||
1. The path provided by the environment variable `FUN_LIB_DIR` (highest precedence)
|
||||
2. The compiled‑in default `DEFAULT_LIB_DIR` (configured during build/install)
|
||||
|
||||
Tips:
|
||||
- When running from the repository without installing, set `FUN_LIB_DIR` to the local `./lib` directory so examples can find the stdlib.
|
||||
- See also: `docs/includes.md` for namespacing (`include ... as ...`) and search order details.
|
||||
|
||||
## REPL
|
||||
If interactive mode is enabled at build time, starting `fun` with `-i` (or without a script) opens the REPL.
|
||||
|
||||
Useful commands/patterns in REPL:
|
||||
- Enter expressions and statements directly.
|
||||
- Use arrow keys/history for editing (availability depends on build flags).
|
||||
- See `docs/repl.md` for details and tips.
|
||||
|
||||
## Running scripts
|
||||
Basic run (installed system‑wide):
|
||||
```
|
||||
fun /usr/share/fun/examples/hello.fun
|
||||
```
|
||||
|
||||
Running from a build tree (not installed):
|
||||
```
|
||||
FUN_LIB_DIR=./lib /path/to/build_dir/fun examples/hello.fun
|
||||
```
|
||||
|
||||
Passing arguments to scripts (arguments after `--` are forwarded to the script environment):
|
||||
```
|
||||
fun myscript.fun -- arg1 arg2
|
||||
```
|
||||
|
||||
## Build and install locations
|
||||
- Build targets: `fun` is produced by the `fun` target. In CLion/CMake, typical build directories are `build_debug` or `build_release`.
|
||||
- Install locations (by default):
|
||||
- Binary: `/usr/bin/fun`
|
||||
- Stdlib: `/usr/share/fun/lib`
|
||||
- Examples (optional): `/usr/share/fun/examples`
|
||||
|
||||
To stage an install without touching the system:
|
||||
```
|
||||
DESTDIR=./tmp/stage cmake --build <build_dir> --target install
|
||||
./tmp/stage/usr/bin/fun ./examples/hello.fun
|
||||
```
|
||||
|
||||
## See also
|
||||
- `docs/cli.md` — concise CLI reference (synopsis/options/exit codes)
|
||||
- `docs/funstx.md` — syntax checker for `.fun` files with optional `--fix`
|
||||
- `docs/examples.md` — how to run the bundled examples
|
||||
- `docs/includes.md` — include paths, namespacing, and `FUN_LIB_DIR`
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue