REDLINE Programming Language
High-Speed Science (v1.0)
Welcome to the official guide for the REDLINE Programming Language. You're here because you're not satisfied with the status quo. You want the simplicity of modern scripting languages and the raw power of compiled, low-level code. You want to have your cake and eat it too. We're here to tell you that you can.
What is REDLINE?
REDLINE is a high-performance, transpiled systems programming language. Our motto is "C++ but Simplified." We've engineered a language that combines the clean, readable, indentation-based syntax of Python with the near-bare-metal speed of C++.
How? We don't try to reinvent sixty years of compiler technology. Instead, REDLINE is a "transpiled" language. Your REDLINE code is converted into highly optimized, human-readable C++17 code, which is then compiled by a standard C++ compiler (like G++) into a native executable. This gives you the best of both worlds: a beautiful, modern language on the frontend, and a battle-tested, performance-obsessed toolchain on the backend.
Who is this book for?
This book is for any developer who has ever said, "I love how easy Python is, but I wish it were faster," or, "I love how fast C++ is, but I wish it were simpler." Whether you're a student building your first project, a hobbyist making a game, or a professional engineering a high-performance application, REDLINE is your new favorite tool.
The REDLINE Philosophy: Why Transpilation?
Our philosophy is simple: focus on results, not on reinventing the wheel.
- Leverage the Best: By compiling to C++, we instantly inherit decades of compiler optimization research. We get access to the massive C++ ecosystem of libraries and tools for free.
- Focus on the Developer: Since we don't have to write a new code optimizer from scratch, we can focus on what matters most: the developer experience. We've poured our resources into creating a clean syntax, a powerful standard library, and intuitive tooling.
- Transparency: You can always look at the generated C++ code in the
temp_builddirectory. There's no magic here—just efficient, high-speed science.
How to Install REDLINE
Installation is a simple process of cloning the repository and initializing the compiler. Please follow the official instructions in the README.md file.
Chapter 1: The Basics - Your First REDLINE Program
This chapter covers the fundamental building blocks of any REDLINE program.
"Hello, World!" with print()
The traditional first step in any language is to make it talk. In REDLINE, this is a single, clean line.
print("Hello, World!")
This calls the built-in print function, which outputs the given string to the console, followed by a newline character.
Comments: Leaving Notes for Your Future Self
Use the # symbol for single-line comments. The compiler will ignore them completely. Good comments explain the why, not the what. If your code is so complex you have to explain what it does, you probably wrote it wrong.
# Calculate the velocity based on a fixed acceleration.
val velocity: float = initial_velocity + (acceleration * time) # a = 9.8
Variables and Constants: var vs. val
REDLINE forces you to be intentional about your data. This is a core feature for writing safe and predictable code.
val(Value): Creates an immutable constant. Once you assign a value to it, it can never be changed. This is the default you should always reach for. It signals to other developers (and the compiler) that this piece of data is a fixed point.var(Variable): Creates a mutable variable. You can update its value later. Use this only when you know the data must change during its lifetime.
val LAUNCH_CODE: string = "Project-A-113" # A constant. Cannot be changed.
var reactor_temp: int = 900 # A variable that will fluctuate.
reactor_temp = 950 # This is valid.
# LAUNCH_CODE = "New-Code" # This would cause a compiler error.
Preferring val makes your code easier to reason about and helps prevent a whole class of bugs caused by accidental modification of data.
Core Data Types
REDLINE is a strictly typed language. You must declare the type of your data. This eliminates runtime errors where you might, for example, try to do math on a string.
| REDLINE Type | C++ Equivalent | Description |
|---|---|---|
int |
int |
Whole numbers, positive or negative. |
float |
double |
64-bit floating-point (decimal) numbers. |
string |
std::string |
A sequence of characters. |
bool |
bool |
Logical values: true or false. |
void |
void |
Represents the absence of a value. |
Chapter 2: Control Flow - Making Decisions and Looping
This is where your programs stop being a straight line and start adapting to changing conditions.
If/Else
Use if and else to execute code based on a condition. The colon (:) and indentation are mandatory and define the code blocks.
val shield_integrity: float = 0.45
if shield_integrity < 0.5:
print("Warning: Shields are below 50%.")
else:
print("Shields are holding strong.")
While Loops
A while loop runs as long as its condition evaluates to true. Make sure something inside the loop eventually causes the condition to become false, or you've just invented an infinite loop.
var countdown: int = 10
while countdown > 0:
print(f"T-minus {countdown}")
countdown = countdown - 1
print("Liftoff!")
For Loops
The for loop is the workhorse for iteration. It walks through a sequence or a range of numbers.
# Iterate over a range (0 to 4)
for i in range(5):
print(f"Iteration: {i}")
# Iterate over a list
val crew: list[string] = ["Alice", "Bob", "Charlie"]
for member in crew:
print(f"Crew member: {member}")
Break and Continue
break: Exit the loop immediately.continue: Skip the rest of this iteration and jump to the next one.
for i in range(100):
if i == 42:
print("Found the answer!")
break
if i % 2 == 0:
continue # Skip even numbers
print(i)
Chapter 3: Functions - Code Reusability and Organization
Functions are the fundamental building blocks for organizing logic. A function is a named chunk of code that you can call multiple times.
Defining a Function
Use the def keyword, followed by the function name, parameters with their types, and a return type.
def calculate_energy(mass: float, speed: float) -> float:
return 0.5 * mass * (speed * speed)
val kinetic_energy: float = calculate_energy(100.0, 30.0)
print(f"Energy: {kinetic_energy} Joules")
Void Functions
If a function doesn't return a value, use -> void.
def log_message(message: string) -> void:
print(f"[LOG]: {message}")
log_message("System initialized.")
Multiple Parameters and Return Values
Functions can accept multiple parameters and return a single value of any type.
def divide(a: float, b: float) -> float:
if b == 0.0:
print("Error: Division by zero!")
return 0.0
return a / b
val result: float = divide(10.0, 2.0)
Chapter 4: Data Structures - Managing Collections
Variables are great, but you often need to manage a collection of related data. REDLINE provides two primary structures: lists and dictionaries.
Lists
A list is an ordered, indexed collection of elements of a single type. Think of it as a dynamic array.
val temperatures: list[float] = [23.5, 24.1, 22.9, 25.0]
val first_temp: float = temperatures[0] # Index access (0-based)
# Adding elements
var log: list[string] = []
append(log, "System start")
append(log, "All systems nominal")
print(f"Log entries: {len(log)}")
Dictionaries
A dict (dictionary) is a key-value store. Unlike lists, which are accessed by numeric indices, dictionaries use keys of any type.
val crew_roles: dict[string, string] = {
"Alice": "Captain",
"Bob": "Engineer",
"Charlie": "Pilot"
}
val alice_role: string = crew_roles["Alice"]
print(f"Alice is the {alice_role}")
Built-In Functions for Collections
len(collection): Returns the size of a list or dictionary.append(list, value): Adds an element to the end of a list.sort(list): Sorts a list in ascending order (in-place).reverse(list): Reverses a list in-place.find(list, value): Returns the index of a value in a list, or-1if not found.
Chapter 5: Object-Oriented Programming - Building Complex Systems
For larger programs, you need to organize your data and behavior into cohesive units. That's where classes come in.
Defining a Class
A class is a blueprint for creating objects. It combines data (fields) and behavior (methods).
class Spaceship:
val name: string
var fuel: float
var speed: float
def __init__(self, ship_name: string, initial_fuel: float) -> void:
this.name = ship_name
this.fuel = initial_fuel
this.speed = 0.0
def accelerate(self, amount: float) -> void:
if this.fuel > 0.0:
this.speed = this.speed + amount
this.fuel = this.fuel - (amount * 0.1)
else:
print("Out of fuel!")
def status(self) -> string:
return f"{this.name}: Speed={this.speed}, Fuel={this.fuel}"
Creating and Using Objects
val my_ship: Spaceship = new Spaceship("Phoenix", 100.0)
my_ship.accelerate(50.0)
print(my_ship.status())
The this Keyword
Inside a method, this refers to the current instance. Use it to access fields and methods of the object.
Public vs. Private (Simplified)
In REDLINE, all members are public by default. For production systems, you can use the pub keyword explicitly to indicate intent, though it has no effect on visibility in the current version.
Chapter 6: The Standard Library - Essential Tools
REDLINE ships with a carefully curated standard library. Each module is a .hpp C++ header that gets included automatically in the generated code.
System & Utilities (rl_system.hpp)
args -> list[string]: Returns the command-line arguments passed to the program.len(collection): Returns the size of a list or dictionary.append(list, value),sort(list),reverse(list),find(list, value): Collection operations.to_string(value) -> string,to_int(string) -> int,to_float(string) -> float: Type conversions.
I/O (rl_io.hpp)
print(value): Prints a value to the console, followed by a newline.input(prompt: string) -> string: Displays a prompt and reads a line of text from the user.
File System (rl_file.hpp)
read_file(path: string) -> string: Reads an entire file into a single string. Throws an error if the file can't be opened.write_file(path: string, content: string): Writes a string to a file, overwriting it if it exists.exists(path: string) -> bool: Returnstrueif a file or directory exists.mkdir(path: string): Creates a new directory.remove(path: string): Deletes a file or an empty directory.list_dir(path: string) -> list[string]: Returns a list of filenames in a directory.
Time (rl_time.hpp)
time() -> float: Returns the current system time as a Unix timestamp (seconds since 1970).sleep(seconds: float): Pauses the program's execution for the given number of seconds.
Random (rl_random.hpp)
random_int(min: int, max: int) -> int: Returns a random integer betweenminandmax(inclusive).random_float() -> float: Returns a random float between 0.0 and 1.0.
Strings & F-Strings
For complex string formatting, f-strings are the best tool for the job. Any valid REDLINE expression can be placed inside the curly braces.
val name: string = "Redline"
print(f"The current time is {time()}.")
print(f"A random number: {random_int(1, 100)}.")
Chapter 7: Building & Projects - From Blueprint to Reality
Single-File Compilation
For simple scripts, you can compile a single file directly.
python redline.py build my_script.rl
Multi-File Projects with RedConfig.toml
For any real project, you'll want a RedConfig.toml file. This is the master blueprint for your project. It tells the compiler everything it needs to know.
[project]
name = "MyAwesomeProject"
version = "1.0.0"
entry_point = "src/main.rl"
output_dir = "bin"
With this file in your project's root directory, the build script will automatically use it.
# Run from your project's root directory
python path/to/redline.py build
Chapter 8: The Philosophy - How It All Works
So, how does the magic happen? It's not magic, it's efficient science.
The Transpilation Pipeline: RL → C++ → Executable
When you run redline build, a three-stage process kicks off:
- Parsing (Rust): Our high-speed Rust core reads your
.rlfiles, validates the syntax, and builds an Abstract Syntax Tree (AST)—an internal representation of your code. - Code Generation (Rust): The core then walks the AST and generates clean, human-readable C++17 code.
- Compilation (C++): Finally, we hand that generated code off to your system's G++ compiler, which creates a highly-optimized, native executable.
Why C++ is the Target
Simple: performance and ecosystem. C++ is one of the fastest languages on the planet, and by compiling to it, we get that speed for free. We also get to tap into decades of C++ libraries and tools.
Why Rust is the Core
The compiler itself needs to be fast, safe, and reliable. Rust's focus on memory safety and performance makes it the perfect tool for building a rock-solid compiler that won't crash while it's processing your genius ideas. This means fewer bugs in our tools, so you can focus on the bugs in your own brilliant, world-changing experiments.
Appendix A: Keyword Reference
| Keyword | Description |
|---|---|
val / var | Declare a constant / variable. |
def | Defines a function. |
class | Defines a class. |
if / else | Conditional branching. |
while / for | Looping constructs. |
break / continue | Loop control. |
return | Return a value from a function. |
print | Print a value to the console. |
import | Import another REDLINE module. |
pub | Make a function or class public. |
new | Allocate a new object instance. |
this | Reference the current object instance. |
try / catch | Handle runtime errors. |
true / false | Boolean literals. |
Appendix B: Standard Library Quick Reference
- System:
args,len,append,sort,reverse,find,to_string,to_int,to_float - I/O:
print,input - File System:
read_file,write_file,exists,mkdir,remove,list_dir - Time:
time,sleep - Random:
random_int,random_float