You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This update introduces a new `include` keyword for including header files (.kh) alongside the existing `import` functionality for modules.
Signed-off-by: Cong Wang <cwang@multikernel.io>
Copy file name to clipboardExpand all lines: SPEC.md
+34-3Lines changed: 34 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,9 +89,9 @@ fn main(args: Args) -> i32 {
89
89
}
90
90
```
91
91
92
-
### 1.4 Unified Import System
92
+
### 1.4 Unified Import and Include System
93
93
94
-
KernelScript supports importing both KernelScript modules and external language modules using a unified syntax. Import behavior is automatically determined by file extension:
94
+
KernelScript supports both importing modules and including headers using distinct keywords for different use cases:
95
95
96
96
```kernelscript
97
97
// Import KernelScript modules (.ks files)
@@ -132,6 +132,30 @@ fn main() -> i32 {
132
132
}
133
133
```
134
134
135
+
#### Include System for Headers (.kh files)
136
+
137
+
```kernelscript
138
+
// Include KernelScript headers (.kh files) - declarations only, flattened into global namespace
139
+
include "generated/common_kfuncs.kh" // extern kfunc declarations
140
+
include "generated/xdp_kfuncs.kh" // XDP-specific kfuncs
141
+
include "types/networking.kh" // Type definitions
142
+
143
+
@xdp
144
+
fn packet_processor(ctx: *xdp_md) -> xdp_action {
145
+
// Direct access to included extern kfuncs (no namespace)
146
+
var timestamp = bpf_ktime_get_ns() // From common_kfuncs.kh
147
+
bpf_xdp_adjust_head(ctx, -14) // From xdp_kfuncs.kh
148
+
149
+
return XDP_PASS
150
+
}
151
+
```
152
+
153
+
**Key Distinctions:**
154
+
-**`import name from "file"`**: Creates namespace, works with full implementations (.ks/.py files)
155
+
-**`include "file"`**: Flattens into global namespace, works with headers only (.kh files)
156
+
-**Use cases**: Import for libraries/modules, include for extern declarations and types
157
+
-**Validation**: Include validates that .kh files contain only declarations (no function bodies)
158
+
135
159
## 2. Lexical Structure
136
160
137
161
### 2.1 Keywords
@@ -141,7 +165,7 @@ pin type struct enum if else
141
165
while loop break continue return import
142
166
pub priv impl true false null
143
167
try catch throw defer delete match
144
-
extern
168
+
extern include
145
169
```
146
170
147
171
**Note**: The `pin` keyword is used for both maps and global variables to enable filesystem persistence.
0 commit comments