Master
Cocotte.
An exhaustive guide to every feature, module, and optimization within the Cocotte ecosystem.
Introduction
Cocotte is a compiled, dynamically-typed language built with Rust. It bridges the gap between the rapid prototyping of scripting languages and the performance profile of native software.
Zero Dependencies
Binaries are statically linked and standalone.
Rust Performance
Engine leverages the safety and speed of Rust.
Multi-Paradigm
Full support for OOP, functional, and procedural code.
Installation
Automated (Recommended)
curl -fsSL https://cocotte-lang.pages.dev/install.sh | bashInstaller Scope
cocotte binary in /usr/local/bin and configures executable permissions. You may need sudo if running as a non-root user.Manual Installation
Download the binary for your platform from the GitHub releases page, rename it to cocotte, make it executable, and move it to a directory in your $PATH.
chmod +x cocotte
mv cocotte /usr/local/bin/Environment Variables
Cocotte respects the following environment variables:
| Variable | Purpose |
|---|---|
| COCOTTE_PATH | Custom directory for looking up .cotmod files. |
| COCOTTE_DEBUG | Set to "true" to force verbose logs on all runs. |
| COCOTTE_INSTALL_DIR | Custom install path for the automated installer. |
CLI Reference
cocotte init <name>Bootstrap a new project with the standard directory structure.
cocotte run [path]Execute a source file using the tree-walk interpreter. Defaults to src/main.cot.
cocotte build [path]AOT compile a project to a native machine binary.
cocotte test [dir]Recursive test runner. Executes all *_test.cot files.
cocotte exec <task>Run a custom task defined in the project Charlotfile.
cocotte add <module>Fetch and register a remote or local module into the current project.
Project Layout
Cocotte follows a "convention over configuration" approach. A standard project structure ensures compatibility with all CLI tools.
Syntax: Core
Data Types
3.14, 4264-bit floating point numbers.
"Hello"UTF-8 encoded string literals.
true, falseLogical values.
nilThe absence of a value.
[1, 2, 3]Ordered, dynamic arrays.
{"a": 1}Unordered key-value pairs.
Variables & Scoping
Cocotte uses block-level scoping. Use var for declarations. Re-declaration in the same scope is a compile-time error.
var x = 10
{
var x = 20 # New scope, valid shadowing
print x # Prints 20
}
print x # Prints 10Truthiness
Only false and nil are falsy. Everything else, including 0 and "", is truthy.
if 0
print "Zero is truthy!"
end
if ""
print "Empty string is truthy!"
endSyntax: Classes & OOP
Cocotte implements a prototype-based class system. The init method serves as the constructor.
class Animal
func init(name)
self.name = name
end
func eat()
print self.name + " is eating"
end
end
class Cat < Animal # Inheritance
func speak()
print "Meow"
end
end
var kitty = Cat("Luna")
kitty.eat()
kitty.speak()Error Handling
Cocotte uses a try/catch mechanism for runtime exceptions. You can manually trigger errors using the error keyword.
try
var f = open("missing.txt", "r")
catch e
print "Failed to open file: " + e
end
func validate(n)
if n < 0
error "Number must be positive"
end
endString Methods
.len()numberReturns the number of characters in the string.
.upper()stringReturns a new string in all uppercase.
.lower()stringReturns a new string in all lowercase.
.trim()stringRemoves whitespace from both ends.
.split(s)listSplits the string by a separator into a list.
.replace(f, t)stringReplaces all instances of 'f' with 't'.
.slice(f, t)stringExtracts a substring from index 'f' to 't'.
Global Functions
print(val)nilOutputs a value to the standard output stream.
input(prompt)stringReads a line of text from standard input.
range(s, e)listReturns an iterable list of numbers from s to e.
type(val)stringReturns a string representing the type of the value.
clock()numberReturns the current system time in seconds since epoch.
len(val)numberReturns the length of a string, list, or map.
List Methods
.push(v)nilAppends a value to the end of the list.
.pop()anyRemoves and returns the last element.
.join(s)stringJoins elements into a string using a separator.
.map(f)listCreates a new list by applying 'f' to each element.
.filter(f)listCreates a new list with elements that pass 'f'.
.sort()nilSorts the list in-place (if elements are comparable).
Map Methods
.get(k)anyReturns the value associated with key 'k'.
.set(k, v)nilSets or updates the value for key 'k'.
.keys()listReturns a list of all keys in the map.
.values()listReturns a list of all values in the map.
.remove(k)nilDeletes the key-value pair for 'k'.
.clear()nilRemoves all entries from the map.
File I/O
Cocotte provides high-level primitives for interacting with the file system. These operations are synchronous and optimized for developer productivity.
# Reading a file
var content = read_file("config.json")
# Writing a file
write_file("logs.txt", "Execution started
")
# Path manipulation
var exists = file_exists("data.db")
if exists
delete_file("data.db")
endSQLite Integration
Embedded database support for persistent data storage. Uses the standard SQLite engine.
module add "sqlite"
var db = sqlite.open("data.db")
db.execute("CREATE TABLE users (id INT, name TEXT)")
db.execute("INSERT INTO users VALUES (1, 'Alice')")
var rows = db.query("SELECT * FROM users")
for row in rows
print row.get("name")
end
db.close()JSON Handling
Bidirectional conversion between Cocotte data structures and JSON strings.
module add "json"
var raw = '{"name": "Cocotte", "version": 1.0}'
var data = json.parse(raw)
print data.get("name")
var encoded = json.stringify({"id": 42})
print encodedMathematics
math.PInumberThe ratio of a circle's circumference to its diameter.
math.sin(x)numberReturns the sine of 'x' (in radians).
math.cos(x)numberReturns the cosine of 'x' (in radians).
math.sqrt(x)numberReturns the square root of 'x'.
math.pow(b, e)numberReturns 'b' to the power of 'e'.
math.random()numberReturns a pseudo-random number between 0 and 1.
HTTP Client & Server
HTTP Client
Highly optimized networking backed by Rust's reqwest. Bundled with native TLS.
module add "http"
# GET Request
var data = http.get("https://api.github.com/zen")
print data
# POST with JSON
var user = {"name": "Cocotte"}
var resp = http.post_json("https://httpbin.org/post", user)HTTP Server
Built-in synchronous TCP server. Extremely lightweight for internal APIs or local tools.
module add "http"
http.serve(3000, func(req)
var method = req.get("method")
var path = req.get("path")
print "Log: " + method + " " + path
return {
"status": 200,
"body": "Hello from Cocotte Server!",
"headers": {"Content-Type": "text/plain"}
}
end)GUI: Charlotte
Charlotte is an immediate-mode GUI toolkit powered by egui. It renders hardware-accelerated interfaces with minimal overhead.
module add "charlotte"
var state = {"clicks": 0}
charlotte.window("App", 400, 300, func(ui)
ui.heading("Click Counter")
ui.label("Current count: " + state.get("clicks"))
if ui.button("Add +1")
state.set("clicks", state.get("clicks") + 1)
end
end)Cross-Platform GUI
Testing & Debugging
Built-in Assertions
Use the global assertion suite for robust unit testing.
# my_test.cot
func add(a, b) return a + b end
assert_eq(add(1, 1), 2)
assert_ne(add(1, 1), 3)
assert(true) # General boolean checkDebugging Hooks
The debug_inspect(val) function provides a deep print of any data structure, including class instances.
var complex = {"a": [1, 2], "b": {"c": true}}
debug_inspect(complex)Automation: Charlotfile
The Charlotfile allows you to define project-specific tasks and automation scripts using Cocotte syntax. Run tasks with cocotte exec <task>.
# Charlotfile
task "build"
exec "cocotte build --release"
end
task "clean"
delete_file("bin/main")
endConfig: Millet.toml
The project manifest file defines metadata, dependencies, and compilation targets. It's the central configuration for your Cocotte project.
[project]
name = "MyProject"
version = "0.1.0"
authors = ["You"]
[dependencies]
http = "latest"
json = "local:./lib/json"
[build]
entry = "src/main.cot"
target = "native"Cross-Compilation
Cocotte leverages LLVM to enable seamless cross-compilation from a single host machine to various targets, making it easy to distribute your application.
# Compile for Windows from Linux
cocotte build --target x86_64-pc-windows-msvc
# Compile for ARM64 Linux
cocotte build --target aarch64-unknown-linux-gnuDeployment Guide
Since Cocotte compiles to a static, standalone binary with zero dependencies, deployment is as simple as copying the file to your server or packaging it in a minimal Docker container.
FROM scratch
COPY bin/app /app
ENTRYPOINT ["/app"]Performance & Profiling
Release Builds
Always use the --release flag for production. This enables LLVM LTO, symbol stripping, and maximum optimizations.
cocotte build --releaseProfiling
Run with --profile to generate a profile.json file compatible with Chrome's tracing tool.
cocotte run --profile main.cot