restructure: move el compiler content into lang/

This commit is contained in:
Will Anderson
2026-05-05 01:38:51 -05:00
parent ce68f91a38
commit 1ae68962cf
143 changed files with 0 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
// sleep-typed.el sleep(Duration) lowers to el_sleep_duration. The actual
// elapsed Duration is measured by Instant - Instant arithmetic. The check
// returns 1 if elapsed is at least 50 millis but under 1 second the wide
// upper bound tolerates scheduler jitter on shared CI runners while the
// lower bound proves the sleep actually waited.
// `test` is reserved; using `run_test` instead.
fn run_test() -> Int {
let start: Instant = now()
sleep(50.millis)
let elapsed: Duration = now() - start
if elapsed >= 50.millis {
if elapsed < 1.second {
return 1
}
}
return 0
}
fn main() -> Void {
println(int_to_str(run_test()))
}
@@ -0,0 +1,20 @@
// time-arithmetic.el Instant + Duration -> Instant, then Instant - Instant
// -> Duration. The codegen routes each BinOp through the typed wrappers
// (el_instant_add_dur, el_instant_diff). Returns 1 if the elapsed span is at
// least 5 minutes, 0 otherwise. Because the two now() calls are very close
// together, the span is very nearly 5.minutes, so >= 5.minutes holds.
// `test` is reserved; using `run_test` instead.
fn run_test() -> Int {
let later: Instant = now() + 5.minutes
let span: Duration = later - now()
if span >= 5.minutes {
return 1
} else {
return 0
}
}
fn main() -> Void {
println(int_to_str(run_test()))
}
@@ -0,0 +1,16 @@
// time-comparison.el Duration < Duration is type-checked at codegen time.
// Both operands are DurationLits (postfix literals). Codegen routes through
// el_duration_lt; the runtime returns 1 when 5.minutes < 1.hour holds.
// `test` is reserved; using `run_test` instead.
fn run_test() -> Bool {
return 5.minutes < 1.hour
}
fn main() -> Void {
if run_test() {
println("1")
} else {
println("0")
}
}
+15
View File
@@ -0,0 +1,15 @@
// time-literals.el postfix-literal duration recognition.
// `30.seconds` lowers to a DurationLit AST node carrying the count and the
// unit; codegen emits a literal int64 nanosecond constant. duration_to_seconds
// reverses the lowering and yields the original count.
// `test` is reserved by El's lexer as a property-test keyword, so the
// example body lives in `run_test()`.
fn run_test() -> Int {
let d: Duration = 30.seconds
return duration_to_seconds(d)
}
fn main() -> Void {
println(int_to_str(run_test()))
}
@@ -0,0 +1,23 @@
// time-typeerror.el Instant + Instant is structurally meaningless.
// Path taken: COMPILE-TIME error. The codegen records the violation in the
// __time_violations accumulator; emit_time_violations writes a #error
// directive at the top of the generated C, so cc fails the build with a
// clear El-source-level message before any link step.
//
// This file is NOT expected to compile to a working binary. The runner
// asserts that:
// 1. elc emits the C source successfully (the violation is recorded but
// codegen still completes the #error sits at the bottom).
// 2. cc on that C fails with the temporal-type-error message.
// `test` is reserved; using `run_test` instead.
fn run_test() -> Int {
let a: Instant = now()
let b: Instant = now()
let bad: Instant = a + b
return 0
}
fn main() -> Void {
let r: Int = run_test()
}
+14
View File
@@ -0,0 +1,14 @@
// ttl-cache.el TTL helpers backed by typed Duration. Storing under a key
// stamps the set time as an Instant; ttl_cache_get computes the age and
// returns the value only if the age is within the supplied Duration.
// `test` is reserved; using `run_test` instead.
fn run_test() -> String {
ttl_cache_set("key1", "hello")
let v: String = ttl_cache_get("key1", 1.hour)
return v
}
fn main() -> Void {
println(run_test())
}