Wado

WEP: Compile-Time Location Literals

Context

Debugging and logging often require source location information. Languages handle this differently:

Wado has no macros and no preprocessor, so we need a distinct syntax that clearly signals compile-time evaluation.

Decision

Introduce compile-time literals with # prefix:

Literal Type Value
#file String Current source file path
#line i32 Current line number (1-indexed)
#function String Fully specialized function name
#data String __DATA__ section content (compile error if none)

Syntax

fn example() {
    println(`Error at {#file}:{#line}`);
    println(`In function: {#function}`);
}

#function Format

Returns the fully specialized name without signature:

Context #function value
Free function my_function
Method Point::distance
Generic method List<String>::len
Closure parent_function::{closure}

Call-Site Evaluation in Default Arguments

As a function or method default argument, #file / #line / #function evaluate at the call site, so a defaulted location parameter captures its caller — the basis for logging and assertion helpers (cf. Swift's #file/#line defaults, C++ std::source_location::current()).

pub fn log(msg: String, file: String = #file, line: i32 = #line) { ... }

log("started"); // file/line report this call, not where `log` is defined

A default's name resolution otherwise binds in the callee's scope, so only these three literals are redirected. #data, #include_str, #include_bytes and struct field defaults always report their own defining file. For a nested defaulted call (fn outer(x = loc())), only the outermost expansion fixes the call site and inner ones inherit it, so every literal consistently reports outer(...).

#data

Returns the raw text content of the file's __DATA__ section as a String. Using #data in a source file that has no __DATA__ section is a compile error. This allows programs to embed and access static data inline without a separate data file.

export fn run() with Stdout {
    let config = #data;
    println(config);
}

__DATA__
{"key": "value"}

Not Included

Future: Line Directives

If line directives become necessary (e.g., for code generators), use inner attribute syntax to avoid conflict:

#![line = 123]
#![file = "./original_source.wado"]

Consequences