Skip to main content

TSol Compiler - Transpiles Sol language to C

Project description

TSol Compiler (tsolc)

Sol — Embrace modularity, ease of use, and speed.

TSol is a lightweight scripting language that compiles to C. It gives you the raw performance of C with a cleaner, more modern syntax — and a module system that actually makes sense.


Why Sol?

C is fast. C is everywhere. But C is also verbose, error-prone, and lacks a sane way to organize code across files.

Sol fixes that.

  • Modular by designget("path/to/module.sol") imports just work, including nested subdirectories
  • Familiar syntax — C-style types and control flow, minus the footguns
  • Zero-cost abstraction — transpiles to clean C, then compiles with clang or gcc
  • No build system headaches — one command compiles and runs

Install

pip install tsolc

Requires Python 3.10+ and a C compiler (clang, gcc, or cc).


Quick Start

hello.sol

main() out int
    string msg -> "Hello, World!"
    out("%s\n", msg)
    return 0
tsolc hello.sol --run

Language Features

Types

Sol C
int, float, double, char, bool Same
string char*
int8int64, uint8uint64 int8_tint64_t, uint8_tuint64_t
int[], float[], ... Pointer + compound literal

Variables & Assignment

int count -> 42
float pi -> 3.14
string name -> "Sol"
int[] nums -> [1, 2, 3, 4, 5]

Assignment uses -> to avoid confusion with ==:

count -> count + 1

Functions

pub square(int n) out int
    return n * n
  • pub marks the function as public (importable from other files)
  • out type specifies the return type; omit for void

Imports

get("std/math.sol")
get("utils/helpers.sol")

Paths are relative to the importing file. Subdirectories work naturally:

get("std/io/file.sol")
get("../shared/types.sol")

Imports are deduplicated automatically — no header guards needed.

Control Flow

Indentation-based blocks — no braces, no end keyword:

if (x > 0)
    out("positive\n")
elseif (x < 0)
    out("negative\n")
else
    out("zero\n")

for (int i -> 0; i < 10; i++)
    out("%d\n", i)

while (running)
    running -> false

Ternary / Guard Operator

string sign -> x > 0 ? "positive" : "negative"
int abs -> x < 0 ? -x : x

Console I/O

// Output
out("Hello, %s!\n", name)

// Input
string name
in(name)

Raw C Injection

Drop straight into C when you need it:

C -> "#include <math.h>"
C -> "double result = sqrt(2.0);"

Structs

struct Point
    float x
    float y

Project Structure Example

myproject/
├── main.sol
├── std/
│   └── math.sol
└── utils/
    └── string.sol

main.sol

get("std/math.sol")

main() out int
    int result -> pow(2, 10)
    out("2^10 = %d\n", result)
    return 0

CLI Usage

tsolc file.sol           # Compile only
tsolc file.sol --run     # Compile and run
tsolc file.sol --keep-c  # Keep the generated .c file

How It Works

  1. Parse — Sol source is tokenized and parsed into an AST (indentation-aware)
  2. Resolveget() imports are recursively resolved and merged
  3. Generate — Clean C11 code is emitted (structs first, then forward declarations, then definitions)
  4. Compile — clang/gcc compiles the C to a native executable
  5. Run — The binary is executed (with ./ prefix and proper permissions on Unix)

License

MIT — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tsolc-1.0.5.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tsolc-1.0.5-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file tsolc-1.0.5.tar.gz.

File metadata

  • Download URL: tsolc-1.0.5.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for tsolc-1.0.5.tar.gz
Algorithm Hash digest
SHA256 deccb51177e0a9ef4eb9d6c0659294076c2a583068d962d233e1caaff94cca9e
MD5 2e8f0345a80e0c58317127818a1e775e
BLAKE2b-256 f2d6681ee8f5a8886132b9be3b241f3d43199ba2a0de0c8982706bbe4a8b51ea

See more details on using hashes here.

File details

Details for the file tsolc-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: tsolc-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for tsolc-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e0ae0d9aa567a40cc58a1133adf72e2c72adead02919dd8043b7dc0b72098930
MD5 1e9f4572455a707cbc3b101aa25360a7
BLAKE2b-256 b842f6e1bb7042ad5b2f156fd9b15b7203d25cd14118def3d7a117925dee7b12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page