interplane.Get Omega
Read in your language

omega-kernel-template

aien-dev/omega-kernel-template

Brought by drakestapleton

branch main Branches Tags History

omega-kernel-template / reference.py

22 lines · 538 bytes Raw Blame History
1"""CPU reference for kernel.om, in plain Python.
2
3Every fn in kernel.om needs a function here with the same name and parameters.
4Return the exact mathematical answer; the check fails if the kernel disagrees.
5Raise Trap(n) where the kernel executes `trap n` (Trap is provided by the check).
6"""
7
8
9def avg(a, b):
10 return (a + b) // 2
11
12
13def gcd(a, b):
14 while b:
15 a, b = b, a % b
16 return a
17
18
19def clamp(x, lo, hi):
20 if lo > hi:
21 raise Trap(3) # noqa: F821 - provided by tools/cases.py
22 return min(max(x, lo), hi)