hạt_nhân
Translation status: Tiếng Việt reader-locale proof. Term names and code fences follow the vi pack; supporting prose may still be English.
Sugar @ hạt_nhân fragment modifier marks a fragment-shader entry on the hạt_nhân surface.
Syntax: @ hạt_nhân mảnh
Category#
lane
Related#
- nucleum
- annotation-sugar
Examples#
radix/corpus/annotation-sugar/nucleum-fragment.fab (canonical · annotation)#
Sugar @ hạt_nhân fragment modifier marks a fragment-shader entry on the hạt_nhân surface.
# =============================================================================
# hạt_nhân — sugar @ hạt_nhân mảnh modifier
# =============================================================================
#
# What this teaches:
# • Sugar modifier — `@ hạt_nhân mảnh` on a function declaration marks
# it as the fragment-shader entry (NucleumRole::Fragment); the parser
# reads `mảnh` as structured modifier data on the hạt_nhân annotation,
# never as an untyped name/argument pair
# • The la reader spelling — `hạt_nhân` is the la surface of the kernel
# annotation identity; the en twin is `@ kernel mảnh`
# • A marked mảnh function is a systems/shaders entry, not a host
# entry — the plain `bắt_đầu` driver below proves the module still
# checks and runs on the host làn
#
# Common mistakes:
# • writing `@ mảnh` alone — the bare mảnh name stays the graphics
# statement annotation, not the hạt_nhân modifier
# • expecting the marked function to be called from a host `bắt_đầu`
#
# See also: hạt_nhân, annotation-sugar
# =============================================================================
@ hạt_nhân { mảnh = đúng }
hàm umbra() → trống {
}
hàm identitas(số x) → số {
trả x
}
bắt_đầu {
ghi_chú identitas(5)
}Expected output:
5
radix/corpus/kernel-closure/argument-escape.fab (supporting · reject)#
A kernel closure cannot be passed to an ordinary function argument.
# =============================================================================
# hạt_nhân — reject ordinary-argument escape
# =============================================================================
fn apply(int value) → int {
return value
}
fn take() → void {
const _ kernel ← (int value) kernel ∴ value
const int result ← apply(kernel)
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/bag-result.fab (supporting · reject)#
A kernel closure cannot return a host list/bag, including an append-built result.
# =============================================================================
# hạt_nhân — reject list/bag result protocol
# =============================================================================
# A list is a host-managed bag/result carrier. The closure cannot return it,
# even when it is populated with append before the return.
# =============================================================================
fn take(int value) → void {
const _ bad ← (int value) kernel → list<int> ∴ do {
var list<int> items ← empty
items.append(value)
return items
}
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/bare-body.fab (supporting · reject)#
A compact closure body cannot be a bare block; use do in the body joint.
# =============================================================================
# hạt_nhân — reject bare compact brace body
# =============================================================================
main {
const _ bad ← (int value) kernel ∴ {
return value
}
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/cape.fab (supporting · reject)#
A kernel closure cannot contain do/catch recovery.
# =============================================================================
# hạt_nhân — reject bắt/catch recovery in closure body
# =============================================================================
fn take(int value) → void {
const _ bad ← (int value) kernel → int ∴ do {
do {
const int probe ← value
} catch err {
print err
}
return value
}
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/capture.fab (supporting · reject)#
A kernel closure cannot capture an enclosing value local.
# =============================================================================
# hạt_nhân — reject enclosing local capture
# =============================================================================
main {
const int seed ← 2
const _ bad ← (int value) kernel ∴ value + seed
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/dynamic-value.fab (supporting · reject)#
A kernel closure cannot produce a nested dynamic closure value.
# =============================================================================
# hạt_nhân — reject dynamic closure value
# =============================================================================
fn take(int value) → void {
const _ bad ← (int value) kernel ∴ (int inner) ∴ inner
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/error-channel.fab (supporting · reject)#
A kernel closure cannot declare an alternate-exit error channel.
# =============================================================================
# hạt_nhân — reject closure error channel
# =============================================================================
main {
const _ bad ← (int value) kernel → int ⇥ string ∴ value
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/field-escape.fab (supporting · reject)#
A kernel closure cannot be stored in a field.
# =============================================================================
# hạt_nhân — reject field escape
# =============================================================================
class Capsule {
var int stored
}
fn take() → void {
const _ kernel ← (int value) kernel ∴ value
const Capsule boxed ← Capsule { stored = kernel }
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/host-effect.fab (supporting · reject)#
A kernel closure cannot perform host output.
# =============================================================================
# hạt_nhân — reject host effect in closure body
# =============================================================================
fn take(int value) → void {
const _ bad ← (int value) kernel → int ∴ do {
print value
return value
}
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/list-escape.fab (supporting · reject)#
A kernel closure cannot be stored in a list.
# =============================================================================
# hạt_nhân — reject list escape
# =============================================================================
fn take() → void {
const _ kernel ← (int value) kernel ∴ value
const list<int> items ← [kernel, kernel]
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/reject.fab (supporting · reject)#
A kernel closure cannot use a reject guard that throws.
# =============================================================================
# hạt_nhân — reject reject guard in closure body
# =============================================================================
fn take(int value) → void {
const _ bad ← (int value) kernel → int ∴ do {
reject value > 10 throw value
return value
}
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/require.fab (supporting · reject)#
A kernel closure cannot use a require guard that throws.
# =============================================================================
# hạt_nhân — reject require guard in closure body
# =============================================================================
fn take(int value) → void {
const _ bad ← (int value) kernel → int ∴ do {
require value < 10 throw value
return value
}
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/return-escape.fab (supporting · reject)#
A kernel closure cannot be returned as an outer function value.
# =============================================================================
# hạt_nhân — reject return escape
# =============================================================================
fn take() → void {
const _ kernel ← (int value) kernel ∴ value
return kernel
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/source-callback.fab (supporting · reject)#
A kernel closure cannot capture a host source callback value.
# =============================================================================
# hạt_nhân — reject source callback capture
# =============================================================================
# A source callback is an enclosing function value. Referencing it from a
# kernel closure is a capture and therefore cannot cross the device boundary.
# =============================================================================
fn take((string, int) → int source, int value) → void {
const _ bad ← (int x) kernel → int ∴ source("weights", x)
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/stack-free-kernel.fab (supporting · reject)#
A closure cannot stack free and kernel modifiers.
# =============================================================================
# hạt_nhân — reject stacked free then kernel modifiers
# =============================================================================
main {
const _ bad ← (int value) free kernel ∴ value
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/stack-kernel-free.fab (supporting · reject)#
A closure cannot stack kernel and free modifiers.
# =============================================================================
# hạt_nhân — reject stacked kernel then free modifiers
# =============================================================================
main {
const _ bad ← (int value) kernel free ∴ value
}Expected: compilation rejects this example.
radix/corpus/kernel-closure/throw.fab (supporting · reject)#
A kernel closure cannot throw an alternate-exit value.
# =============================================================================
# hạt_nhân — reject throw in closure body
# =============================================================================
fn take(int value) → void {
const _ bad ← (int value) kernel → int ∴ do {
throw value
return value
}
}Expected: compilation rejects this example.
radix/corpus/kernel/legality-reject.fab (supporting · reject)#
Kernel legality at check time: host output, host-only types, calls to non-kernels, host calls to private kernels, and raw thread-id calls are named diagnostics.
# =============================================================================
# hạt_nhân — kernel legality is decided by `faber check`
# =============================================================================
#
# What this teaches:
# • A kernel body must not need the host runtime: no console output, no
# conversations, no async or generator forms, no heap-backed values
# (`list`, `map`, `set`, `string`, `json`, `value`), no local handlers.
# • A kernel may call another kernel or a built-in device operation, never
# an ordinary function.
# • Only a public kernel is launchable: host code may call a public kernel
# but not a private one.
# • A kernel never names its own làn: the thread-id builtins
# (`global_invocation_id()` and its siblings) are raw làn ids and are
# rejected in user code; the parallel pattern is an `lặp … tại`
# loop over the ten_xo.
# • Each violation is a named diagnostic on the offending line, reported
# by `faber check` before any device lowering runs.
#
# Common mistakes:
# • printing from a kernel to debug it — run the kernel on the runner
# oracle instead.
# • passing a `list` to a kernel — use a ten_xo.
#
# See also: hạt_nhân, công_khai
# =============================================================================
fn host_double(f32 x) → f32 {
return x * 2.0
}
# 1. host output
@ kernel
@ public
fn noisy(f32 x) → f32 {
print x
return x
}
# 2. call to an ordinary function
@ kernel
@ public
fn calls_host(f32 x) → f32 {
return host_double(x)
}
# 3. host-only parameter type
@ kernel
@ public
fn takes_list(list<f32> xs) → void {
}
# 4. host call to a private kernel
@ kernel
fn helper(f32 x) → f32 {
return x + 1.0
}
fn launches_private() → f32 {
return helper(1.0)
}
# 5. raw làn id
@ kernel
@ public
fn names_its_lane(f32 x) → f32 {
const vectơ<u32, 3> gid ← global_invocation_id()
return x
}Expected: compilation rejects this example.