diff --git a/CMakeLists.txt b/CMakeLists.txt index 64e060a..bce0fbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.16) -project(fun VERSION 0.14.0 LANGUAGES C) +project(fun VERSION 0.15.0 LANGUAGES C) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) diff --git a/LICENSE b/LICENSE index 439d098..7fa41de 100644 --- a/LICENSE +++ b/LICENSE @@ -1,13 +1,13 @@ -Copyright 2025 Johannes Findeisen +Copyright 2025 Johannes Findeisen -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/README.md b/README.md index b8ab609..d41038c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,147 @@ # Fun -Fun Uses Nothing — Life is too short not to code with fun... ;) +## What is Fun? -Go here for more information: [https://hanez.org/project/fun](https://hanez.org/project/fun) +Fun is a highly strict programming language, but also highly simple. It looks like Python (My favorite language), but there are differences. + +Influenced by Bash, **[C](https://en.wikipedia.org/wiki/The_C_Programming_Language)**, Go, **[Lua](https://www.lua.org/)**, **[Python](https://www.python.org/)**, and Rust (Most influences came from linked languages). + +Fun is and will ever be 100% free under the terms of the [ISC-License](https://opensource.org/license/isc-license-txt). + +## Idea + +* Simplicity +* Consistency +* Joy in coding +* Fun! + +## Characteristics + +* Dynamic and optionally statically typed +* Type safety +* Written in C +* Internal libs are written with no_camel_case even when written in Fun +* Only a minimal function set is written in C and most other core libraries are implemented in Fun + +## The Fun Manifesto + +Fun is a programming language built on a simple idea: +Coding should be enjoyable, elegant, and consistent. + +### Philosophy + +- **Fun is Fun**
+ Programming should spark creativity, not frustration. Code in Fun feels light, playful, and rewarding. +- **Fun Uses Nothing**
+ Minimalism is power. No unnecessary features, no endless syntax variations, no formatting debates. Just clean, uniform code. +- **Indentation is Truth**
+ Two spaces, always. No tabs, no four-space wars. Code should look the same everywhere, from your laptop to /usr/bin/fun. +- **One Way to Do It**
+ No clutter, no 15 ways of writing the same thing. Simplicity means clarity. +- **Hackable by Nature**
+ Fun should be small and embeddable, like Lua. Easy to understand, extend, and tinker with — true to the hacker spirit. +- **Beautiful Defaults**
+ 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: + +- Respectful +- Curious +- Creative + +Like the name says: Fun Unites Nerds. + +## The Goal + +A language that feels like home for developers who: + +- Love minimal, elegant tools +- 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. + +## Documentation + +Actually there does not exist any documenation. In the [examples/](https://git.xw3.org/fun/fun/src/branch/main/examples){:class="git"} directory should be an example of most Fun features. + +## Development + +This section is a work in progress... Please excuse the lack of more information. There are daily updates here. + +### Requirements + +A C compiler, a libc and [Git](https://git-scm.com/). + +Actually Fun requires both CMake and Make as build utils. You always can build Fun only using CMake. Make is just used as a wrapper around CMake. + +#### FreeBSD + +- [CMake](https://cmake.org/) +- [Clang](https://clang.llvm.org/) +- [GNU Make](https://www.gnu.org/software/make) (gmake) + +#### Linux + +- [CMake](https://cmake.org/) +- [GCC](https://gcc.gnu.org/) (Clang should work here too, not tested!) +- [GNU make](https://www.gnu.org/software/make) (make) + +#### Windows + +This requires Cygwin to be installed and configured. I will not cover this here. + +- [CMake](https://cmake.org/) +- [GNU make](https://www.gnu.org/software/make) (make) +- [MinGW](https://en.wikipedia.org/wiki/MinGW) + +### Rules + +- Every commit requires a version incremantion in CMakeLists.txt before committing +- Every commit message must contain the version at the end in the following format (1.2.3) +- Version numbering follows "[Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html)" + +### Developement systems + +- [GNU](https://gnu.org/)/[Linux](https://kernel.org/) ([Arch](https://archlinux.org/)/[Artix](https://artixlinux.org/), [Debian](https://www.debian.org/)) using [GCC](https://gcc.gnu.org/) and the [GNU C library](https://www.gnu.org/software/libc/) ([glibc](https://en.wikipedia.org/wiki/Glibc)) +- GNU/Linux ([Alpine](https://alpinelinux.org/)) using GCC and the [musl libc](https://musl.libc.org/) +- [FreeBSD](https://www.freebsd.org/) using [Clang](https://clang.llvm.org/) and the [BSD libc](https://en.wikipedia.org/wiki/C_standard_library#BSD_libc) +- [Windows](https://en.wikipedia.org/wiki/Microsoft_Windows) using [MinGW](https://en.wikipedia.org/wiki/MinGW) + +### Other systems + +- [macOS](https://en.wikipedia.org/wiki/MacOS), [NetBSD](https://netbsd.org/), [OpenBSD](https://www.openbsd.org/), etc. should fully work, but I don't know. I do not use these systems actually. You wanna try and report? + +### To Do + +Everything... ;) No, a lot of stuff works already, but only a tiny set of functionality is available in the Fun programming language. It grows from day to day... + +### Build Fun + +Linux/UNIX only covered here for now. + +Clone repository: + +``` +git clone https://git.xw3.org/fun/fun.git +``` + +Change directory: + +``` +cd fun +``` + +Build: + +``` +make # gmake on FeeBSD +``` + +That's it! For testing it run: + +``` +./build/fun ./demo.fun +``` diff --git a/demo.fun b/demo.fun index 1dc4e60..1a3c164 100755 --- a/demo.fun +++ b/demo.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-30 */ diff --git a/examples/arrays.fun b/examples/arrays.fun index 2bc6c61..0de3914 100755 --- a/examples/arrays.fun +++ b/examples/arrays.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/arrays_advanced.fun b/examples/arrays_advanced.fun index a8c3d45..7125d48 100755 --- a/examples/arrays_advanced.fun +++ b/examples/arrays_advanced.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/arrays_iter.fun b/examples/arrays_iter.fun index 60f60c2..df9da6b 100755 --- a/examples/arrays_iter.fun +++ b/examples/arrays_iter.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/builtins_conversions.fun b/examples/builtins_conversions.fun index 4af832a..8c448f8 100755 --- a/examples/builtins_conversions.fun +++ b/examples/builtins_conversions.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/builtins_extended.fun b/examples/builtins_extended.fun index a5b6e01..0517a8d 100755 --- a/examples/builtins_extended.fun +++ b/examples/builtins_extended.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/builtins_maps_and_more.fun b/examples/builtins_maps_and_more.fun index 7f40c03..afb05d4 100755 --- a/examples/builtins_maps_and_more.fun +++ b/examples/builtins_maps_and_more.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/cast_demo.fun b/examples/cast_demo.fun index 15cf359..da67808 100755 --- a/examples/cast_demo.fun +++ b/examples/cast_demo.fun @@ -5,7 +5,7 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. + * Licensed under the terms of the Apache-2.0 license. * * Added: 2025-09-29 */ diff --git a/examples/classes_demo.fun b/examples/classes_demo.fun index 97ae1ca..3db659f 100755 --- a/examples/classes_demo.fun +++ b/examples/classes_demo.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/crc32_demo.fun b/examples/crc32_demo.fun index 1a8df56..4b89d9a 100755 --- a/examples/crc32_demo.fun +++ b/examples/crc32_demo.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/examples/expressions_test.fun b/examples/expressions_test.fun index 47d6257..c36365a 100755 --- a/examples/expressions_test.fun +++ b/examples/expressions_test.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/file_io.fun b/examples/file_io.fun index 1e623ae..c7365f0 100755 --- a/examples/file_io.fun +++ b/examples/file_io.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/file_print_for_file_line_by_line.fun b/examples/file_print_for_file_line_by_line.fun index a4f1a33..381121c 100755 --- a/examples/file_print_for_file_line_by_line.fun +++ b/examples/file_print_for_file_line_by_line.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/for_range_test.fun b/examples/for_range_test.fun index 60cdbf9..9f6fd50 100755 --- a/examples/for_range_test.fun +++ b/examples/for_range_test.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/functions_test.fun b/examples/functions_test.fun index 42f2770..39645f8 100755 --- a/examples/functions_test.fun +++ b/examples/functions_test.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* @@ -49,7 +49,7 @@ print(sum3(1, 2, 3)) // expect 6 print(add(add(1, 2), 3)) // expect 6 print(id(42)) // expect 42 -// Call as statement (result discarded) +// Call as statement (result dApache-2.0arded) add(100, 23) // Globals interacting with functions diff --git a/examples/have_fun.fun b/examples/have_fun.fun index 5733b56..34e04a7 100755 --- a/examples/have_fun.fun +++ b/examples/have_fun.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/have_fun_function.fun b/examples/have_fun_function.fun index 640f2c0..ab0a468 100755 --- a/examples/have_fun_function.fun +++ b/examples/have_fun_function.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Have fun in Fun diff --git a/examples/if_else_test.fun b/examples/if_else_test.fun index f7267a1..850a887 100755 --- a/examples/if_else_test.fun +++ b/examples/if_else_test.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/include_lib.fun b/examples/include_lib.fun index ad9de94..93ddb85 100755 --- a/examples/include_lib.fun +++ b/examples/include_lib.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Demonstrates system library includes after installation to /usr/lib/fun diff --git a/examples/include_local.fun b/examples/include_local.fun index b284f8d..bb5cf8a 100755 --- a/examples/include_local.fun +++ b/examples/include_local.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // To test this you need to go to ./examples/ and test includes running ../build/fun include_local.fun diff --git a/examples/include_local_util.fun b/examples/include_local_util.fun index ca4ef60..8245ce4 100644 --- a/examples/include_local_util.fun +++ b/examples/include_local_util.fun @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Simple utility module to be included locally with: #include "include_local_util.fun" diff --git a/examples/include_namespace.fun b/examples/include_namespace.fun index fac81ba..02a4ac0 100755 --- a/examples/include_namespace.fun +++ b/examples/include_namespace.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-30 */ diff --git a/examples/loops_break_continue.fun b/examples/loops_break_continue.fun index 98b4663..90d0b4a 100755 --- a/examples/loops_break_continue.fun +++ b/examples/loops_break_continue.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/examples/md5_demo.fun b/examples/md5_demo.fun index 96b0a30..7ef6aa7 100755 --- a/examples/md5_demo.fun +++ b/examples/md5_demo.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/examples/namespaced_mod.fun b/examples/namespaced_mod.fun index d77f831..3918737 100644 --- a/examples/namespaced_mod.fun +++ b/examples/namespaced_mod.fun @@ -7,8 +7,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-30 */ diff --git a/examples/nested_loops.fun b/examples/nested_loops.fun index a5eb09d..a461389 100755 --- a/examples/nested_loops.fun +++ b/examples/nested_loops.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Nested loops: break and continue behavior diff --git a/examples/objects_basic.fun b/examples/objects_basic.fun index 0a93b4a..5ed1846 100755 --- a/examples/objects_basic.fun +++ b/examples/objects_basic.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Objects via maps: bracket access and method calls with explicit self diff --git a/examples/objects_more.fun b/examples/objects_more.fun index 69a00b6..9ffad90 100755 --- a/examples/objects_more.fun +++ b/examples/objects_more.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Objects as maps: nested fields, methods with explicit self diff --git a/examples/os_env.fun b/examples/os_env.fun index 63dc2e1..b3fc770 100755 --- a/examples/os_env.fun +++ b/examples/os_env.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Environment variables via env(name): diff --git a/examples/sha256_demo.fun b/examples/sha256_demo.fun index 03eac10..1365aa1 100755 --- a/examples/sha256_demo.fun +++ b/examples/sha256_demo.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/examples/sha256_str_demo.fun b/examples/sha256_str_demo.fun index 567448f..c18c653 100755 --- a/examples/sha256_str_demo.fun +++ b/examples/sha256_str_demo.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/examples/sha512_demo.fun b/examples/sha512_demo.fun index c693fbe..63437eb 100755 --- a/examples/sha512_demo.fun +++ b/examples/sha512_demo.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/examples/sha512_str_demo.fun b/examples/sha512_str_demo.fun index 1518f62..b2e058f 100755 --- a/examples/sha512_str_demo.fun +++ b/examples/sha512_str_demo.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/examples/short_circuit_test.fun b/examples/short_circuit_test.fun index 28fad57..aea7d6c 100755 --- a/examples/short_circuit_test.fun +++ b/examples/short_circuit_test.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Short-circuit demo for || and && diff --git a/examples/signed_ints.fun b/examples/signed_ints.fun index f5c12bd..627fa48 100755 --- a/examples/signed_ints.fun +++ b/examples/signed_ints.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Signed integer type examples with two's complement wrapping diff --git a/examples/strings_test.fun b/examples/strings_test.fun index 65abe31..52861d9 100755 --- a/examples/strings_test.fun +++ b/examples/strings_test.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Strings test: concatenation with variables and literals, functions returning strings diff --git a/examples/threads_demo.fun b/examples/threads_demo.fun new file mode 100644 index 0000000..a40b6fe --- /dev/null +++ b/examples/threads_demo.fun @@ -0,0 +1,62 @@ +#!/usr/bin/env fun + +/* + * This file is part of the Fun programming language. + * https://hanez.org/project/fun/ + * + * Copyright 2025 Johannes Findeisen + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 + * + * Added: 2025-09-30 + */ + +// Threading demo for Fun +// Run without installing: +// FUN_LIB_DIR="$(pwd)/lib" ./build/fun examples/threads_demo.fun +// (Windows PowerShell) $env:FUN_LIB_DIR="$PWD\lib"; .\build\fun.exe examples\threads_demo.fun + +print("=== Threads demo ===") + +// A worker function that does some work and returns a value +fun square(n) + // simulate work + sleep(100) + return n * n + +// Spawn several workers +ids = [] +for x in [1, 2, 3, 4, 5] + id = thread_spawn(square, x) // pass a single argument + push(ids, id) + print("spawned thread id=" + to_string(id) + " for x=" + to_string(x)) + +print("Joining threads...") +results = [] +for id in ids + r = thread_join(id) + push(results, r) + +print("Squares: " + to_string(results)) + +// Example: pass multiple args via array +fun add3(a, b, c) + return a + b + c + +tid = thread_spawn(add3, [10, 20, 30]) +print("join add3 -> " + to_string(thread_join(tid))) + +print("=== Threads demo done ===") + +/* Expected output: +=== Threads demo === +spawned thread id=1 for x=1 +spawned thread id=2 for x=2 +spawned thread id=3 for x=3 +spawned thread id=4 for x=4 +spawned thread id=5 for x=5 +Joining threads... +Squares: [array n=5] +join add3 -> 60 +=== Threads demo done === +*/ diff --git a/examples/type_safety.fun b/examples/type_safety.fun index c7ff797..6667f29 100755 --- a/examples/type_safety.fun +++ b/examples/type_safety.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Type Safety demonstration in Fun diff --git a/examples/type_safety_fails.fun b/examples/type_safety_fails.fun index 1a097b4..f112972 100755 --- a/examples/type_safety_fails.fun +++ b/examples/type_safety_fails.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ print("Reassigning typed variables to another type should fail") diff --git a/examples/typeof.fun b/examples/typeof.fun index 3d11071..5ee855a 100755 --- a/examples/typeof.fun +++ b/examples/typeof.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ print("=== Typeof test start ===") diff --git a/examples/typeof_features.fun b/examples/typeof_features.fun index c7dd18f..a2174e7 100755 --- a/examples/typeof_features.fun +++ b/examples/typeof_features.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Demonstration of enhanced typeof behavior: diff --git a/examples/types_integers.fun b/examples/types_integers.fun index 0f8783b..349bf3b 100755 --- a/examples/types_integers.fun +++ b/examples/types_integers.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Integer (number) and boolean usage examples diff --git a/examples/types_overview.fun b/examples/types_overview.fun index adb4384..8bc774f 100755 --- a/examples/types_overview.fun +++ b/examples/types_overview.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ print("=== Dynamic (untyped) ===") diff --git a/examples/uint_types.fun b/examples/uint_types.fun index 0becafc..7e69c4f 100755 --- a/examples/uint_types.fun +++ b/examples/uint_types.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Unsigned integer type examples with wrapping behavior diff --git a/examples/while_test.fun b/examples/while_test.fun index 4572743..1f64457 100755 --- a/examples/while_test.fun +++ b/examples/while_test.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // While loops feature test: simple loops, nested with if/else, and functions diff --git a/lib/crypt/crc32.fun b/lib/crypt/crc32.fun index fe44063..5f1c8ee 100644 --- a/lib/crypt/crc32.fun +++ b/lib/crypt/crc32.fun @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/lib/crypt/md5.fun b/lib/crypt/md5.fun index 81474c7..82cb3e7 100644 --- a/lib/crypt/md5.fun +++ b/lib/crypt/md5.fun @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/lib/crypt/sha256.fun b/lib/crypt/sha256.fun index 2ec7ad5..17d657c 100644 --- a/lib/crypt/sha256.fun +++ b/lib/crypt/sha256.fun @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/lib/crypt/sha512.fun b/lib/crypt/sha512.fun index d9ff9ec..c565143 100644 --- a/lib/crypt/sha512.fun +++ b/lib/crypt/sha512.fun @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/lib/hello.fun b/lib/hello.fun index 72f69fb..9f36fca 100644 --- a/lib/hello.fun +++ b/lib/hello.fun @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* diff --git a/lib/utils/math.fun b/lib/utils/math.fun index 9147e85..fe910f1 100644 --- a/lib/utils/math.fun +++ b/lib/utils/math.fun @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Basic math helpers to be included from system lib: diff --git a/play.fun b/play.fun index 889b523..5cc2e67 100755 --- a/play.fun +++ b/play.fun @@ -5,8 +5,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ fun foo() diff --git a/scripts/check_op_includes.py b/scripts/check_op_includes.py index c6f4a27..fb65a79 100755 --- a/scripts/check_op_includes.py +++ b/scripts/check_op_includes.py @@ -5,8 +5,8 @@ This file is part of the Fun programming language. https://hanez.org/project/fun/ Copyright 2025 Johannes Findeisen -Licensed under the terms of the ISC license. -https://opensource.org/license/isc-license-txt +Licensed under the terms of the Apache-2.0 license. +https://opensource.org/license/apache-2-0 """ import re diff --git a/scripts/run_examples.sh b/scripts/run_examples.sh index 8918e76..e62b7ec 100755 --- a/scripts/run_examples.sh +++ b/scripts/run_examples.sh @@ -5,8 +5,8 @@ set -euo pipefail # https://hanez.org/project/fun/ # # Copyright 2025 Johannes Findeisen -# Licensed under the terms of the ISC license. -# https://opensource.org/license/isc-license-txt +# Licensed under the terms of the Apache-2.0 license. +# https://opensource.org/license/apache-2-0 ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)" EX_DIR="$ROOT/examples" diff --git a/spec/draft.fun b/spec/draft.fun index d3d87c3..c298169 100644 --- a/spec/draft.fun +++ b/spec/draft.fun @@ -6,7 +6,7 @@ implementation or programming. Just a compiled version of many ideas... ;) Copyright 2025 Johannes Findeisen - License: ISC License, https://opensource.org/license/isc-license-txt + License: Apache-2.0 License, https://opensource.org/license/apache-2-0 Birthdate: 2025-09-10 */ diff --git a/spec/v0.1.md b/spec/v0.1.md index 7502c4b..3cea6fa 100644 --- a/spec/v0.1.md +++ b/spec/v0.1.md @@ -306,4 +306,4 @@ print "Current time: " + now ## 12. License -This document and the Fun language reference are licensed under the ISC License. +This document and the Fun language reference are licensed under the Apache-2.0 License. diff --git a/spec/v0.2.md b/spec/v0.2.md index 88c6333..31f12b7 100644 --- a/spec/v0.2.md +++ b/spec/v0.2.md @@ -413,4 +413,4 @@ print("Current time: " + now) ## 15. License -This document and the Fun language reference are licensed under the ISC License. +This document and the Fun language reference are licensed under the Apache-2.0 License. diff --git a/src/array_utils.c b/src/array_utils.c index 71c3cac..0c05461 100644 --- a/src/array_utils.c +++ b/src/array_utils.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ #include "value.h" diff --git a/src/bytecode.c b/src/bytecode.c index 3451469..6468910 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ #include "bytecode.h" diff --git a/src/bytecode.h b/src/bytecode.h index b29f812..96b1c9f 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ #ifndef FUN_BYTECODE_H @@ -35,7 +35,7 @@ typedef enum { OP_EQ, // a == b -> push 1/0 OP_NEQ, // a != b -> push 1/0 - OP_POP, // discard top of stack + OP_POP, // dApache-2.0ard top of stack OP_JUMP, // unconditional jump OP_JUMP_IF_FALSE, // jump if top of stack is false (0) @@ -115,6 +115,11 @@ typedef enum { // OS OP_ENV, // pops name string; pushes value string (or "") + // Threads + OP_THREAD_SPAWN, // operand: 0=no args, 1=has args; pops [args?], fn; pushes thread id (int>0) + OP_THREAD_JOIN, // pops thread id; waits; pushes result value (or Nil) + OP_SLEEP_MS, // pops milliseconds; sleeps; pushes Nil (for statement POP safety) + // Bitwise (32-bit) and shifts/rotates OP_BAND, // pops b, a; pushes (uint32_t)(a & b) OP_BOR, // pops b, a; pushes (uint32_t)(a | b) diff --git a/src/fun.c b/src/fun.c index f20ffcc..fd23001 100644 --- a/src/fun.c +++ b/src/fun.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/fun_test.c b/src/fun_test.c index 9f331a5..79964de 100644 --- a/src/fun_test.c +++ b/src/fun_test.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ #include "bytecode.h" @@ -118,7 +118,7 @@ int main(void) { bytecode_add_instruction(bc, OP_PRINT, 0); // top=1 bytecode_add_instruction(bc, OP_LOAD_CONST, c1); - bytecode_add_instruction(bc, OP_POP, 0); // discard 1 (stack now empty) + bytecode_add_instruction(bc, OP_POP, 0); // dApache-2.0ard 1 (stack now empty) // ---------- HALT ---------- bytecode_add_instruction(bc, OP_HALT, 0); diff --git a/src/iter.c b/src/iter.c index 4e55979..8e991a7 100644 --- a/src/iter.c +++ b/src/iter.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ #include "value.h" diff --git a/src/map.c b/src/map.c index 62d38f3..c98c2ab 100644 --- a/src/map.c +++ b/src/map.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ #include "value.h" diff --git a/src/parser.c b/src/parser.c index bfc1bbb..132a71d 100644 --- a/src/parser.c +++ b/src/parser.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** @@ -798,7 +798,7 @@ static int emit_primary(Bytecode *bc, const char *src, size_t len, size_t *pos) /* Append via insert: res.insert(index=len(res), value) */ bytecode_add_instruction(bc, OP_INSERT, 0); - /* discard returned new length */ + /* dApache-2.0ard returned new length */ bytecode_add_instruction(bc, OP_POP, 0); /* i++ */ @@ -877,7 +877,7 @@ static int emit_primary(Bytecode *bc, const char *src, size_t len, size_t *pos) /* Append via insert: res.insert(index=len(res), value) */ bytecode_add_instruction(bc, OP_INSERT, 0); - /* discard returned new length */ + /* dApache-2.0ard returned new length */ bytecode_add_instruction(bc, OP_POP, 0); int c1 = bytecode_add_constant(bc, make_int(1)); @@ -1029,6 +1029,39 @@ static int emit_primary(Bytecode *bc, const char *src, size_t len, size_t *pos) return 1; } + /* threading */ + if (strcmp(name, "thread_spawn") == 0) { + (*pos)++; /* '(' */ + /* thread_spawn(fn [, args]) */ + if (!emit_expression(bc, src, len, pos)) { parser_fail(*pos, "thread_spawn expects function as first arg"); free(name); return 0; } + int hasArgs = 0; + skip_spaces(src, len, pos); + if (*pos < len && src[*pos] == ',') { + (*pos)++; + skip_spaces(src, len, pos); + if (!emit_expression(bc, src, len, pos)) { parser_fail(*pos, "thread_spawn second arg must be array or value"); free(name); return 0; } + hasArgs = 1; + } + if (!consume_char(src, len, pos, ')')) { parser_fail(*pos, "Expected ')' after thread_spawn args"); free(name); return 0; } + bytecode_add_instruction(bc, OP_THREAD_SPAWN, hasArgs ? 1 : 0); + free(name); + return 1; + } + if (strcmp(name, "thread_join") == 0) { + (*pos)++; /* '(' */ + if (!emit_expression(bc, src, len, pos) || !consume_char(src, len, pos, ')')) { parser_fail(*pos, "thread_join expects 1 arg (thread id)"); free(name); return 0; } + bytecode_add_instruction(bc, OP_THREAD_JOIN, 0); + free(name); + return 1; + } + if (strcmp(name, "sleep") == 0) { + (*pos)++; /* '(' */ + if (!emit_expression(bc, src, len, pos) || !consume_char(src, len, pos, ')')) { parser_fail(*pos, "sleep expects 1 arg (milliseconds)"); free(name); return 0; } + bytecode_add_instruction(bc, OP_SLEEP_MS, 0); + free(name); + return 1; + } + /* bitwise ops (32-bit) */ if (strcmp(name, "band") == 0) { (*pos)++; /* '(' */ @@ -2317,7 +2350,7 @@ static void parse_simple_statement(Bytecode *bc, const char *src, size_t len, si /* rewind to statement start and emit as expression */ local_pos = *pos; if (emit_expression(bc, src, len, &local_pos)) { - bytecode_add_instruction(bc, OP_POP, 0); /* discard return value */ + bytecode_add_instruction(bc, OP_POP, 0); /* dApache-2.0ard return value */ } *pos = local_pos; skip_to_eol(src, len, pos); diff --git a/src/parser.h b/src/parser.h index c754693..1c2279d 100644 --- a/src/parser.h +++ b/src/parser.h @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** @@ -13,7 +13,7 @@ * - Optional shebang on the first line. * - Optional single function wrapper: fun () { ... } * - print("...") statements inside function or at top-level. - * Produces bytecode that executes all discovered print statements and halts. + * Produces bytecode that executes all dApache-2.0overed print statements and halts. * * Returns: newly allocated Bytecode*, or NULL on error. */ diff --git a/src/parser_utils.c b/src/parser_utils.c index 13c0ab0..857a207 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ #include diff --git a/src/str_utils.c b/src/str_utils.c index ee6e72c..5835a68 100644 --- a/src/str_utils.c +++ b/src/str_utils.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ #include "value.h" diff --git a/src/string.c b/src/string.c index fb8273b..423ade8 100644 --- a/src/string.c +++ b/src/string.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ #include "value.h" diff --git a/src/test_opcodes.c b/src/test_opcodes.c index c85e32d..3db19b5 100644 --- a/src/test_opcodes.c +++ b/src/test_opcodes.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ #include "vm.h" diff --git a/src/value.c b/src/value.c index 18c31c9..baa800c 100644 --- a/src/value.c +++ b/src/value.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ #include "value.h" diff --git a/src/value.h b/src/value.h index 57ce712..fcb7552 100644 --- a/src/value.h +++ b/src/value.h @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm.c b/src/vm.c index 2abedd7..4c53302 100644 --- a/src/vm.c +++ b/src/vm.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /* Bring in split-out built-ins without changing the build system yet */ @@ -18,6 +18,9 @@ #include #include +/* Threading internals (registry and platform glue) */ +#include "vm/os/thread_common.c" + /* Track the currently running VM to annotate error messages */ static VM *g_active_vm = NULL; @@ -268,7 +271,7 @@ void vm_run(VM *vm, Bytecode *entry) { #include "vm/bitwise/shr.c" #include "vm/bitwise/rol.c" #include "vm/bitwise/ror.c" - + #include "vm/core/call.c" #include "vm/core/dup.c" #include "vm/core/halt.c" @@ -283,11 +286,10 @@ void vm_run(VM *vm, Bytecode *entry) { #include "vm/core/store_global.c" #include "vm/core/store_local.c" #include "vm/core/swap.c" - + #include "vm/io/read_file.c" #include "vm/io/write_file.c" - #include "vm/os/env.c" - + #include "vm/logic/and.c" #include "vm/logic/eq.c" #include "vm/logic/gt.c" @@ -302,7 +304,7 @@ void vm_run(VM *vm, Bytecode *entry) { #include "vm/maps/keys.c" #include "vm/maps/make_map.c" #include "vm/maps/values.c" - + #include "vm/math/abs.c" #include "vm/math/clamp.c" #include "vm/math/max.c" @@ -312,6 +314,11 @@ void vm_run(VM *vm, Bytecode *entry) { #include "vm/math/random_int.c" #include "vm/math/random_seed.c" + #include "vm/os/env.c" + #include "vm/os/sleep_ms.c" + #include "vm/os/thread_join.c" + #include "vm/os/thread_spawn.c" + #include "vm/strings/find.c" #include "vm/strings/split.c" #include "vm/strings/substr.c" diff --git a/src/vm.h b/src/vm.h index f19038c..a053146 100644 --- a/src/vm.h +++ b/src/vm.h @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ #ifndef FUN_VM_H @@ -34,6 +34,7 @@ static const char *opcode_names[] = { "MIN","MAX","CLAMP","ABS","POW","RANDOM_SEED","RANDOM_INT", "MAKE_MAP","KEYS","VALUES","HAS_KEY", "READ_FILE","WRITE_FILE","ENV", + "THREAD_SPAWN","THREAD_JOIN","SLEEP_MS", "BAND","BOR","BXOR","BNOT","SHL","SHR","ROTL","ROTR" }; diff --git a/src/vm/arithmetic/add.c b/src/vm/arithmetic/add.c index 91e8db1..8e97946 100644 --- a/src/vm/arithmetic/add.c +++ b/src/vm/arithmetic/add.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arithmetic/div.c b/src/vm/arithmetic/div.c index 5dbf833..c6dad0b 100644 --- a/src/vm/arithmetic/div.c +++ b/src/vm/arithmetic/div.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arithmetic/mul.c b/src/vm/arithmetic/mul.c index 8c41d79..8e0139e 100644 --- a/src/vm/arithmetic/mul.c +++ b/src/vm/arithmetic/mul.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arithmetic/sub.c b/src/vm/arithmetic/sub.c index 072049a..b9e1d79 100644 --- a/src/vm/arithmetic/sub.c +++ b/src/vm/arithmetic/sub.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/apop.c b/src/vm/arrays/apop.c index 41a84fa..9bc7d01 100644 --- a/src/vm/arrays/apop.c +++ b/src/vm/arrays/apop.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/clear.c b/src/vm/arrays/clear.c index 4493c26..a7bebb5 100644 --- a/src/vm/arrays/clear.c +++ b/src/vm/arrays/clear.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/contains.c b/src/vm/arrays/contains.c index 7f9868c..e61983a 100644 --- a/src/vm/arrays/contains.c +++ b/src/vm/arrays/contains.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/enumerate.c b/src/vm/arrays/enumerate.c index 7a38d85..5e328cb 100644 --- a/src/vm/arrays/enumerate.c +++ b/src/vm/arrays/enumerate.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/index_get.c b/src/vm/arrays/index_get.c index 40c93f7..08eca93 100644 --- a/src/vm/arrays/index_get.c +++ b/src/vm/arrays/index_get.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/index_of.c b/src/vm/arrays/index_of.c index 5164d00..52e5184 100644 --- a/src/vm/arrays/index_of.c +++ b/src/vm/arrays/index_of.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/index_set.c b/src/vm/arrays/index_set.c index bedbc0a..c58bb20 100644 --- a/src/vm/arrays/index_set.c +++ b/src/vm/arrays/index_set.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/insert.c b/src/vm/arrays/insert.c index 2c56eed..6426469 100644 --- a/src/vm/arrays/insert.c +++ b/src/vm/arrays/insert.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/join.c b/src/vm/arrays/join.c index 1f60c31..a299c2d 100644 --- a/src/vm/arrays/join.c +++ b/src/vm/arrays/join.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/make_array.c b/src/vm/arrays/make_array.c index aa40b26..c8288ba 100644 --- a/src/vm/arrays/make_array.c +++ b/src/vm/arrays/make_array.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/push.c b/src/vm/arrays/push.c index a969ca0..19338c8 100644 --- a/src/vm/arrays/push.c +++ b/src/vm/arrays/push.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/remove.c b/src/vm/arrays/remove.c index a06b474..7616d96 100644 --- a/src/vm/arrays/remove.c +++ b/src/vm/arrays/remove.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/set.c b/src/vm/arrays/set.c index 3c139ef..142c585 100644 --- a/src/vm/arrays/set.c +++ b/src/vm/arrays/set.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/slice.c b/src/vm/arrays/slice.c index 79bbc1b..97fa26f 100644 --- a/src/vm/arrays/slice.c +++ b/src/vm/arrays/slice.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/arrays/zip.c b/src/vm/arrays/zip.c index a461184..d7116e9 100644 --- a/src/vm/arrays/zip.c +++ b/src/vm/arrays/zip.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/bitwise/band.c b/src/vm/bitwise/band.c index 7c58e97..7699751 100644 --- a/src/vm/bitwise/band.c +++ b/src/vm/bitwise/band.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/src/vm/bitwise/bnot.c b/src/vm/bitwise/bnot.c index c207b9a..4f25cc1 100644 --- a/src/vm/bitwise/bnot.c +++ b/src/vm/bitwise/bnot.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/src/vm/bitwise/bor.c b/src/vm/bitwise/bor.c index a831472..218f8b8 100644 --- a/src/vm/bitwise/bor.c +++ b/src/vm/bitwise/bor.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/src/vm/bitwise/bxor.c b/src/vm/bitwise/bxor.c index 21fa7ec..7c069f5 100644 --- a/src/vm/bitwise/bxor.c +++ b/src/vm/bitwise/bxor.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/src/vm/bitwise/rol.c b/src/vm/bitwise/rol.c index 9d7ae0f..3b18128 100644 --- a/src/vm/bitwise/rol.c +++ b/src/vm/bitwise/rol.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/src/vm/bitwise/ror.c b/src/vm/bitwise/ror.c index fb7f94a..f83f1a2 100644 --- a/src/vm/bitwise/ror.c +++ b/src/vm/bitwise/ror.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/src/vm/bitwise/shl.c b/src/vm/bitwise/shl.c index e1831a4..975ea81 100644 --- a/src/vm/bitwise/shl.c +++ b/src/vm/bitwise/shl.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/src/vm/bitwise/shr.c b/src/vm/bitwise/shr.c index f581ac1..2df80de 100644 --- a/src/vm/bitwise/shr.c +++ b/src/vm/bitwise/shr.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 * * Added: 2025-09-29 */ diff --git a/src/vm/cast.c b/src/vm/cast.c index ebf0607..4b2e7dd 100644 --- a/src/vm/cast.c +++ b/src/vm/cast.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/call.c b/src/vm/core/call.c index fcbccbe..aac0e00 100644 --- a/src/vm/core/call.c +++ b/src/vm/core/call.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/dup.c b/src/vm/core/dup.c index 20fa710..49b7a4a 100644 --- a/src/vm/core/dup.c +++ b/src/vm/core/dup.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/halt.c b/src/vm/core/halt.c index f4aa9aa..c440387 100644 --- a/src/vm/core/halt.c +++ b/src/vm/core/halt.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/jump.c b/src/vm/core/jump.c index f3221b8..c3a7fd5 100644 --- a/src/vm/core/jump.c +++ b/src/vm/core/jump.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/jump_if_false.c b/src/vm/core/jump_if_false.c index 29f6d26..804c267 100644 --- a/src/vm/core/jump_if_false.c +++ b/src/vm/core/jump_if_false.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/load_const.c b/src/vm/core/load_const.c index 4355099..2883bf4 100644 --- a/src/vm/core/load_const.c +++ b/src/vm/core/load_const.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/load_global.c b/src/vm/core/load_global.c index 85a55f2..152d450 100644 --- a/src/vm/core/load_global.c +++ b/src/vm/core/load_global.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/load_local.c b/src/vm/core/load_local.c index 460357a..b1762e9 100644 --- a/src/vm/core/load_local.c +++ b/src/vm/core/load_local.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/nop.c b/src/vm/core/nop.c index ffdd285..69f6d4e 100644 --- a/src/vm/core/nop.c +++ b/src/vm/core/nop.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/pop.c b/src/vm/core/pop.c index a332c8e..4db7ed6 100644 --- a/src/vm/core/pop.c +++ b/src/vm/core/pop.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/return.c b/src/vm/core/return.c index 610dea9..8e80290 100644 --- a/src/vm/core/return.c +++ b/src/vm/core/return.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/store_global.c b/src/vm/core/store_global.c index b40476b..275ac21 100644 --- a/src/vm/core/store_global.c +++ b/src/vm/core/store_global.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/store_local.c b/src/vm/core/store_local.c index e4b51da..604c085 100644 --- a/src/vm/core/store_local.c +++ b/src/vm/core/store_local.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/core/swap.c b/src/vm/core/swap.c index 183b7d1..c1baa95 100644 --- a/src/vm/core/swap.c +++ b/src/vm/core/swap.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/io/read_file.c b/src/vm/io/read_file.c index b0f141a..5d1a298 100644 --- a/src/vm/io/read_file.c +++ b/src/vm/io/read_file.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/io/write_file.c b/src/vm/io/write_file.c index a7a32a9..90c6d48 100644 --- a/src/vm/io/write_file.c +++ b/src/vm/io/write_file.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/len.c b/src/vm/len.c index 8c36078..794af72 100644 --- a/src/vm/len.c +++ b/src/vm/len.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/line.c b/src/vm/line.c index b7fe944..34b6c3b 100644 --- a/src/vm/line.c +++ b/src/vm/line.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ case OP_LINE: { diff --git a/src/vm/logic/and.c b/src/vm/logic/and.c index a1ffb4a..d2cd11c 100644 --- a/src/vm/logic/and.c +++ b/src/vm/logic/and.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/logic/eq.c b/src/vm/logic/eq.c index 4b38535..ad1578b 100644 --- a/src/vm/logic/eq.c +++ b/src/vm/logic/eq.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/logic/gt.c b/src/vm/logic/gt.c index 1e2b186..97f627e 100644 --- a/src/vm/logic/gt.c +++ b/src/vm/logic/gt.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/logic/gte.c b/src/vm/logic/gte.c index 645aa8b..70005ec 100644 --- a/src/vm/logic/gte.c +++ b/src/vm/logic/gte.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/logic/lt.c b/src/vm/logic/lt.c index a4130ee..4926fb4 100644 --- a/src/vm/logic/lt.c +++ b/src/vm/logic/lt.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/logic/lte.c b/src/vm/logic/lte.c index 98b6be8..9599ce7 100644 --- a/src/vm/logic/lte.c +++ b/src/vm/logic/lte.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/logic/neq.c b/src/vm/logic/neq.c index 8497660..6bbd565 100644 --- a/src/vm/logic/neq.c +++ b/src/vm/logic/neq.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/logic/not.c b/src/vm/logic/not.c index 07adac2..774c87c 100644 --- a/src/vm/logic/not.c +++ b/src/vm/logic/not.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/logic/or.c b/src/vm/logic/or.c index 0387a32..a109305 100644 --- a/src/vm/logic/or.c +++ b/src/vm/logic/or.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/maps/has_key.c b/src/vm/maps/has_key.c index 4844811..ebb4f17 100644 --- a/src/vm/maps/has_key.c +++ b/src/vm/maps/has_key.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/maps/keys.c b/src/vm/maps/keys.c index 72c0b69..76af043 100644 --- a/src/vm/maps/keys.c +++ b/src/vm/maps/keys.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/maps/make_map.c b/src/vm/maps/make_map.c index 5dcc718..6d4b92d 100644 --- a/src/vm/maps/make_map.c +++ b/src/vm/maps/make_map.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/maps/values.c b/src/vm/maps/values.c index 8adb8e6..506cbf3 100644 --- a/src/vm/maps/values.c +++ b/src/vm/maps/values.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/math/abs.c b/src/vm/math/abs.c index ad66e8a..c1f75d8 100644 --- a/src/vm/math/abs.c +++ b/src/vm/math/abs.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/math/clamp.c b/src/vm/math/clamp.c index a8a9d44..d188f8d 100644 --- a/src/vm/math/clamp.c +++ b/src/vm/math/clamp.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/math/max.c b/src/vm/math/max.c index 01bf052..b549b1b 100644 --- a/src/vm/math/max.c +++ b/src/vm/math/max.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/math/min.c b/src/vm/math/min.c index 707dd29..0d3b4c3 100644 --- a/src/vm/math/min.c +++ b/src/vm/math/min.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/math/mod.c b/src/vm/math/mod.c index 4c08977..10069ef 100644 --- a/src/vm/math/mod.c +++ b/src/vm/math/mod.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/math/pow.c b/src/vm/math/pow.c index e719ae1..47b7f8d 100644 --- a/src/vm/math/pow.c +++ b/src/vm/math/pow.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/math/random_int.c b/src/vm/math/random_int.c index 703029d..386e974 100644 --- a/src/vm/math/random_int.c +++ b/src/vm/math/random_int.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/math/random_seed.c b/src/vm/math/random_seed.c index e30255f..edcd880 100644 --- a/src/vm/math/random_seed.c +++ b/src/vm/math/random_seed.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/os/env.c b/src/vm/os/env.c index 5968472..6616fab 100644 --- a/src/vm/os/env.c +++ b/src/vm/os/env.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ // Get environment variables of the operation system. diff --git a/src/vm/os/sleep_ms.c b/src/vm/os/sleep_ms.c new file mode 100644 index 0000000..3d2fe2f --- /dev/null +++ b/src/vm/os/sleep_ms.c @@ -0,0 +1,27 @@ +/** + * This file is part of the Fun programming language. + * https://hanez.org/project/fun/ + * + * Copyright 2025 Johannes Findeisen + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 + * + * Added: 2025-09-30 + */ + +case OP_SLEEP_MS: { + Value ms = pop_value(vm); + if (ms.type != VAL_INT) { + fprintf(stderr, "Runtime type error: sleep(ms) expects Number (milliseconds)\n"); + free_value(ms); + /* push Nil so caller-side POP is safe */ + push_value(vm, make_nil()); + break; + } + long t = (long)ms.i; + if (t > 0) fun_sleep_ms(t); + free_value(ms); + /* push Nil so statement POP does not underflow */ + push_value(vm, make_nil()); + break; +} diff --git a/src/vm/os/thread_common.c b/src/vm/os/thread_common.c new file mode 100644 index 0000000..0f4014a --- /dev/null +++ b/src/vm/os/thread_common.c @@ -0,0 +1,261 @@ +/** + * This file is part of the Fun programming language. + * https://hanez.org/project/fun/ + * + * Copyright 2025 Johannes Findeisen + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 + * + * Added: 2025-09-30 + */ + +/* Cross-platform minimal threading support embedded into vm.c TU */ + +#include +#include + +#ifdef _WIN32 + #include + typedef HANDLE fun_thread_handle_t; + typedef DWORD fun_thread_ret_t; + #define FUN_THREAD_CALL WINAPI + #define fun_sleep_ms(ms) Sleep((DWORD)(ms)) +#else + #include + #include + typedef pthread_t fun_thread_handle_t; + typedef void* fun_thread_ret_t; + #define FUN_THREAD_CALL + static inline void fun_sleep_ms(long ms) { + if (ms <= 0) return; + struct timespec ts; + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000000L; + nanosleep(&ts, NULL); + } +#endif + +#ifndef FUN_MAX_THREADS +#define FUN_MAX_THREADS 64 +#endif + +typedef struct { + fun_thread_handle_t handle; + int used; + int done; + Value result; /* owned */ +#ifdef _WIN32 + DWORD threadId; +#endif +} FunThreadEntry; + +static FunThreadEntry g_threads[FUN_MAX_THREADS]; + +#ifdef _WIN32 +static CRITICAL_SECTION g_thr_lock; +static int g_thr_lock_inited = 0; +static void fun_thr_lock_init(void) { + if (!g_thr_lock_inited) { + InitializeCriticalSection(&g_thr_lock); + g_thr_lock_inited = 1; + } +} +static void fun_lock(void) { if (!g_thr_lock_inited) fun_thr_lock_init(); EnterCriticalSection(&g_thr_lock); } +static void fun_unlock(void) { LeaveCriticalSection(&g_thr_lock); } +#else +static pthread_mutex_t g_thr_lock = PTHREAD_MUTEX_INITIALIZER; +static void fun_lock(void) { pthread_mutex_lock(&g_thr_lock); } +static void fun_unlock(void) { pthread_mutex_unlock(&g_thr_lock); } +#endif + +typedef struct { + Bytecode *fn; /* function to call */ + int argc; + Value *args; /* array of argc Values (owned by task, will be freed) */ + int slot; /* registry slot */ +} FunTask; + +#ifdef _WIN32 +static fun_thread_ret_t FUN_THREAD_CALL fun_thread_main(LPVOID param) +#else +static fun_thread_ret_t fun_thread_main(void *param) +#endif +{ + FunTask *task = (FunTask*)param; + VM tvm; + vm_init(&tvm); + + /* Build wrapper: LOAD_CONST ; LOAD_CONST ...; CALL argc; HALT */ + Bytecode *wrap = bytecode_new(); + int cFn = bytecode_add_constant(wrap, copy_value(&(Value){ .type = VAL_FUNCTION, .fn = task->fn })); + bytecode_add_instruction(wrap, OP_LOAD_CONST, cFn); + for (int i = 0; i < task->argc; ++i) { + int cArg = bytecode_add_constant(wrap, deep_copy_value(&task->args[i])); + bytecode_add_instruction(wrap, OP_LOAD_CONST, cArg); + } + bytecode_add_instruction(wrap, OP_CALL, task->argc); + bytecode_add_instruction(wrap, OP_HALT, 0); + + vm_run(&tvm, wrap); + + /* Take the top of stack as result if present, else Nil */ + Value res = make_nil(); + if (tvm.sp >= 0) { + res = deep_copy_value(&tvm.stack[tvm.sp]); + } + + /* cleanup */ + for (int i = 0; i < task->argc; ++i) { + free_value(task->args[i]); + } + free(task->args); + bytecode_free(wrap); + + /* store result */ + fun_lock(); + g_threads[task->slot].result = res; + g_threads[task->slot].done = 1; + fun_unlock(); + + free(task); + +#ifdef _WIN32 + return 0; +#else + return NULL; +#endif +} + +static int fun_alloc_thread_slot(void) { + fun_lock(); + int idx = -1; + for (int i = 0; i < FUN_MAX_THREADS; ++i) { + if (!g_threads[i].used) { g_threads[i].used = 1; g_threads[i].done = 0; g_threads[i].result = make_nil(); idx = i; break; } + } + fun_unlock(); + return idx; +} + +static int fun_thread_spawn(Value fnVal, Value argsMaybe, int hasArgs) { + if (fnVal.type != VAL_FUNCTION || !fnVal.fn) { + fprintf(stderr, "Runtime error: thread_spawn expects Function as first argument\n"); + return 0; + } + + /* Collect args */ + int argc = 0; + Value *args = NULL; + + if (hasArgs) { + if (argsMaybe.type == VAL_ARRAY && argsMaybe.arr) { + int n = array_length(&argsMaybe); + if (n > 0) { + args = (Value*)calloc((size_t)n, sizeof(Value)); + if (!args) n = 0; + for (int i = 0; i < n; ++i) { + Value vi; + if (array_get_copy(&argsMaybe, i, &vi)) { + args[i] = deep_copy_value(&vi); + free_value(vi); + } else { + args[i] = make_nil(); + } + } + argc = n; + } + } else if (argsMaybe.type != VAL_NIL) { + args = (Value*)calloc(1, sizeof(Value)); + if (args) { + args[0] = deep_copy_value(&argsMaybe); + argc = 1; + } + } + } + + int slot = fun_alloc_thread_slot(); + if (slot < 0) { + fprintf(stderr, "Runtime error: too many threads\n"); + /* free args */ + for (int i = 0; i < argc; ++i) free_value(args[i]); + free(args); + return 0; + } + + FunTask *task = (FunTask*)calloc(1, sizeof(FunTask)); + if (!task) { + for (int i = 0; i < argc; ++i) free_value(args[i]); + free(args); + fun_lock(); g_threads[slot].used = 0; fun_unlock(); + return 0; + } + task->fn = fnVal.fn; + task->argc = argc; + task->args = args; + task->slot = slot; + +#ifdef _WIN32 + HANDLE h = CreateThread(NULL, 0, fun_thread_main, (LPVOID)task, 0, &g_threads[slot].threadId); + if (!h) { + fprintf(stderr, "Runtime error: CreateThread failed\n"); + for (int i = 0; i < argc; ++i) free_value(args[i]); + free(args); + free(task); + fun_lock(); g_threads[slot].used = 0; fun_unlock(); + return 0; + } + fun_lock(); g_threads[slot].handle = h; fun_unlock(); +#else + pthread_t tid; + int rc = pthread_create(&tid, NULL, fun_thread_main, (void*)task); + if (rc != 0) { + fprintf(stderr, "Runtime error: pthread_create failed\n"); + for (int i = 0; i < argc; ++i) free_value(args[i]); + free(args); + free(task); + fun_lock(); g_threads[slot].used = 0; fun_unlock(); + return 0; + } + fun_lock(); g_threads[slot].handle = tid; fun_unlock(); +#endif + + return slot + 1; /* external thread id: 1..N */ +} + +static Value fun_thread_join(int tid) { + if (tid <= 0 || tid > FUN_MAX_THREADS) { + fprintf(stderr, "Runtime error: thread_join invalid id %d\n", tid); + return make_nil(); + } + int idx = tid - 1; + +#ifdef _WIN32 + fun_lock(); + HANDLE h = g_threads[idx].handle; + int used = g_threads[idx].used; + fun_unlock(); + if (!used || !h) return make_nil(); + WaitForSingleObject(h, INFINITE); + CloseHandle(h); +#else + fun_lock(); + pthread_t h = g_threads[idx].handle; + int used = g_threads[idx].used; + fun_unlock(); + if (!used) return make_nil(); + pthread_join(h, NULL); +#endif + + /* fetch result and free slot */ + fun_lock(); + Value res = deep_copy_value(&g_threads[idx].result); + free_value(g_threads[idx].result); + g_threads[idx].result = make_nil(); + g_threads[idx].used = 0; + g_threads[idx].done = 0; +#ifdef _WIN32 + g_threads[idx].threadId = 0; +#endif + fun_unlock(); + + return res; +} diff --git a/src/vm/os/thread_join.c b/src/vm/os/thread_join.c new file mode 100644 index 0000000..fb02ad8 --- /dev/null +++ b/src/vm/os/thread_join.c @@ -0,0 +1,24 @@ +/** + * This file is part of the Fun programming language. + * https://hanez.org/project/fun/ + * + * Copyright 2025 Johannes Findeisen + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 + * + * Added: 2025-09-30 + */ + +case OP_THREAD_JOIN: { + Value vtid = pop_value(vm); + if (vtid.type != VAL_INT) { + fprintf(stderr, "Runtime type error: thread_join expects thread id (int)\n"); + push_value(vm, make_nil()); + free_value(vtid); + break; + } + Value res = fun_thread_join((int)vtid.i); + free_value(vtid); + push_value(vm, res); /* takes ownership */ + break; +} diff --git a/src/vm/os/thread_spawn.c b/src/vm/os/thread_spawn.c new file mode 100644 index 0000000..6263a20 --- /dev/null +++ b/src/vm/os/thread_spawn.c @@ -0,0 +1,24 @@ +/** + * This file is part of the Fun programming language. + * https://hanez.org/project/fun/ + * + * Copyright 2025 Johannes Findeisen + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 + * + * Added: 2025-09-30 + */ + +case OP_THREAD_SPAWN: { + /* operand: 0 -> no args; 1 -> has args array or single arg */ + Value argsMaybe = make_nil(); + if (inst.operand == 1) { + argsMaybe = pop_value(vm); /* maybe array or scalar */ + } + Value fnv = pop_value(vm); + int tid = fun_thread_spawn(fnv, argsMaybe, inst.operand == 1); + free_value(fnv); + if (inst.operand == 1) free_value(argsMaybe); + push_value(vm, make_int(tid)); + break; +} diff --git a/src/vm/print.c b/src/vm/print.c index 78194eb..d54f58d 100644 --- a/src/vm/print.c +++ b/src/vm/print.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/sclamp.c b/src/vm/sclamp.c index 0f6bc30..d688323 100644 --- a/src/vm/sclamp.c +++ b/src/vm/sclamp.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ case OP_SCLAMP: { diff --git a/src/vm/strings/find.c b/src/vm/strings/find.c index c98d9a2..e594146 100644 --- a/src/vm/strings/find.c +++ b/src/vm/strings/find.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/strings/split.c b/src/vm/strings/split.c index a705ce8..edd2d43 100644 --- a/src/vm/strings/split.c +++ b/src/vm/strings/split.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/strings/substr.c b/src/vm/strings/substr.c index 29ff86e..f485bb3 100644 --- a/src/vm/strings/substr.c +++ b/src/vm/strings/substr.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/to_number.c b/src/vm/to_number.c index f688178..1e58b19 100644 --- a/src/vm/to_number.c +++ b/src/vm/to_number.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/to_string.c b/src/vm/to_string.c index 1a61698..1a4ba38 100644 --- a/src/vm/to_string.c +++ b/src/vm/to_string.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ /** diff --git a/src/vm/typeof.c b/src/vm/typeof.c index 34d1387..ad96e27 100644 --- a/src/vm/typeof.c +++ b/src/vm/typeof.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ case OP_TYPEOF: { @@ -23,4 +23,4 @@ case OP_TYPEOF: { push_value(vm, make_string(tname)); free_value(v); break; -} \ No newline at end of file +} diff --git a/src/vm/uclamp.c b/src/vm/uclamp.c index e22bc21..954dc33 100644 --- a/src/vm/uclamp.c +++ b/src/vm/uclamp.c @@ -3,8 +3,8 @@ * https://hanez.org/project/fun/ * * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the ISC license. - * https://opensource.org/license/isc-license-txt + * Licensed under the terms of the Apache-2.0 license. + * https://opensource.org/license/apache-2-0 */ case OP_UCLAMP: {