diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-07 18:14:20 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-07 18:14:20 -0400 |
| commit | 3efd7d9cfbd330ebb45f39648ee96a3e429a06f9 (patch) | |
| tree | 29acb9e2b2370bd155fed24fba79d01b553a24f3 | |
| parent | 15fabfb9be3e3620e4b96983a49017116cea40e2 (diff) | |
Move core libraries into their own folder
| -rw-r--r-- | Makefile | 11 | ||||
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | examples/README.md | 10 | ||||
| -rw-r--r-- | lib/base64/README.md (renamed from examples/base64/README.md) | 0 | ||||
| -rw-r--r-- | lib/base64/base64.tm (renamed from examples/base64/base64.tm) | 0 | ||||
| -rw-r--r-- | lib/commands/README.md (renamed from examples/commands/README.md) | 0 | ||||
| -rw-r--r-- | lib/commands/commands.c (renamed from examples/commands/commands.c) | 0 | ||||
| -rw-r--r-- | lib/commands/commands.tm (renamed from examples/commands/commands.tm) | 0 | ||||
| -rw-r--r-- | lib/core/core.tm (renamed from examples/core/core.tm) | 3 | ||||
| -rw-r--r-- | lib/patterns/README.md (renamed from examples/patterns/README.md) | 0 | ||||
| -rw-r--r-- | lib/patterns/match_type.h (renamed from examples/patterns/match_type.h) | 0 | ||||
| -rw-r--r-- | lib/patterns/patterns.c (renamed from examples/patterns/patterns.c) | 0 | ||||
| -rw-r--r-- | lib/patterns/patterns.tm (renamed from examples/patterns/patterns.tm) | 0 | ||||
| -rw-r--r-- | lib/pthreads/pthreads.tm (renamed from examples/pthreads/pthreads.tm) | 0 | ||||
| -rw-r--r-- | lib/random/README.md (renamed from examples/random/README.md) | 0 | ||||
| -rw-r--r-- | lib/random/chacha.h (renamed from examples/random/chacha.h) | 0 | ||||
| -rw-r--r-- | lib/random/random.tm (renamed from examples/random/random.tm) | 0 | ||||
| -rw-r--r-- | lib/random/sysrandom.h (renamed from examples/random/sysrandom.h) | 0 | ||||
| -rw-r--r-- | lib/shell/shell.tm (renamed from examples/shell/shell.tm) | 0 | ||||
| -rw-r--r-- | lib/time/README.md (renamed from examples/time/README.md) | 0 | ||||
| -rw-r--r-- | lib/time/time.tm (renamed from examples/time/time.tm) | 0 | ||||
| -rw-r--r-- | lib/time/time_defs.h (renamed from examples/time/time_defs.h) | 0 | ||||
| -rw-r--r-- | lib/uuid/uuid.tm | 36 |
23 files changed, 45 insertions, 18 deletions
@@ -99,17 +99,15 @@ test: $(TESTS) @printf '\033[32;7m ALL TESTS PASSED! \033[m\n' clean: - rm -rf build/* $(COMPILER_OBJS) $(STDLIB_OBJS) test/*.tm.testresult test/.build examples/.build examples/*/.build + rm -rf build/* $(COMPILER_OBJS) $(STDLIB_OBJS) test/*.tm.testresult test/.build lib/*/.build examples/.build examples/*/.build %: %.md pandoc --lua-filter=docs/.pandoc/bold-code.lua -s $< -t man -o $@ examples: - ./build/tomo -qIL examples/patterns examples/time examples/commands examples/shell examples/random \ - examples/base64 examples/log examples/ini examples/vectors examples/http \ - examples/wrap examples/pthreads examples/colorful examples/core - ./build/tomo -e examples/base64/base64.tm examples/ini/ini.tm examples/game/game.tm examples/http-server/http-server.tm \ - examples/tomodeps/tomodeps.tm examples/tomo-install/tomo-install.tm examples/wrap/wrap.tm examples/colorful/colorful.tm + ./build/tomo -qIL examples/log examples/ini examples/vectors examples/http examples/wrap examples/colorful + ./build/tomo -e examples/game/game.tm examples/http-server/http-server.tm \ + examples/tomodeps/tomodeps.tm examples/tomo-install/tomo-install.tm ./build/tomo examples/learnxiny.tm deps: check-gcc @@ -139,6 +137,7 @@ install: build/tomo build/$(LIB_FILE) rm -f "$(PREFIX)/bin/tomo" cp -v build/tomo "$(PREFIX)/bin/" cp -v docs/tomo.1 "$(PREFIX)/man/man1/" + ./build/tomo -qIL lib/patterns lib/time lib/commands lib/shell lib/random lib/base64 lib/pthreads lib/core uninstall: rm -rvf "$(PREFIX)/bin/tomo" "$(PREFIX)/include/tomo" "$(PREFIX)/lib/$(LIB_FILE) "$(PREFIX)/share/tomo"; \ @@ -29,7 +29,8 @@ Hello John Doe!!! For more examples, see [learnXinY](/examples/learnxiny.tm) which as an overview of many language features or the other example programs/modules in -[examples/](examples/). +[examples/](examples/). You can also look at the [core libraries](lib/) which +are implemented in Tomo. ## Features diff --git a/examples/README.md b/examples/README.md index 6dbd50df..fc7d9406 100644 --- a/examples/README.md +++ b/examples/README.md @@ -5,6 +5,7 @@ This folder contains some example programs and libraries. ## Example Programs - [learnxiny.tm](learnxiny.tm): A quick overview of language features in the + style of [learnxinyminutes.com](https://learnxinyminutes.com/). - [game](game/): An example game using raylib. - [http-server](http-server/): A multithreaded HTTP server. - [tomodeps](tomodeps/): A library for finding Tomo dependencies. @@ -14,19 +15,10 @@ This folder contains some example programs and libraries. Libraries can be installed with `tomo -IL ./library-folder` -- [base64](base64/): A base64 encoding/decoding library. - [colorful](colorful/): A DSL useful for rendering terminal colors. - [commands](commands/): A library for running commands. -- [core](core/): Bundling up commonly used libraries into a single library. - [http](http/): An HTTP library to make basic synchronous HTTP requests. - [ini](ini/): An INI configuration file reader tool. - style of [learnxinyminutes.com](https://learnxinyminutes.com/). - [log](log/): A logging utility. -- [patterns](patterns/): Pattern matching for text. -- [pthreads](pthreads/): A POSIX threads library. -- [random](random/): Pseudorandom number generators. -- [shell](shell/): A DSL for running shell commands. -- [time](time/): A module for working with dates and times. - [vectors](vectors/): A math vector library. -- [uuid](uuid/): A universally unique identifier library. - [wrap](wrap/): A command-line program to wrap text. diff --git a/examples/base64/README.md b/lib/base64/README.md index 8db0f8ec..8db0f8ec 100644 --- a/examples/base64/README.md +++ b/lib/base64/README.md diff --git a/examples/base64/base64.tm b/lib/base64/base64.tm index bf512a83..bf512a83 100644 --- a/examples/base64/base64.tm +++ b/lib/base64/base64.tm diff --git a/examples/commands/README.md b/lib/commands/README.md index 040f4bd5..040f4bd5 100644 --- a/examples/commands/README.md +++ b/lib/commands/README.md diff --git a/examples/commands/commands.c b/lib/commands/commands.c index 973fc0c5..973fc0c5 100644 --- a/examples/commands/commands.c +++ b/lib/commands/commands.c diff --git a/examples/commands/commands.tm b/lib/commands/commands.tm index d72398b9..d72398b9 100644 --- a/examples/commands/commands.tm +++ b/lib/commands/commands.tm diff --git a/examples/core/core.tm b/lib/core/core.tm index f7259b7f..6aa4c267 100644 --- a/examples/core/core.tm +++ b/lib/core/core.tm @@ -4,7 +4,6 @@ use patterns use commands use shell -use colorful -use log use pthreads use random +use time diff --git a/examples/patterns/README.md b/lib/patterns/README.md index faf2854e..faf2854e 100644 --- a/examples/patterns/README.md +++ b/lib/patterns/README.md diff --git a/examples/patterns/match_type.h b/lib/patterns/match_type.h index abbc4fce..abbc4fce 100644 --- a/examples/patterns/match_type.h +++ b/lib/patterns/match_type.h diff --git a/examples/patterns/patterns.c b/lib/patterns/patterns.c index ee27e4e3..ee27e4e3 100644 --- a/examples/patterns/patterns.c +++ b/lib/patterns/patterns.c diff --git a/examples/patterns/patterns.tm b/lib/patterns/patterns.tm index bab0c3dc..bab0c3dc 100644 --- a/examples/patterns/patterns.tm +++ b/lib/patterns/patterns.tm diff --git a/examples/pthreads/pthreads.tm b/lib/pthreads/pthreads.tm index fee7ce5d..fee7ce5d 100644 --- a/examples/pthreads/pthreads.tm +++ b/lib/pthreads/pthreads.tm diff --git a/examples/random/README.md b/lib/random/README.md index 183b9d0b..183b9d0b 100644 --- a/examples/random/README.md +++ b/lib/random/README.md diff --git a/examples/random/chacha.h b/lib/random/chacha.h index 7df352f9..7df352f9 100644 --- a/examples/random/chacha.h +++ b/lib/random/chacha.h diff --git a/examples/random/random.tm b/lib/random/random.tm index 14b68d7f..14b68d7f 100644 --- a/examples/random/random.tm +++ b/lib/random/random.tm diff --git a/examples/random/sysrandom.h b/lib/random/sysrandom.h index ea29296b..ea29296b 100644 --- a/examples/random/sysrandom.h +++ b/lib/random/sysrandom.h diff --git a/examples/shell/shell.tm b/lib/shell/shell.tm index da03f843..da03f843 100644 --- a/examples/shell/shell.tm +++ b/lib/shell/shell.tm diff --git a/examples/time/README.md b/lib/time/README.md index 55f725f1..55f725f1 100644 --- a/examples/time/README.md +++ b/lib/time/README.md diff --git a/examples/time/time.tm b/lib/time/time.tm index 1796654d..1796654d 100644 --- a/examples/time/time.tm +++ b/lib/time/time.tm diff --git a/examples/time/time_defs.h b/lib/time/time_defs.h index fd8fd4f3..fd8fd4f3 100644 --- a/examples/time/time_defs.h +++ b/lib/time/time_defs.h diff --git a/lib/uuid/uuid.tm b/lib/uuid/uuid.tm new file mode 100644 index 00000000..002b4808 --- /dev/null +++ b/lib/uuid/uuid.tm @@ -0,0 +1,36 @@ +lang UUID + func v4(-> UUID) # Random UUID + bytes := &random.bytes(16) + bytes[7; unchecked] = 0x40 or (bytes[7; unchecked] and 0x0F) + bytes[9; unchecked] = (Byte(random.int8(0x8, 0xB)) << 4) or (bytes[9; unchecked] and 0x0F) + hex := "".join([b.hex() for b in bytes]) + uuid := "$(hex.slice(1, 8))-$(hex.slice(9, 12))-$(hex.slice(13, 16))-$(hex.slice(17, -1))" + return UUID.from_text(uuid) + + func v7(-> UUID) # Timestamp + random UUID + n := now() + timestamp := n.seconds*1000 + n.microseconds/1_000 + + bytes := [ + Byte((timestamp >> 40)), + Byte((timestamp >> 32)), + Byte((timestamp >> 24)), + Byte((timestamp >> 16)), + Byte((timestamp >> 8)), + Byte(timestamp), + (random.byte() and 0x0F) or 0x70, + random.byte(), + (random.byte() and 0x3F) or 0x80, + random.byte() for _ in 7, + ] + + hex := "".join([b.hex() for b in bytes]) + uuid := "$(hex.slice(1, 8))-$(hex.slice(9, 12))-$(hex.slice(13, 16))-$(hex.slice(17, -1))" + return UUID.from_text(uuid) + +enum UUIDVersion(v4, v7) +func main(version=UUIDVersion.v7) + when version is v4 + say(UUID.v4().text_content) + is v7 + say(UUID.v7().text_content) |
