#code Region

The default

#code is the default region. If a file has no region markers, it’s entirely #code. You only need to write #code explicitly when other regions follow.

tape
#code
@profile(t1);
import io from "io";

var state: i64 = 0;

pub fn process(val: i64) -> i64 {
    state = state + val;
    return state;
}

What lives in #code

  • Import statements
  • Module-level variables and constants
  • Function declarations
  • Struct, enum, and tagged union definitions
  • Component declarations
  • Type aliases
  • @tape blocks and @tape fn (compile-time execution)
  • @tape const (compile-time constants)
  • extern fn and @export pub fn declarations
  • @link directives
  • User-defined attributes (attr)

Relationship to other regions

#code provides the backing logic for the rest of the file:

  • #view components can call functions and reference variables defined here
  • #test tests exercise functions declared here

Last modified: