code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(210 lines)

Tomo - Tomorrow's Language

Tomo is a statically typed, safe, simple, lightweight, efficient programming language that cross-compiles to C. Tomo is designed to anticipate and influence the language design decisions of the future.

Please visit tomo.bruce-hill.com for full documentation.

func greeting(name:Text, add_exclamation:Bool -> Text)
    message := "hello $name"
    message = " ".join([w.title() for w in message.split_any(" ")])
    if add_exclamation
        message ++= "!!!"
    return message

func main(name:Text, shout=no)
    to_say := greeting(name, add_exclamation=shout)
    say(to_say)
$ tomo hello.tm -- world
Hello World
$ tomo hello.tm -- --name=Ã¥ke
Hello Ã…ke
$ tomo -e hello.tm
$ ./hello "john doe" --shout
Hello John Doe!!!

For more examples, see learnXinY which as an overview of many language features or the other example programs/packages in examples/.

Quick Installation

Quick script to install to ~/.local on your machine:

curl -L "https://tomo.bruce-hill.com/dist/tomo_$(uname -sm | tr ' ' '-').tar.gz" \
  | tar -xz -C ~/.local --strip-components=1

Arch User Repository (AUR)

yay -Sy tomo-bin

Install Script

If you don't want to build from source but just want to install, run this script:

curl -o /tmp/install_tomo.sh https://raw.githubusercontent.com/bruce-hill/tomo/refs/heads/main/install_script.sh \
  && bash /tmp/install_tomo.sh
rm -f /tmp/install_tomo.sh

Features

Performance

Safety

Simplicity

  • Simple, low-boilerplate type system with type inference
  • Well-defined reference and value semantics and mutability rules
  • No polymorphism, generics, or inheritance

User-friendliness

Dependencies

Tomo has a very small set of dependencies:

If you're feeling incautious, you can run make deps or ./install_dependencies.sh to install all the necessary dependencies. I can't guarantee this works on all platforms, but has a reasonably high chance of success.

Building

The Tomo compiler can be compiled with either GCC or Clang by running make. The first time you build, you will need to specify the Tomo installation location (the place where the installer will put the tomo binary, the shared library, and the header files), the Tomo home directory (where Tomo packages will be installed), and the default C compiler for Tomo to use when compiling and running your programs. The answers you give will be saved in config.mk, which you can edit at any time.

Once the configuration options have been set, make will continue along with building tomo. The resulting compiler and shared library will be put into ./build/.

You can run make test to verify that everything works correctly.

Running Locally

To run Tomo locally (without installing), you can use the script ./local-tomo, which sets some environment variables and runs the version of Tomo that you have built in this directory.

You can run a program like this:

./local-tomo my-program.tm

Installing

To install Tomo, run:

make install

This will install it to the location you gave during initial configuration. After this point, you can now run tomo to invoke the compiler and run your Tomo programs.

Usage

To run a Tomo file directly:

tomo foo.tm

To compile a Tomo file into an object file:

tomo -c foo.tm
# Output: .build/foo.tm.o

To transpile a Tomo file into a C header and source file:

tomo -t foo.tm
# Outputs: .build/foo.tm.h .build/foo.tm.c

You can see the full list of compiler options by running man tomo or tomo --help.

License

Tomo is provided under the Sustainable Use License (see LICENSE.md for full details). This is a source-available fair-code license that does not grant unlimited rights for commercial use, but otherwise has permissive rights for noncommercial use and allows distributing and modifying the source code. It does not comply with the Open Source Initiative's definition of "Open Source", which does not allow any restrictions on commercial use. If you would like to use this project commercially, please contact me to work out a licensing agreement.

