Skip to content

Semantics & Execution Model

The semantics describe what the language means and how execution behaves in detail. This matters because Coldwave Script is designed for deterministic behavior: a program should behave the same way no matter when or where it runs.

Cycle‑Based Execution

+-----------+     +------------------+     +---------+
| Prefeed   | --> | Main Execution   | --> | Commit  |
+-----------+     +------------------+     +---------+
  1. Prefeed — read inputs (IN), set initial values
  2. Main Execution — execute code line by line, use temporary values (TMP)
  3. Commit — write results from OUT segments to outputs
vb
PROGRAM  
DIM T AS TON  
T(IN = TRUE, PT = T#500ms)  
PRINT T.Q  
END PROGRAM

WCET & Determinism

WCET (Worst Case Execution Time) refers to the maximum time a program may require in the worst case.

Coldwave Script is designed to remain deterministic:

  • No dynamic memory allocation in scripts
  • Standard functions operate on bounded types (fixed max string length, fixed integer ranges, etc.)
  • Loops must be constructed so the maximum iteration count is known from code (e.g., FOR with fixed bounds)

Example:

vb
PROGRAM  
    DIM i AS INT  
    FOR i = 1 TO 10  
        PRINT i  
    NEXT i  
END PROGRAM

This loop runs exactly 10 iterations. Unbounded or infinite loops are not allowed and cause the VM to abort execution.

The precise WCET of a full program depends on the target system (CPU clock, implementation of runtime libraries), but due to the above constraints it can be estimated systematically.

Arithmetic Rules

Coldwave Script uses saturating arithmetic. Overflow is clamped to the upper bound, underflow to the lower bound or to 0 for unsigned types.

vb
PROGRAM  
DIM a AS INT = 32760  
DIM b AS INT = 100  
PRINT a + b ' Output: 32767 (clamped)
END PROGRAM

Exercises with Solutions

Exercise 1

Explain the execution cycle.

Solution: Prefeed → read inputs, Main → execute code, Commit → write outputs.

Exercise 2

Program a FOR loop from 1 to 5.

vb
PROGRAM  
DIM i AS INT  
FOR i = 1 TO 5  
PRINT i  
NEXT i  
END PROGRAM

' Output: 1 2 3 4 5

Exercise 3

Overflow calculation (32760 + 100).

vb
PROGRAM  
DIM a AS INT = 32760  
DIM b AS INT = 100  
PRINT a + b  
END PROGRAM

' Output: 32767 (clamped, saturating)

Summary

  • Coldwave Script runs cyclically (Prefeed → Main → Commit).
  • WCET ensures deterministic behavior.
  • Banking separates variable contexts.
  • Arithmetic is saturating and safe.
  • Beginners need only the basics; experts can leverage full WCET and memory segment details.