1 # Tomo - Tomorrow's Language
3 ![](tomo.svg)
5 Tomo is a statically typed, safe, simple, lightweight, efficient programming
6 language that cross-compiles to C. Tomo is designed to anticipate and influence
7 the language design decisions of the future.
9 Please visit [tomo.bruce-hill.com](https://tomo.bruce-hill.com) for full
10 documentation.
12 ```
13 func greeting(name:Text, add_exclamation:Bool -> Text)
14 message := "hello $name"
15 message = " ".join([w.title() for w in message.split_any(" ")])
16 if add_exclamation
17 message ++= "!!!"
18 return message
20 func main(name:Text, shout=no)
21 to_say := greeting(name, add_exclamation=shout)
22 say(to_say)
23 ```
25 ```bash
26 $ tomo hello.tm -- world
27 Hello World
28 $ tomo hello.tm -- --name=Ã¥ke
29 Hello Ã…ke
30 $ tomo -e hello.tm
31 $ ./hello "john doe" --shout
32 Hello John Doe!!!
33 ```
35 For more examples, see [learnXinY](/examples/learnxiny.tm) which as an overview
36 of many language features or the other example programs/packages in
37 [examples/](examples/).
39 ## Quick Installation
41 Quick script to install to `~/.local` on your machine:
43 ```
44 curl -L "https://tomo.bruce-hill.com/dist/tomo_$(uname -sm | tr ' ' '-').tar.gz" \
45 | tar -xz -C ~/.local --strip-components=1
46 ```
48 ### Arch User Repository (AUR)
50 ```
51 yay -Sy tomo-bin
52 ```
54 ### Install Script
56 If you don't want to build from source but just want to install, run this script:
58 ```
59 curl -o /tmp/install_tomo.sh https://raw.githubusercontent.com/bruce-hill/tomo/refs/heads/main/install_script.sh \
60 && bash /tmp/install_tomo.sh
61 rm -f /tmp/install_tomo.sh
62 ```
64 ## Features
66 ### Performance
68 - Generates performant C code with minimal overhead that runs as fast as C
69 code, because it *is* C code.
70 - Extremely fast [incremental and parallel compilation](docs/compilation.md)
71 - Language-level support for [correct function caching](docs/functions.md)
72 - [Structs](docs/structs.md) with known-at-compile-time methods, not OOP
73 objects with vtable lookups
75 ### Safety
77 - Memory safety (garbage collection, [compiler-enforced null
78 safety](docs/pointers.md), [automatic array bounds
79 checking](docs/lists.md), and no uninitialized variables)
80 - High-performance [arbitrary-precision integers](docs/integers.md) by default
81 with opt-in fixed-size integers with arithmetic overflow checking
82 - [Type-safe strings representing different languages](docs/langs.md) with
83 automatic prevention of code injection
84 - Pattern matching with exhaustiveness checking for [enumerated types (tagged
85 unions/enums)](docs/enums.md)
86 - Type-safe [optional values](docs/optionals.tm) with low syntax overhead
87 - Efficient datastructures with immutable value semantics:
88 [lists](docs/lists.md), [tables](docs/tables.md), [sets](docs/sets.md),
89 [text](docs/text.md).
90 - [Privacy-protecting types](docs/structs.md#Secret-Values) that help prevent
91 accidentally logging sensitive information
93 ### Simplicity
95 - Simple, low-boilerplate type system with type inference
96 - Well-defined reference and value semantics and mutability rules
97 - No polymorphism, generics, or inheritance
99 ### User-friendliness
101 - [String interpolation](docs/text.md) and debug printing builtins
102 - Built-in datastructures with a rich library of commonly used methods:
103 [lists](docs/lists.md), [tables](docs/tables.md), [sets](docs/sets.md),
104 [text](docs/text.md).
105 - Full-featured [packages](docs/packages.md)
106 - [Full UTF8 support](docs/text.md) for all text operations
107 - Built-in debugging prints with syntax highlighting
108 - [Automatic command line argument parsing with type safety](docs/command-line-parsing.md)
109 - [Easy interoperability with C](docs/c-interoperability.md)
110 - Built-in [data serialization and deserialization](docs/serialization.md).
111 - [Paths](docs/paths.md) are a native datatype with built-in syntax and a
112 user-friendly API for filesystem operations.
114 ## Dependencies
116 Tomo has a very small set of dependencies:
118 - GCC version 12 or higher (might work on lower versions, but has not been tested)
119 - The [Boehm garbage collector](https://www.hboehm.info/gc/) for runtime
120 garbage collection.
121 - [libunistring](https://www.gnu.org/software/libunistring/) for unicode
122 string support (version 1.0 or higher)
123 - [GNU multiple precision arithmetic library](https://gmplib.org/manual/index)
124 for arbitrary precision integer math (version 6.2.1 or higher)
125 - [Binutils](https://www.gnu.org/software/binutils/) to use `addr2line` for
126 stack traces.
127 - and libc/libm, which should definitely already be installed.
129 If you're feeling incautious, you can run `make deps` or
130 `./install_dependencies.sh` to install all the necessary dependencies. I can't
131 guarantee this works on all platforms, but has a reasonably high chance of
132 success.
134 ## Building
136 The Tomo compiler can be compiled with either GCC or Clang by running `make`.
137 The first time you build, you will need to specify the Tomo installation
138 location (the place where the installer will put the `tomo` binary, the shared
139 library, and the header files), the Tomo home directory (where Tomo packages
140 will be installed), and the default C compiler for Tomo to use when compiling
141 and running your programs. The answers you give will be saved in `config.mk`,
142 which you can edit at any time.
144 Once the configuration options have been set, `make` will continue along with
145 building `tomo`. The resulting compiler and shared library will be put into
146 `./build/`.
148 You can run `make test` to verify that everything works correctly.
150 ## Running Locally
152 To run Tomo locally (without installing), you can use the script
153 `./local-tomo`, which sets some environment variables and runs the version
154 of Tomo that you have built in this directory.
156 You can run a program like this:
158 ```
159 ./local-tomo my-program.tm
160 ```
162 ## Installing
164 To install Tomo, run:
166 ```
167 make install
168 ```
170 This will install it to the location you gave during initial configuration.
171 After this point, you can now run `tomo` to invoke the compiler and run your
172 Tomo programs.
174 ## Usage
176 To run a Tomo file directly:
178 ```bash
179 tomo foo.tm
180 ```
182 To compile a Tomo file into an object file:
184 ```bash
185 tomo -c foo.tm
186 # Output: .build/foo.tm.o
187 ```
189 To transpile a Tomo file into a C header and source file:
191 ```bash
192 tomo -t foo.tm
193 # Outputs: .build/foo.tm.h .build/foo.tm.c
194 ```
196 You can see the full list of compiler options by running `man tomo` or `tomo
197 --help`.
200 ## License
202 Tomo is provided under the Sustainable Use License (see
203 [LICENSE.md](LICENSE.md) for full details). This is a source-available
204 [fair-code](https://faircode.io) license that does not grant unlimited rights
205 for commercial use, but otherwise has permissive rights for noncommercial use
206 and allows distributing and modifying the source code. It does not comply with
207 the [Open Source Initiative's definition of "Open
208 Source"](https://opensource.org/osd), which does not allow any restrictions on
209 commercial use. If you would like to use this project commercially, please
210 contact me to work out a licensing agreement.