diff --git a/.llm/BETA_9_COLLECTION_ALIAS_UNIFICATION_AND_GENERIC_RESERVATION.md b/.llm/BETA_9_COLLECTION_ALIAS_UNIFICATION_AND_GENERIC_RESERVATION.md new file mode 100644 index 0000000..ab2999c --- /dev/null +++ b/.llm/BETA_9_COLLECTION_ALIAS_UNIFICATION_AND_GENERIC_RESERVATION.md @@ -0,0 +1,62 @@ +# 1.0.0-beta.9 Collection Alias Unification And Generic Reservation + +Status: release scope for `1.0.0-beta.9`. + +`1.0.0-beta.9` is a Slovo stdlib/docs slice on top of the beta.8 concrete +alias foundation. It applies transparent aliases to the repeated concrete +collection and value-family facades without changing the public helper surface +or executable semantics. + +## Source Surface + +Current source-authored facades may declare module-local aliases such as: + +```slo +(type VecBool (vec bool)) +(type OptionString (option string)) +(type ResultU64 (result u64 i32)) +``` + +The aliases are used only inside their defining module. Exported helper names +and helper meanings remain concrete, and importers observe normalized concrete +types. + +## Applied Scope + +- `lib/std/vec_i32.slo` +- `lib/std/vec_i64.slo` +- `lib/std/vec_f64.slo` +- `lib/std/vec_bool.slo` +- `lib/std/vec_string.slo` +- `lib/std/option.slo` +- `lib/std/result.slo` + +The vector facades use one local alias for the concrete vector family. The +option and result facades use local aliases for the current concrete option and +result families. + +## Contract + +- Current vectors remain concrete families: `(vec i32)`, `(vec i64)`, + `(vec f64)`, `(vec bool)`, and `(vec string)`. +- Current options and results remain concrete families over the explicitly + promoted payload shapes. +- Aliases are transparent, module-local, and erased before typed-core lowering, + backend layout, ABI decisions, runtime behavior, and cross-module signatures. +- Public helper names, exports, constructors, runtime calls, and behavior are + preserved. +- Public API documentation must not turn these local aliases into imported + public type names; the semantic contract is the normalized concrete target + type. + +## Deferrals + +This release does not add executable generics, generic aliases, parameterized +aliases, maps, sets, traits, inference, monomorphization, iterators, new +compiler-known runtime names, stable ABI/layout promises, or a stable +standard-library API freeze. + +The generic/map/set direction is reserved through diagnostics and design +language only. Future work must define syntax, typed-core representation, +lowering, conformance gates, compatibility policy, and stdlib migration rules +before any executable generic collection surface is promoted. diff --git a/.llm/ROADMAP_TO_STABLE.md b/.llm/ROADMAP_TO_STABLE.md index 3599e86..e542422 100644 --- a/.llm/ROADMAP_TO_STABLE.md +++ b/.llm/ROADMAP_TO_STABLE.md @@ -35,7 +35,9 @@ implementation scope. option/result, array, JSON, and resource-handle signatures can be named without changing runtime representation (released in `1.0.0-beta.8`). 9. Design generics and collection unification from real stdlib duplication - pressure. + pressure by first applying concrete aliases to existing collection/value + facades and reserving generic/map/set directions without executable + semantics (released in `1.0.0-beta.9`). 10. Add editor-facing diagnostics, watch mode, and generated documentation improvements. 11. Freeze migration/deprecation policy and cut stable only after beta feedback. diff --git a/.llm/reviews/BETA_9_RELEASE_REVIEW.md b/.llm/reviews/BETA_9_RELEASE_REVIEW.md new file mode 100644 index 0000000..98a18c2 --- /dev/null +++ b/.llm/reviews/BETA_9_RELEASE_REVIEW.md @@ -0,0 +1,50 @@ +# 1.0.0-beta.9 Release Review + +Status: ready for publication after the controller release gate. + +## Verdict + +No blocking issues found after integrating the Slovo stdlib/docs worker and +the Glagol compiler/test worker. + +## Scope Checked + +- `lib/std/vec_i32.slo`, `lib/std/vec_i64.slo`, `lib/std/vec_f64.slo`, + `lib/std/vec_bool.slo`, `lib/std/vec_string.slo`, `lib/std/option.slo`, and + `lib/std/result.slo` now use module-local concrete aliases without exporting + alias names. +- Compiler diagnostics reserve generic functions, parameterized aliases, + uppercase single-letter generic type parameters in unsupported positions, + map/set type forms, and future generic stdlib calls. +- Formatter diagnostics mirror the compiler rejection path for reserved + generic/map/set syntax. +- Docs and whitepapers describe beta9 as alias-backed collection cleanup and + diagnostic reservation only. They do not claim executable generics, maps, + sets, traits, inference, monomorphization, iterators, stable ABI/layout, or a + stable stdlib API freeze. + +## Verification + +- `cargo fmt --check` +- `cargo test --test diagnostics_contract current_negative_cases_match_machine_diagnostic_snapshots` +- `cargo test --test formatter formatter_re` +- `cargo test --test project_mode` +- `cargo test --test concrete_type_aliases_beta` +- `cargo test --test promotion_gate` +- `cargo test standard_` +- `./scripts/render-stdlib-api-doc.sh` +- `./scripts/render-doc-pdfs.sh` +- `git diff --check` +- `./scripts/release-gate.sh` + +Final gate result: passed. The release gate completed docs, generated stdlib +API catalog, formatter, default tests, ignored promotion checks, binary smoke, +and LLVM smoke checks. + +## Residual Risk + +Beta9 intentionally reserves generics without implementing them. Future +generic work still needs typed-core representation, monomorphization policy, +project/import semantics, formatter stability, stdlib migration rules, and +explicit compatibility gates before any executable generic collection surface +is promoted. diff --git a/README.md b/README.md index 4c4c061..9519f31 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This repository is the canonical public monorepo for the language design, standard library source, compiler, runtime, examples, benchmarks, and technical documents. -Current release: `1.0.0-beta.8`. +Current release: `1.0.0-beta.9`. ## Repository Layout @@ -24,15 +24,16 @@ scripts/ local release and document tooling ## Beta Scope -`1.0.0-beta.8` keeps the `1.0.0-beta` language baseline, includes the +`1.0.0-beta.9` keeps the `1.0.0-beta` language baseline, includes the `1.0.0-beta.1` tooling/install hardening slice, the `1.0.0-beta.2` runtime/resource foundation bundle, the `1.0.0-beta.3` standard-library stabilization bundle, the `1.0.0-beta.4` language-usability diagnostics bundle, the `1.0.0-beta.5` local package/workspace discipline bundle, and the `1.0.0-beta.6` loopback networking foundation, plus the `1.0.0-beta.7` serialization/data-interchange foundation and the `1.0.0-beta.8` concrete type -alias foundation. The language baseline supports practical local command-line, -file, and loopback-network programs with: +alias foundation, and the `1.0.0-beta.9` collection alias unification and +generic reservation slice. The language baseline supports practical local +command-line, file, and loopback-network programs with: - modules, explicit imports, packages, and local workspaces - `new`, `check`, `fmt`, `test`, `doc`, and `build` @@ -50,10 +51,11 @@ Still deferred before stable: generics, maps/sets, broad package registry semantics, DNS/TLS/async networking, LSP/watch/debug-adapter guarantees, stable ABI and layout, and a stable standard-library compatibility freeze. -The next likely language slice is `1.0.0-beta.9`, focused on the first -generics and collection-unification design pressure. It should build on the -alias foundation without adding maps/sets or standard-library API freeze claims -until the contract and gates are explicit. +The next likely language slice after `1.0.0-beta.9` should continue from the +reserved generic and collection diagnostics without claiming executable +generics, maps, sets, traits, inference, monomorphization, iterators, ABI +stability, or a standard-library API freeze until the contract and gates are +explicit. ## Build And Test @@ -216,6 +218,18 @@ use aliases see the resolved concrete target type. Alias exports, imports, re-exports, generic aliases, parameterized aliases, maps/sets, and new compiler-known runtime names remain out of scope. +## 1.0.0-beta.9 Collection Alias Unification And Generic Reservation + +The `1.0.0-beta.9` release applies beta.8 concrete aliases inside the current +source-authored collection/value-family facades. The public helper names and +runtime behavior remain concrete: current vectors, options, and results are +still concrete families, and the local aliases are erased before lowering. + +This release also reserves the generic/map/set direction through diagnostics +and documentation only. It does not implement executable generics, maps, sets, +traits, inference, monomorphization, iterators, stable ABI/layout promises, or +a stable standard-library API freeze. + ## Documentation - [Language Manifest](docs/language/MANIFEST.md) diff --git a/compiler/Cargo.lock b/compiler/Cargo.lock index 65fea67..c49dc87 100644 --- a/compiler/Cargo.lock +++ b/compiler/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "glagol" -version = "1.0.0-beta.8" +version = "1.0.0-beta.9" diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index c274425..bdad071 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "glagol" -version = "1.0.0-beta.8" +version = "1.0.0-beta.9" edition = "2021" description = "Glagol, the first compiler for the Slovo language" license = "MIT OR Apache-2.0" diff --git a/compiler/src/check.rs b/compiler/src/check.rs index 0eca950..be1e5e1 100644 --- a/compiler/src/check.rs +++ b/compiler/src/check.rs @@ -847,6 +847,10 @@ fn resolve_alias_target_type( Some(Type::Named(name.clone())) } Type::Named(name) => { + if is_generic_type_parameter_name(name) { + errors.push(unsupported_generic_type_parameter(file, span, name)); + return None; + } errors.push( Diagnostic::new( file, @@ -1009,7 +1013,7 @@ fn unsupported_type_alias_target(file: &str, span: Span, ty: &Type) -> Diagnosti Diagnostic::new( file, "UnsupportedTypeAliasTarget", - "type alias target type is not supported in beta.8", + "type alias target type is not supported in the current beta", ) .with_span(span) .expected("i32, i64, u32, u64, f64, bool, string, known struct, known enum, supported array, supported option, supported result, or supported vec") @@ -2653,6 +2657,10 @@ fn check_local_type( } fn unknown_named_type(file: &str, span: Span, name: &str, context: &str) -> Diagnostic { + if is_generic_type_parameter_name(name) { + return unsupported_generic_type_parameter(file, span, name); + } + Diagnostic::new( file, "UnknownStructType", @@ -5503,6 +5511,12 @@ fn check_vector_type(file: &str, ty: &Type, span: Span) -> Result<(), Diagnostic return Ok(()); }; + if let Type::Named(name) = &**inner { + if is_generic_type_parameter_name(name) { + return Err(unsupported_generic_type_parameter(file, span, name)); + } + } + if **inner != Type::I32 && **inner != Type::I64 && **inner != Type::F64 @@ -5523,6 +5537,25 @@ fn check_vector_type(file: &str, ty: &Type, span: Span) -> Result<(), Diagnostic Ok(()) } +fn unsupported_generic_type_parameter(file: &str, span: Span, name: &str) -> Diagnostic { + Diagnostic::new( + file, + "UnsupportedGenericTypeParameter", + format!( + "generic type parameter `{}` is reserved but not supported in beta.9", + name + ), + ) + .with_span(span) + .expected("concrete supported type") + .found(name.to_string()) + .hint("use a concrete promoted type such as `i32`, `string`, or `(vec i32)`") +} + +fn is_generic_type_parameter_name(name: &str) -> bool { + name.len() == 1 && name.bytes().all(|byte| byte.is_ascii_uppercase()) +} + fn array_index_range(len: usize) -> String { if len == 1 { "0".to_string() diff --git a/compiler/src/formatter.rs b/compiler/src/formatter.rs index 712bf3e..81956e4 100644 --- a/compiler/src/formatter.rs +++ b/compiler/src/formatter.rs @@ -267,6 +267,14 @@ impl Formatter<'_> { return; }; + if matches!(items.get(2).and_then(list_head), Some("type_params")) { + self.errors.push(unsupported_generic_type_alias( + self.file, + items.get(2).map_or(form.span, |item| item.span), + )); + return; + } + if items.len() != 3 { self.errors.push( Diagnostic::new( @@ -657,6 +665,12 @@ impl Formatter<'_> { return; } + if matches!(items.get(2).and_then(list_head), Some("type_params")) { + self.errors + .push(unsupported_generic_function(self.file, items[2].span)); + return; + } + let Some(name) = expect_ident(&items[1]) else { self.errors.push( Diagnostic::new( @@ -908,6 +922,8 @@ impl Formatter<'_> { || self.type_alias_names.contains(name) { name.to_string() + } else if self.push_reserved_type_error(&pair[1]) { + continue; } else { self.errors.push( Diagnostic::new( @@ -932,6 +948,8 @@ impl Formatter<'_> { } else if let Some(text) = render_supported_vec_type(items, &self.type_alias_names) { text + } else if self.push_reserved_type_error(&pair[1]) { + continue; } else { self.errors.push( Diagnostic::new( @@ -1017,6 +1035,10 @@ impl Formatter<'_> { } } + if self.push_reserved_type_error(form) { + return None; + } + let Some(items) = expect_list(form) else { self.errors.push( Diagnostic::new( @@ -1046,6 +1068,10 @@ impl Formatter<'_> { return Some(text); } + if self.push_reserved_type_error(form) { + return None; + } + self.errors.push( Diagnostic::new( self.file, @@ -1067,6 +1093,10 @@ impl Formatter<'_> { return Some(text); } + if self.push_reserved_type_error(form) { + return None; + } + let Some(items) = expect_list(form) else { self.errors.push( Diagnostic::new( @@ -1097,6 +1127,10 @@ impl Formatter<'_> { return Some(text); } + if self.push_reserved_type_error(form) { + return None; + } + self.errors.push( Diagnostic::new( self.file, @@ -1281,6 +1315,14 @@ impl Formatter<'_> { Some(format!("({})", name)) } } + other if is_unsupported_generic_standard_library_call(other) => { + self.errors.push(unsupported_generic_standard_library_call( + self.file, + items[0].span, + other, + )); + None + } other if std_runtime::is_standard_path(other) => { self.errors .push(std_runtime::unsupported_standard_library_call( @@ -1448,6 +1490,10 @@ impl Formatter<'_> { } } + if self.push_reserved_type_error(form) { + return None; + } + let Some(items) = expect_list(form) else { self.errors.push( Diagnostic::new( @@ -1474,6 +1520,10 @@ impl Formatter<'_> { }); } + if self.push_reserved_type_error(form) { + return None; + } + if items.len() != 3 || !is_ident(&items[0], "array") { self.errors.push( Diagnostic::new( @@ -1492,6 +1542,9 @@ impl Formatter<'_> { &self.enum_names, &self.type_alias_names, ) else { + if self.push_reserved_type_error(&items[1]) { + return None; + } self.errors.push( Diagnostic::new( self.file, @@ -1559,6 +1612,10 @@ impl Formatter<'_> { } } + if self.push_reserved_type_error(form) { + return None; + } + let Some(items) = expect_list(form) else { self.errors.push( Diagnostic::new( @@ -1588,6 +1645,10 @@ impl Formatter<'_> { return Some(text); } + if self.push_reserved_type_error(form) { + return None; + } + self.errors.push( Diagnostic::new( self.file, @@ -2251,6 +2312,9 @@ impl Formatter<'_> { } let Some(payload_type) = render_payload_type_atom(&items[1], &self.type_alias_names) else { + if self.push_reserved_type_error(&items[1]) { + return None; + } self.errors.push( Diagnostic::new( self.file, @@ -2293,6 +2357,9 @@ impl Formatter<'_> { } let Some(ok_ty) = render_payload_type_atom(&items[1], &self.type_alias_names) else { + if self.push_reserved_type_error(&items[1]) { + return None; + } self.errors.push( Diagnostic::new( self.file, @@ -2304,6 +2371,9 @@ impl Formatter<'_> { return None; }; let Some(err_ty) = render_result_err_type_atom(&items[2], &self.type_alias_names) else { + if self.push_reserved_type_error(&items[2]) { + return None; + } self.errors.push( Diagnostic::new( self.file, @@ -2354,6 +2424,15 @@ impl Formatter<'_> { Some(output) } + fn push_reserved_type_error(&mut self, form: &SExpr) -> bool { + if let Some(diagnostic) = unsupported_reserved_type_diagnostic(self.file, form) { + self.errors.push(diagnostic); + true + } else { + false + } + } + fn write_indented_rendered(&mut self, indent: &str, rendered: &str) { push_indented(&mut self.output, indent, rendered); } @@ -2417,6 +2496,138 @@ struct RenderedMatchPattern<'a> { text: String, } +fn unsupported_reserved_type_diagnostic(file: &str, form: &SExpr) -> Option { + if let Some(name) = expect_ident(form) { + if is_generic_type_parameter_name(name) { + return Some(unsupported_generic_type_parameter(file, form.span, name)); + } + } + + let items = expect_list(form)?; + let head = items.first().and_then(expect_ident)?; + match head { + "map" => Some( + Diagnostic::new( + file, + "UnsupportedMapType", + "`map` types are reserved but not supported in beta.9", + ) + .with_span(form.span) + .expected("supported concrete type") + .found(render_type_form(form)) + .hint( + "use current concrete arrays, vectors, option/result, structs, enums, or scalars", + ), + ), + "set" => Some( + Diagnostic::new( + file, + "UnsupportedSetType", + "`set` types are reserved but not supported in beta.9", + ) + .with_span(form.span) + .expected("supported concrete type") + .found(render_type_form(form)) + .hint( + "use current concrete arrays, vectors, option/result, structs, enums, or scalars", + ), + ), + "vec" if items.len() != 2 => Some( + Diagnostic::new( + file, + "UnsupportedGenericTypeParameter", + "generic vector syntax is reserved but not supported in beta.9", + ) + .with_span(form.span) + .expected("(vec i32), (vec i64), (vec f64), (vec bool), or (vec string)") + .found(render_type_form(form)) + .hint("choose one current concrete vector family explicitly"), + ), + _ => items + .iter() + .find_map(|item| unsupported_reserved_type_diagnostic(file, item)), + } +} + +fn unsupported_generic_function(file: &str, span: Span) -> Diagnostic { + Diagnostic::new( + file, + "UnsupportedGenericFunction", + "generic function declarations are reserved but not supported in beta.9", + ) + .with_span(span) + .expected("(fn name ((arg ConcreteType) ...) -> ConcreteType body...)") + .found("(type_params ...)") + .hint("write a concrete function for each currently supported type family") +} + +fn unsupported_generic_type_alias(file: &str, span: Span) -> Diagnostic { + Diagnostic::new( + file, + "UnsupportedGenericTypeAlias", + "parameterized type aliases are reserved but not supported in beta.9", + ) + .with_span(span) + .expected("(type Alias ConcreteType)") + .found("(type_params ...)") + .hint("aliases remain transparent names for concrete supported target types") +} + +fn unsupported_generic_type_parameter(file: &str, span: Span, name: &str) -> Diagnostic { + Diagnostic::new( + file, + "UnsupportedGenericTypeParameter", + format!( + "generic type parameter `{}` is reserved but not supported in beta.9", + name + ), + ) + .with_span(span) + .expected("concrete supported type") + .found(name.to_string()) + .hint("use a concrete promoted type such as `i32`, `string`, or `(vec i32)`") +} + +fn unsupported_generic_standard_library_call(file: &str, span: Span, name: &str) -> Diagnostic { + Diagnostic::new( + file, + "UnsupportedGenericStandardLibraryCall", + format!( + "generic standard-library call `{}` is reserved but not supported in beta.9", + name + ), + ) + .with_span(span) + .expected("promoted concrete standard-library function") + .found(name.to_string()) + .hint("use current concrete families such as `std.vec.i32.empty`") +} + +fn is_unsupported_generic_standard_library_call(name: &str) -> bool { + matches!(name, "std.vec.empty" | "std.result.map") +} + +fn is_generic_type_parameter_name(name: &str) -> bool { + name.len() == 1 && name.bytes().all(|byte| byte.is_ascii_uppercase()) +} + +fn render_type_form(form: &SExpr) -> String { + match &form.kind { + SExprKind::Atom(Atom::Ident(name)) => name.clone(), + SExprKind::Atom(Atom::Int(value)) => value.to_string(), + SExprKind::Atom(Atom::I64(value)) => format!("{}i64", value), + SExprKind::Atom(Atom::U32(value)) => format!("{}u32", value), + SExprKind::Atom(Atom::U64(value)) => format!("{}u64", value), + SExprKind::Atom(Atom::Float(value)) => value.to_string(), + SExprKind::Atom(Atom::String(value)) => format!("{:?}", value), + SExprKind::Atom(Atom::Arrow) => "->".to_string(), + SExprKind::List(items) => { + let parts = items.iter().map(render_type_form).collect::>(); + format!("({})", parts.join(" ")) + } + } +} + fn collect_function_names(forms: &[SExpr]) -> HashSet { let mut names = HashSet::new(); for form in forms { diff --git a/compiler/src/lower.rs b/compiler/src/lower.rs index 43cba05..9daab13 100644 --- a/compiler/src/lower.rs +++ b/compiler/src/lower.rs @@ -623,6 +623,13 @@ fn lower_type_alias(file: &str, form: &SExpr) -> Result Result ty, None => { - errors.push( - Diagnostic::new( - file, - "InvalidTypeAliasTarget", - "type alias target type is invalid", - ) - .with_span(items[2].span) - .expected("concrete type"), - ); + errors.push(invalid_type_diagnostic( + file, + &items[2], + "InvalidTypeAliasTarget", + "type alias target type is invalid", + Some("concrete type"), + None, + )); Type::Unit } }; @@ -751,10 +757,14 @@ fn lower_struct(file: &str, form: &SExpr) -> Result> }; let Some(ty) = lower_type(&pair[1]) else { - errors.push( - Diagnostic::new(file, "InvalidStructFieldType", "invalid struct field type") - .with_span(pair[1].span), - ); + errors.push(invalid_type_diagnostic( + file, + &pair[1], + "InvalidStructFieldType", + "invalid struct field type", + None, + None, + )); continue; }; @@ -858,15 +868,14 @@ fn lower_enum(file: &str, form: &SExpr) -> Result> { }; let Some(payload_ty) = lower_type(&variant_items[1]) else { - errors.push( - Diagnostic::new( - file, - "InvalidEnumVariant", - "enum variant payload type is invalid", - ) - .with_span(variant_items[1].span) - .expected("i32"), - ); + errors.push(invalid_type_diagnostic( + file, + &variant_items[1], + "InvalidEnumVariant", + "enum variant payload type is invalid", + Some("i32"), + None, + )); continue; }; @@ -918,6 +927,10 @@ fn lower_function( .hint("expected `(fn name ((arg Type) ...) -> ReturnType body...)`")]); } + if matches!(items.get(2).and_then(list_head), Some("type_params")) { + return Err(vec![unsupported_generic_function(file, items[2].span)]); + } + let name = match expect_ident(&items[1]) { Some(name) => name.to_string(), None => { @@ -955,10 +968,14 @@ fn lower_function( } Some(ty) => ty, None => { - errors.push( - Diagnostic::new(file, "InvalidReturnType", "invalid return type") - .with_span(items[4].span), - ); + errors.push(invalid_type_diagnostic( + file, + &items[4], + "InvalidReturnType", + "invalid return type", + None, + None, + )); Type::Unit } }; @@ -1055,10 +1072,14 @@ fn lower_c_import(file: &str, form: &SExpr) -> Result ty, None => { - errors.push( - Diagnostic::new(file, "MalformedCImport", "invalid C import return type") - .with_span(items[4].span), - ); + errors.push(invalid_type_diagnostic( + file, + &items[4], + "MalformedCImport", + "invalid C import return type", + None, + None, + )); Type::Unit } }; @@ -1164,10 +1185,14 @@ fn lower_c_import_params(file: &str, form: &SExpr) -> Result, Vec Result, Vec> }; let Some(ty) = lower_type(&pair[1]) else { - errors.push( - Diagnostic::new(file, "InvalidParamType", "invalid parameter type") - .with_span(pair[1].span), - ); + errors.push(invalid_type_diagnostic( + file, + &pair[1], + "InvalidParamType", + "invalid parameter type", + None, + None, + )); continue; }; @@ -1400,6 +1429,8 @@ fn is_reserved_type_name(name: &str) -> bool { | "result" | "array" | "vec" + | "map" + | "set" ) } @@ -1710,6 +1741,9 @@ fn lower_expr( span: form.span, }) } + name if is_unsupported_generic_standard_library_call(name) => Err( + unsupported_generic_standard_library_call(file, items[0].span, name), + ), name => { let mut args = Vec::new(); for item in &items[1..] { @@ -2084,13 +2118,14 @@ fn lower_array_init( } let Some(elem_ty) = lower_type(&items[1]) else { - return Err(Diagnostic::new( + return Err(invalid_type_diagnostic( file, + &items[1], "InvalidArrayElementType", "array constructor element type is invalid", - ) - .with_span(items[1].span) - .hint("fixed arrays use direct scalar `i32`, `i64`, `f64`, `bool`, `string`, known enum, or known non-recursive struct elements")); + None, + Some("fixed arrays use direct scalar `i32`, `i64`, `f64`, `bool`, `string`, known enum, or known non-recursive struct elements"), + )); }; let mut elements = Vec::new(); @@ -2126,13 +2161,14 @@ fn lower_option_some( } let Some(payload_ty) = lower_type(&items[1]) else { - return Err(Diagnostic::new( + return Err(invalid_type_diagnostic( file, + &items[1], "InvalidOptionPayloadType", "option constructor payload type is invalid", - ) - .with_span(items[1].span) - .hint("first-pass options use `i32` payloads")); + None, + Some("first-pass options use `i32` payloads"), + )); }; Ok(Expr { @@ -2157,13 +2193,14 @@ fn lower_option_none(file: &str, form: &SExpr, items: &[SExpr]) -> Result, + fallback_expected: Option<&str>, + fallback_hint: Option<&str>, +) -> Diagnostic { + if let Some(diagnostic) = unsupported_reserved_type_diagnostic(file, form) { + return diagnostic; + } + + let mut diagnostic = + Diagnostic::new(file, fallback_code, fallback_message).with_span(form.span); + if let Some(expected) = fallback_expected { + diagnostic = diagnostic.expected(expected); + } + if let Some(hint) = fallback_hint { + diagnostic = diagnostic.hint(hint); + } + diagnostic +} + +fn unsupported_reserved_type_diagnostic(file: &str, form: &SExpr) -> Option { + if let Some(name) = expect_ident(form) { + if is_generic_type_parameter_name(name) { + return Some(unsupported_generic_type_parameter(file, form.span, name)); + } + } + + let items = expect_list(form)?; + let head = items.first().and_then(expect_ident)?; + match head { + "map" => Some( + Diagnostic::new( + file, + "UnsupportedMapType", + "`map` types are reserved but not supported in beta.9", + ) + .with_span(form.span) + .expected("supported concrete type") + .found(render_type_form(form)) + .hint( + "use current concrete arrays, vectors, option/result, structs, enums, or scalars", + ), + ), + "set" => Some( + Diagnostic::new( + file, + "UnsupportedSetType", + "`set` types are reserved but not supported in beta.9", + ) + .with_span(form.span) + .expected("supported concrete type") + .found(render_type_form(form)) + .hint( + "use current concrete arrays, vectors, option/result, structs, enums, or scalars", + ), + ), + "vec" if items.len() != 2 => Some( + Diagnostic::new( + file, + "UnsupportedGenericTypeParameter", + "generic vector syntax is reserved but not supported in beta.9", + ) + .with_span(form.span) + .expected("(vec i32), (vec i64), (vec f64), (vec bool), or (vec string)") + .found(render_type_form(form)) + .hint("choose one current concrete vector family explicitly"), + ), + _ => items + .iter() + .find_map(|item| unsupported_reserved_type_diagnostic(file, item)), + } +} + +fn unsupported_generic_function(file: &str, span: Span) -> Diagnostic { + Diagnostic::new( + file, + "UnsupportedGenericFunction", + "generic function declarations are reserved but not supported in beta.9", + ) + .with_span(span) + .expected("(fn name ((arg ConcreteType) ...) -> ConcreteType body...)") + .found("(type_params ...)") + .hint("write a concrete function for each currently supported type family") +} + +fn unsupported_generic_type_alias(file: &str, span: Span) -> Diagnostic { + Diagnostic::new( + file, + "UnsupportedGenericTypeAlias", + "parameterized type aliases are reserved but not supported in beta.9", + ) + .with_span(span) + .expected("(type Alias ConcreteType)") + .found("(type_params ...)") + .hint("aliases remain transparent names for concrete supported target types") +} + +fn unsupported_generic_type_parameter(file: &str, span: Span, name: &str) -> Diagnostic { + Diagnostic::new( + file, + "UnsupportedGenericTypeParameter", + format!( + "generic type parameter `{}` is reserved but not supported in beta.9", + name + ), + ) + .with_span(span) + .expected("concrete supported type") + .found(name.to_string()) + .hint("use a concrete promoted type such as `i32`, `string`, or `(vec i32)`") +} + +fn unsupported_generic_standard_library_call(file: &str, span: Span, name: &str) -> Diagnostic { + Diagnostic::new( + file, + "UnsupportedGenericStandardLibraryCall", + format!( + "generic standard-library call `{}` is reserved but not supported in beta.9", + name + ), + ) + .with_span(span) + .expected("promoted concrete standard-library function") + .found(name.to_string()) + .hint("use current concrete families such as `std.vec.i32.empty`") +} + +fn is_unsupported_generic_standard_library_call(name: &str) -> bool { + matches!(name, "std.vec.empty" | "std.result.map") +} + +fn is_generic_type_parameter_name(name: &str) -> bool { + name.len() == 1 && name.bytes().all(|byte| byte.is_ascii_uppercase()) +} + +fn render_type_form(form: &SExpr) -> String { + match &form.kind { + SExprKind::Atom(Atom::Ident(name)) => name.clone(), + SExprKind::Atom(Atom::Int(value)) => value.to_string(), + SExprKind::Atom(Atom::I64(value)) => format!("{}i64", value), + SExprKind::Atom(Atom::U32(value)) => format!("{}u32", value), + SExprKind::Atom(Atom::U64(value)) => format!("{}u64", value), + SExprKind::Atom(Atom::Float(value)) => value.to_string(), + SExprKind::Atom(Atom::String(value)) => format!("{:?}", value), + SExprKind::Atom(Atom::Arrow) => "->".to_string(), + SExprKind::List(items) => { + let parts = items.iter().map(render_type_form).collect::>(); + format!("({})", parts.join(" ")) + } + } +} + fn list_head(form: &SExpr) -> Option<&str> { let items = expect_list(form)?; let first = items.first()?; diff --git a/compiler/tests/diagnostics_contract.rs b/compiler/tests/diagnostics_contract.rs index 19d2659..5aab05a 100644 --- a/compiler/tests/diagnostics_contract.rs +++ b/compiler/tests/diagnostics_contract.rs @@ -175,6 +175,56 @@ const CASES: &[DiagnosticCase] = &[ "#, snapshot: "../tests/cyclic-type-alias.diag", }, + DiagnosticCase { + name: "unsupported-generic-function", + source: r#" +(module main) + +(fn id (type_params T) ((value T)) -> T + value) +"#, + snapshot: "../tests/unsupported-generic-function.diag", + }, + DiagnosticCase { + name: "unsupported-generic-type-alias", + source: r#" +(module main) + +(type VecOf (type_params T) (vec T)) +"#, + snapshot: "../tests/unsupported-generic-type-alias.diag", + }, + DiagnosticCase { + name: "unsupported-generic-type-parameter", + source: r#" +(module main) + +(fn main () -> i32 + (let xs (vec T) (std.vec.i32.empty)) + 0) +"#, + snapshot: "../tests/unsupported-generic-type-parameter.diag", + }, + DiagnosticCase { + name: "unsupported-map-type", + source: r#" +(module main) + +(fn main () -> (map string i32) + 0) +"#, + snapshot: "../tests/unsupported-map-type.diag", + }, + DiagnosticCase { + name: "unsupported-set-type", + source: r#" +(module main) + +(fn main () -> (set string) + 0) +"#, + snapshot: "../tests/unsupported-set-type.diag", + }, DiagnosticCase { name: "enum-empty", source: r#" @@ -2143,11 +2193,22 @@ const CASES: &[DiagnosticCase] = &[ (module main) (fn main () -> i32 - (std.result.map (ok string i32 "a")) + (std.result.map (ok string i32 "a") mapper) 0) "#, snapshot: "../tests/std-result-map-unsupported.diag", }, + DiagnosticCase { + name: "std-vec-empty-generic-unsupported", + source: r#" +(module main) + +(fn main () -> i32 + (std.vec.empty i32) + 0) +"#, + snapshot: "../tests/std-vec-empty-generic-unsupported.diag", + }, DiagnosticCase { name: "std-package-load-unsupported", source: r#" diff --git a/compiler/tests/formatter.rs b/compiler/tests/formatter.rs index a8bd604..4e51474 100644 --- a/compiler/tests/formatter.rs +++ b/compiler/tests/formatter.rs @@ -334,6 +334,103 @@ fn formatter_reports_unsupported_standard_library_calls() { } } +#[test] +fn formatter_rejects_reserved_generic_collection_syntax() { + let compiler = env!("CARGO_BIN_EXE_glagol"); + let cases = [ + ( + "generic-function", + r#" +(module main) + +(fn id (type_params T) ((value T)) -> T + value) +"#, + "UnsupportedGenericFunction", + ), + ( + "generic-type-alias", + r#" +(module main) + +(type VecOf (type_params T) (vec T)) +"#, + "UnsupportedGenericTypeAlias", + ), + ( + "generic-type-parameter", + r#" +(module main) + +(fn main () -> i32 + (let xs (vec T) (std.vec.i32.empty)) + 0) +"#, + "UnsupportedGenericTypeParameter", + ), + ( + "map-type", + r#" +(module main) + +(fn main () -> (map string i32) + 0) +"#, + "UnsupportedMapType", + ), + ( + "set-type", + r#" +(module main) + +(fn main () -> (set string) + 0) +"#, + "UnsupportedSetType", + ), + ( + "generic-std-call", + r#" +(module main) + +(fn main () -> i32 + (std.vec.empty i32) + 0) +"#, + "UnsupportedGenericStandardLibraryCall", + ), + ]; + + for (name, source, code) in cases { + let fixture = write_fixture(name, source); + let output = run_formatter(compiler, &fixture); + let stdout = String::from_utf8_lossy(&output.stdout); + let stderr = String::from_utf8_lossy(&output.stderr); + + assert!( + !output.status.success(), + "formatter unexpectedly accepted reserved generic syntax `{}`\nstdout:\n{}\nstderr:\n{}", + name, + stdout, + stderr, + ); + assert!( + stdout.is_empty(), + "formatter emitted stdout for reserved generic syntax `{}`\nstdout:\n{}\nstderr:\n{}", + name, + stdout, + stderr, + ); + assert!( + stderr.contains(code), + "formatter stderr did not contain {} for `{}`\nstderr:\n{}", + code, + name, + stderr, + ); + } +} + #[test] fn formatter_preserves_full_line_comments_inside_function_bodies() { let compiler = env!("CARGO_BIN_EXE_glagol"); diff --git a/compiler/tests/project_mode.rs b/compiler/tests/project_mode.rs index 6285822..3122ed3 100644 --- a/compiler/tests/project_mode.rs +++ b/compiler/tests/project_mode.rs @@ -1336,6 +1336,41 @@ fn type_aliases_are_local_across_project_visibility() { assert_stderr_contains("alias import duplicate", &duplicate_output, "DuplicateName"); } +#[test] +fn project_rejects_exported_generic_alias_and_function_before_visibility_leakage() { + let generic_function = write_project( + "generic-function-export", + &[( + "ids", + "(module ids (export id))\n\n(fn id (type_params T) ((value T)) -> T\n value)\n", + )], + "(module main)\n", + ); + let function_output = run_glagol(["check".as_ref(), generic_function.as_os_str()]); + assert_exit_code("generic function export", &function_output, 1); + assert_stderr_contains( + "generic function export", + &function_output, + "UnsupportedGenericFunction", + ); + + let generic_alias = write_project( + "generic-alias-export", + &[( + "types", + "(module types (export VecOf))\n\n(type VecOf (type_params T) (vec T))\n", + )], + "(module main)\n", + ); + let alias_output = run_glagol(["check".as_ref(), generic_alias.as_os_str()]); + assert_exit_code("generic alias export", &alias_output, 1); + assert_stderr_contains( + "generic alias export", + &alias_output, + "UnsupportedGenericTypeAlias", + ); +} + #[test] fn project_diagnostic_families_have_json_golden_coverage() { let duplicate = write_project( diff --git a/compiler/tests/promotion_gate.rs b/compiler/tests/promotion_gate.rs index 08364c1..b78a7e4 100644 --- a/compiler/tests/promotion_gate.rs +++ b/compiler/tests/promotion_gate.rs @@ -166,6 +166,7 @@ const DIAGNOSTIC_SNAPSHOTS: &[&str] = &[ "std-random-string-unsupported.diag", "std-random-uuid-unsupported.diag", "std-result-map-unsupported.diag", + "std-vec-empty-generic-unsupported.diag", "std-string-concat-arity.diag", "std-string-concat-helper-shadow.diag", "std-string-concat-result-context.diag", @@ -324,8 +325,13 @@ const DIAGNOSTIC_SNAPSHOTS: &[&str] = &[ "unsupported-array-print.diag", "unsupported-array-signature-element-type.diag", "unsupported-float-literal.diag", + "unsupported-generic-function.diag", + "unsupported-generic-type-alias.diag", + "unsupported-generic-type-parameter.diag", "unsupported-generic-vec-type.diag", + "unsupported-map-type.diag", "unsupported-signature-type.diag", + "unsupported-set-type.diag", "unsupported-result-parameter-payload-type.diag", "unsupported-result-return-payload-type.diag", "unsupported-unit-parameter-signature.diag", diff --git a/compiler/tests/result_based_host_errors.rs b/compiler/tests/result_based_host_errors.rs index 29666ff..da1933f 100644 --- a/compiler/tests/result_based_host_errors.rs +++ b/compiler/tests/result_based_host_errors.rs @@ -354,7 +354,7 @@ fn exp10_diagnostics_cover_promoted_and_deferred_boundaries() { (std.result.map (ok string i32 "a")) 0) "#, - "UnsupportedStandardLibraryCall", + "UnsupportedGenericStandardLibraryCall", ), ( "promoted-name-shadow", diff --git a/compiler/tests/result_helpers_alpha.rs b/compiler/tests/result_helpers_alpha.rs index 18e6d25..88769ed 100644 --- a/compiler/tests/result_helpers_alpha.rs +++ b/compiler/tests/result_helpers_alpha.rs @@ -94,7 +94,7 @@ fn result_helpers_alpha_rejects_deferred_and_misused_std_names() { (std.result.map (ok i32 i32 1)) 0) "#, - "UnsupportedStandardLibraryCall", + "UnsupportedGenericStandardLibraryCall", ), ( "unwrap-or-deferred", diff --git a/docs/POST_BETA_ROADMAP.md b/docs/POST_BETA_ROADMAP.md index a2caa27..82c3385 100644 --- a/docs/POST_BETA_ROADMAP.md +++ b/docs/POST_BETA_ROADMAP.md @@ -227,18 +227,28 @@ Why eighth: concrete aliases remove real noise from current stdlib and fixture code while deliberately postponing generic type parameters until the compiler and standard library have stronger design pressure. -### 9. Generics And Collection Unification +### 9. Collection Alias Unification And Generic Reservation -Goal: stop duplicating every helper across concrete vector, option, and result -families. +Goal: apply concrete aliases to the existing collection/value facades and +reserve the generic/map/set direction without changing executable semantics. Work: -- design generic function syntax and typed-core representation -- gate generic stdlib helpers behind conformance tests -- migrate repeated concrete helpers only after compatibility policy is written -- add generic arrays/vectors first, then maps and sets -- keep stable ABI/layout promises deferred until after real beta use +- use beta.8 concrete aliases sparingly inside current vector, option, and + result source facades to reduce repeated long concrete types +- preserve all public helper names, exports, imports, runtime calls, and + concrete cross-module signatures +- document that current vectors/options/results are still concrete families + and that local aliases erase before lowering +- reserve executable generics, maps, sets, traits, inference, + monomorphization, iterators, and ABI stability for later gated releases + +Released in `1.0.0-beta.9`: the concrete `std.vec_i32`, `std.vec_i64`, +`std.vec_f64`, `std.vec_bool`, `std.vec_string`, `std.option`, and +`std.result` facades now use module-local transparent aliases internally. +The exported helper surface remains concrete after alias normalization. +The release does not implement executable generics, maps, sets, traits, +inference, monomorphization, iterators, or stable ABI/layout promises. Why ninth: generics are important, but they should be introduced after the compiler, docs, tests, and stdlib have enough real pressure to validate the diff --git a/docs/compiler/RELEASE_NOTES.md b/docs/compiler/RELEASE_NOTES.md index 704161e..3bcda4d 100644 --- a/docs/compiler/RELEASE_NOTES.md +++ b/docs/compiler/RELEASE_NOTES.md @@ -10,12 +10,41 @@ integration/readiness release, not the first real beta. ## Unreleased -Next scoped Glagol work is expected to use the `1.0.0-beta.9` release line. -Generics and collection unification are the likely next design pressure, but -remain unreleased until their contracts and gates are explicit. +Next scoped Glagol work is expected to continue after the `1.0.0-beta.9` +reservation update. No unreleased compiler scope is committed here yet. +## 1.0.0-beta.9 + +Release label: `1.0.0-beta.9` + +Release date: 2026-05-22 + +Release state: compiler generic and collection reservation update + +### Summary + +Glagol `1.0.0-beta.9` reserves generic-shaped collection and stdlib syntax +with explicit diagnostics instead of letting future-looking forms degrade into +unknown-name or generic type errors. + +- Reject generic function declarations such as `(fn id (type_params T) ...)` + with `UnsupportedGenericFunction`. +- Reject parameterized aliases such as `(type VecOf (type_params T) ...)` with + `UnsupportedGenericTypeAlias`. +- Reject generic type-parameter use in concrete type positions, map types, + set types, and future generic stdlib calls with focused diagnostic codes. +- Mirror the rejection in `glagol fmt` and promotion-gate inventory. +- Keep runtime, backend, ABI, and current concrete collection behavior + unchanged. + +### Explicit Deferrals + +This release does not implement generics, generic aliases, generic stdlib +dispatch, generic vectors, maps, sets, iterators, collection unification, +stable collection ABI/layout, or new standard-library APIs. + ## 1.0.0-beta.8 Release label: `1.0.0-beta.8` diff --git a/docs/compiler/ROADMAP.md b/docs/compiler/ROADMAP.md index b1d26f0..4d640e5 100644 --- a/docs/compiler/ROADMAP.md +++ b/docs/compiler/ROADMAP.md @@ -22,24 +22,25 @@ general-purpose beta release. A Glagol feature is done only when it has parser/lowerer support, checker behavior, diagnostics for invalid forms, backend behavior or explicit unsupported diagnostics, and tests. -Current stage: `1.0.0-beta.8`, released on 2026-05-22 as the first post-beta -concrete type alias foundation update. It keeps the `1.0.0-beta` language/compiler -support baseline and includes the `1.0.0-beta.1` tooling hardening release, the -`1.0.0-beta.2` runtime/resource foundation release, the `1.0.0-beta.3` -standard-library stabilization release, the `1.0.0-beta.4` -language-usability diagnostics release, the `1.0.0-beta.5` package/workspace -discipline release, and the `1.0.0-beta.6` compiler-known `std.net` loopback -TCP runtime family with focused lowering, interpreter, diagnostics, -source-facade, promotion, and hosted smoke coverage, plus the `1.0.0-beta.7` -compiler-known `std.json.quote_string` runtime family with matching -source-facade, test-runner, hosted smoke, and benchmark-scaffold coverage, plus -top-level `(type Alias TargetType)` parsing, checking, formatting, lowering -inspection, project import normalization, and diagnostics coverage for concrete -aliases. +Current stage: `1.0.0-beta.9`, released on 2026-05-22 as a compiler +reservation update for generic-shaped collection and stdlib syntax. It keeps +the `1.0.0-beta` language/compiler support baseline and includes the +`1.0.0-beta.1` tooling hardening release, the `1.0.0-beta.2` runtime/resource +foundation release, the `1.0.0-beta.3` standard-library stabilization release, +the `1.0.0-beta.4` language-usability diagnostics release, the +`1.0.0-beta.5` package/workspace discipline release, the `1.0.0-beta.6` +compiler-known `std.net` loopback TCP runtime family with focused lowering, +interpreter, diagnostics, source-facade, promotion, and hosted smoke coverage, +the `1.0.0-beta.7` compiler-known `std.json.quote_string` runtime family with +matching source-facade, test-runner, hosted smoke, and benchmark-scaffold +coverage, the `1.0.0-beta.8` concrete type alias foundation update, and +focused diagnostics/formatter/project-mode gates for reserved generic +functions, parameterized aliases, generic type parameters, maps, sets, and +future generic stdlib calls. -Next stage target: `1.0.0-beta.9`, likely generics and collection -unification. The exact compiler-side contract must be frozen from the manifest -and roadmap before implementation. +Next stage target: post-`1.0.0-beta.9` collection/generic planning. Generic +vectors, maps, sets, generic stdlib dispatch, and collection unification remain +unimplemented until a later scoped contract promotes them explicitly. The final experimental precursor scope is `exp-125`. Its unsigned direct-value flow, parse/format runtime lanes, and matching staged stdlib helper breadth diff --git a/docs/language/RELEASE_NOTES.md b/docs/language/RELEASE_NOTES.md index 6669dbe..ce0ea5a 100644 --- a/docs/language/RELEASE_NOTES.md +++ b/docs/language/RELEASE_NOTES.md @@ -8,7 +8,7 @@ Historical `exp-*` releases listed here are experimental maturity milestones. The pushed tag `v2.0.0-beta.1` is historical. It is now documented as an experimental integration/readiness release, not as a beta maturity claim. -The current release is `1.0.0-beta.8`, published on 2026-05-22. It keeps the +The current release is `1.0.0-beta.9`, published on 2026-05-22. It keeps the `1.0.0-beta` language surface, includes the first post-beta tooling/install hardening bundle from `1.0.0-beta.1`, and adds the first runtime/resource foundation bundle from `1.0.0-beta.2` plus the first standard-library @@ -17,16 +17,43 @@ diagnostics bundle from `1.0.0-beta.4`, and the first local package/workspace discipline bundle from `1.0.0-beta.5`, plus the first loopback networking foundation bundle from `1.0.0-beta.6`, and the first serialization/data-interchange foundation bundle from `1.0.0-beta.7`, and the -first concrete type alias foundation from `1.0.0-beta.8`. +first concrete type alias foundation from `1.0.0-beta.8`, plus the first +collection alias unification and generic reservation slice from +`1.0.0-beta.9`. ## Unreleased -Next scoped Slovo-side work is expected to use the `1.0.0-beta.9` release -line. Generics and collection unification are the likely next design pressure, -but remain unreleased until their contracts and gates are explicit. - No unreleased language scope is committed here yet. +## 1.0.0-beta.9 + +Release label: `1.0.0-beta.9` + +Release name: Collection Alias Unification And Generic Reservation + +Release date: 2026-05-22 + +Status: released beta collection-alias documentation/source update on the +`1.0.0-beta` language baseline. + +`1.0.0-beta.9` applies beta.8 transparent concrete aliases sparingly inside +the source-authored collection and value-family facades: + +- `std.vec_i32`, `std.vec_i64`, `std.vec_f64`, `std.vec_bool`, and + `std.vec_string` name their local concrete vector family once and reuse that + alias through helper signatures. +- `std.option` and `std.result` name the current concrete option/result helper + families once and reuse those local aliases through their facade signatures. +- Public helper names, imports, exports, constructors, runtime calls, and + behavior stay concrete. Cross-module users still see normalized concrete + types such as `(vec bool)`, `(option string)`, and `(result u64 i32)`. + +This release does not add executable generics, generic aliases, parameterized +aliases, maps, sets, traits, inference, monomorphization, iterators, new +compiler-known runtime names, stable ABI/layout promises, or a stable +standard-library API freeze. The generic/map/set direction is reserved for +future diagnostics and design work only. + ## 1.0.0-beta.8 Release label: `1.0.0-beta.8` diff --git a/docs/language/ROADMAP.md b/docs/language/ROADMAP.md index 84df965..dffae0c 100644 --- a/docs/language/ROADMAP.md +++ b/docs/language/ROADMAP.md @@ -10,8 +10,8 @@ Long-horizon planning lives in release train from the historical `v2.0.0-beta.1` tag toward and beyond the first real general-purpose beta Slovo contract. -Current stage: `1.0.0-beta.8`, released on 2026-05-22 as the first post-beta -concrete type alias foundation update. It keeps the `1.0.0-beta` language contract and +Current stage: `1.0.0-beta.9`, released on 2026-05-22 as the first post-beta +collection alias unification and generic reservation update. It keeps the `1.0.0-beta` language contract and includes the `1.0.0-beta.1` tooling hardening release, the `1.0.0-beta.2` runtime/resource foundation release, the `1.0.0-beta.3` standard-library stabilization release, the `1.0.0-beta.4` language-usability diagnostics @@ -19,15 +19,17 @@ release, the `1.0.0-beta.5` package/workspace discipline release, and a narrow `std.net` source facade for blocking loopback TCP client/server primitives over opaque `i32` handles and concrete `result` families, plus a narrow `std.json` source facade for compact JSON text construction, plus top-level module-local -transparent aliases for supported concrete target types. JSON parsing, -recursive JSON values, generic aliases, parameterized aliases, cross-module -alias visibility, maps/sets, DNS, TLS, UDP, async IO, non-loopback binding, +transparent aliases for supported concrete target types, plus local alias use +inside the current concrete vector, option, and result facades. JSON parsing, +recursive JSON values, executable generics, generic aliases, parameterized +aliases, cross-module alias visibility, maps/sets, traits, inference, +monomorphization, iterators, DNS, TLS, UDP, async IO, non-loopback binding, HTTP frameworks, rich host-error ADTs, stable ABI/layout, and a stable standard-library API freeze remain deferred. -Next stage target: `1.0.0-beta.9`, likely generics and collection -unification. The exact scope must be frozen from the manifest and roadmap -before implementation. +Next stage target: continue from the reserved generic/map/set diagnostics and +collection-unification design pressure without claiming executable generics +until the exact scope is frozen from the manifest and roadmap. The final experimental precursor scope is `exp-125`, defined in `.llm/EXP_125_UNSIGNED_U32_U64_NUMERIC_AND_STDLIB_BREADTH_ALPHA.md`. Its diff --git a/docs/language/SPEC-v1.md b/docs/language/SPEC-v1.md index 72b9fb2..efbf8d9 100644 --- a/docs/language/SPEC-v1.md +++ b/docs/language/SPEC-v1.md @@ -114,20 +114,28 @@ Current v1 release surface and explicit experimental targets: aliases, alias exports/imports/re-exports, cross-module alias visibility, maps/sets, or runtime changes are included, once the matching Glagol gates pass +- `1.0.0-beta.9` collection alias unification and generic reservation target: + existing concrete vector, option, and result source facades may use + module-local concrete aliases internally while exported helper behavior and + cross-module types remain concrete; executable generics, maps, sets, traits, + inference, monomorphization, iterators, and stable ABI/layout remain deferred - `exp-1` owned runtime strings: compiler-known `std.string.concat` accepts two `string` values and returns an immutable runtime-owned `string`; existing string equality, length, printing, locals, parameters, returns, and calls work over both literal-backed and runtime-owned strings - `exp-2` collections alpha plus `exp-94` vec-i64 baseline, `exp-99` - vec-string baseline, and `exp-103` vec-f64 baseline: concrete growable - vector types `(vec i32)`, `(vec i64)`, `(vec f64)`, and `(vec string)`, + vec-string baseline, `exp-103` vec-f64 baseline, and `exp-104` vec-bool + baseline: concrete growable vector types `(vec i32)`, `(vec i64)`, + `(vec f64)`, `(vec bool)`, and `(vec string)`, compiler-known `std.vec.i32.empty`, `std.vec.i32.append`, `std.vec.i32.len`, `std.vec.i32.index`, compiler-known `std.vec.i64.empty`, `std.vec.i64.append`, `std.vec.i64.len`, and `std.vec.i64.index`, compiler-known `std.vec.f64.empty`, `std.vec.f64.append`, - `std.vec.f64.len`, and `std.vec.f64.index`, + `std.vec.f64.len`, and `std.vec.f64.index`, compiler-known + `std.vec.bool.empty`, `std.vec.bool.append`, `std.vec.bool.len`, and + `std.vec.bool.index`, compiler-known `std.vec.string.empty`, `std.vec.string.append`, `std.vec.string.len`, and `std.vec.string.index`, vector equality with `=` on same-family operands, and immutable vector flow through locals, @@ -1180,6 +1188,32 @@ alias imports, import aliases, glob imports, maps/sets, alias-driven overloads, implicit casts, new runtime helpers, standard-runtime names, stable ABI/layout promises, or a stable standard-library API freeze. +### 4.4.7 Post-Beta Collection Alias Unification And Generic Reservation + +Status: released in `1.0.0-beta.9` as a Slovo stdlib/docs contract update on +top of the beta.8 alias semantics. + +`1.0.0-beta.9` applies beta.8 concrete aliases to the source-authored +collection/value-family facades where they remove repeated concrete type +spellings: + +- `std.vec_i32`, `std.vec_i64`, `std.vec_f64`, `std.vec_bool`, and + `std.vec_string` use one module-local alias for their concrete vector family. +- `std.option` and `std.result` use module-local aliases for the current + concrete option/result helper families. + +These aliases are not public standard-library API names. They are normalized to +their concrete targets for imports, typed-core lowering, backend layout, ABI +decisions, runtime behavior, and generated cross-module signatures. Current +vectors, options, and results remain concrete families such as `(vec bool)`, +`(option string)`, and `(result u64 i32)`. + +This target reserves generic and collection-unification spelling space through +diagnostics and documentation only. It does not add executable generics, +generic aliases, parameterized aliases, maps, sets, traits, inference, +monomorphization, iterators, new runtime helpers, stable ABI/layout promises, +or a stable standard-library API freeze. + ## 4.5 v2.0.0-beta.1 Experimental Integration Readiness Status: current experimental Slovo-side release contract, released 2026-05-17. diff --git a/docs/language/STANDARD_RUNTIME.md b/docs/language/STANDARD_RUNTIME.md index d219631..e148967 100644 --- a/docs/language/STANDARD_RUNTIME.md +++ b/docs/language/STANDARD_RUNTIME.md @@ -1,14 +1,16 @@ # Slovo Standard Runtime Catalog -Status: standard-runtime catalog through exp-101 over the released exp-14 +Status: standard-runtime catalog through exp-104 over the released exp-14 conformance baseline. The latest Slovo experimental alpha release is -`exp-101`, Standard Vec String Option And Transform Helpers Alpha. exp-29, exp-30, exp-32, +`exp-104`, Standard Vec Bool Baseline Alpha. exp-29, exp-30, exp-32, exp-33, and exp-35 through exp-93 add no compiler-known `std.*` names; exp-31 adds exactly one checked numeric conversion name; exp-34 adds exactly one strict bool parse name; exp-94 adds exactly four concrete `(vec i64)` -vector names; exp-95 through exp-98 add no compiler-known `std.*` names; and -exp-99 adds exactly four concrete `(vec string)` vector names. exp-100 and -exp-101 add no new compiler-known `std.*` names. +vector names; exp-95 through exp-98 add no compiler-known `std.*` names; +exp-99 adds exactly four concrete `(vec string)` vector names; exp-100 and +exp-101 add no new compiler-known `std.*` names; exp-103 adds exactly four +concrete `(vec f64)` vector names; and exp-104 adds exactly four concrete +`(vec bool)` vector names. This document catalogs promoted compiler-known `std.*` operations only. It does not add source syntax, runtime APIs, standard library functions, manifest @@ -32,7 +34,7 @@ The `1.0.0-beta.7` serialization/data-interchange foundation release adds deterministic compact JSON string quoting before source-level string scanning, slicing, maps, or recursive JSON values are available. -The exp-era catalog is closed to names promoted through exp-101. exp-29, +The exp-era catalog is closed to names promoted through exp-104. exp-29, exp-30, exp-32, exp-33, and exp-35 through exp-93 add no new standard-runtime operation names. exp-32/exp-39/exp-56/exp-57 `std/math.slo` helpers, exp-33/exp-35 `std/result.slo` helpers, exp-36 `std/option.slo` helpers, @@ -49,7 +51,10 @@ entries; exp-99 adds `std.vec.string.empty`, `std.vec.string.append`, `std.vec.string.len`, and `std.vec.string.index`; exp-100 broadens option language/source-helper support only and adds no new catalog entries; exp-101 broadens vec-string source-helper support only and adds no new catalog -entries. +entries; exp-103 adds `std.vec.f64.empty`, `std.vec.f64.append`, +`std.vec.f64.len`, and `std.vec.f64.index`; and exp-104 adds +`std.vec.bool.empty`, `std.vec.bool.append`, `std.vec.bool.len`, and +`std.vec.bool.index`. Legacy compatibility aliases such as `print_i32`, `print_string`, `print_bool`, and `string_len` are not `std.*` names and are therefore excluded from this catalog. Legacy @@ -77,15 +82,23 @@ source-level result helper names are the `std.result.*` names cataloged below. | `std.string.len` | `(string) -> i32` | v1.5 | `examples/supported/standard-runtime.slo` | Returns the existing decoded byte-count length used by legacy `string_len`. | Uses existing standard-runtime usage recording if present; no schema change. | Unicode scalar/grapheme length, slicing, indexing, stable string ABI/layout. | | `std.string.concat` | `(string, string) -> string` | exp-1 | `examples/supported/owned-string-concat.slo` | Returns an immutable runtime-owned string; allocation failure traps as `slovo runtime error: string allocation failed`. | Uses existing standard-runtime usage recording if present; no concat-specific schema field. | Mutable strings, string containers, user-visible allocation/deallocation, stable string ABI/layout. | | `std.json.quote_string` | `(string) -> string` | `1.0.0-beta.7` | `examples/projects/std-layout-local-json` | Returns a compact JSON string literal for the input text, including surrounding quotes; it escapes quote, backslash, newline, tab, carriage return, backspace, form feed, and other control bytes as JSON escapes. Allocation failure traps as `slovo runtime error: string allocation failed`. | Uses existing standard-runtime usage recording if present; no schema change. | JSON parsing, recursive JSON values, maps/sets, streaming encoders, schema validation, Unicode normalization, embedded NUL support in the current null-terminated string ABI, stable helper ABI/layout/ownership. | -| `std.vec.i32.empty` | `() -> (vec i32)` | exp-2 | `examples/supported/vec-i32.slo` | Returns an empty immutable runtime-owned `(vec i32)`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic vectors, element families beyond `i32`, `i64`, and `string`, vector mutation, stable vector ABI/layout. | +| `std.vec.i32.empty` | `() -> (vec i32)` | exp-2 | `examples/supported/vec-i32.slo` | Returns an empty immutable runtime-owned `(vec i32)`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic vectors, element families beyond current concrete vector families, vector mutation, stable vector ABI/layout. | | `std.vec.i32.append` | `((vec i32), i32) -> (vec i32)` | exp-2 | `examples/supported/vec-i32.slo` | Returns a new immutable vector containing the input elements and appended value; allocation failure traps with the exp-2 vector allocation message. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Mutation, `push`, capacity APIs, user deallocation, stable vector ABI/layout. | | `std.vec.i32.len` | `((vec i32)) -> i32` | exp-2 | `examples/supported/vec-i32.slo` | Returns vector length as `i32`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic length APIs and stable vector ABI/layout. | | `std.vec.i32.index` | `((vec i32), i32) -> i32` | exp-2 | `examples/supported/vec-i32.slo` | Returns the indexed value; out-of-bounds access traps with the exp-2 vector bounds message. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Slices/views, iterators, mutation, stable vector ABI/layout. | -| `std.vec.i64.empty` | `() -> (vec i64)` | exp-94 | `examples/supported/vec-i64.slo` | Returns an empty immutable runtime-owned `(vec i64)`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic vectors, element families beyond `i32`, `i64`, and `string`, vector mutation, stable vector ABI/layout. | +| `std.vec.i64.empty` | `() -> (vec i64)` | exp-94 | `examples/supported/vec-i64.slo` | Returns an empty immutable runtime-owned `(vec i64)`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic vectors, element families beyond current concrete vector families, vector mutation, stable vector ABI/layout. | | `std.vec.i64.append` | `((vec i64), i64) -> (vec i64)` | exp-94 | `examples/supported/vec-i64.slo` | Returns a new immutable vector containing the input elements and appended value; allocation failure traps with the existing vector allocation message. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Mutation, `push`, capacity APIs, user deallocation, stable vector ABI/layout. | | `std.vec.i64.len` | `((vec i64)) -> i32` | exp-94 | `examples/supported/vec-i64.slo` | Returns vector length as `i32`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic length APIs and stable vector ABI/layout. | | `std.vec.i64.index` | `((vec i64), i32) -> i64` | exp-94 | `examples/supported/vec-i64.slo` | Returns the indexed value; out-of-bounds access traps with the existing vector bounds message. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Slices/views, iterators, mutation, stable vector ABI/layout. | -| `std.vec.string.empty` | `() -> (vec string)` | exp-99 | `examples/supported/vec-string.slo` | Returns an empty immutable runtime-owned `(vec string)`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic vectors, element families beyond `i32`, `i64`, and `string`, vector mutation, stable vector ABI/layout. | +| `std.vec.f64.empty` | `() -> (vec f64)` | exp-103 | `examples/supported/vec-f64.slo` | Returns an empty immutable runtime-owned `(vec f64)`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic vectors, element families beyond current concrete vector families, vector mutation, stable vector ABI/layout. | +| `std.vec.f64.append` | `((vec f64), f64) -> (vec f64)` | exp-103 | `examples/supported/vec-f64.slo` | Returns a new immutable vector containing the input elements and appended value; allocation failure traps with the existing vector allocation message. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Mutation, `push`, capacity APIs, user deallocation, stable vector ABI/layout. | +| `std.vec.f64.len` | `((vec f64)) -> i32` | exp-103 | `examples/supported/vec-f64.slo` | Returns vector length as `i32`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic length APIs and stable vector ABI/layout. | +| `std.vec.f64.index` | `((vec f64), i32) -> f64` | exp-103 | `examples/supported/vec-f64.slo` | Returns the indexed value; out-of-bounds access traps with the existing vector bounds message. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Slices/views, iterators, mutation, stable vector ABI/layout. | +| `std.vec.bool.empty` | `() -> (vec bool)` | exp-104 | `examples/supported/vec-bool.slo` | Returns an empty immutable runtime-owned `(vec bool)`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic vectors, element families beyond current concrete vector families, vector mutation, stable vector ABI/layout. | +| `std.vec.bool.append` | `((vec bool), bool) -> (vec bool)` | exp-104 | `examples/supported/vec-bool.slo` | Returns a new immutable vector containing the input elements and appended value; allocation failure traps with the existing vector allocation message. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Mutation, `push`, capacity APIs, user deallocation, stable vector ABI/layout. | +| `std.vec.bool.len` | `((vec bool)) -> i32` | exp-104 | `examples/supported/vec-bool.slo` | Returns vector length as `i32`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic length APIs and stable vector ABI/layout. | +| `std.vec.bool.index` | `((vec bool), i32) -> bool` | exp-104 | `examples/supported/vec-bool.slo` | Returns the indexed value; out-of-bounds access traps with the existing vector bounds message. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Slices/views, iterators, mutation, stable vector ABI/layout. | +| `std.vec.string.empty` | `() -> (vec string)` | exp-99 | `examples/supported/vec-string.slo` | Returns an empty immutable runtime-owned `(vec string)`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic vectors, element families beyond current concrete vector families, vector mutation, stable vector ABI/layout. | | `std.vec.string.append` | `((vec string), string) -> (vec string)` | exp-99 | `examples/supported/vec-string.slo` | Returns a new immutable vector containing the input elements and appended string; allocation failure traps with the existing vector allocation message. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Mutation, `push`, capacity APIs, user deallocation, stable vector ABI/layout. | | `std.vec.string.len` | `((vec string)) -> i32` | exp-99 | `examples/supported/vec-string.slo` | Returns vector length as `i32`. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Generic length APIs and stable vector ABI/layout. | | `std.vec.string.index` | `((vec string), i32) -> string` | exp-99 | `examples/supported/vec-string.slo` | Returns the indexed value; out-of-bounds access traps with the existing vector bounds message. | Uses existing standard-runtime usage recording if present; no vector-specific schema field. | Slices/views, iterators, mutation, stable vector ABI/layout. | diff --git a/docs/language/STDLIB_API.md b/docs/language/STDLIB_API.md index ce2df53..0b94a6f 100644 --- a/docs/language/STDLIB_API.md +++ b/docs/language/STDLIB_API.md @@ -6,7 +6,7 @@ Do not edit this file by hand. ## Stability Tiers - `beta-supported`: exported from `lib/std` and covered by source-search, promotion, or facade gates in the current beta line. -- `experimental`: not used for exported `lib/std` helpers in `1.0.0-beta.8`; future releases may mark new helpers this way before they graduate. +- `experimental`: not used for exported `lib/std` helpers in `1.0.0-beta.9`; future releases may mark new helpers this way before they graduate. - `internal`: helper names that are not exported from their module; they are intentionally omitted from this catalog. The catalog is a beta compatibility aid, not a stable `1.0.0` API freeze. diff --git a/docs/language/examples/README.md b/docs/language/examples/README.md index 2e585ce..7f58cd6 100644 --- a/docs/language/examples/README.md +++ b/docs/language/examples/README.md @@ -14,6 +14,8 @@ catalog and the checked `projects/stdlib-composition/` example. `projects/std-layout-local-json/` examples for compact JSON text construction. `1.0.0-beta.8` reuses those JSON projects for local `JsonText`/`JsonField` concrete type alias fixtures. +`1.0.0-beta.9` keeps the existing explicit std-import projects concrete while +the underlying vector, option, and result facades use module-local aliases. The language baseline absorbs the final exp-125 unsigned precursor scope alongside the already promoted project/package, stdlib-source, collection, composite-data, diff --git a/docs/papers/GLAGOL_COMPILER_MANIFEST.pdf b/docs/papers/GLAGOL_COMPILER_MANIFEST.pdf index e279851..a779905 100644 Binary files a/docs/papers/GLAGOL_COMPILER_MANIFEST.pdf and b/docs/papers/GLAGOL_COMPILER_MANIFEST.pdf differ diff --git a/docs/papers/GLAGOL_WHITEPAPER.md b/docs/papers/GLAGOL_WHITEPAPER.md index a61bfbf..d421c23 100644 --- a/docs/papers/GLAGOL_WHITEPAPER.md +++ b/docs/papers/GLAGOL_WHITEPAPER.md @@ -5,7 +5,7 @@ Sanjin Gumbarevic
hermeticum_lab@protonmail.com -Publication release: `1.0.0-beta.8` +Publication release: `1.0.0-beta.9` Technical behavior baseline: compiler and language support through `1.0.0-beta`; tooling and install workflow through `1.0.0-beta.1`; @@ -14,13 +14,14 @@ stabilization through `1.0.0-beta.3`; language-usability diagnostics through `1.0.0-beta.4`; package/workspace discipline through `1.0.0-beta.5`; loopback networking foundation through `1.0.0-beta.6`; serialization/data-interchange foundation through `1.0.0-beta.7`; -concrete type alias foundation through `1.0.0-beta.8` +concrete type alias foundation through `1.0.0-beta.8`; +generic and collection reservation diagnostics through `1.0.0-beta.9` Date: 2026-05-22 -Evidence source: paired local Slovo/Glagol monorepo verification and benchmark -reruns from a local checkout; beta.8 release-gate verification from the public -monorepo +Evidence source: paired Slovo/Glagol monorepo verification and benchmark +reruns from the public source tree; beta.9 release-gate verification from the +public monorepo Maturity: beta @@ -31,26 +32,29 @@ Slovo. It exists to make the language support boundary inspectable: tokens, S-expression tree, AST, typed AST, LLVM IR, hosted native executable, tests, diagnostics, and release documents should agree. -The current publication release, `1.0.0-beta.8`, keeps the first real +The current publication release, `1.0.0-beta.9`, keeps the first real general-purpose beta toolchain baseline from `1.0.0-beta` and records the first post-beta tooling/install hardening update plus the first runtime/resource foundation update plus the first standard-library stabilization update plus the first language-usability diagnostics update and the first local package/workspace discipline update plus the first loopback networking foundation update plus the first serialization/data-interchange -foundation update plus the first concrete type alias foundation. The beta +foundation update plus the first concrete type alias foundation and the first +generic/collection reservation diagnostic update. The beta baseline includes the completed `u32` / `u64` unsigned compiler and stdlib breadth scope, the narrow `std.net` loopback TCP runtime family, the narrow `std.json.quote_string` runtime family, transparent concrete alias parsing and -erasure, and the current ten-scaffold benchmark suite. This paper records the +erasure, explicit beta9 diagnostics for reserved generic/map/set shapes, and +the current ten-scaffold benchmark suite. This paper records the current beta implementation surface, the benchmark method and results, the distinction between Glagol and Lisp-family implementations, the beta.1 tooling update, the beta.2 runtime/resource foundation, the beta.3 standard-library stabilization slice, the beta.4 diagnostics usability slice, the beta.5 package discipline slice, the beta.6 networking foundation slice, the beta.7 serialization -foundation slice, the beta.8 concrete alias foundation slice, and the compiler -path from beta to stable. +foundation slice, the beta.8 concrete alias foundation slice, the beta.9 +generic/collection reservation slice, and the compiler path from beta to +stable. ## 1. Compiler Thesis @@ -310,8 +314,10 @@ standard-library catalog and composition coverage, `1.0.0-beta.4` improves diagnostics, `1.0.0-beta.5` tightens package/workspace discipline, and `1.0.0-beta.6` adds a narrow loopback networking foundation, and `1.0.0-beta.7` adds a narrow JSON construction foundation, and -`1.0.0-beta.8` adds transparent concrete type aliases. None of these post-beta -slices claims changed benchmark performance. The beta.7 `json-quote-loop` +`1.0.0-beta.8` adds transparent concrete type aliases, and `1.0.0-beta.9` +adds focused diagnostics for reserved generic, map, set, and future generic +stdlib forms. None of these post-beta slices claims changed benchmark +performance. The beta.7 `json-quote-loop` scaffold is present for local follow-up timing and is not part of the exp-123 nine-row result table below. @@ -401,15 +407,16 @@ coverage and compatibility: - package behavior becoming stable before dependency, manifest, and versioning rules are precise -## 9. Path Beyond `1.0.0-beta.8` +## 9. Path Beyond `1.0.0-beta.9` Glagol now implements the first real beta Slovo contract, the first post-beta tooling/install hardening release, the first runtime/resource foundation release, the first standard-library stabilization release, and the first diagnostics usability release, the first package/workspace discipline release, the first loopback networking foundation release, and the first -serialization/data-interchange foundation release, and the first concrete type -alias foundation release. The remaining path is from beta to stable. +serialization/data-interchange foundation release, the first concrete type +alias foundation release, and the first generic/collection reservation +diagnostic release. The remaining path is from beta to stable. Recommended compiler sequence: diff --git a/docs/papers/GLAGOL_WHITEPAPER.pdf b/docs/papers/GLAGOL_WHITEPAPER.pdf index a7bff57..87d207f 100644 Binary files a/docs/papers/GLAGOL_WHITEPAPER.pdf and b/docs/papers/GLAGOL_WHITEPAPER.pdf differ diff --git a/docs/papers/SLOVO_MANIFEST.pdf b/docs/papers/SLOVO_MANIFEST.pdf index a8a2c62..064c7a9 100644 Binary files a/docs/papers/SLOVO_MANIFEST.pdf and b/docs/papers/SLOVO_MANIFEST.pdf differ diff --git a/docs/papers/SLOVO_WHITEPAPER.md b/docs/papers/SLOVO_WHITEPAPER.md index 1650968..d0cd68a 100644 --- a/docs/papers/SLOVO_WHITEPAPER.md +++ b/docs/papers/SLOVO_WHITEPAPER.md @@ -5,7 +5,7 @@ Sanjin Gumbarevic
hermeticum_lab@protonmail.com -Publication release: `1.0.0-beta.8` +Publication release: `1.0.0-beta.9` Technical behavior baseline: language surface through `1.0.0-beta`; tooling and install workflow through `1.0.0-beta.1`; runtime/resource foundation through @@ -13,13 +13,14 @@ and install workflow through `1.0.0-beta.1`; runtime/resource foundation through language-usability diagnostics through `1.0.0-beta.4`; package/workspace discipline through `1.0.0-beta.5`; loopback networking foundation through `1.0.0-beta.6`; serialization/data-interchange foundation through -`1.0.0-beta.7`; concrete type alias foundation through `1.0.0-beta.8` +`1.0.0-beta.7`; concrete type alias foundation through `1.0.0-beta.8`; +collection alias unification and generic reservation through `1.0.0-beta.9` Date: 2026-05-22 -Evidence source: paired local Slovo/Glagol monorepo verification and benchmark -reruns from a local checkout; beta.8 release-gate verification from the public -monorepo +Evidence source: paired Slovo/Glagol monorepo verification and benchmark +reruns from the public source tree; beta.9 release-gate verification from the +public monorepo Maturity: beta @@ -33,15 +34,16 @@ explicit types, explicit failure through `option` and `result`, lexical `unsafe`, and native compilation through the Glagol compiler to LLVM IR and hosted executables. -The current publication release, `1.0.0-beta.8`, keeps the first real +The current publication release, `1.0.0-beta.9`, keeps the first real general-purpose beta language baseline from `1.0.0-beta` and records the first post-beta tooling/install hardening update plus the first runtime/resource foundation update, the first standard-library stabilization update, and the first language-usability diagnostics update, plus the first local package/workspace discipline update, the first loopback networking foundation update, the first serialization/data-interchange foundation update, and the -first concrete type alias foundation. The beta baseline includes the completed -`u32` / `u64` +first concrete type alias foundation plus the first collection alias +unification and generic-reservation update. The beta baseline includes the +completed `u32` / `u64` unsigned scope, the staged stdlib breadth that makes ordinary command-line programs practical, the current narrow `std.net` loopback TCP surface, the current narrow `std.json` text-construction surface, module-local transparent @@ -52,15 +54,15 @@ benchmark methodology, the beta.1 tooling update, the beta.2 runtime/resource foundation, the beta.3 standard-library stabilization slice, the beta.4 diagnostics usability slice, the beta.5 package discipline slice, the beta.6 networking foundation slice, the beta.7 serialization foundation slice, and -the beta.8 concrete alias foundation slice, and the remaining path from beta -to stable. +the beta.8 concrete alias foundation slice, the beta.9 collection alias and +generic-reservation slice, and the remaining path from beta to stable. ## 1. Scope This document is a technical state paper for the current beta baseline. It -summarizes the behavior represented by the paired local Slovo and Glagol -workspaces, with `1.0.0-beta` as the current language-surface baseline and -`1.0.0-beta.8` as the current publication baseline. +summarizes the behavior represented by the paired Slovo and Glagol source +tree, with `1.0.0-beta` as the current language-surface baseline and +`1.0.0-beta.9` as the current publication baseline. The support rule remains strict: @@ -72,7 +74,7 @@ The support rule remains strict: - partial parser recognition or speculative examples do not count as support Historical `exp-*` releases remain experimental alpha maturity. The current -publication accompanies `1.0.0-beta.8`. +publication accompanies `1.0.0-beta.9`. ## 2. Design Thesis @@ -384,8 +386,10 @@ standard-library catalog and composition coverage, `1.0.0-beta.4` improves diagnostics, `1.0.0-beta.5` tightens package/workspace discipline, and `1.0.0-beta.6` adds a narrow loopback networking foundation, and `1.0.0-beta.7` adds a narrow JSON construction foundation, and -`1.0.0-beta.8` adds transparent concrete type aliases. None of these post-beta -slices claims changed benchmark performance. The beta.7 `json-quote-loop` +`1.0.0-beta.8` adds transparent concrete type aliases, and `1.0.0-beta.9` +applies those aliases inside current collection/value-family facades while +reserving generic, map, and set syntax through diagnostics. None of these +post-beta slices claims changed benchmark performance. The beta.7 `json-quote-loop` scaffold is present for local follow-up timing and is not part of the exp-123 nine-row result table below. @@ -508,7 +512,7 @@ Major remaining gaps before `1.0.0`: - semantic versioning and deprecation policy - a clear separation between stable and experimental features -## 10. Path Beyond `1.0.0-beta.8` +## 10. Path Beyond `1.0.0-beta.9` The beta threshold is now real. The next work should treat `1.0.0-beta` as the language compatibility-governed baseline, `1.0.0-beta.1` as the first @@ -518,8 +522,9 @@ stabilization point, and `1.0.0-beta.4` as the first diagnostics usability point, and `1.0.0-beta.5` as the first package/workspace discipline point, and `1.0.0-beta.6` as the first loopback networking foundation point, and `1.0.0-beta.7` as the first serialization/data-interchange foundation point, -and `1.0.0-beta.8` as the first concrete type alias foundation point, then -move deliberately toward stable general-purpose status. +`1.0.0-beta.8` as the first concrete type alias foundation point, and +`1.0.0-beta.9` as the first collection alias unification and generic +reservation point, then move deliberately toward stable general-purpose status. Recommended sequence: diff --git a/docs/papers/SLOVO_WHITEPAPER.pdf b/docs/papers/SLOVO_WHITEPAPER.pdf index 092f7e8..e71e038 100644 Binary files a/docs/papers/SLOVO_WHITEPAPER.pdf and b/docs/papers/SLOVO_WHITEPAPER.pdf differ diff --git a/examples/projects/std-layout-local-option/src/option.slo b/examples/projects/std-layout-local-option/src/option.slo index 1076cfd..bb8def1 100644 --- a/examples/projects/std-layout-local-option/src/option.slo +++ b/examples/projects/std-layout-local-option/src/option.slo @@ -1,176 +1,204 @@ (module option (export some_i32 none_i32 is_some_i32 is_none_i32 unwrap_some_i32 unwrap_or_i32 some_or_err_i32 some_u32 none_u32 is_some_u32 is_none_u32 unwrap_some_u32 unwrap_or_u32 some_or_err_u32 some_i64 none_i64 is_some_i64 is_none_i64 unwrap_some_i64 unwrap_or_i64 some_or_err_i64 some_u64 none_u64 is_some_u64 is_none_u64 unwrap_some_u64 unwrap_or_u64 some_or_err_u64 some_f64 none_f64 is_some_f64 is_none_f64 unwrap_some_f64 unwrap_or_f64 some_or_err_f64 some_bool none_bool is_some_bool is_none_bool unwrap_some_bool unwrap_or_bool some_or_err_bool some_string none_string is_some_string is_none_string unwrap_some_string unwrap_or_string some_or_err_string)) -(fn some_i32 ((value i32)) -> (option i32) +(type OptionI32 (option i32)) + +(type ResultI32 (result i32 i32)) + +(type OptionU32 (option u32)) + +(type ResultU32 (result u32 i32)) + +(type OptionI64 (option i64)) + +(type ResultI64 (result i64 i32)) + +(type OptionU64 (option u64)) + +(type ResultU64 (result u64 i32)) + +(type OptionF64 (option f64)) + +(type ResultF64 (result f64 i32)) + +(type OptionBool (option bool)) + +(type ResultBool (result bool i32)) + +(type OptionString (option string)) + +(type ResultString (result string i32)) + +(fn some_i32 ((value i32)) -> OptionI32 (some i32 value)) -(fn none_i32 () -> (option i32) +(fn none_i32 () -> OptionI32 (none i32)) -(fn is_some_i32 ((value (option i32))) -> bool +(fn is_some_i32 ((value OptionI32)) -> bool (is_some value)) -(fn is_none_i32 ((value (option i32))) -> bool +(fn is_none_i32 ((value OptionI32)) -> bool (is_none value)) -(fn unwrap_some_i32 ((value (option i32))) -> i32 +(fn unwrap_some_i32 ((value OptionI32)) -> i32 (unwrap_some value)) -(fn unwrap_or_i32 ((value (option i32)) (fallback i32)) -> i32 +(fn unwrap_or_i32 ((value OptionI32) (fallback i32)) -> i32 (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_i32 ((value (option i32)) (err_code i32)) -> (result i32 i32) +(fn some_or_err_i32 ((value OptionI32) (err_code i32)) -> ResultI32 (if (is_some value) (ok i32 i32 (unwrap_some value)) (err i32 i32 err_code))) -(fn some_u32 ((value u32)) -> (option u32) +(fn some_u32 ((value u32)) -> OptionU32 (some u32 value)) -(fn none_u32 () -> (option u32) +(fn none_u32 () -> OptionU32 (none u32)) -(fn is_some_u32 ((value (option u32))) -> bool +(fn is_some_u32 ((value OptionU32)) -> bool (is_some value)) -(fn is_none_u32 ((value (option u32))) -> bool +(fn is_none_u32 ((value OptionU32)) -> bool (is_none value)) -(fn unwrap_some_u32 ((value (option u32))) -> u32 +(fn unwrap_some_u32 ((value OptionU32)) -> u32 (unwrap_some value)) -(fn unwrap_or_u32 ((value (option u32)) (fallback u32)) -> u32 +(fn unwrap_or_u32 ((value OptionU32) (fallback u32)) -> u32 (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_u32 ((value (option u32)) (err_code i32)) -> (result u32 i32) +(fn some_or_err_u32 ((value OptionU32) (err_code i32)) -> ResultU32 (if (is_some value) (ok u32 i32 (unwrap_some value)) (err u32 i32 err_code))) -(fn some_i64 ((value i64)) -> (option i64) +(fn some_i64 ((value i64)) -> OptionI64 (some i64 value)) -(fn none_i64 () -> (option i64) +(fn none_i64 () -> OptionI64 (none i64)) -(fn is_some_i64 ((value (option i64))) -> bool +(fn is_some_i64 ((value OptionI64)) -> bool (is_some value)) -(fn is_none_i64 ((value (option i64))) -> bool +(fn is_none_i64 ((value OptionI64)) -> bool (is_none value)) -(fn unwrap_some_i64 ((value (option i64))) -> i64 +(fn unwrap_some_i64 ((value OptionI64)) -> i64 (unwrap_some value)) -(fn unwrap_or_i64 ((value (option i64)) (fallback i64)) -> i64 +(fn unwrap_or_i64 ((value OptionI64) (fallback i64)) -> i64 (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_i64 ((value (option i64)) (err_code i32)) -> (result i64 i32) +(fn some_or_err_i64 ((value OptionI64) (err_code i32)) -> ResultI64 (if (is_some value) (ok i64 i32 (unwrap_some value)) (err i64 i32 err_code))) -(fn some_u64 ((value u64)) -> (option u64) +(fn some_u64 ((value u64)) -> OptionU64 (some u64 value)) -(fn none_u64 () -> (option u64) +(fn none_u64 () -> OptionU64 (none u64)) -(fn is_some_u64 ((value (option u64))) -> bool +(fn is_some_u64 ((value OptionU64)) -> bool (is_some value)) -(fn is_none_u64 ((value (option u64))) -> bool +(fn is_none_u64 ((value OptionU64)) -> bool (is_none value)) -(fn unwrap_some_u64 ((value (option u64))) -> u64 +(fn unwrap_some_u64 ((value OptionU64)) -> u64 (unwrap_some value)) -(fn unwrap_or_u64 ((value (option u64)) (fallback u64)) -> u64 +(fn unwrap_or_u64 ((value OptionU64) (fallback u64)) -> u64 (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_u64 ((value (option u64)) (err_code i32)) -> (result u64 i32) +(fn some_or_err_u64 ((value OptionU64) (err_code i32)) -> ResultU64 (if (is_some value) (ok u64 i32 (unwrap_some value)) (err u64 i32 err_code))) -(fn some_f64 ((value f64)) -> (option f64) +(fn some_f64 ((value f64)) -> OptionF64 (some f64 value)) -(fn none_f64 () -> (option f64) +(fn none_f64 () -> OptionF64 (none f64)) -(fn is_some_f64 ((value (option f64))) -> bool +(fn is_some_f64 ((value OptionF64)) -> bool (is_some value)) -(fn is_none_f64 ((value (option f64))) -> bool +(fn is_none_f64 ((value OptionF64)) -> bool (is_none value)) -(fn unwrap_some_f64 ((value (option f64))) -> f64 +(fn unwrap_some_f64 ((value OptionF64)) -> f64 (unwrap_some value)) -(fn unwrap_or_f64 ((value (option f64)) (fallback f64)) -> f64 +(fn unwrap_or_f64 ((value OptionF64) (fallback f64)) -> f64 (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_f64 ((value (option f64)) (err_code i32)) -> (result f64 i32) +(fn some_or_err_f64 ((value OptionF64) (err_code i32)) -> ResultF64 (if (is_some value) (ok f64 i32 (unwrap_some value)) (err f64 i32 err_code))) -(fn some_bool ((value bool)) -> (option bool) +(fn some_bool ((value bool)) -> OptionBool (some bool value)) -(fn none_bool () -> (option bool) +(fn none_bool () -> OptionBool (none bool)) -(fn is_some_bool ((value (option bool))) -> bool +(fn is_some_bool ((value OptionBool)) -> bool (is_some value)) -(fn is_none_bool ((value (option bool))) -> bool +(fn is_none_bool ((value OptionBool)) -> bool (is_none value)) -(fn unwrap_some_bool ((value (option bool))) -> bool +(fn unwrap_some_bool ((value OptionBool)) -> bool (unwrap_some value)) -(fn unwrap_or_bool ((value (option bool)) (fallback bool)) -> bool +(fn unwrap_or_bool ((value OptionBool) (fallback bool)) -> bool (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_bool ((value (option bool)) (err_code i32)) -> (result bool i32) +(fn some_or_err_bool ((value OptionBool) (err_code i32)) -> ResultBool (if (is_some value) (ok bool i32 (unwrap_some value)) (err bool i32 err_code))) -(fn some_string ((value string)) -> (option string) +(fn some_string ((value string)) -> OptionString (some string value)) -(fn none_string () -> (option string) +(fn none_string () -> OptionString (none string)) -(fn is_some_string ((value (option string))) -> bool +(fn is_some_string ((value OptionString)) -> bool (is_some value)) -(fn is_none_string ((value (option string))) -> bool +(fn is_none_string ((value OptionString)) -> bool (is_none value)) -(fn unwrap_some_string ((value (option string))) -> string +(fn unwrap_some_string ((value OptionString)) -> string (unwrap_some value)) -(fn unwrap_or_string ((value (option string)) (fallback string)) -> string +(fn unwrap_or_string ((value OptionString) (fallback string)) -> string (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_string ((value (option string)) (err_code i32)) -> (result string i32) +(fn some_or_err_string ((value OptionString) (err_code i32)) -> ResultString (if (is_some value) (ok string i32 (unwrap_some value)) (err string i32 err_code))) diff --git a/examples/projects/std-layout-local-result/src/result.slo b/examples/projects/std-layout-local-result/src/result.slo index 4a7b77b..8f497bb 100644 --- a/examples/projects/std-layout-local-result/src/result.slo +++ b/examples/projects/std-layout-local-result/src/result.slo @@ -1,199 +1,227 @@ (module result (export ok_i32 err_i32 is_ok_i32 is_err_i32 unwrap_ok_i32 unwrap_err_i32 unwrap_or_i32 ok_or_none_i32 ok_u32 err_u32 is_ok_u32 is_err_u32 unwrap_ok_u32 unwrap_err_u32 unwrap_or_u32 ok_or_none_u32 ok_i64 err_i64 is_ok_i64 is_err_i64 unwrap_ok_i64 unwrap_err_i64 unwrap_or_i64 ok_or_none_i64 ok_u64 err_u64 is_ok_u64 is_err_u64 unwrap_ok_u64 unwrap_err_u64 unwrap_or_u64 ok_or_none_u64 ok_string err_string is_ok_string is_err_string unwrap_ok_string unwrap_err_string unwrap_or_string ok_or_none_string ok_f64 err_f64 is_ok_f64 is_err_f64 unwrap_ok_f64 unwrap_err_f64 unwrap_or_f64 ok_or_none_f64 ok_bool err_bool is_ok_bool is_err_bool unwrap_ok_bool unwrap_err_bool unwrap_or_bool ok_or_none_bool)) -(fn ok_i32 ((value i32)) -> (result i32 i32) +(type ResultI32 (result i32 i32)) + +(type OptionI32 (option i32)) + +(type ResultU32 (result u32 i32)) + +(type OptionU32 (option u32)) + +(type ResultI64 (result i64 i32)) + +(type OptionI64 (option i64)) + +(type ResultU64 (result u64 i32)) + +(type OptionU64 (option u64)) + +(type ResultString (result string i32)) + +(type OptionString (option string)) + +(type ResultF64 (result f64 i32)) + +(type OptionF64 (option f64)) + +(type ResultBool (result bool i32)) + +(type OptionBool (option bool)) + +(fn ok_i32 ((value i32)) -> ResultI32 (ok i32 i32 value)) -(fn err_i32 ((code i32)) -> (result i32 i32) +(fn err_i32 ((code i32)) -> ResultI32 (err i32 i32 code)) -(fn is_ok_i32 ((value (result i32 i32))) -> bool +(fn is_ok_i32 ((value ResultI32)) -> bool (std.result.is_ok value)) -(fn is_err_i32 ((value (result i32 i32))) -> bool +(fn is_err_i32 ((value ResultI32)) -> bool (std.result.is_err value)) -(fn unwrap_ok_i32 ((value (result i32 i32))) -> i32 +(fn unwrap_ok_i32 ((value ResultI32)) -> i32 (std.result.unwrap_ok value)) -(fn unwrap_err_i32 ((value (result i32 i32))) -> i32 +(fn unwrap_err_i32 ((value ResultI32)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_i32 ((value (result i32 i32)) (fallback i32)) -> i32 +(fn unwrap_or_i32 ((value ResultI32) (fallback i32)) -> i32 (if (std.result.is_ok value) (std.result.unwrap_ok value) fallback)) -(fn ok_or_none_i32 ((value (result i32 i32))) -> (option i32) +(fn ok_or_none_i32 ((value ResultI32)) -> OptionI32 (if (std.result.is_ok value) (some i32 (std.result.unwrap_ok value)) (none i32))) -(fn ok_u32 ((value u32)) -> (result u32 i32) +(fn ok_u32 ((value u32)) -> ResultU32 (ok u32 i32 value)) -(fn err_u32 ((code i32)) -> (result u32 i32) +(fn err_u32 ((code i32)) -> ResultU32 (err u32 i32 code)) -(fn is_ok_u32 ((value (result u32 i32))) -> bool +(fn is_ok_u32 ((value ResultU32)) -> bool (std.result.is_ok value)) -(fn is_err_u32 ((value (result u32 i32))) -> bool +(fn is_err_u32 ((value ResultU32)) -> bool (std.result.is_err value)) -(fn unwrap_ok_u32 ((value (result u32 i32))) -> u32 +(fn unwrap_ok_u32 ((value ResultU32)) -> u32 (std.result.unwrap_ok value)) -(fn unwrap_err_u32 ((value (result u32 i32))) -> i32 +(fn unwrap_err_u32 ((value ResultU32)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_u32 ((value (result u32 i32)) (fallback u32)) -> u32 +(fn unwrap_or_u32 ((value ResultU32) (fallback u32)) -> u32 (if (std.result.is_ok value) (std.result.unwrap_ok value) fallback)) -(fn ok_or_none_u32 ((value (result u32 i32))) -> (option u32) +(fn ok_or_none_u32 ((value ResultU32)) -> OptionU32 (if (std.result.is_ok value) (some u32 (std.result.unwrap_ok value)) (none u32))) -(fn ok_i64 ((value i64)) -> (result i64 i32) +(fn ok_i64 ((value i64)) -> ResultI64 (ok i64 i32 value)) -(fn err_i64 ((code i32)) -> (result i64 i32) +(fn err_i64 ((code i32)) -> ResultI64 (err i64 i32 code)) -(fn is_ok_i64 ((value (result i64 i32))) -> bool +(fn is_ok_i64 ((value ResultI64)) -> bool (std.result.is_ok value)) -(fn is_err_i64 ((value (result i64 i32))) -> bool +(fn is_err_i64 ((value ResultI64)) -> bool (std.result.is_err value)) -(fn unwrap_ok_i64 ((value (result i64 i32))) -> i64 +(fn unwrap_ok_i64 ((value ResultI64)) -> i64 (std.result.unwrap_ok value)) -(fn unwrap_err_i64 ((value (result i64 i32))) -> i32 +(fn unwrap_err_i64 ((value ResultI64)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_i64 ((value (result i64 i32)) (fallback i64)) -> i64 +(fn unwrap_or_i64 ((value ResultI64) (fallback i64)) -> i64 (if (std.result.is_ok value) (std.result.unwrap_ok value) fallback)) -(fn ok_or_none_i64 ((value (result i64 i32))) -> (option i64) +(fn ok_or_none_i64 ((value ResultI64)) -> OptionI64 (if (std.result.is_ok value) (some i64 (std.result.unwrap_ok value)) (none i64))) -(fn ok_u64 ((value u64)) -> (result u64 i32) +(fn ok_u64 ((value u64)) -> ResultU64 (ok u64 i32 value)) -(fn err_u64 ((code i32)) -> (result u64 i32) +(fn err_u64 ((code i32)) -> ResultU64 (err u64 i32 code)) -(fn is_ok_u64 ((value (result u64 i32))) -> bool +(fn is_ok_u64 ((value ResultU64)) -> bool (std.result.is_ok value)) -(fn is_err_u64 ((value (result u64 i32))) -> bool +(fn is_err_u64 ((value ResultU64)) -> bool (std.result.is_err value)) -(fn unwrap_ok_u64 ((value (result u64 i32))) -> u64 +(fn unwrap_ok_u64 ((value ResultU64)) -> u64 (std.result.unwrap_ok value)) -(fn unwrap_err_u64 ((value (result u64 i32))) -> i32 +(fn unwrap_err_u64 ((value ResultU64)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_u64 ((value (result u64 i32)) (fallback u64)) -> u64 +(fn unwrap_or_u64 ((value ResultU64) (fallback u64)) -> u64 (if (std.result.is_ok value) (std.result.unwrap_ok value) fallback)) -(fn ok_or_none_u64 ((value (result u64 i32))) -> (option u64) +(fn ok_or_none_u64 ((value ResultU64)) -> OptionU64 (if (std.result.is_ok value) (some u64 (std.result.unwrap_ok value)) (none u64))) -(fn ok_string ((value string)) -> (result string i32) +(fn ok_string ((value string)) -> ResultString (ok string i32 value)) -(fn err_string ((code i32)) -> (result string i32) +(fn err_string ((code i32)) -> ResultString (err string i32 code)) -(fn is_ok_string ((value (result string i32))) -> bool +(fn is_ok_string ((value ResultString)) -> bool (std.result.is_ok value)) -(fn is_err_string ((value (result string i32))) -> bool +(fn is_err_string ((value ResultString)) -> bool (std.result.is_err value)) -(fn unwrap_ok_string ((value (result string i32))) -> string +(fn unwrap_ok_string ((value ResultString)) -> string (std.result.unwrap_ok value)) -(fn unwrap_err_string ((value (result string i32))) -> i32 +(fn unwrap_err_string ((value ResultString)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_string ((value (result string i32)) (fallback string)) -> string +(fn unwrap_or_string ((value ResultString) (fallback string)) -> string (match value ((ok payload) payload) ((err code) fallback))) -(fn ok_or_none_string ((value (result string i32))) -> (option string) +(fn ok_or_none_string ((value ResultString)) -> OptionString (if (std.result.is_ok value) (some string (std.result.unwrap_ok value)) (none string))) -(fn ok_f64 ((value f64)) -> (result f64 i32) +(fn ok_f64 ((value f64)) -> ResultF64 (ok f64 i32 value)) -(fn err_f64 ((code i32)) -> (result f64 i32) +(fn err_f64 ((code i32)) -> ResultF64 (err f64 i32 code)) -(fn is_ok_f64 ((value (result f64 i32))) -> bool +(fn is_ok_f64 ((value ResultF64)) -> bool (std.result.is_ok value)) -(fn is_err_f64 ((value (result f64 i32))) -> bool +(fn is_err_f64 ((value ResultF64)) -> bool (std.result.is_err value)) -(fn unwrap_ok_f64 ((value (result f64 i32))) -> f64 +(fn unwrap_ok_f64 ((value ResultF64)) -> f64 (std.result.unwrap_ok value)) -(fn unwrap_err_f64 ((value (result f64 i32))) -> i32 +(fn unwrap_err_f64 ((value ResultF64)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_f64 ((value (result f64 i32)) (fallback f64)) -> f64 +(fn unwrap_or_f64 ((value ResultF64) (fallback f64)) -> f64 (if (std.result.is_ok value) (std.result.unwrap_ok value) fallback)) -(fn ok_or_none_f64 ((value (result f64 i32))) -> (option f64) +(fn ok_or_none_f64 ((value ResultF64)) -> OptionF64 (if (std.result.is_ok value) (some f64 (std.result.unwrap_ok value)) (none f64))) -(fn ok_bool ((value bool)) -> (result bool i32) +(fn ok_bool ((value bool)) -> ResultBool (ok bool i32 value)) -(fn err_bool ((code i32)) -> (result bool i32) +(fn err_bool ((code i32)) -> ResultBool (err bool i32 code)) -(fn is_ok_bool ((value (result bool i32))) -> bool +(fn is_ok_bool ((value ResultBool)) -> bool (std.result.is_ok value)) -(fn is_err_bool ((value (result bool i32))) -> bool +(fn is_err_bool ((value ResultBool)) -> bool (std.result.is_err value)) -(fn unwrap_ok_bool ((value (result bool i32))) -> bool +(fn unwrap_ok_bool ((value ResultBool)) -> bool (std.result.unwrap_ok value)) -(fn unwrap_err_bool ((value (result bool i32))) -> i32 +(fn unwrap_err_bool ((value ResultBool)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_bool ((value (result bool i32)) (fallback bool)) -> bool +(fn unwrap_or_bool ((value ResultBool) (fallback bool)) -> bool (if (std.result.is_ok value) (std.result.unwrap_ok value) fallback)) -(fn ok_or_none_bool ((value (result bool i32))) -> (option bool) +(fn ok_or_none_bool ((value ResultBool)) -> OptionBool (if (std.result.is_ok value) (some bool (std.result.unwrap_ok value)) (none bool))) diff --git a/examples/projects/std-layout-local-vec_bool/src/vec_bool.slo b/examples/projects/std-layout-local-vec_bool/src/vec_bool.slo index bc08933..4ea8796 100644 --- a/examples/projects/std-layout-local-vec_bool/src/vec_bool.slo +++ b/examples/projects/std-layout-local-vec_bool/src/vec_bool.slo @@ -1,120 +1,122 @@ (module vec_bool (export empty append len at singleton append2 append3 pair triple is_empty index_or first_or last_or index_option first_option last_option index_of_option last_index_of_option contains count_of concat take starts_with without_prefix ends_with without_suffix drop reverse subvec insert_at insert_range replace_at replace_range remove_at remove_range)) -(fn empty () -> (vec bool) +(type VecBool (vec bool)) + +(fn empty () -> VecBool (std.vec.bool.empty)) -(fn append ((values (vec bool)) (value bool)) -> (vec bool) +(fn append ((values VecBool) (value bool)) -> VecBool (std.vec.bool.append values value)) -(fn len ((values (vec bool))) -> i32 +(fn len ((values VecBool)) -> i32 (std.vec.bool.len values)) -(fn at ((values (vec bool)) (position i32)) -> bool +(fn at ((values VecBool) (position i32)) -> bool (std.vec.bool.index values position)) -(fn singleton ((value bool)) -> (vec bool) +(fn singleton ((value bool)) -> VecBool (append (empty) value)) -(fn append2 ((values (vec bool)) (first bool) (second bool)) -> (vec bool) +(fn append2 ((values VecBool) (first bool) (second bool)) -> VecBool (append (append values first) second)) -(fn append3 ((values (vec bool)) (first bool) (second bool) (third bool)) -> (vec bool) +(fn append3 ((values VecBool) (first bool) (second bool) (third bool)) -> VecBool (append (append2 values first second) third)) -(fn pair ((first bool) (second bool)) -> (vec bool) +(fn pair ((first bool) (second bool)) -> VecBool (append2 (empty) first second)) -(fn triple ((first bool) (second bool) (third bool)) -> (vec bool) +(fn triple ((first bool) (second bool) (third bool)) -> VecBool (append3 (empty) first second third)) -(fn is_empty ((values (vec bool))) -> bool +(fn is_empty ((values VecBool)) -> bool (= (len values) 0)) -(fn index_or ((values (vec bool)) (position i32) (fallback bool)) -> bool +(fn index_or ((values VecBool) (position i32) (fallback bool)) -> bool (if (< position 0) fallback (if (< position (len values)) (at values position) fallback))) -(fn first_or ((values (vec bool)) (fallback bool)) -> bool +(fn first_or ((values VecBool) (fallback bool)) -> bool (index_or values 0 fallback)) -(fn last_or ((values (vec bool)) (fallback bool)) -> bool +(fn last_or ((values VecBool) (fallback bool)) -> bool (if (is_empty values) fallback (at values (- (len values) 1)))) -(fn index_option ((values (vec bool)) (position i32)) -> (option bool) +(fn index_option ((values VecBool) (position i32)) -> (option bool) (if (< position 0) (none bool) (if (< position (len values)) (some bool (at values position)) (none bool)))) -(fn first_option ((values (vec bool))) -> (option bool) +(fn first_option ((values VecBool)) -> (option bool) (index_option values 0)) -(fn last_option ((values (vec bool))) -> (option bool) +(fn last_option ((values VecBool)) -> (option bool) (if (is_empty values) (none bool) (some bool (at values (- (len values) 1))))) -(fn index_of_option_loop ((values (vec bool)) (target bool) (position i32) (values_len i32)) -> (option i32) +(fn index_of_option_loop ((values VecBool) (target bool) (position i32) (values_len i32)) -> (option i32) (if (< position values_len) (if (= (at values position) target) (some i32 position) (index_of_option_loop values target (+ position 1) values_len)) (none i32))) -(fn index_of_option ((values (vec bool)) (target bool)) -> (option i32) +(fn index_of_option ((values VecBool) (target bool)) -> (option i32) (index_of_option_loop values target 0 (len values))) -(fn last_index_of_option_loop ((values (vec bool)) (target bool) (position i32) (values_len i32) (found_position (option i32))) -> (option i32) +(fn last_index_of_option_loop ((values VecBool) (target bool) (position i32) (values_len i32) (found_position (option i32))) -> (option i32) (if (< position values_len) (last_index_of_option_loop values target (+ position 1) values_len (if (= (at values position) target) (some i32 position) found_position)) found_position)) -(fn last_index_of_option ((values (vec bool)) (target bool)) -> (option i32) +(fn last_index_of_option ((values VecBool) (target bool)) -> (option i32) (last_index_of_option_loop values target 0 (len values) (none i32))) -(fn contains_loop ((values (vec bool)) (target bool) (position i32) (values_len i32)) -> bool +(fn contains_loop ((values VecBool) (target bool) (position i32) (values_len i32)) -> bool (if (< position values_len) (if (= (at values position) target) true (contains_loop values target (+ position 1) values_len)) false)) -(fn contains ((values (vec bool)) (target bool)) -> bool +(fn contains ((values VecBool) (target bool)) -> bool (contains_loop values target 0 (len values))) -(fn count_of_loop ((values (vec bool)) (target bool) (position i32) (values_len i32) (hits i32)) -> i32 +(fn count_of_loop ((values VecBool) (target bool) (position i32) (values_len i32) (hits i32)) -> i32 (if (< position values_len) (count_of_loop values target (+ position 1) values_len (+ hits (if (= (at values position) target) 1 0))) hits)) -(fn count_of ((values (vec bool)) (target bool)) -> i32 +(fn count_of ((values VecBool) (target bool)) -> i32 (count_of_loop values target 0 (len values) 0)) -(fn concat_loop ((result (vec bool)) (right (vec bool)) (position i32) (right_len i32)) -> (vec bool) +(fn concat_loop ((result VecBool) (right VecBool) (position i32) (right_len i32)) -> VecBool (if (< position right_len) (concat_loop (append result (at right position)) right (+ position 1) right_len) result)) -(fn concat ((left (vec bool)) (right (vec bool))) -> (vec bool) +(fn concat ((left VecBool) (right VecBool)) -> VecBool (let right_len i32 (len right)) (concat_loop left right 0 right_len)) -(fn take_loop ((values (vec bool)) (position i32) (limit i32) (result (vec bool))) -> (vec bool) +(fn take_loop ((values VecBool) (position i32) (limit i32) (result VecBool)) -> VecBool (if (< position limit) (take_loop values (+ position 1) limit (append result (at values position))) result)) -(fn take ((values (vec bool)) (count i32)) -> (vec bool) +(fn take ((values VecBool) (count i32)) -> VecBool (let values_len i32 (len values)) (if (< count 0) (empty) @@ -122,35 +124,35 @@ (take_loop values 0 count (empty)) values))) -(fn starts_with ((values (vec bool)) (prefix (vec bool))) -> bool +(fn starts_with ((values VecBool) (prefix VecBool)) -> bool (let prefix_len i32 (len prefix)) (if (< (len values) prefix_len) false (= (take values prefix_len) prefix))) -(fn without_prefix ((values (vec bool)) (prefix (vec bool))) -> (vec bool) +(fn without_prefix ((values VecBool) (prefix VecBool)) -> VecBool (if (starts_with values prefix) (drop values (len prefix)) values)) -(fn ends_with ((values (vec bool)) (suffix (vec bool))) -> bool +(fn ends_with ((values VecBool) (suffix VecBool)) -> bool (let values_len i32 (len values)) (let suffix_len i32 (len suffix)) (if (< values_len suffix_len) false (= (drop values (- values_len suffix_len)) suffix))) -(fn without_suffix ((values (vec bool)) (suffix (vec bool))) -> (vec bool) +(fn without_suffix ((values VecBool) (suffix VecBool)) -> VecBool (if (ends_with values suffix) (take values (- (len values) (len suffix))) values)) -(fn drop_loop ((values (vec bool)) (position i32) (values_len i32) (result (vec bool))) -> (vec bool) +(fn drop_loop ((values VecBool) (position i32) (values_len i32) (result VecBool)) -> VecBool (if (< position values_len) (drop_loop values (+ position 1) values_len (append result (at values position))) result)) -(fn drop ((values (vec bool)) (count i32)) -> (vec bool) +(fn drop ((values VecBool) (count i32)) -> VecBool (let values_len i32 (len values)) (if (< count 0) values @@ -158,22 +160,22 @@ (drop_loop values count values_len (empty)) (empty)))) -(fn reverse_loop ((values (vec bool)) (position i32) (result (vec bool))) -> (vec bool) +(fn reverse_loop ((values VecBool) (position i32) (result VecBool)) -> VecBool (if (< position 0) result (reverse_loop values (- position 1) (append result (at values position))))) -(fn reverse ((values (vec bool))) -> (vec bool) +(fn reverse ((values VecBool)) -> VecBool (reverse_loop values (- (len values) 1) (empty))) -(fn subvec ((values (vec bool)) (start i32) (end_exclusive i32)) -> (vec bool) +(fn subvec ((values VecBool) (start i32) (end_exclusive i32)) -> VecBool (if (< start 0) (empty) (if (< start end_exclusive) (take (drop values start) (- end_exclusive start)) (empty)))) -(fn insert_at ((values (vec bool)) (position i32) (value bool)) -> (vec bool) +(fn insert_at ((values VecBool) (position i32) (value bool)) -> VecBool (let values_len i32 (len values)) (if (< position 0) values @@ -183,7 +185,7 @@ (append values value) values)))) -(fn insert_range ((values (vec bool)) (position i32) (inserted (vec bool))) -> (vec bool) +(fn insert_range ((values VecBool) (position i32) (inserted VecBool)) -> VecBool (let values_len i32 (len values)) (if (< position 0) values @@ -193,14 +195,14 @@ (concat values inserted) values)))) -(fn replace_at ((values (vec bool)) (position i32) (replacement bool)) -> (vec bool) +(fn replace_at ((values VecBool) (position i32) (replacement bool)) -> VecBool (if (< position 0) values (if (< position (len values)) (concat (append (take values position) replacement) (drop values (+ position 1))) values))) -(fn replace_range ((values (vec bool)) (start i32) (end_exclusive i32) (replacement (vec bool))) -> (vec bool) +(fn replace_range ((values VecBool) (start i32) (end_exclusive i32) (replacement VecBool)) -> VecBool (let values_len i32 (len values)) (if (< start 0) values @@ -210,14 +212,14 @@ values) values))) -(fn remove_at ((values (vec bool)) (position i32)) -> (vec bool) +(fn remove_at ((values VecBool) (position i32)) -> VecBool (if (< position 0) values (if (< position (len values)) (concat (take values position) (drop values (+ position 1))) values))) -(fn remove_range ((values (vec bool)) (start i32) (end_exclusive i32)) -> (vec bool) +(fn remove_range ((values VecBool) (start i32) (end_exclusive i32)) -> VecBool (let values_len i32 (len values)) (if (< start 0) values diff --git a/examples/projects/std-layout-local-vec_f64/src/vec_f64.slo b/examples/projects/std-layout-local-vec_f64/src/vec_f64.slo index 0b36953..8e8f6ef 100644 --- a/examples/projects/std-layout-local-vec_f64/src/vec_f64.slo +++ b/examples/projects/std-layout-local-vec_f64/src/vec_f64.slo @@ -1,118 +1,120 @@ (module vec_f64 (export empty append len at singleton append2 append3 pair triple is_empty index_or first_or last_or index_option first_option last_option index_of_option last_index_of_option contains sum concat take starts_with without_prefix ends_with without_suffix drop reverse subvec insert_at insert_range replace_at replace_range remove_at remove_range)) -(fn empty () -> (vec f64) +(type VecF64 (vec f64)) + +(fn empty () -> VecF64 (std.vec.f64.empty)) -(fn append ((values (vec f64)) (value f64)) -> (vec f64) +(fn append ((values VecF64) (value f64)) -> VecF64 (std.vec.f64.append values value)) -(fn len ((values (vec f64))) -> i32 +(fn len ((values VecF64)) -> i32 (std.vec.f64.len values)) -(fn at ((values (vec f64)) (position i32)) -> f64 +(fn at ((values VecF64) (position i32)) -> f64 (std.vec.f64.index values position)) -(fn singleton ((value f64)) -> (vec f64) +(fn singleton ((value f64)) -> VecF64 (append (empty) value)) -(fn append2 ((values (vec f64)) (first f64) (second f64)) -> (vec f64) +(fn append2 ((values VecF64) (first f64) (second f64)) -> VecF64 (append (append values first) second)) -(fn append3 ((values (vec f64)) (first f64) (second f64) (third f64)) -> (vec f64) +(fn append3 ((values VecF64) (first f64) (second f64) (third f64)) -> VecF64 (append (append2 values first second) third)) -(fn pair ((first f64) (second f64)) -> (vec f64) +(fn pair ((first f64) (second f64)) -> VecF64 (append2 (empty) first second)) -(fn triple ((first f64) (second f64) (third f64)) -> (vec f64) +(fn triple ((first f64) (second f64) (third f64)) -> VecF64 (append3 (empty) first second third)) -(fn is_empty ((values (vec f64))) -> bool +(fn is_empty ((values VecF64)) -> bool (= (len values) 0)) -(fn index_or ((values (vec f64)) (position i32) (fallback f64)) -> f64 +(fn index_or ((values VecF64) (position i32) (fallback f64)) -> f64 (if (< position 0) fallback (if (< position (len values)) (at values position) fallback))) -(fn first_or ((values (vec f64)) (fallback f64)) -> f64 +(fn first_or ((values VecF64) (fallback f64)) -> f64 (index_or values 0 fallback)) -(fn last_or ((values (vec f64)) (fallback f64)) -> f64 +(fn last_or ((values VecF64) (fallback f64)) -> f64 (if (is_empty values) fallback (at values (- (len values) 1)))) -(fn index_option ((values (vec f64)) (position i32)) -> (option f64) +(fn index_option ((values VecF64) (position i32)) -> (option f64) (if (< position 0) (none f64) (if (< position (len values)) (some f64 (at values position)) (none f64)))) -(fn first_option ((values (vec f64))) -> (option f64) +(fn first_option ((values VecF64)) -> (option f64) (index_option values 0)) -(fn last_option ((values (vec f64))) -> (option f64) +(fn last_option ((values VecF64)) -> (option f64) (if (is_empty values) (none f64) (some f64 (at values (- (len values) 1))))) -(fn index_of_option_loop ((values (vec f64)) (target f64) (position i32) (values_len i32)) -> (option i32) +(fn index_of_option_loop ((values VecF64) (target f64) (position i32) (values_len i32)) -> (option i32) (if (< position values_len) (if (= (at values position) target) (some i32 position) (index_of_option_loop values target (+ position 1) values_len)) (none i32))) -(fn index_of_option ((values (vec f64)) (target f64)) -> (option i32) +(fn index_of_option ((values VecF64) (target f64)) -> (option i32) (index_of_option_loop values target 0 (len values))) -(fn last_index_of_option_loop ((values (vec f64)) (target f64) (position i32) (values_len i32) (found_position (option i32))) -> (option i32) +(fn last_index_of_option_loop ((values VecF64) (target f64) (position i32) (values_len i32) (found_position (option i32))) -> (option i32) (if (< position values_len) (last_index_of_option_loop values target (+ position 1) values_len (if (= (at values position) target) (some i32 position) found_position)) found_position)) -(fn last_index_of_option ((values (vec f64)) (target f64)) -> (option i32) +(fn last_index_of_option ((values VecF64) (target f64)) -> (option i32) (last_index_of_option_loop values target 0 (len values) (none i32))) -(fn contains_loop ((values (vec f64)) (target f64) (position i32) (values_len i32)) -> bool +(fn contains_loop ((values VecF64) (target f64) (position i32) (values_len i32)) -> bool (if (< position values_len) (if (= (at values position) target) true (contains_loop values target (+ position 1) values_len)) false)) -(fn contains ((values (vec f64)) (target f64)) -> bool +(fn contains ((values VecF64) (target f64)) -> bool (contains_loop values target 0 (len values))) -(fn sum_loop ((values (vec f64)) (position i32) (values_len i32) (total f64)) -> f64 +(fn sum_loop ((values VecF64) (position i32) (values_len i32) (total f64)) -> f64 (if (< position values_len) (sum_loop values (+ position 1) values_len (+ total (at values position))) total)) -(fn sum ((values (vec f64))) -> f64 +(fn sum ((values VecF64)) -> f64 (sum_loop values 0 (len values) 0.0)) -(fn concat_loop ((result (vec f64)) (right (vec f64)) (position i32) (right_len i32)) -> (vec f64) +(fn concat_loop ((result VecF64) (right VecF64) (position i32) (right_len i32)) -> VecF64 (if (< position right_len) (concat_loop (append result (at right position)) right (+ position 1) right_len) result)) -(fn concat ((left (vec f64)) (right (vec f64))) -> (vec f64) +(fn concat ((left VecF64) (right VecF64)) -> VecF64 (let right_len i32 (len right)) (concat_loop left right 0 right_len)) -(fn take_loop ((values (vec f64)) (position i32) (limit i32) (result (vec f64))) -> (vec f64) +(fn take_loop ((values VecF64) (position i32) (limit i32) (result VecF64)) -> VecF64 (if (< position limit) (take_loop values (+ position 1) limit (append result (at values position))) result)) -(fn take ((values (vec f64)) (count i32)) -> (vec f64) +(fn take ((values VecF64) (count i32)) -> VecF64 (let values_len i32 (len values)) (if (< count 0) (empty) @@ -120,35 +122,35 @@ (take_loop values 0 count (empty)) values))) -(fn starts_with ((values (vec f64)) (prefix (vec f64))) -> bool +(fn starts_with ((values VecF64) (prefix VecF64)) -> bool (let prefix_len i32 (len prefix)) (if (< (len values) prefix_len) false (= (take values prefix_len) prefix))) -(fn without_prefix ((values (vec f64)) (prefix (vec f64))) -> (vec f64) +(fn without_prefix ((values VecF64) (prefix VecF64)) -> VecF64 (if (starts_with values prefix) (drop values (len prefix)) values)) -(fn ends_with ((values (vec f64)) (suffix (vec f64))) -> bool +(fn ends_with ((values VecF64) (suffix VecF64)) -> bool (let values_len i32 (len values)) (let suffix_len i32 (len suffix)) (if (< values_len suffix_len) false (= (drop values (- values_len suffix_len)) suffix))) -(fn without_suffix ((values (vec f64)) (suffix (vec f64))) -> (vec f64) +(fn without_suffix ((values VecF64) (suffix VecF64)) -> VecF64 (if (ends_with values suffix) (take values (- (len values) (len suffix))) values)) -(fn drop_loop ((values (vec f64)) (position i32) (values_len i32) (result (vec f64))) -> (vec f64) +(fn drop_loop ((values VecF64) (position i32) (values_len i32) (result VecF64)) -> VecF64 (if (< position values_len) (drop_loop values (+ position 1) values_len (append result (at values position))) result)) -(fn drop ((values (vec f64)) (count i32)) -> (vec f64) +(fn drop ((values VecF64) (count i32)) -> VecF64 (let values_len i32 (len values)) (if (< count 0) values @@ -156,22 +158,22 @@ (drop_loop values count values_len (empty)) (empty)))) -(fn reverse_loop ((values (vec f64)) (position i32) (result (vec f64))) -> (vec f64) +(fn reverse_loop ((values VecF64) (position i32) (result VecF64)) -> VecF64 (if (< position 0) result (reverse_loop values (- position 1) (append result (at values position))))) -(fn reverse ((values (vec f64))) -> (vec f64) +(fn reverse ((values VecF64)) -> VecF64 (reverse_loop values (- (len values) 1) (empty))) -(fn subvec ((values (vec f64)) (start i32) (end_exclusive i32)) -> (vec f64) +(fn subvec ((values VecF64) (start i32) (end_exclusive i32)) -> VecF64 (if (< start 0) (empty) (if (< start end_exclusive) (take (drop values start) (- end_exclusive start)) (empty)))) -(fn insert_at ((values (vec f64)) (position i32) (value f64)) -> (vec f64) +(fn insert_at ((values VecF64) (position i32) (value f64)) -> VecF64 (let values_len i32 (len values)) (if (< position 0) values @@ -181,7 +183,7 @@ (append values value) values)))) -(fn insert_range ((values (vec f64)) (position i32) (inserted (vec f64))) -> (vec f64) +(fn insert_range ((values VecF64) (position i32) (inserted VecF64)) -> VecF64 (let values_len i32 (len values)) (if (< position 0) values @@ -191,14 +193,14 @@ (concat values inserted) values)))) -(fn replace_at ((values (vec f64)) (position i32) (replacement f64)) -> (vec f64) +(fn replace_at ((values VecF64) (position i32) (replacement f64)) -> VecF64 (if (< position 0) values (if (< position (len values)) (concat (append (take values position) replacement) (drop values (+ position 1))) values))) -(fn replace_range ((values (vec f64)) (start i32) (end_exclusive i32) (replacement (vec f64))) -> (vec f64) +(fn replace_range ((values VecF64) (start i32) (end_exclusive i32) (replacement VecF64)) -> VecF64 (let values_len i32 (len values)) (if (< start 0) values @@ -208,14 +210,14 @@ values) values))) -(fn remove_at ((values (vec f64)) (position i32)) -> (vec f64) +(fn remove_at ((values VecF64) (position i32)) -> VecF64 (if (< position 0) values (if (< position (len values)) (concat (take values position) (drop values (+ position 1))) values))) -(fn remove_range ((values (vec f64)) (start i32) (end_exclusive i32)) -> (vec f64) +(fn remove_range ((values VecF64) (start i32) (end_exclusive i32)) -> VecF64 (let values_len i32 (len values)) (if (< start 0) values diff --git a/examples/projects/std-layout-local-vec_i32/src/option.slo b/examples/projects/std-layout-local-vec_i32/src/option.slo index 20baf8f..99e227b 100644 --- a/examples/projects/std-layout-local-vec_i32/src/option.slo +++ b/examples/projects/std-layout-local-vec_i32/src/option.slo @@ -1,7 +1,9 @@ (module option (export some_i32 none_i32)) -(fn some_i32 ((value i32)) -> (option i32) +(type OptionI32 (option i32)) + +(fn some_i32 ((value i32)) -> OptionI32 (some i32 value)) -(fn none_i32 () -> (option i32) +(fn none_i32 () -> OptionI32 (none i32)) diff --git a/examples/projects/std-layout-local-vec_i32/src/vec_i32.slo b/examples/projects/std-layout-local-vec_i32/src/vec_i32.slo index 43a052b..346e3a0 100644 --- a/examples/projects/std-layout-local-vec_i32/src/vec_i32.slo +++ b/examples/projects/std-layout-local-vec_i32/src/vec_i32.slo @@ -2,97 +2,99 @@ (import option (some_i32 none_i32)) -(fn empty () -> (vec i32) +(type VecI32 (vec i32)) + +(fn empty () -> VecI32 (std.vec.i32.empty)) -(fn append ((values (vec i32)) (value i32)) -> (vec i32) +(fn append ((values VecI32) (value i32)) -> VecI32 (std.vec.i32.append values value)) -(fn len ((values (vec i32))) -> i32 +(fn len ((values VecI32)) -> i32 (std.vec.i32.len values)) -(fn at ((values (vec i32)) (position i32)) -> i32 +(fn at ((values VecI32) (position i32)) -> i32 (std.vec.i32.index values position)) -(fn singleton ((value i32)) -> (vec i32) +(fn singleton ((value i32)) -> VecI32 (append (empty) value)) -(fn append2 ((values (vec i32)) (first i32) (second i32)) -> (vec i32) +(fn append2 ((values VecI32) (first i32) (second i32)) -> VecI32 (append (append values first) second)) -(fn append3 ((values (vec i32)) (first i32) (second i32) (third i32)) -> (vec i32) +(fn append3 ((values VecI32) (first i32) (second i32) (third i32)) -> VecI32 (append (append2 values first second) third)) -(fn pair ((first i32) (second i32)) -> (vec i32) +(fn pair ((first i32) (second i32)) -> VecI32 (append2 (empty) first second)) -(fn triple ((first i32) (second i32) (third i32)) -> (vec i32) +(fn triple ((first i32) (second i32) (third i32)) -> VecI32 (append3 (empty) first second third)) -(fn repeat_loop ((value i32) (remaining i32) (result (vec i32))) -> (vec i32) +(fn repeat_loop ((value i32) (remaining i32) (result VecI32)) -> VecI32 (if (< remaining 1) result (repeat_loop value (- remaining 1) (append result value)))) -(fn repeat ((value i32) (count i32)) -> (vec i32) +(fn repeat ((value i32) (count i32)) -> VecI32 (if (< count 1) (empty) (repeat_loop value count (empty)))) -(fn range_from_zero_loop ((current i32) (count i32) (result (vec i32))) -> (vec i32) +(fn range_from_zero_loop ((current i32) (count i32) (result VecI32)) -> VecI32 (if (< current count) (range_from_zero_loop (+ current 1) count (append result current)) result)) -(fn range_loop ((current i32) (end_exclusive i32) (result (vec i32))) -> (vec i32) +(fn range_loop ((current i32) (end_exclusive i32) (result VecI32)) -> VecI32 (if (< current end_exclusive) (range_loop (+ current 1) end_exclusive (append result current)) result)) -(fn range ((start i32) (end_exclusive i32)) -> (vec i32) +(fn range ((start i32) (end_exclusive i32)) -> VecI32 (if (< start end_exclusive) (range_loop start end_exclusive (empty)) (empty))) -(fn range_from_zero ((count i32)) -> (vec i32) +(fn range_from_zero ((count i32)) -> VecI32 (if (< count 1) (empty) (range_from_zero_loop 0 count (empty)))) -(fn is_empty ((values (vec i32))) -> bool +(fn is_empty ((values VecI32)) -> bool (= (len values) 0)) -(fn index_or ((values (vec i32)) (position i32) (fallback i32)) -> i32 +(fn index_or ((values VecI32) (position i32) (fallback i32)) -> i32 (if (< position 0) fallback (if (< position (len values)) (at values position) fallback))) -(fn first_or ((values (vec i32)) (fallback i32)) -> i32 +(fn first_or ((values VecI32) (fallback i32)) -> i32 (index_or values 0 fallback)) -(fn last_or ((values (vec i32)) (fallback i32)) -> i32 +(fn last_or ((values VecI32) (fallback i32)) -> i32 (if (is_empty values) fallback (at values (- (len values) 1)))) -(fn index_option ((values (vec i32)) (position i32)) -> (option i32) +(fn index_option ((values VecI32) (position i32)) -> (option i32) (if (< position 0) (none_i32) (if (< position (len values)) (some_i32 (at values position)) (none_i32)))) -(fn first_option ((values (vec i32))) -> (option i32) +(fn first_option ((values VecI32)) -> (option i32) (index_option values 0)) -(fn last_option ((values (vec i32))) -> (option i32) +(fn last_option ((values VecI32)) -> (option i32) (if (is_empty values) (none_i32) (some_i32 (at values (- (len values) 1))))) -(fn index_of_option ((values (vec i32)) (target i32)) -> (option i32) +(fn index_of_option ((values VecI32) (target i32)) -> (option i32) (var position i32 0) (var found_position i32 -1) (while (and (< position (len values)) (< found_position 0)) @@ -104,7 +106,7 @@ (none_i32) (some_i32 found_position))) -(fn last_index_of_option ((values (vec i32)) (target i32)) -> (option i32) +(fn last_index_of_option ((values VecI32) (target i32)) -> (option i32) (var position i32 0) (var found_position i32 -1) (while (< position (len values)) @@ -116,7 +118,7 @@ (none_i32) (some_i32 found_position))) -(fn count_of ((values (vec i32)) (target i32)) -> i32 +(fn count_of ((values VecI32) (target i32)) -> i32 (var position i32 0) (var hits i32 0) (while (< position (len values)) @@ -126,7 +128,7 @@ (set position (+ position 1))) hits) -(fn contains ((values (vec i32)) (target i32)) -> bool +(fn contains ((values VecI32) (target i32)) -> bool (var position i32 0) (var hits i32 0) (while (< position (len values)) @@ -136,7 +138,7 @@ (set position (+ position 1))) (> hits 0)) -(fn sum ((values (vec i32))) -> i32 +(fn sum ((values VecI32)) -> i32 (var position i32 0) (var total i32 0) (while (< position (len values)) @@ -144,21 +146,21 @@ (set position (+ position 1))) total) -(fn concat_loop ((result (vec i32)) (right (vec i32)) (position i32) (right_len i32)) -> (vec i32) +(fn concat_loop ((result VecI32) (right VecI32) (position i32) (right_len i32)) -> VecI32 (if (< position right_len) (concat_loop (append result (at right position)) right (+ position 1) right_len) result)) -(fn concat ((left (vec i32)) (right (vec i32))) -> (vec i32) +(fn concat ((left VecI32) (right VecI32)) -> VecI32 (let right_len i32 (len right)) (concat_loop left right 0 right_len)) -(fn take_loop ((values (vec i32)) (position i32) (limit i32) (result (vec i32))) -> (vec i32) +(fn take_loop ((values VecI32) (position i32) (limit i32) (result VecI32)) -> VecI32 (if (< position limit) (take_loop values (+ position 1) limit (append result (at values position))) result)) -(fn take ((values (vec i32)) (count i32)) -> (vec i32) +(fn take ((values VecI32) (count i32)) -> VecI32 (let values_len i32 (len values)) (if (< count 0) (empty) @@ -166,35 +168,35 @@ (take_loop values 0 count (empty)) values))) -(fn starts_with ((values (vec i32)) (prefix (vec i32))) -> bool +(fn starts_with ((values VecI32) (prefix VecI32)) -> bool (let prefix_len i32 (len prefix)) (if (< (len values) prefix_len) false (= (take values prefix_len) prefix))) -(fn without_prefix ((values (vec i32)) (prefix (vec i32))) -> (vec i32) +(fn without_prefix ((values VecI32) (prefix VecI32)) -> VecI32 (if (starts_with values prefix) (drop values (len prefix)) values)) -(fn ends_with ((values (vec i32)) (suffix (vec i32))) -> bool +(fn ends_with ((values VecI32) (suffix VecI32)) -> bool (let values_len i32 (len values)) (let suffix_len i32 (len suffix)) (if (< values_len suffix_len) false (= (drop values (- values_len suffix_len)) suffix))) -(fn without_suffix ((values (vec i32)) (suffix (vec i32))) -> (vec i32) +(fn without_suffix ((values VecI32) (suffix VecI32)) -> VecI32 (if (ends_with values suffix) (take values (- (len values) (len suffix))) values)) -(fn drop_loop ((values (vec i32)) (position i32) (values_len i32) (result (vec i32))) -> (vec i32) +(fn drop_loop ((values VecI32) (position i32) (values_len i32) (result VecI32)) -> VecI32 (if (< position values_len) (drop_loop values (+ position 1) values_len (append result (at values position))) result)) -(fn drop ((values (vec i32)) (count i32)) -> (vec i32) +(fn drop ((values VecI32) (count i32)) -> VecI32 (let values_len i32 (len values)) (if (< count 0) values @@ -202,22 +204,22 @@ (drop_loop values count values_len (empty)) (empty)))) -(fn reverse_loop ((values (vec i32)) (position i32) (result (vec i32))) -> (vec i32) +(fn reverse_loop ((values VecI32) (position i32) (result VecI32)) -> VecI32 (if (< position 0) result (reverse_loop values (- position 1) (append result (at values position))))) -(fn reverse ((values (vec i32))) -> (vec i32) +(fn reverse ((values VecI32)) -> VecI32 (reverse_loop values (- (len values) 1) (empty))) -(fn subvec ((values (vec i32)) (start i32) (end_exclusive i32)) -> (vec i32) +(fn subvec ((values VecI32) (start i32) (end_exclusive i32)) -> VecI32 (if (< start 0) (empty) (if (< start end_exclusive) (take (drop values start) (- end_exclusive start)) (empty)))) -(fn insert_at ((values (vec i32)) (position i32) (value i32)) -> (vec i32) +(fn insert_at ((values VecI32) (position i32) (value i32)) -> VecI32 (if (< position 0) values (if (< position (len values)) @@ -226,7 +228,7 @@ (append values value) values)))) -(fn insert_range ((values (vec i32)) (position i32) (inserted (vec i32))) -> (vec i32) +(fn insert_range ((values VecI32) (position i32) (inserted VecI32)) -> VecI32 (if (< position 0) values (if (< position (len values)) @@ -235,14 +237,14 @@ (concat values inserted) values)))) -(fn replace_at ((values (vec i32)) (position i32) (replacement i32)) -> (vec i32) +(fn replace_at ((values VecI32) (position i32) (replacement i32)) -> VecI32 (if (< position 0) values (if (< position (len values)) (concat (append (take values position) replacement) (drop values (+ position 1))) values))) -(fn replace_range ((values (vec i32)) (start i32) (end_exclusive i32) (replacement (vec i32))) -> (vec i32) +(fn replace_range ((values VecI32) (start i32) (end_exclusive i32) (replacement VecI32)) -> VecI32 (let values_len i32 (len values)) (if (< start 0) values @@ -252,14 +254,14 @@ values) values))) -(fn remove_at ((values (vec i32)) (position i32)) -> (vec i32) +(fn remove_at ((values VecI32) (position i32)) -> VecI32 (if (< position 0) values (if (< position (len values)) (concat (take values position) (drop values (+ position 1))) values))) -(fn remove_range ((values (vec i32)) (start i32) (end_exclusive i32)) -> (vec i32) +(fn remove_range ((values VecI32) (start i32) (end_exclusive i32)) -> VecI32 (let values_len i32 (len values)) (if (< start 0) values diff --git a/examples/projects/std-layout-local-vec_i64/src/vec_i64.slo b/examples/projects/std-layout-local-vec_i64/src/vec_i64.slo index 7327e52..7feeece 100644 --- a/examples/projects/std-layout-local-vec_i64/src/vec_i64.slo +++ b/examples/projects/std-layout-local-vec_i64/src/vec_i64.slo @@ -1,118 +1,120 @@ (module vec_i64 (export empty append len at singleton append2 append3 pair triple is_empty index_or first_or last_or index_option first_option last_option index_of_option last_index_of_option contains sum concat take drop reverse subvec insert_at insert_range replace_at replace_range remove_at remove_range)) -(fn empty () -> (vec i64) +(type VecI64 (vec i64)) + +(fn empty () -> VecI64 (std.vec.i64.empty)) -(fn append ((values (vec i64)) (value i64)) -> (vec i64) +(fn append ((values VecI64) (value i64)) -> VecI64 (std.vec.i64.append values value)) -(fn len ((values (vec i64))) -> i32 +(fn len ((values VecI64)) -> i32 (std.vec.i64.len values)) -(fn at ((values (vec i64)) (position i32)) -> i64 +(fn at ((values VecI64) (position i32)) -> i64 (std.vec.i64.index values position)) -(fn singleton ((value i64)) -> (vec i64) +(fn singleton ((value i64)) -> VecI64 (append (empty) value)) -(fn append2 ((values (vec i64)) (first i64) (second i64)) -> (vec i64) +(fn append2 ((values VecI64) (first i64) (second i64)) -> VecI64 (append (append values first) second)) -(fn append3 ((values (vec i64)) (first i64) (second i64) (third i64)) -> (vec i64) +(fn append3 ((values VecI64) (first i64) (second i64) (third i64)) -> VecI64 (append (append2 values first second) third)) -(fn pair ((first i64) (second i64)) -> (vec i64) +(fn pair ((first i64) (second i64)) -> VecI64 (append2 (empty) first second)) -(fn triple ((first i64) (second i64) (third i64)) -> (vec i64) +(fn triple ((first i64) (second i64) (third i64)) -> VecI64 (append3 (empty) first second third)) -(fn is_empty ((values (vec i64))) -> bool +(fn is_empty ((values VecI64)) -> bool (= (len values) 0)) -(fn index_or ((values (vec i64)) (position i32) (fallback i64)) -> i64 +(fn index_or ((values VecI64) (position i32) (fallback i64)) -> i64 (if (< position 0) fallback (if (< position (len values)) (at values position) fallback))) -(fn first_or ((values (vec i64)) (fallback i64)) -> i64 +(fn first_or ((values VecI64) (fallback i64)) -> i64 (index_or values 0 fallback)) -(fn last_or ((values (vec i64)) (fallback i64)) -> i64 +(fn last_or ((values VecI64) (fallback i64)) -> i64 (if (is_empty values) fallback (at values (- (len values) 1)))) -(fn index_option ((values (vec i64)) (position i32)) -> (option i64) +(fn index_option ((values VecI64) (position i32)) -> (option i64) (if (< position 0) (none i64) (if (< position (len values)) (some i64 (at values position)) (none i64)))) -(fn first_option ((values (vec i64))) -> (option i64) +(fn first_option ((values VecI64)) -> (option i64) (index_option values 0)) -(fn last_option ((values (vec i64))) -> (option i64) +(fn last_option ((values VecI64)) -> (option i64) (if (is_empty values) (none i64) (some i64 (at values (- (len values) 1))))) -(fn index_of_option_loop ((values (vec i64)) (target i64) (position i32) (values_len i32)) -> (option i32) +(fn index_of_option_loop ((values VecI64) (target i64) (position i32) (values_len i32)) -> (option i32) (if (< position values_len) (if (= (at values position) target) (some i32 position) (index_of_option_loop values target (+ position 1) values_len)) (none i32))) -(fn index_of_option ((values (vec i64)) (target i64)) -> (option i32) +(fn index_of_option ((values VecI64) (target i64)) -> (option i32) (index_of_option_loop values target 0 (len values))) -(fn last_index_of_option_loop ((values (vec i64)) (target i64) (position i32) (values_len i32) (found (option i32))) -> (option i32) +(fn last_index_of_option_loop ((values VecI64) (target i64) (position i32) (values_len i32) (found_position (option i32))) -> (option i32) (if (< position values_len) - (if (= (at values position) target) - (last_index_of_option_loop values target (+ position 1) values_len (some i32 position)) - (last_index_of_option_loop values target (+ position 1) values_len found)) - found)) + (last_index_of_option_loop values target (+ position 1) values_len (if (= (at values position) target) + (some i32 position) + found_position)) + found_position)) -(fn last_index_of_option ((values (vec i64)) (target i64)) -> (option i32) +(fn last_index_of_option ((values VecI64) (target i64)) -> (option i32) (last_index_of_option_loop values target 0 (len values) (none i32))) -(fn contains_loop ((values (vec i64)) (target i64) (position i32) (values_len i32)) -> bool +(fn contains_loop ((values VecI64) (target i64) (position i32) (values_len i32)) -> bool (if (< position values_len) (if (= (at values position) target) true (contains_loop values target (+ position 1) values_len)) false)) -(fn contains ((values (vec i64)) (target i64)) -> bool +(fn contains ((values VecI64) (target i64)) -> bool (contains_loop values target 0 (len values))) -(fn sum_loop ((values (vec i64)) (position i32) (values_len i32) (total i64)) -> i64 +(fn sum_loop ((values VecI64) (position i32) (values_len i32) (total i64)) -> i64 (if (< position values_len) (sum_loop values (+ position 1) values_len (+ total (at values position))) total)) -(fn sum ((values (vec i64))) -> i64 +(fn sum ((values VecI64)) -> i64 (sum_loop values 0 (len values) 0i64)) -(fn concat_loop ((built (vec i64)) (right (vec i64)) (position i32) (right_len i32)) -> (vec i64) +(fn concat_loop ((result VecI64) (right VecI64) (position i32) (right_len i32)) -> VecI64 (if (< position right_len) - (concat_loop (append built (at right position)) right (+ position 1) right_len) - built)) + (concat_loop (append result (at right position)) right (+ position 1) right_len) + result)) -(fn concat ((left (vec i64)) (right (vec i64))) -> (vec i64) +(fn concat ((left VecI64) (right VecI64)) -> VecI64 (let right_len i32 (len right)) (concat_loop left right 0 right_len)) -(fn take_loop ((values (vec i64)) (position i32) (limit i32) (built (vec i64))) -> (vec i64) +(fn take_loop ((values VecI64) (position i32) (limit i32) (result VecI64)) -> VecI64 (if (< position limit) - (take_loop values (+ position 1) limit (append built (at values position))) - built)) + (take_loop values (+ position 1) limit (append result (at values position))) + result)) -(fn take ((values (vec i64)) (count i32)) -> (vec i64) +(fn take ((values VecI64) (count i32)) -> VecI64 (let values_len i32 (len values)) (if (< count 0) (empty) @@ -120,12 +122,12 @@ (take_loop values 0 count (empty)) values))) -(fn drop_loop ((values (vec i64)) (position i32) (values_len i32) (built (vec i64))) -> (vec i64) +(fn drop_loop ((values VecI64) (position i32) (values_len i32) (result VecI64)) -> VecI64 (if (< position values_len) - (drop_loop values (+ position 1) values_len (append built (at values position))) - built)) + (drop_loop values (+ position 1) values_len (append result (at values position))) + result)) -(fn drop ((values (vec i64)) (count i32)) -> (vec i64) +(fn drop ((values VecI64) (count i32)) -> VecI64 (let values_len i32 (len values)) (if (< count 0) values @@ -133,47 +135,49 @@ (drop_loop values count values_len (empty)) (empty)))) -(fn reverse_loop ((values (vec i64)) (position i32) (built (vec i64))) -> (vec i64) +(fn reverse_loop ((values VecI64) (position i32) (result VecI64)) -> VecI64 (if (< position 0) - built - (reverse_loop values (- position 1) (append built (at values position))))) + result + (reverse_loop values (- position 1) (append result (at values position))))) -(fn reverse ((values (vec i64))) -> (vec i64) +(fn reverse ((values VecI64)) -> VecI64 (reverse_loop values (- (len values) 1) (empty))) -(fn subvec ((values (vec i64)) (start i32) (end_exclusive i32)) -> (vec i64) +(fn subvec ((values VecI64) (start i32) (end_exclusive i32)) -> VecI64 (if (< start 0) (empty) (if (< start end_exclusive) (take (drop values start) (- end_exclusive start)) (empty)))) -(fn insert_at ((values (vec i64)) (position i32) (value i64)) -> (vec i64) +(fn insert_at ((values VecI64) (position i32) (value i64)) -> VecI64 + (let values_len i32 (len values)) (if (< position 0) values - (if (< position (len values)) + (if (< position values_len) (concat (append (take values position) value) (drop values position)) - (if (= position (len values)) + (if (= position values_len) (append values value) values)))) -(fn insert_range ((values (vec i64)) (position i32) (inserted (vec i64))) -> (vec i64) +(fn insert_range ((values VecI64) (position i32) (inserted VecI64)) -> VecI64 + (let values_len i32 (len values)) (if (< position 0) values - (if (< position (len values)) + (if (< position values_len) (concat (concat (take values position) inserted) (drop values position)) - (if (= position (len values)) + (if (= position values_len) (concat values inserted) values)))) -(fn replace_at ((values (vec i64)) (position i32) (replacement i64)) -> (vec i64) +(fn replace_at ((values VecI64) (position i32) (replacement i64)) -> VecI64 (if (< position 0) values (if (< position (len values)) (concat (append (take values position) replacement) (drop values (+ position 1))) values))) -(fn replace_range ((values (vec i64)) (start i32) (end_exclusive i32) (replacement (vec i64))) -> (vec i64) +(fn replace_range ((values VecI64) (start i32) (end_exclusive i32) (replacement VecI64)) -> VecI64 (let values_len i32 (len values)) (if (< start 0) values @@ -183,14 +187,14 @@ values) values))) -(fn remove_at ((values (vec i64)) (position i32)) -> (vec i64) +(fn remove_at ((values VecI64) (position i32)) -> VecI64 (if (< position 0) values (if (< position (len values)) (concat (take values position) (drop values (+ position 1))) values))) -(fn remove_range ((values (vec i64)) (start i32) (end_exclusive i32)) -> (vec i64) +(fn remove_range ((values VecI64) (start i32) (end_exclusive i32)) -> VecI64 (let values_len i32 (len values)) (if (< start 0) values diff --git a/examples/projects/std-layout-local-vec_string/src/vec_string.slo b/examples/projects/std-layout-local-vec_string/src/vec_string.slo index d72c4b5..e92607d 100644 --- a/examples/projects/std-layout-local-vec_string/src/vec_string.slo +++ b/examples/projects/std-layout-local-vec_string/src/vec_string.slo @@ -1,120 +1,122 @@ (module vec_string (export empty append len at singleton append2 append3 pair triple is_empty index_or first_or last_or index_option first_option last_option index_of_option last_index_of_option contains count_of concat take starts_with without_prefix ends_with without_suffix drop reverse subvec insert_at insert_range replace_at replace_range remove_at remove_range)) -(fn empty () -> (vec string) +(type VecString (vec string)) + +(fn empty () -> VecString (std.vec.string.empty)) -(fn append ((values (vec string)) (value string)) -> (vec string) +(fn append ((values VecString) (value string)) -> VecString (std.vec.string.append values value)) -(fn len ((values (vec string))) -> i32 +(fn len ((values VecString)) -> i32 (std.vec.string.len values)) -(fn at ((values (vec string)) (position i32)) -> string +(fn at ((values VecString) (position i32)) -> string (std.vec.string.index values position)) -(fn singleton ((value string)) -> (vec string) +(fn singleton ((value string)) -> VecString (append (empty) value)) -(fn append2 ((values (vec string)) (first string) (second string)) -> (vec string) +(fn append2 ((values VecString) (first string) (second string)) -> VecString (append (append values first) second)) -(fn append3 ((values (vec string)) (first string) (second string) (third string)) -> (vec string) +(fn append3 ((values VecString) (first string) (second string) (third string)) -> VecString (append (append2 values first second) third)) -(fn pair ((first string) (second string)) -> (vec string) +(fn pair ((first string) (second string)) -> VecString (append2 (empty) first second)) -(fn triple ((first string) (second string) (third string)) -> (vec string) +(fn triple ((first string) (second string) (third string)) -> VecString (append3 (empty) first second third)) -(fn is_empty ((values (vec string))) -> bool +(fn is_empty ((values VecString)) -> bool (= (len values) 0)) -(fn index_or ((values (vec string)) (position i32) (fallback string)) -> string +(fn index_or ((values VecString) (position i32) (fallback string)) -> string (if (< position 0) fallback (if (< position (len values)) (at values position) fallback))) -(fn first_or ((values (vec string)) (fallback string)) -> string +(fn first_or ((values VecString) (fallback string)) -> string (index_or values 0 fallback)) -(fn last_or ((values (vec string)) (fallback string)) -> string +(fn last_or ((values VecString) (fallback string)) -> string (if (is_empty values) fallback (at values (- (len values) 1)))) -(fn index_option ((values (vec string)) (position i32)) -> (option string) +(fn index_option ((values VecString) (position i32)) -> (option string) (if (< position 0) (none string) (if (< position (len values)) (some string (at values position)) (none string)))) -(fn first_option ((values (vec string))) -> (option string) +(fn first_option ((values VecString)) -> (option string) (index_option values 0)) -(fn last_option ((values (vec string))) -> (option string) +(fn last_option ((values VecString)) -> (option string) (if (is_empty values) (none string) (some string (at values (- (len values) 1))))) -(fn index_of_option_loop ((values (vec string)) (target string) (position i32) (values_len i32)) -> (option i32) +(fn index_of_option_loop ((values VecString) (target string) (position i32) (values_len i32)) -> (option i32) (if (< position values_len) (if (= (at values position) target) (some i32 position) (index_of_option_loop values target (+ position 1) values_len)) (none i32))) -(fn index_of_option ((values (vec string)) (target string)) -> (option i32) +(fn index_of_option ((values VecString) (target string)) -> (option i32) (index_of_option_loop values target 0 (len values))) -(fn last_index_of_option_loop ((values (vec string)) (target string) (position i32) (values_len i32) (found (option i32))) -> (option i32) +(fn last_index_of_option_loop ((values VecString) (target string) (position i32) (values_len i32) (found (option i32))) -> (option i32) (if (< position values_len) (if (= (at values position) target) (last_index_of_option_loop values target (+ position 1) values_len (some i32 position)) (last_index_of_option_loop values target (+ position 1) values_len found)) found)) -(fn last_index_of_option ((values (vec string)) (target string)) -> (option i32) +(fn last_index_of_option ((values VecString) (target string)) -> (option i32) (last_index_of_option_loop values target 0 (len values) (none i32))) -(fn contains_loop ((values (vec string)) (target string) (position i32) (values_len i32)) -> bool +(fn contains_loop ((values VecString) (target string) (position i32) (values_len i32)) -> bool (if (< position values_len) (if (= (at values position) target) true (contains_loop values target (+ position 1) values_len)) false)) -(fn contains ((values (vec string)) (target string)) -> bool +(fn contains ((values VecString) (target string)) -> bool (contains_loop values target 0 (len values))) -(fn count_of_loop ((values (vec string)) (target string) (position i32) (values_len i32) (hits i32)) -> i32 +(fn count_of_loop ((values VecString) (target string) (position i32) (values_len i32) (hits i32)) -> i32 (if (< position values_len) (count_of_loop values target (+ position 1) values_len (+ hits (if (= (at values position) target) 1 0))) hits)) -(fn count_of ((values (vec string)) (target string)) -> i32 +(fn count_of ((values VecString) (target string)) -> i32 (count_of_loop values target 0 (len values) 0)) -(fn concat_loop ((built (vec string)) (right (vec string)) (position i32) (right_len i32)) -> (vec string) +(fn concat_loop ((built VecString) (right VecString) (position i32) (right_len i32)) -> VecString (if (< position right_len) (concat_loop (append built (at right position)) right (+ position 1) right_len) built)) -(fn concat ((left (vec string)) (right (vec string))) -> (vec string) +(fn concat ((left VecString) (right VecString)) -> VecString (let right_len i32 (len right)) (concat_loop left right 0 right_len)) -(fn take_loop ((values (vec string)) (position i32) (limit i32) (built (vec string))) -> (vec string) +(fn take_loop ((values VecString) (position i32) (limit i32) (built VecString)) -> VecString (if (< position limit) (take_loop values (+ position 1) limit (append built (at values position))) built)) -(fn take ((values (vec string)) (count i32)) -> (vec string) +(fn take ((values VecString) (count i32)) -> VecString (let values_len i32 (len values)) (if (< count 0) (empty) @@ -122,35 +124,35 @@ (take_loop values 0 count (empty)) values))) -(fn starts_with ((values (vec string)) (prefix (vec string))) -> bool +(fn starts_with ((values VecString) (prefix VecString)) -> bool (let prefix_len i32 (len prefix)) (if (< (len values) prefix_len) false (= (take values prefix_len) prefix))) -(fn without_prefix ((values (vec string)) (prefix (vec string))) -> (vec string) +(fn without_prefix ((values VecString) (prefix VecString)) -> VecString (if (starts_with values prefix) (drop values (len prefix)) values)) -(fn ends_with ((values (vec string)) (suffix (vec string))) -> bool +(fn ends_with ((values VecString) (suffix VecString)) -> bool (let values_len i32 (len values)) (let suffix_len i32 (len suffix)) (if (< values_len suffix_len) false (= (drop values (- values_len suffix_len)) suffix))) -(fn without_suffix ((values (vec string)) (suffix (vec string))) -> (vec string) +(fn without_suffix ((values VecString) (suffix VecString)) -> VecString (if (ends_with values suffix) (take values (- (len values) (len suffix))) values)) -(fn drop_loop ((values (vec string)) (position i32) (values_len i32) (built (vec string))) -> (vec string) +(fn drop_loop ((values VecString) (position i32) (values_len i32) (built VecString)) -> VecString (if (< position values_len) (drop_loop values (+ position 1) values_len (append built (at values position))) built)) -(fn drop ((values (vec string)) (count i32)) -> (vec string) +(fn drop ((values VecString) (count i32)) -> VecString (let values_len i32 (len values)) (if (< count 0) values @@ -158,22 +160,22 @@ (drop_loop values count values_len (empty)) (empty)))) -(fn reverse_loop ((values (vec string)) (position i32) (built (vec string))) -> (vec string) +(fn reverse_loop ((values VecString) (position i32) (built VecString)) -> VecString (if (< position 0) built (reverse_loop values (- position 1) (append built (at values position))))) -(fn reverse ((values (vec string))) -> (vec string) +(fn reverse ((values VecString)) -> VecString (reverse_loop values (- (len values) 1) (empty))) -(fn subvec ((values (vec string)) (start i32) (end_exclusive i32)) -> (vec string) +(fn subvec ((values VecString) (start i32) (end_exclusive i32)) -> VecString (if (< start 0) (empty) (if (< start end_exclusive) (take (drop values start) (- end_exclusive start)) (empty)))) -(fn insert_at ((values (vec string)) (position i32) (value string)) -> (vec string) +(fn insert_at ((values VecString) (position i32) (value string)) -> VecString (let values_len i32 (len values)) (if (< position 0) values @@ -183,7 +185,7 @@ (append values value) values)))) -(fn insert_range ((values (vec string)) (position i32) (inserted (vec string))) -> (vec string) +(fn insert_range ((values VecString) (position i32) (inserted VecString)) -> VecString (let values_len i32 (len values)) (if (< position 0) values @@ -193,14 +195,14 @@ (concat values inserted) values)))) -(fn replace_at ((values (vec string)) (position i32) (replacement string)) -> (vec string) +(fn replace_at ((values VecString) (position i32) (replacement string)) -> VecString (if (< position 0) values (if (< position (len values)) (concat (append (take values position) replacement) (drop values (+ position 1))) values))) -(fn replace_range ((values (vec string)) (start i32) (end_exclusive i32) (replacement (vec string))) -> (vec string) +(fn replace_range ((values VecString) (start i32) (end_exclusive i32) (replacement VecString)) -> VecString (let values_len i32 (len values)) (if (< start 0) values @@ -210,14 +212,14 @@ values) values))) -(fn remove_at ((values (vec string)) (position i32)) -> (vec string) +(fn remove_at ((values VecString) (position i32)) -> VecString (if (< position 0) values (if (< position (len values)) (concat (take values position) (drop values (+ position 1))) values))) -(fn remove_range ((values (vec string)) (start i32) (end_exclusive i32)) -> (vec string) +(fn remove_range ((values VecString) (start i32) (end_exclusive i32)) -> VecString (let values_len i32 (len values)) (if (< start 0) values diff --git a/lib/std/option.slo b/lib/std/option.slo index 1076cfd..bb8def1 100644 --- a/lib/std/option.slo +++ b/lib/std/option.slo @@ -1,176 +1,204 @@ (module option (export some_i32 none_i32 is_some_i32 is_none_i32 unwrap_some_i32 unwrap_or_i32 some_or_err_i32 some_u32 none_u32 is_some_u32 is_none_u32 unwrap_some_u32 unwrap_or_u32 some_or_err_u32 some_i64 none_i64 is_some_i64 is_none_i64 unwrap_some_i64 unwrap_or_i64 some_or_err_i64 some_u64 none_u64 is_some_u64 is_none_u64 unwrap_some_u64 unwrap_or_u64 some_or_err_u64 some_f64 none_f64 is_some_f64 is_none_f64 unwrap_some_f64 unwrap_or_f64 some_or_err_f64 some_bool none_bool is_some_bool is_none_bool unwrap_some_bool unwrap_or_bool some_or_err_bool some_string none_string is_some_string is_none_string unwrap_some_string unwrap_or_string some_or_err_string)) -(fn some_i32 ((value i32)) -> (option i32) +(type OptionI32 (option i32)) + +(type ResultI32 (result i32 i32)) + +(type OptionU32 (option u32)) + +(type ResultU32 (result u32 i32)) + +(type OptionI64 (option i64)) + +(type ResultI64 (result i64 i32)) + +(type OptionU64 (option u64)) + +(type ResultU64 (result u64 i32)) + +(type OptionF64 (option f64)) + +(type ResultF64 (result f64 i32)) + +(type OptionBool (option bool)) + +(type ResultBool (result bool i32)) + +(type OptionString (option string)) + +(type ResultString (result string i32)) + +(fn some_i32 ((value i32)) -> OptionI32 (some i32 value)) -(fn none_i32 () -> (option i32) +(fn none_i32 () -> OptionI32 (none i32)) -(fn is_some_i32 ((value (option i32))) -> bool +(fn is_some_i32 ((value OptionI32)) -> bool (is_some value)) -(fn is_none_i32 ((value (option i32))) -> bool +(fn is_none_i32 ((value OptionI32)) -> bool (is_none value)) -(fn unwrap_some_i32 ((value (option i32))) -> i32 +(fn unwrap_some_i32 ((value OptionI32)) -> i32 (unwrap_some value)) -(fn unwrap_or_i32 ((value (option i32)) (fallback i32)) -> i32 +(fn unwrap_or_i32 ((value OptionI32) (fallback i32)) -> i32 (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_i32 ((value (option i32)) (err_code i32)) -> (result i32 i32) +(fn some_or_err_i32 ((value OptionI32) (err_code i32)) -> ResultI32 (if (is_some value) (ok i32 i32 (unwrap_some value)) (err i32 i32 err_code))) -(fn some_u32 ((value u32)) -> (option u32) +(fn some_u32 ((value u32)) -> OptionU32 (some u32 value)) -(fn none_u32 () -> (option u32) +(fn none_u32 () -> OptionU32 (none u32)) -(fn is_some_u32 ((value (option u32))) -> bool +(fn is_some_u32 ((value OptionU32)) -> bool (is_some value)) -(fn is_none_u32 ((value (option u32))) -> bool +(fn is_none_u32 ((value OptionU32)) -> bool (is_none value)) -(fn unwrap_some_u32 ((value (option u32))) -> u32 +(fn unwrap_some_u32 ((value OptionU32)) -> u32 (unwrap_some value)) -(fn unwrap_or_u32 ((value (option u32)) (fallback u32)) -> u32 +(fn unwrap_or_u32 ((value OptionU32) (fallback u32)) -> u32 (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_u32 ((value (option u32)) (err_code i32)) -> (result u32 i32) +(fn some_or_err_u32 ((value OptionU32) (err_code i32)) -> ResultU32 (if (is_some value) (ok u32 i32 (unwrap_some value)) (err u32 i32 err_code))) -(fn some_i64 ((value i64)) -> (option i64) +(fn some_i64 ((value i64)) -> OptionI64 (some i64 value)) -(fn none_i64 () -> (option i64) +(fn none_i64 () -> OptionI64 (none i64)) -(fn is_some_i64 ((value (option i64))) -> bool +(fn is_some_i64 ((value OptionI64)) -> bool (is_some value)) -(fn is_none_i64 ((value (option i64))) -> bool +(fn is_none_i64 ((value OptionI64)) -> bool (is_none value)) -(fn unwrap_some_i64 ((value (option i64))) -> i64 +(fn unwrap_some_i64 ((value OptionI64)) -> i64 (unwrap_some value)) -(fn unwrap_or_i64 ((value (option i64)) (fallback i64)) -> i64 +(fn unwrap_or_i64 ((value OptionI64) (fallback i64)) -> i64 (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_i64 ((value (option i64)) (err_code i32)) -> (result i64 i32) +(fn some_or_err_i64 ((value OptionI64) (err_code i32)) -> ResultI64 (if (is_some value) (ok i64 i32 (unwrap_some value)) (err i64 i32 err_code))) -(fn some_u64 ((value u64)) -> (option u64) +(fn some_u64 ((value u64)) -> OptionU64 (some u64 value)) -(fn none_u64 () -> (option u64) +(fn none_u64 () -> OptionU64 (none u64)) -(fn is_some_u64 ((value (option u64))) -> bool +(fn is_some_u64 ((value OptionU64)) -> bool (is_some value)) -(fn is_none_u64 ((value (option u64))) -> bool +(fn is_none_u64 ((value OptionU64)) -> bool (is_none value)) -(fn unwrap_some_u64 ((value (option u64))) -> u64 +(fn unwrap_some_u64 ((value OptionU64)) -> u64 (unwrap_some value)) -(fn unwrap_or_u64 ((value (option u64)) (fallback u64)) -> u64 +(fn unwrap_or_u64 ((value OptionU64) (fallback u64)) -> u64 (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_u64 ((value (option u64)) (err_code i32)) -> (result u64 i32) +(fn some_or_err_u64 ((value OptionU64) (err_code i32)) -> ResultU64 (if (is_some value) (ok u64 i32 (unwrap_some value)) (err u64 i32 err_code))) -(fn some_f64 ((value f64)) -> (option f64) +(fn some_f64 ((value f64)) -> OptionF64 (some f64 value)) -(fn none_f64 () -> (option f64) +(fn none_f64 () -> OptionF64 (none f64)) -(fn is_some_f64 ((value (option f64))) -> bool +(fn is_some_f64 ((value OptionF64)) -> bool (is_some value)) -(fn is_none_f64 ((value (option f64))) -> bool +(fn is_none_f64 ((value OptionF64)) -> bool (is_none value)) -(fn unwrap_some_f64 ((value (option f64))) -> f64 +(fn unwrap_some_f64 ((value OptionF64)) -> f64 (unwrap_some value)) -(fn unwrap_or_f64 ((value (option f64)) (fallback f64)) -> f64 +(fn unwrap_or_f64 ((value OptionF64) (fallback f64)) -> f64 (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_f64 ((value (option f64)) (err_code i32)) -> (result f64 i32) +(fn some_or_err_f64 ((value OptionF64) (err_code i32)) -> ResultF64 (if (is_some value) (ok f64 i32 (unwrap_some value)) (err f64 i32 err_code))) -(fn some_bool ((value bool)) -> (option bool) +(fn some_bool ((value bool)) -> OptionBool (some bool value)) -(fn none_bool () -> (option bool) +(fn none_bool () -> OptionBool (none bool)) -(fn is_some_bool ((value (option bool))) -> bool +(fn is_some_bool ((value OptionBool)) -> bool (is_some value)) -(fn is_none_bool ((value (option bool))) -> bool +(fn is_none_bool ((value OptionBool)) -> bool (is_none value)) -(fn unwrap_some_bool ((value (option bool))) -> bool +(fn unwrap_some_bool ((value OptionBool)) -> bool (unwrap_some value)) -(fn unwrap_or_bool ((value (option bool)) (fallback bool)) -> bool +(fn unwrap_or_bool ((value OptionBool) (fallback bool)) -> bool (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_bool ((value (option bool)) (err_code i32)) -> (result bool i32) +(fn some_or_err_bool ((value OptionBool) (err_code i32)) -> ResultBool (if (is_some value) (ok bool i32 (unwrap_some value)) (err bool i32 err_code))) -(fn some_string ((value string)) -> (option string) +(fn some_string ((value string)) -> OptionString (some string value)) -(fn none_string () -> (option string) +(fn none_string () -> OptionString (none string)) -(fn is_some_string ((value (option string))) -> bool +(fn is_some_string ((value OptionString)) -> bool (is_some value)) -(fn is_none_string ((value (option string))) -> bool +(fn is_none_string ((value OptionString)) -> bool (is_none value)) -(fn unwrap_some_string ((value (option string))) -> string +(fn unwrap_some_string ((value OptionString)) -> string (unwrap_some value)) -(fn unwrap_or_string ((value (option string)) (fallback string)) -> string +(fn unwrap_or_string ((value OptionString) (fallback string)) -> string (if (is_some value) (unwrap_some value) fallback)) -(fn some_or_err_string ((value (option string)) (err_code i32)) -> (result string i32) +(fn some_or_err_string ((value OptionString) (err_code i32)) -> ResultString (if (is_some value) (ok string i32 (unwrap_some value)) (err string i32 err_code))) diff --git a/lib/std/result.slo b/lib/std/result.slo index 4a7b77b..8f497bb 100644 --- a/lib/std/result.slo +++ b/lib/std/result.slo @@ -1,199 +1,227 @@ (module result (export ok_i32 err_i32 is_ok_i32 is_err_i32 unwrap_ok_i32 unwrap_err_i32 unwrap_or_i32 ok_or_none_i32 ok_u32 err_u32 is_ok_u32 is_err_u32 unwrap_ok_u32 unwrap_err_u32 unwrap_or_u32 ok_or_none_u32 ok_i64 err_i64 is_ok_i64 is_err_i64 unwrap_ok_i64 unwrap_err_i64 unwrap_or_i64 ok_or_none_i64 ok_u64 err_u64 is_ok_u64 is_err_u64 unwrap_ok_u64 unwrap_err_u64 unwrap_or_u64 ok_or_none_u64 ok_string err_string is_ok_string is_err_string unwrap_ok_string unwrap_err_string unwrap_or_string ok_or_none_string ok_f64 err_f64 is_ok_f64 is_err_f64 unwrap_ok_f64 unwrap_err_f64 unwrap_or_f64 ok_or_none_f64 ok_bool err_bool is_ok_bool is_err_bool unwrap_ok_bool unwrap_err_bool unwrap_or_bool ok_or_none_bool)) -(fn ok_i32 ((value i32)) -> (result i32 i32) +(type ResultI32 (result i32 i32)) + +(type OptionI32 (option i32)) + +(type ResultU32 (result u32 i32)) + +(type OptionU32 (option u32)) + +(type ResultI64 (result i64 i32)) + +(type OptionI64 (option i64)) + +(type ResultU64 (result u64 i32)) + +(type OptionU64 (option u64)) + +(type ResultString (result string i32)) + +(type OptionString (option string)) + +(type ResultF64 (result f64 i32)) + +(type OptionF64 (option f64)) + +(type ResultBool (result bool i32)) + +(type OptionBool (option bool)) + +(fn ok_i32 ((value i32)) -> ResultI32 (ok i32 i32 value)) -(fn err_i32 ((code i32)) -> (result i32 i32) +(fn err_i32 ((code i32)) -> ResultI32 (err i32 i32 code)) -(fn is_ok_i32 ((value (result i32 i32))) -> bool +(fn is_ok_i32 ((value ResultI32)) -> bool (std.result.is_ok value)) -(fn is_err_i32 ((value (result i32 i32))) -> bool +(fn is_err_i32 ((value ResultI32)) -> bool (std.result.is_err value)) -(fn unwrap_ok_i32 ((value (result i32 i32))) -> i32 +(fn unwrap_ok_i32 ((value ResultI32)) -> i32 (std.result.unwrap_ok value)) -(fn unwrap_err_i32 ((value (result i32 i32))) -> i32 +(fn unwrap_err_i32 ((value ResultI32)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_i32 ((value (result i32 i32)) (fallback i32)) -> i32 +(fn unwrap_or_i32 ((value ResultI32) (fallback i32)) -> i32 (if (std.result.is_ok value) (std.result.unwrap_ok value) fallback)) -(fn ok_or_none_i32 ((value (result i32 i32))) -> (option i32) +(fn ok_or_none_i32 ((value ResultI32)) -> OptionI32 (if (std.result.is_ok value) (some i32 (std.result.unwrap_ok value)) (none i32))) -(fn ok_u32 ((value u32)) -> (result u32 i32) +(fn ok_u32 ((value u32)) -> ResultU32 (ok u32 i32 value)) -(fn err_u32 ((code i32)) -> (result u32 i32) +(fn err_u32 ((code i32)) -> ResultU32 (err u32 i32 code)) -(fn is_ok_u32 ((value (result u32 i32))) -> bool +(fn is_ok_u32 ((value ResultU32)) -> bool (std.result.is_ok value)) -(fn is_err_u32 ((value (result u32 i32))) -> bool +(fn is_err_u32 ((value ResultU32)) -> bool (std.result.is_err value)) -(fn unwrap_ok_u32 ((value (result u32 i32))) -> u32 +(fn unwrap_ok_u32 ((value ResultU32)) -> u32 (std.result.unwrap_ok value)) -(fn unwrap_err_u32 ((value (result u32 i32))) -> i32 +(fn unwrap_err_u32 ((value ResultU32)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_u32 ((value (result u32 i32)) (fallback u32)) -> u32 +(fn unwrap_or_u32 ((value ResultU32) (fallback u32)) -> u32 (if (std.result.is_ok value) (std.result.unwrap_ok value) fallback)) -(fn ok_or_none_u32 ((value (result u32 i32))) -> (option u32) +(fn ok_or_none_u32 ((value ResultU32)) -> OptionU32 (if (std.result.is_ok value) (some u32 (std.result.unwrap_ok value)) (none u32))) -(fn ok_i64 ((value i64)) -> (result i64 i32) +(fn ok_i64 ((value i64)) -> ResultI64 (ok i64 i32 value)) -(fn err_i64 ((code i32)) -> (result i64 i32) +(fn err_i64 ((code i32)) -> ResultI64 (err i64 i32 code)) -(fn is_ok_i64 ((value (result i64 i32))) -> bool +(fn is_ok_i64 ((value ResultI64)) -> bool (std.result.is_ok value)) -(fn is_err_i64 ((value (result i64 i32))) -> bool +(fn is_err_i64 ((value ResultI64)) -> bool (std.result.is_err value)) -(fn unwrap_ok_i64 ((value (result i64 i32))) -> i64 +(fn unwrap_ok_i64 ((value ResultI64)) -> i64 (std.result.unwrap_ok value)) -(fn unwrap_err_i64 ((value (result i64 i32))) -> i32 +(fn unwrap_err_i64 ((value ResultI64)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_i64 ((value (result i64 i32)) (fallback i64)) -> i64 +(fn unwrap_or_i64 ((value ResultI64) (fallback i64)) -> i64 (if (std.result.is_ok value) (std.result.unwrap_ok value) fallback)) -(fn ok_or_none_i64 ((value (result i64 i32))) -> (option i64) +(fn ok_or_none_i64 ((value ResultI64)) -> OptionI64 (if (std.result.is_ok value) (some i64 (std.result.unwrap_ok value)) (none i64))) -(fn ok_u64 ((value u64)) -> (result u64 i32) +(fn ok_u64 ((value u64)) -> ResultU64 (ok u64 i32 value)) -(fn err_u64 ((code i32)) -> (result u64 i32) +(fn err_u64 ((code i32)) -> ResultU64 (err u64 i32 code)) -(fn is_ok_u64 ((value (result u64 i32))) -> bool +(fn is_ok_u64 ((value ResultU64)) -> bool (std.result.is_ok value)) -(fn is_err_u64 ((value (result u64 i32))) -> bool +(fn is_err_u64 ((value ResultU64)) -> bool (std.result.is_err value)) -(fn unwrap_ok_u64 ((value (result u64 i32))) -> u64 +(fn unwrap_ok_u64 ((value ResultU64)) -> u64 (std.result.unwrap_ok value)) -(fn unwrap_err_u64 ((value (result u64 i32))) -> i32 +(fn unwrap_err_u64 ((value ResultU64)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_u64 ((value (result u64 i32)) (fallback u64)) -> u64 +(fn unwrap_or_u64 ((value ResultU64) (fallback u64)) -> u64 (if (std.result.is_ok value) (std.result.unwrap_ok value) fallback)) -(fn ok_or_none_u64 ((value (result u64 i32))) -> (option u64) +(fn ok_or_none_u64 ((value ResultU64)) -> OptionU64 (if (std.result.is_ok value) (some u64 (std.result.unwrap_ok value)) (none u64))) -(fn ok_string ((value string)) -> (result string i32) +(fn ok_string ((value string)) -> ResultString (ok string i32 value)) -(fn err_string ((code i32)) -> (result string i32) +(fn err_string ((code i32)) -> ResultString (err string i32 code)) -(fn is_ok_string ((value (result string i32))) -> bool +(fn is_ok_string ((value ResultString)) -> bool (std.result.is_ok value)) -(fn is_err_string ((value (result string i32))) -> bool +(fn is_err_string ((value ResultString)) -> bool (std.result.is_err value)) -(fn unwrap_ok_string ((value (result string i32))) -> string +(fn unwrap_ok_string ((value ResultString)) -> string (std.result.unwrap_ok value)) -(fn unwrap_err_string ((value (result string i32))) -> i32 +(fn unwrap_err_string ((value ResultString)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_string ((value (result string i32)) (fallback string)) -> string +(fn unwrap_or_string ((value ResultString) (fallback string)) -> string (match value ((ok payload) payload) ((err code) fallback))) -(fn ok_or_none_string ((value (result string i32))) -> (option string) +(fn ok_or_none_string ((value ResultString)) -> OptionString (if (std.result.is_ok value) (some string (std.result.unwrap_ok value)) (none string))) -(fn ok_f64 ((value f64)) -> (result f64 i32) +(fn ok_f64 ((value f64)) -> ResultF64 (ok f64 i32 value)) -(fn err_f64 ((code i32)) -> (result f64 i32) +(fn err_f64 ((code i32)) -> ResultF64 (err f64 i32 code)) -(fn is_ok_f64 ((value (result f64 i32))) -> bool +(fn is_ok_f64 ((value ResultF64)) -> bool (std.result.is_ok value)) -(fn is_err_f64 ((value (result f64 i32))) -> bool +(fn is_err_f64 ((value ResultF64)) -> bool (std.result.is_err value)) -(fn unwrap_ok_f64 ((value (result f64 i32))) -> f64 +(fn unwrap_ok_f64 ((value ResultF64)) -> f64 (std.result.unwrap_ok value)) -(fn unwrap_err_f64 ((value (result f64 i32))) -> i32 +(fn unwrap_err_f64 ((value ResultF64)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_f64 ((value (result f64 i32)) (fallback f64)) -> f64 +(fn unwrap_or_f64 ((value ResultF64) (fallback f64)) -> f64 (if (std.result.is_ok value) (std.result.unwrap_ok value) fallback)) -(fn ok_or_none_f64 ((value (result f64 i32))) -> (option f64) +(fn ok_or_none_f64 ((value ResultF64)) -> OptionF64 (if (std.result.is_ok value) (some f64 (std.result.unwrap_ok value)) (none f64))) -(fn ok_bool ((value bool)) -> (result bool i32) +(fn ok_bool ((value bool)) -> ResultBool (ok bool i32 value)) -(fn err_bool ((code i32)) -> (result bool i32) +(fn err_bool ((code i32)) -> ResultBool (err bool i32 code)) -(fn is_ok_bool ((value (result bool i32))) -> bool +(fn is_ok_bool ((value ResultBool)) -> bool (std.result.is_ok value)) -(fn is_err_bool ((value (result bool i32))) -> bool +(fn is_err_bool ((value ResultBool)) -> bool (std.result.is_err value)) -(fn unwrap_ok_bool ((value (result bool i32))) -> bool +(fn unwrap_ok_bool ((value ResultBool)) -> bool (std.result.unwrap_ok value)) -(fn unwrap_err_bool ((value (result bool i32))) -> i32 +(fn unwrap_err_bool ((value ResultBool)) -> i32 (std.result.unwrap_err value)) -(fn unwrap_or_bool ((value (result bool i32)) (fallback bool)) -> bool +(fn unwrap_or_bool ((value ResultBool) (fallback bool)) -> bool (if (std.result.is_ok value) (std.result.unwrap_ok value) fallback)) -(fn ok_or_none_bool ((value (result bool i32))) -> (option bool) +(fn ok_or_none_bool ((value ResultBool)) -> OptionBool (if (std.result.is_ok value) (some bool (std.result.unwrap_ok value)) (none bool))) diff --git a/lib/std/vec_bool.slo b/lib/std/vec_bool.slo index bc08933..4ea8796 100644 --- a/lib/std/vec_bool.slo +++ b/lib/std/vec_bool.slo @@ -1,120 +1,122 @@ (module vec_bool (export empty append len at singleton append2 append3 pair triple is_empty index_or first_or last_or index_option first_option last_option index_of_option last_index_of_option contains count_of concat take starts_with without_prefix ends_with without_suffix drop reverse subvec insert_at insert_range replace_at replace_range remove_at remove_range)) -(fn empty () -> (vec bool) +(type VecBool (vec bool)) + +(fn empty () -> VecBool (std.vec.bool.empty)) -(fn append ((values (vec bool)) (value bool)) -> (vec bool) +(fn append ((values VecBool) (value bool)) -> VecBool (std.vec.bool.append values value)) -(fn len ((values (vec bool))) -> i32 +(fn len ((values VecBool)) -> i32 (std.vec.bool.len values)) -(fn at ((values (vec bool)) (position i32)) -> bool +(fn at ((values VecBool) (position i32)) -> bool (std.vec.bool.index values position)) -(fn singleton ((value bool)) -> (vec bool) +(fn singleton ((value bool)) -> VecBool (append (empty) value)) -(fn append2 ((values (vec bool)) (first bool) (second bool)) -> (vec bool) +(fn append2 ((values VecBool) (first bool) (second bool)) -> VecBool (append (append values first) second)) -(fn append3 ((values (vec bool)) (first bool) (second bool) (third bool)) -> (vec bool) +(fn append3 ((values VecBool) (first bool) (second bool) (third bool)) -> VecBool (append (append2 values first second) third)) -(fn pair ((first bool) (second bool)) -> (vec bool) +(fn pair ((first bool) (second bool)) -> VecBool (append2 (empty) first second)) -(fn triple ((first bool) (second bool) (third bool)) -> (vec bool) +(fn triple ((first bool) (second bool) (third bool)) -> VecBool (append3 (empty) first second third)) -(fn is_empty ((values (vec bool))) -> bool +(fn is_empty ((values VecBool)) -> bool (= (len values) 0)) -(fn index_or ((values (vec bool)) (position i32) (fallback bool)) -> bool +(fn index_or ((values VecBool) (position i32) (fallback bool)) -> bool (if (< position 0) fallback (if (< position (len values)) (at values position) fallback))) -(fn first_or ((values (vec bool)) (fallback bool)) -> bool +(fn first_or ((values VecBool) (fallback bool)) -> bool (index_or values 0 fallback)) -(fn last_or ((values (vec bool)) (fallback bool)) -> bool +(fn last_or ((values VecBool) (fallback bool)) -> bool (if (is_empty values) fallback (at values (- (len values) 1)))) -(fn index_option ((values (vec bool)) (position i32)) -> (option bool) +(fn index_option ((values VecBool) (position i32)) -> (option bool) (if (< position 0) (none bool) (if (< position (len values)) (some bool (at values position)) (none bool)))) -(fn first_option ((values (vec bool))) -> (option bool) +(fn first_option ((values VecBool)) -> (option bool) (index_option values 0)) -(fn last_option ((values (vec bool))) -> (option bool) +(fn last_option ((values VecBool)) -> (option bool) (if (is_empty values) (none bool) (some bool (at values (- (len values) 1))))) -(fn index_of_option_loop ((values (vec bool)) (target bool) (position i32) (values_len i32)) -> (option i32) +(fn index_of_option_loop ((values VecBool) (target bool) (position i32) (values_len i32)) -> (option i32) (if (< position values_len) (if (= (at values position) target) (some i32 position) (index_of_option_loop values target (+ position 1) values_len)) (none i32))) -(fn index_of_option ((values (vec bool)) (target bool)) -> (option i32) +(fn index_of_option ((values VecBool) (target bool)) -> (option i32) (index_of_option_loop values target 0 (len values))) -(fn last_index_of_option_loop ((values (vec bool)) (target bool) (position i32) (values_len i32) (found_position (option i32))) -> (option i32) +(fn last_index_of_option_loop ((values VecBool) (target bool) (position i32) (values_len i32) (found_position (option i32))) -> (option i32) (if (< position values_len) (last_index_of_option_loop values target (+ position 1) values_len (if (= (at values position) target) (some i32 position) found_position)) found_position)) -(fn last_index_of_option ((values (vec bool)) (target bool)) -> (option i32) +(fn last_index_of_option ((values VecBool) (target bool)) -> (option i32) (last_index_of_option_loop values target 0 (len values) (none i32))) -(fn contains_loop ((values (vec bool)) (target bool) (position i32) (values_len i32)) -> bool +(fn contains_loop ((values VecBool) (target bool) (position i32) (values_len i32)) -> bool (if (< position values_len) (if (= (at values position) target) true (contains_loop values target (+ position 1) values_len)) false)) -(fn contains ((values (vec bool)) (target bool)) -> bool +(fn contains ((values VecBool) (target bool)) -> bool (contains_loop values target 0 (len values))) -(fn count_of_loop ((values (vec bool)) (target bool) (position i32) (values_len i32) (hits i32)) -> i32 +(fn count_of_loop ((values VecBool) (target bool) (position i32) (values_len i32) (hits i32)) -> i32 (if (< position values_len) (count_of_loop values target (+ position 1) values_len (+ hits (if (= (at values position) target) 1 0))) hits)) -(fn count_of ((values (vec bool)) (target bool)) -> i32 +(fn count_of ((values VecBool) (target bool)) -> i32 (count_of_loop values target 0 (len values) 0)) -(fn concat_loop ((result (vec bool)) (right (vec bool)) (position i32) (right_len i32)) -> (vec bool) +(fn concat_loop ((result VecBool) (right VecBool) (position i32) (right_len i32)) -> VecBool (if (< position right_len) (concat_loop (append result (at right position)) right (+ position 1) right_len) result)) -(fn concat ((left (vec bool)) (right (vec bool))) -> (vec bool) +(fn concat ((left VecBool) (right VecBool)) -> VecBool (let right_len i32 (len right)) (concat_loop left right 0 right_len)) -(fn take_loop ((values (vec bool)) (position i32) (limit i32) (result (vec bool))) -> (vec bool) +(fn take_loop ((values VecBool) (position i32) (limit i32) (result VecBool)) -> VecBool (if (< position limit) (take_loop values (+ position 1) limit (append result (at values position))) result)) -(fn take ((values (vec bool)) (count i32)) -> (vec bool) +(fn take ((values VecBool) (count i32)) -> VecBool (let values_len i32 (len values)) (if (< count 0) (empty) @@ -122,35 +124,35 @@ (take_loop values 0 count (empty)) values))) -(fn starts_with ((values (vec bool)) (prefix (vec bool))) -> bool +(fn starts_with ((values VecBool) (prefix VecBool)) -> bool (let prefix_len i32 (len prefix)) (if (< (len values) prefix_len) false (= (take values prefix_len) prefix))) -(fn without_prefix ((values (vec bool)) (prefix (vec bool))) -> (vec bool) +(fn without_prefix ((values VecBool) (prefix VecBool)) -> VecBool (if (starts_with values prefix) (drop values (len prefix)) values)) -(fn ends_with ((values (vec bool)) (suffix (vec bool))) -> bool +(fn ends_with ((values VecBool) (suffix VecBool)) -> bool (let values_len i32 (len values)) (let suffix_len i32 (len suffix)) (if (< values_len suffix_len) false (= (drop values (- values_len suffix_len)) suffix))) -(fn without_suffix ((values (vec bool)) (suffix (vec bool))) -> (vec bool) +(fn without_suffix ((values VecBool) (suffix VecBool)) -> VecBool (if (ends_with values suffix) (take values (- (len values) (len suffix))) values)) -(fn drop_loop ((values (vec bool)) (position i32) (values_len i32) (result (vec bool))) -> (vec bool) +(fn drop_loop ((values VecBool) (position i32) (values_len i32) (result VecBool)) -> VecBool (if (< position values_len) (drop_loop values (+ position 1) values_len (append result (at values position))) result)) -(fn drop ((values (vec bool)) (count i32)) -> (vec bool) +(fn drop ((values VecBool) (count i32)) -> VecBool (let values_len i32 (len values)) (if (< count 0) values @@ -158,22 +160,22 @@ (drop_loop values count values_len (empty)) (empty)))) -(fn reverse_loop ((values (vec bool)) (position i32) (result (vec bool))) -> (vec bool) +(fn reverse_loop ((values VecBool) (position i32) (result VecBool)) -> VecBool (if (< position 0) result (reverse_loop values (- position 1) (append result (at values position))))) -(fn reverse ((values (vec bool))) -> (vec bool) +(fn reverse ((values VecBool)) -> VecBool (reverse_loop values (- (len values) 1) (empty))) -(fn subvec ((values (vec bool)) (start i32) (end_exclusive i32)) -> (vec bool) +(fn subvec ((values VecBool) (start i32) (end_exclusive i32)) -> VecBool (if (< start 0) (empty) (if (< start end_exclusive) (take (drop values start) (- end_exclusive start)) (empty)))) -(fn insert_at ((values (vec bool)) (position i32) (value bool)) -> (vec bool) +(fn insert_at ((values VecBool) (position i32) (value bool)) -> VecBool (let values_len i32 (len values)) (if (< position 0) values @@ -183,7 +185,7 @@ (append values value) values)))) -(fn insert_range ((values (vec bool)) (position i32) (inserted (vec bool))) -> (vec bool) +(fn insert_range ((values VecBool) (position i32) (inserted VecBool)) -> VecBool (let values_len i32 (len values)) (if (< position 0) values @@ -193,14 +195,14 @@ (concat values inserted) values)))) -(fn replace_at ((values (vec bool)) (position i32) (replacement bool)) -> (vec bool) +(fn replace_at ((values VecBool) (position i32) (replacement bool)) -> VecBool (if (< position 0) values (if (< position (len values)) (concat (append (take values position) replacement) (drop values (+ position 1))) values))) -(fn replace_range ((values (vec bool)) (start i32) (end_exclusive i32) (replacement (vec bool))) -> (vec bool) +(fn replace_range ((values VecBool) (start i32) (end_exclusive i32) (replacement VecBool)) -> VecBool (let values_len i32 (len values)) (if (< start 0) values @@ -210,14 +212,14 @@ values) values))) -(fn remove_at ((values (vec bool)) (position i32)) -> (vec bool) +(fn remove_at ((values VecBool) (position i32)) -> VecBool (if (< position 0) values (if (< position (len values)) (concat (take values position) (drop values (+ position 1))) values))) -(fn remove_range ((values (vec bool)) (start i32) (end_exclusive i32)) -> (vec bool) +(fn remove_range ((values VecBool) (start i32) (end_exclusive i32)) -> VecBool (let values_len i32 (len values)) (if (< start 0) values diff --git a/lib/std/vec_f64.slo b/lib/std/vec_f64.slo index 0b36953..8e8f6ef 100644 --- a/lib/std/vec_f64.slo +++ b/lib/std/vec_f64.slo @@ -1,118 +1,120 @@ (module vec_f64 (export empty append len at singleton append2 append3 pair triple is_empty index_or first_or last_or index_option first_option last_option index_of_option last_index_of_option contains sum concat take starts_with without_prefix ends_with without_suffix drop reverse subvec insert_at insert_range replace_at replace_range remove_at remove_range)) -(fn empty () -> (vec f64) +(type VecF64 (vec f64)) + +(fn empty () -> VecF64 (std.vec.f64.empty)) -(fn append ((values (vec f64)) (value f64)) -> (vec f64) +(fn append ((values VecF64) (value f64)) -> VecF64 (std.vec.f64.append values value)) -(fn len ((values (vec f64))) -> i32 +(fn len ((values VecF64)) -> i32 (std.vec.f64.len values)) -(fn at ((values (vec f64)) (position i32)) -> f64 +(fn at ((values VecF64) (position i32)) -> f64 (std.vec.f64.index values position)) -(fn singleton ((value f64)) -> (vec f64) +(fn singleton ((value f64)) -> VecF64 (append (empty) value)) -(fn append2 ((values (vec f64)) (first f64) (second f64)) -> (vec f64) +(fn append2 ((values VecF64) (first f64) (second f64)) -> VecF64 (append (append values first) second)) -(fn append3 ((values (vec f64)) (first f64) (second f64) (third f64)) -> (vec f64) +(fn append3 ((values VecF64) (first f64) (second f64) (third f64)) -> VecF64 (append (append2 values first second) third)) -(fn pair ((first f64) (second f64)) -> (vec f64) +(fn pair ((first f64) (second f64)) -> VecF64 (append2 (empty) first second)) -(fn triple ((first f64) (second f64) (third f64)) -> (vec f64) +(fn triple ((first f64) (second f64) (third f64)) -> VecF64 (append3 (empty) first second third)) -(fn is_empty ((values (vec f64))) -> bool +(fn is_empty ((values VecF64)) -> bool (= (len values) 0)) -(fn index_or ((values (vec f64)) (position i32) (fallback f64)) -> f64 +(fn index_or ((values VecF64) (position i32) (fallback f64)) -> f64 (if (< position 0) fallback (if (< position (len values)) (at values position) fallback))) -(fn first_or ((values (vec f64)) (fallback f64)) -> f64 +(fn first_or ((values VecF64) (fallback f64)) -> f64 (index_or values 0 fallback)) -(fn last_or ((values (vec f64)) (fallback f64)) -> f64 +(fn last_or ((values VecF64) (fallback f64)) -> f64 (if (is_empty values) fallback (at values (- (len values) 1)))) -(fn index_option ((values (vec f64)) (position i32)) -> (option f64) +(fn index_option ((values VecF64) (position i32)) -> (option f64) (if (< position 0) (none f64) (if (< position (len values)) (some f64 (at values position)) (none f64)))) -(fn first_option ((values (vec f64))) -> (option f64) +(fn first_option ((values VecF64)) -> (option f64) (index_option values 0)) -(fn last_option ((values (vec f64))) -> (option f64) +(fn last_option ((values VecF64)) -> (option f64) (if (is_empty values) (none f64) (some f64 (at values (- (len values) 1))))) -(fn index_of_option_loop ((values (vec f64)) (target f64) (position i32) (values_len i32)) -> (option i32) +(fn index_of_option_loop ((values VecF64) (target f64) (position i32) (values_len i32)) -> (option i32) (if (< position values_len) (if (= (at values position) target) (some i32 position) (index_of_option_loop values target (+ position 1) values_len)) (none i32))) -(fn index_of_option ((values (vec f64)) (target f64)) -> (option i32) +(fn index_of_option ((values VecF64) (target f64)) -> (option i32) (index_of_option_loop values target 0 (len values))) -(fn last_index_of_option_loop ((values (vec f64)) (target f64) (position i32) (values_len i32) (found_position (option i32))) -> (option i32) +(fn last_index_of_option_loop ((values VecF64) (target f64) (position i32) (values_len i32) (found_position (option i32))) -> (option i32) (if (< position values_len) (last_index_of_option_loop values target (+ position 1) values_len (if (= (at values position) target) (some i32 position) found_position)) found_position)) -(fn last_index_of_option ((values (vec f64)) (target f64)) -> (option i32) +(fn last_index_of_option ((values VecF64) (target f64)) -> (option i32) (last_index_of_option_loop values target 0 (len values) (none i32))) -(fn contains_loop ((values (vec f64)) (target f64) (position i32) (values_len i32)) -> bool +(fn contains_loop ((values VecF64) (target f64) (position i32) (values_len i32)) -> bool (if (< position values_len) (if (= (at values position) target) true (contains_loop values target (+ position 1) values_len)) false)) -(fn contains ((values (vec f64)) (target f64)) -> bool +(fn contains ((values VecF64) (target f64)) -> bool (contains_loop values target 0 (len values))) -(fn sum_loop ((values (vec f64)) (position i32) (values_len i32) (total f64)) -> f64 +(fn sum_loop ((values VecF64) (position i32) (values_len i32) (total f64)) -> f64 (if (< position values_len) (sum_loop values (+ position 1) values_len (+ total (at values position))) total)) -(fn sum ((values (vec f64))) -> f64 +(fn sum ((values VecF64)) -> f64 (sum_loop values 0 (len values) 0.0)) -(fn concat_loop ((result (vec f64)) (right (vec f64)) (position i32) (right_len i32)) -> (vec f64) +(fn concat_loop ((result VecF64) (right VecF64) (position i32) (right_len i32)) -> VecF64 (if (< position right_len) (concat_loop (append result (at right position)) right (+ position 1) right_len) result)) -(fn concat ((left (vec f64)) (right (vec f64))) -> (vec f64) +(fn concat ((left VecF64) (right VecF64)) -> VecF64 (let right_len i32 (len right)) (concat_loop left right 0 right_len)) -(fn take_loop ((values (vec f64)) (position i32) (limit i32) (result (vec f64))) -> (vec f64) +(fn take_loop ((values VecF64) (position i32) (limit i32) (result VecF64)) -> VecF64 (if (< position limit) (take_loop values (+ position 1) limit (append result (at values position))) result)) -(fn take ((values (vec f64)) (count i32)) -> (vec f64) +(fn take ((values VecF64) (count i32)) -> VecF64 (let values_len i32 (len values)) (if (< count 0) (empty) @@ -120,35 +122,35 @@ (take_loop values 0 count (empty)) values))) -(fn starts_with ((values (vec f64)) (prefix (vec f64))) -> bool +(fn starts_with ((values VecF64) (prefix VecF64)) -> bool (let prefix_len i32 (len prefix)) (if (< (len values) prefix_len) false (= (take values prefix_len) prefix))) -(fn without_prefix ((values (vec f64)) (prefix (vec f64))) -> (vec f64) +(fn without_prefix ((values VecF64) (prefix VecF64)) -> VecF64 (if (starts_with values prefix) (drop values (len prefix)) values)) -(fn ends_with ((values (vec f64)) (suffix (vec f64))) -> bool +(fn ends_with ((values VecF64) (suffix VecF64)) -> bool (let values_len i32 (len values)) (let suffix_len i32 (len suffix)) (if (< values_len suffix_len) false (= (drop values (- values_len suffix_len)) suffix))) -(fn without_suffix ((values (vec f64)) (suffix (vec f64))) -> (vec f64) +(fn without_suffix ((values VecF64) (suffix VecF64)) -> VecF64 (if (ends_with values suffix) (take values (- (len values) (len suffix))) values)) -(fn drop_loop ((values (vec f64)) (position i32) (values_len i32) (result (vec f64))) -> (vec f64) +(fn drop_loop ((values VecF64) (position i32) (values_len i32) (result VecF64)) -> VecF64 (if (< position values_len) (drop_loop values (+ position 1) values_len (append result (at values position))) result)) -(fn drop ((values (vec f64)) (count i32)) -> (vec f64) +(fn drop ((values VecF64) (count i32)) -> VecF64 (let values_len i32 (len values)) (if (< count 0) values @@ -156,22 +158,22 @@ (drop_loop values count values_len (empty)) (empty)))) -(fn reverse_loop ((values (vec f64)) (position i32) (result (vec f64))) -> (vec f64) +(fn reverse_loop ((values VecF64) (position i32) (result VecF64)) -> VecF64 (if (< position 0) result (reverse_loop values (- position 1) (append result (at values position))))) -(fn reverse ((values (vec f64))) -> (vec f64) +(fn reverse ((values VecF64)) -> VecF64 (reverse_loop values (- (len values) 1) (empty))) -(fn subvec ((values (vec f64)) (start i32) (end_exclusive i32)) -> (vec f64) +(fn subvec ((values VecF64) (start i32) (end_exclusive i32)) -> VecF64 (if (< start 0) (empty) (if (< start end_exclusive) (take (drop values start) (- end_exclusive start)) (empty)))) -(fn insert_at ((values (vec f64)) (position i32) (value f64)) -> (vec f64) +(fn insert_at ((values VecF64) (position i32) (value f64)) -> VecF64 (let values_len i32 (len values)) (if (< position 0) values @@ -181,7 +183,7 @@ (append values value) values)))) -(fn insert_range ((values (vec f64)) (position i32) (inserted (vec f64))) -> (vec f64) +(fn insert_range ((values VecF64) (position i32) (inserted VecF64)) -> VecF64 (let values_len i32 (len values)) (if (< position 0) values @@ -191,14 +193,14 @@ (concat values inserted) values)))) -(fn replace_at ((values (vec f64)) (position i32) (replacement f64)) -> (vec f64) +(fn replace_at ((values VecF64) (position i32) (replacement f64)) -> VecF64 (if (< position 0) values (if (< position (len values)) (concat (append (take values position) replacement) (drop values (+ position 1))) values))) -(fn replace_range ((values (vec f64)) (start i32) (end_exclusive i32) (replacement (vec f64))) -> (vec f64) +(fn replace_range ((values VecF64) (start i32) (end_exclusive i32) (replacement VecF64)) -> VecF64 (let values_len i32 (len values)) (if (< start 0) values @@ -208,14 +210,14 @@ values) values))) -(fn remove_at ((values (vec f64)) (position i32)) -> (vec f64) +(fn remove_at ((values VecF64) (position i32)) -> VecF64 (if (< position 0) values (if (< position (len values)) (concat (take values position) (drop values (+ position 1))) values))) -(fn remove_range ((values (vec f64)) (start i32) (end_exclusive i32)) -> (vec f64) +(fn remove_range ((values VecF64) (start i32) (end_exclusive i32)) -> VecF64 (let values_len i32 (len values)) (if (< start 0) values diff --git a/lib/std/vec_i32.slo b/lib/std/vec_i32.slo index c2705f9..69d27d0 100644 --- a/lib/std/vec_i32.slo +++ b/lib/std/vec_i32.slo @@ -2,97 +2,99 @@ (import std.option (some_i32 none_i32)) -(fn empty () -> (vec i32) +(type VecI32 (vec i32)) + +(fn empty () -> VecI32 (std.vec.i32.empty)) -(fn append ((values (vec i32)) (value i32)) -> (vec i32) +(fn append ((values VecI32) (value i32)) -> VecI32 (std.vec.i32.append values value)) -(fn len ((values (vec i32))) -> i32 +(fn len ((values VecI32)) -> i32 (std.vec.i32.len values)) -(fn at ((values (vec i32)) (position i32)) -> i32 +(fn at ((values VecI32) (position i32)) -> i32 (std.vec.i32.index values position)) -(fn singleton ((value i32)) -> (vec i32) +(fn singleton ((value i32)) -> VecI32 (append (empty) value)) -(fn append2 ((values (vec i32)) (first i32) (second i32)) -> (vec i32) +(fn append2 ((values VecI32) (first i32) (second i32)) -> VecI32 (append (append values first) second)) -(fn append3 ((values (vec i32)) (first i32) (second i32) (third i32)) -> (vec i32) +(fn append3 ((values VecI32) (first i32) (second i32) (third i32)) -> VecI32 (append (append2 values first second) third)) -(fn pair ((first i32) (second i32)) -> (vec i32) +(fn pair ((first i32) (second i32)) -> VecI32 (append2 (empty) first second)) -(fn triple ((first i32) (second i32) (third i32)) -> (vec i32) +(fn triple ((first i32) (second i32) (third i32)) -> VecI32 (append3 (empty) first second third)) -(fn repeat_loop ((value i32) (remaining i32) (result (vec i32))) -> (vec i32) +(fn repeat_loop ((value i32) (remaining i32) (result VecI32)) -> VecI32 (if (< remaining 1) result (repeat_loop value (- remaining 1) (append result value)))) -(fn repeat ((value i32) (count i32)) -> (vec i32) +(fn repeat ((value i32) (count i32)) -> VecI32 (if (< count 1) (empty) (repeat_loop value count (empty)))) -(fn range_from_zero_loop ((current i32) (count i32) (result (vec i32))) -> (vec i32) +(fn range_from_zero_loop ((current i32) (count i32) (result VecI32)) -> VecI32 (if (< current count) (range_from_zero_loop (+ current 1) count (append result current)) result)) -(fn range_loop ((current i32) (end_exclusive i32) (result (vec i32))) -> (vec i32) +(fn range_loop ((current i32) (end_exclusive i32) (result VecI32)) -> VecI32 (if (< current end_exclusive) (range_loop (+ current 1) end_exclusive (append result current)) result)) -(fn range ((start i32) (end_exclusive i32)) -> (vec i32) +(fn range ((start i32) (end_exclusive i32)) -> VecI32 (if (< start end_exclusive) (range_loop start end_exclusive (empty)) (empty))) -(fn range_from_zero ((count i32)) -> (vec i32) +(fn range_from_zero ((count i32)) -> VecI32 (if (< count 1) (empty) (range_from_zero_loop 0 count (empty)))) -(fn is_empty ((values (vec i32))) -> bool +(fn is_empty ((values VecI32)) -> bool (= (len values) 0)) -(fn index_or ((values (vec i32)) (position i32) (fallback i32)) -> i32 +(fn index_or ((values VecI32) (position i32) (fallback i32)) -> i32 (if (< position 0) fallback (if (< position (len values)) (at values position) fallback))) -(fn first_or ((values (vec i32)) (fallback i32)) -> i32 +(fn first_or ((values VecI32) (fallback i32)) -> i32 (index_or values 0 fallback)) -(fn last_or ((values (vec i32)) (fallback i32)) -> i32 +(fn last_or ((values VecI32) (fallback i32)) -> i32 (if (is_empty values) fallback (at values (- (len values) 1)))) -(fn index_option ((values (vec i32)) (position i32)) -> (option i32) +(fn index_option ((values VecI32) (position i32)) -> (option i32) (if (< position 0) (none_i32) (if (< position (len values)) (some_i32 (at values position)) (none_i32)))) -(fn first_option ((values (vec i32))) -> (option i32) +(fn first_option ((values VecI32)) -> (option i32) (index_option values 0)) -(fn last_option ((values (vec i32))) -> (option i32) +(fn last_option ((values VecI32)) -> (option i32) (if (is_empty values) (none_i32) (some_i32 (at values (- (len values) 1))))) -(fn index_of_option ((values (vec i32)) (target i32)) -> (option i32) +(fn index_of_option ((values VecI32) (target i32)) -> (option i32) (var position i32 0) (var found_position i32 -1) (while (and (< position (len values)) (< found_position 0)) @@ -104,7 +106,7 @@ (none_i32) (some_i32 found_position))) -(fn last_index_of_option ((values (vec i32)) (target i32)) -> (option i32) +(fn last_index_of_option ((values VecI32) (target i32)) -> (option i32) (var position i32 0) (var found_position i32 -1) (while (< position (len values)) @@ -116,7 +118,7 @@ (none_i32) (some_i32 found_position))) -(fn count_of ((values (vec i32)) (target i32)) -> i32 +(fn count_of ((values VecI32) (target i32)) -> i32 (var position i32 0) (var hits i32 0) (while (< position (len values)) @@ -126,7 +128,7 @@ (set position (+ position 1))) hits) -(fn contains ((values (vec i32)) (target i32)) -> bool +(fn contains ((values VecI32) (target i32)) -> bool (var position i32 0) (var hits i32 0) (while (< position (len values)) @@ -136,7 +138,7 @@ (set position (+ position 1))) (> hits 0)) -(fn sum ((values (vec i32))) -> i32 +(fn sum ((values VecI32)) -> i32 (var position i32 0) (var total i32 0) (while (< position (len values)) @@ -144,21 +146,21 @@ (set position (+ position 1))) total) -(fn concat_loop ((result (vec i32)) (right (vec i32)) (position i32) (right_len i32)) -> (vec i32) +(fn concat_loop ((result VecI32) (right VecI32) (position i32) (right_len i32)) -> VecI32 (if (< position right_len) (concat_loop (append result (at right position)) right (+ position 1) right_len) result)) -(fn concat ((left (vec i32)) (right (vec i32))) -> (vec i32) +(fn concat ((left VecI32) (right VecI32)) -> VecI32 (let right_len i32 (len right)) (concat_loop left right 0 right_len)) -(fn take_loop ((values (vec i32)) (position i32) (limit i32) (result (vec i32))) -> (vec i32) +(fn take_loop ((values VecI32) (position i32) (limit i32) (result VecI32)) -> VecI32 (if (< position limit) (take_loop values (+ position 1) limit (append result (at values position))) result)) -(fn take ((values (vec i32)) (count i32)) -> (vec i32) +(fn take ((values VecI32) (count i32)) -> VecI32 (let values_len i32 (len values)) (if (< count 0) (empty) @@ -166,35 +168,35 @@ (take_loop values 0 count (empty)) values))) -(fn starts_with ((values (vec i32)) (prefix (vec i32))) -> bool +(fn starts_with ((values VecI32) (prefix VecI32)) -> bool (let prefix_len i32 (len prefix)) (if (< (len values) prefix_len) false (= (take values prefix_len) prefix))) -(fn without_prefix ((values (vec i32)) (prefix (vec i32))) -> (vec i32) +(fn without_prefix ((values VecI32) (prefix VecI32)) -> VecI32 (if (starts_with values prefix) (drop values (len prefix)) values)) -(fn ends_with ((values (vec i32)) (suffix (vec i32))) -> bool +(fn ends_with ((values VecI32) (suffix VecI32)) -> bool (let values_len i32 (len values)) (let suffix_len i32 (len suffix)) (if (< values_len suffix_len) false (= (drop values (- values_len suffix_len)) suffix))) -(fn without_suffix ((values (vec i32)) (suffix (vec i32))) -> (vec i32) +(fn without_suffix ((values VecI32) (suffix VecI32)) -> VecI32 (if (ends_with values suffix) (take values (- (len values) (len suffix))) values)) -(fn drop_loop ((values (vec i32)) (position i32) (values_len i32) (result (vec i32))) -> (vec i32) +(fn drop_loop ((values VecI32) (position i32) (values_len i32) (result VecI32)) -> VecI32 (if (< position values_len) (drop_loop values (+ position 1) values_len (append result (at values position))) result)) -(fn drop ((values (vec i32)) (count i32)) -> (vec i32) +(fn drop ((values VecI32) (count i32)) -> VecI32 (let values_len i32 (len values)) (if (< count 0) values @@ -202,22 +204,22 @@ (drop_loop values count values_len (empty)) (empty)))) -(fn reverse_loop ((values (vec i32)) (position i32) (result (vec i32))) -> (vec i32) +(fn reverse_loop ((values VecI32) (position i32) (result VecI32)) -> VecI32 (if (< position 0) result (reverse_loop values (- position 1) (append result (at values position))))) -(fn reverse ((values (vec i32))) -> (vec i32) +(fn reverse ((values VecI32)) -> VecI32 (reverse_loop values (- (len values) 1) (empty))) -(fn subvec ((values (vec i32)) (start i32) (end_exclusive i32)) -> (vec i32) +(fn subvec ((values VecI32) (start i32) (end_exclusive i32)) -> VecI32 (if (< start 0) (empty) (if (< start end_exclusive) (take (drop values start) (- end_exclusive start)) (empty)))) -(fn insert_at ((values (vec i32)) (position i32) (value i32)) -> (vec i32) +(fn insert_at ((values VecI32) (position i32) (value i32)) -> VecI32 (if (< position 0) values (if (< position (len values)) @@ -226,7 +228,7 @@ (append values value) values)))) -(fn insert_range ((values (vec i32)) (position i32) (inserted (vec i32))) -> (vec i32) +(fn insert_range ((values VecI32) (position i32) (inserted VecI32)) -> VecI32 (if (< position 0) values (if (< position (len values)) @@ -235,14 +237,14 @@ (concat values inserted) values)))) -(fn replace_at ((values (vec i32)) (position i32) (replacement i32)) -> (vec i32) +(fn replace_at ((values VecI32) (position i32) (replacement i32)) -> VecI32 (if (< position 0) values (if (< position (len values)) (concat (append (take values position) replacement) (drop values (+ position 1))) values))) -(fn replace_range ((values (vec i32)) (start i32) (end_exclusive i32) (replacement (vec i32))) -> (vec i32) +(fn replace_range ((values VecI32) (start i32) (end_exclusive i32) (replacement VecI32)) -> VecI32 (let values_len i32 (len values)) (if (< start 0) values @@ -252,14 +254,14 @@ values) values))) -(fn remove_at ((values (vec i32)) (position i32)) -> (vec i32) +(fn remove_at ((values VecI32) (position i32)) -> VecI32 (if (< position 0) values (if (< position (len values)) (concat (take values position) (drop values (+ position 1))) values))) -(fn remove_range ((values (vec i32)) (start i32) (end_exclusive i32)) -> (vec i32) +(fn remove_range ((values VecI32) (start i32) (end_exclusive i32)) -> VecI32 (let values_len i32 (len values)) (if (< start 0) values diff --git a/lib/std/vec_i64.slo b/lib/std/vec_i64.slo index d041e3e..7feeece 100644 --- a/lib/std/vec_i64.slo +++ b/lib/std/vec_i64.slo @@ -1,118 +1,120 @@ (module vec_i64 (export empty append len at singleton append2 append3 pair triple is_empty index_or first_or last_or index_option first_option last_option index_of_option last_index_of_option contains sum concat take drop reverse subvec insert_at insert_range replace_at replace_range remove_at remove_range)) -(fn empty () -> (vec i64) +(type VecI64 (vec i64)) + +(fn empty () -> VecI64 (std.vec.i64.empty)) -(fn append ((values (vec i64)) (value i64)) -> (vec i64) +(fn append ((values VecI64) (value i64)) -> VecI64 (std.vec.i64.append values value)) -(fn len ((values (vec i64))) -> i32 +(fn len ((values VecI64)) -> i32 (std.vec.i64.len values)) -(fn at ((values (vec i64)) (position i32)) -> i64 +(fn at ((values VecI64) (position i32)) -> i64 (std.vec.i64.index values position)) -(fn singleton ((value i64)) -> (vec i64) +(fn singleton ((value i64)) -> VecI64 (append (empty) value)) -(fn append2 ((values (vec i64)) (first i64) (second i64)) -> (vec i64) +(fn append2 ((values VecI64) (first i64) (second i64)) -> VecI64 (append (append values first) second)) -(fn append3 ((values (vec i64)) (first i64) (second i64) (third i64)) -> (vec i64) +(fn append3 ((values VecI64) (first i64) (second i64) (third i64)) -> VecI64 (append (append2 values first second) third)) -(fn pair ((first i64) (second i64)) -> (vec i64) +(fn pair ((first i64) (second i64)) -> VecI64 (append2 (empty) first second)) -(fn triple ((first i64) (second i64) (third i64)) -> (vec i64) +(fn triple ((first i64) (second i64) (third i64)) -> VecI64 (append3 (empty) first second third)) -(fn is_empty ((values (vec i64))) -> bool +(fn is_empty ((values VecI64)) -> bool (= (len values) 0)) -(fn index_or ((values (vec i64)) (position i32) (fallback i64)) -> i64 +(fn index_or ((values VecI64) (position i32) (fallback i64)) -> i64 (if (< position 0) fallback (if (< position (len values)) (at values position) fallback))) -(fn first_or ((values (vec i64)) (fallback i64)) -> i64 +(fn first_or ((values VecI64) (fallback i64)) -> i64 (index_or values 0 fallback)) -(fn last_or ((values (vec i64)) (fallback i64)) -> i64 +(fn last_or ((values VecI64) (fallback i64)) -> i64 (if (is_empty values) fallback (at values (- (len values) 1)))) -(fn index_option ((values (vec i64)) (position i32)) -> (option i64) +(fn index_option ((values VecI64) (position i32)) -> (option i64) (if (< position 0) (none i64) (if (< position (len values)) (some i64 (at values position)) (none i64)))) -(fn first_option ((values (vec i64))) -> (option i64) +(fn first_option ((values VecI64)) -> (option i64) (index_option values 0)) -(fn last_option ((values (vec i64))) -> (option i64) +(fn last_option ((values VecI64)) -> (option i64) (if (is_empty values) (none i64) (some i64 (at values (- (len values) 1))))) -(fn index_of_option_loop ((values (vec i64)) (target i64) (position i32) (values_len i32)) -> (option i32) +(fn index_of_option_loop ((values VecI64) (target i64) (position i32) (values_len i32)) -> (option i32) (if (< position values_len) (if (= (at values position) target) (some i32 position) (index_of_option_loop values target (+ position 1) values_len)) (none i32))) -(fn index_of_option ((values (vec i64)) (target i64)) -> (option i32) +(fn index_of_option ((values VecI64) (target i64)) -> (option i32) (index_of_option_loop values target 0 (len values))) -(fn last_index_of_option_loop ((values (vec i64)) (target i64) (position i32) (values_len i32) (found_position (option i32))) -> (option i32) +(fn last_index_of_option_loop ((values VecI64) (target i64) (position i32) (values_len i32) (found_position (option i32))) -> (option i32) (if (< position values_len) (last_index_of_option_loop values target (+ position 1) values_len (if (= (at values position) target) (some i32 position) found_position)) found_position)) -(fn last_index_of_option ((values (vec i64)) (target i64)) -> (option i32) +(fn last_index_of_option ((values VecI64) (target i64)) -> (option i32) (last_index_of_option_loop values target 0 (len values) (none i32))) -(fn contains_loop ((values (vec i64)) (target i64) (position i32) (values_len i32)) -> bool +(fn contains_loop ((values VecI64) (target i64) (position i32) (values_len i32)) -> bool (if (< position values_len) (if (= (at values position) target) true (contains_loop values target (+ position 1) values_len)) false)) -(fn contains ((values (vec i64)) (target i64)) -> bool +(fn contains ((values VecI64) (target i64)) -> bool (contains_loop values target 0 (len values))) -(fn sum_loop ((values (vec i64)) (position i32) (values_len i32) (total i64)) -> i64 +(fn sum_loop ((values VecI64) (position i32) (values_len i32) (total i64)) -> i64 (if (< position values_len) (sum_loop values (+ position 1) values_len (+ total (at values position))) total)) -(fn sum ((values (vec i64))) -> i64 +(fn sum ((values VecI64)) -> i64 (sum_loop values 0 (len values) 0i64)) -(fn concat_loop ((result (vec i64)) (right (vec i64)) (position i32) (right_len i32)) -> (vec i64) +(fn concat_loop ((result VecI64) (right VecI64) (position i32) (right_len i32)) -> VecI64 (if (< position right_len) (concat_loop (append result (at right position)) right (+ position 1) right_len) result)) -(fn concat ((left (vec i64)) (right (vec i64))) -> (vec i64) +(fn concat ((left VecI64) (right VecI64)) -> VecI64 (let right_len i32 (len right)) (concat_loop left right 0 right_len)) -(fn take_loop ((values (vec i64)) (position i32) (limit i32) (result (vec i64))) -> (vec i64) +(fn take_loop ((values VecI64) (position i32) (limit i32) (result VecI64)) -> VecI64 (if (< position limit) (take_loop values (+ position 1) limit (append result (at values position))) result)) -(fn take ((values (vec i64)) (count i32)) -> (vec i64) +(fn take ((values VecI64) (count i32)) -> VecI64 (let values_len i32 (len values)) (if (< count 0) (empty) @@ -120,12 +122,12 @@ (take_loop values 0 count (empty)) values))) -(fn drop_loop ((values (vec i64)) (position i32) (values_len i32) (result (vec i64))) -> (vec i64) +(fn drop_loop ((values VecI64) (position i32) (values_len i32) (result VecI64)) -> VecI64 (if (< position values_len) (drop_loop values (+ position 1) values_len (append result (at values position))) result)) -(fn drop ((values (vec i64)) (count i32)) -> (vec i64) +(fn drop ((values VecI64) (count i32)) -> VecI64 (let values_len i32 (len values)) (if (< count 0) values @@ -133,22 +135,22 @@ (drop_loop values count values_len (empty)) (empty)))) -(fn reverse_loop ((values (vec i64)) (position i32) (result (vec i64))) -> (vec i64) +(fn reverse_loop ((values VecI64) (position i32) (result VecI64)) -> VecI64 (if (< position 0) result (reverse_loop values (- position 1) (append result (at values position))))) -(fn reverse ((values (vec i64))) -> (vec i64) +(fn reverse ((values VecI64)) -> VecI64 (reverse_loop values (- (len values) 1) (empty))) -(fn subvec ((values (vec i64)) (start i32) (end_exclusive i32)) -> (vec i64) +(fn subvec ((values VecI64) (start i32) (end_exclusive i32)) -> VecI64 (if (< start 0) (empty) (if (< start end_exclusive) (take (drop values start) (- end_exclusive start)) (empty)))) -(fn insert_at ((values (vec i64)) (position i32) (value i64)) -> (vec i64) +(fn insert_at ((values VecI64) (position i32) (value i64)) -> VecI64 (let values_len i32 (len values)) (if (< position 0) values @@ -158,7 +160,7 @@ (append values value) values)))) -(fn insert_range ((values (vec i64)) (position i32) (inserted (vec i64))) -> (vec i64) +(fn insert_range ((values VecI64) (position i32) (inserted VecI64)) -> VecI64 (let values_len i32 (len values)) (if (< position 0) values @@ -168,14 +170,14 @@ (concat values inserted) values)))) -(fn replace_at ((values (vec i64)) (position i32) (replacement i64)) -> (vec i64) +(fn replace_at ((values VecI64) (position i32) (replacement i64)) -> VecI64 (if (< position 0) values (if (< position (len values)) (concat (append (take values position) replacement) (drop values (+ position 1))) values))) -(fn replace_range ((values (vec i64)) (start i32) (end_exclusive i32) (replacement (vec i64))) -> (vec i64) +(fn replace_range ((values VecI64) (start i32) (end_exclusive i32) (replacement VecI64)) -> VecI64 (let values_len i32 (len values)) (if (< start 0) values @@ -185,14 +187,14 @@ values) values))) -(fn remove_at ((values (vec i64)) (position i32)) -> (vec i64) +(fn remove_at ((values VecI64) (position i32)) -> VecI64 (if (< position 0) values (if (< position (len values)) (concat (take values position) (drop values (+ position 1))) values))) -(fn remove_range ((values (vec i64)) (start i32) (end_exclusive i32)) -> (vec i64) +(fn remove_range ((values VecI64) (start i32) (end_exclusive i32)) -> VecI64 (let values_len i32 (len values)) (if (< start 0) values diff --git a/lib/std/vec_string.slo b/lib/std/vec_string.slo index d72c4b5..e92607d 100644 --- a/lib/std/vec_string.slo +++ b/lib/std/vec_string.slo @@ -1,120 +1,122 @@ (module vec_string (export empty append len at singleton append2 append3 pair triple is_empty index_or first_or last_or index_option first_option last_option index_of_option last_index_of_option contains count_of concat take starts_with without_prefix ends_with without_suffix drop reverse subvec insert_at insert_range replace_at replace_range remove_at remove_range)) -(fn empty () -> (vec string) +(type VecString (vec string)) + +(fn empty () -> VecString (std.vec.string.empty)) -(fn append ((values (vec string)) (value string)) -> (vec string) +(fn append ((values VecString) (value string)) -> VecString (std.vec.string.append values value)) -(fn len ((values (vec string))) -> i32 +(fn len ((values VecString)) -> i32 (std.vec.string.len values)) -(fn at ((values (vec string)) (position i32)) -> string +(fn at ((values VecString) (position i32)) -> string (std.vec.string.index values position)) -(fn singleton ((value string)) -> (vec string) +(fn singleton ((value string)) -> VecString (append (empty) value)) -(fn append2 ((values (vec string)) (first string) (second string)) -> (vec string) +(fn append2 ((values VecString) (first string) (second string)) -> VecString (append (append values first) second)) -(fn append3 ((values (vec string)) (first string) (second string) (third string)) -> (vec string) +(fn append3 ((values VecString) (first string) (second string) (third string)) -> VecString (append (append2 values first second) third)) -(fn pair ((first string) (second string)) -> (vec string) +(fn pair ((first string) (second string)) -> VecString (append2 (empty) first second)) -(fn triple ((first string) (second string) (third string)) -> (vec string) +(fn triple ((first string) (second string) (third string)) -> VecString (append3 (empty) first second third)) -(fn is_empty ((values (vec string))) -> bool +(fn is_empty ((values VecString)) -> bool (= (len values) 0)) -(fn index_or ((values (vec string)) (position i32) (fallback string)) -> string +(fn index_or ((values VecString) (position i32) (fallback string)) -> string (if (< position 0) fallback (if (< position (len values)) (at values position) fallback))) -(fn first_or ((values (vec string)) (fallback string)) -> string +(fn first_or ((values VecString) (fallback string)) -> string (index_or values 0 fallback)) -(fn last_or ((values (vec string)) (fallback string)) -> string +(fn last_or ((values VecString) (fallback string)) -> string (if (is_empty values) fallback (at values (- (len values) 1)))) -(fn index_option ((values (vec string)) (position i32)) -> (option string) +(fn index_option ((values VecString) (position i32)) -> (option string) (if (< position 0) (none string) (if (< position (len values)) (some string (at values position)) (none string)))) -(fn first_option ((values (vec string))) -> (option string) +(fn first_option ((values VecString)) -> (option string) (index_option values 0)) -(fn last_option ((values (vec string))) -> (option string) +(fn last_option ((values VecString)) -> (option string) (if (is_empty values) (none string) (some string (at values (- (len values) 1))))) -(fn index_of_option_loop ((values (vec string)) (target string) (position i32) (values_len i32)) -> (option i32) +(fn index_of_option_loop ((values VecString) (target string) (position i32) (values_len i32)) -> (option i32) (if (< position values_len) (if (= (at values position) target) (some i32 position) (index_of_option_loop values target (+ position 1) values_len)) (none i32))) -(fn index_of_option ((values (vec string)) (target string)) -> (option i32) +(fn index_of_option ((values VecString) (target string)) -> (option i32) (index_of_option_loop values target 0 (len values))) -(fn last_index_of_option_loop ((values (vec string)) (target string) (position i32) (values_len i32) (found (option i32))) -> (option i32) +(fn last_index_of_option_loop ((values VecString) (target string) (position i32) (values_len i32) (found (option i32))) -> (option i32) (if (< position values_len) (if (= (at values position) target) (last_index_of_option_loop values target (+ position 1) values_len (some i32 position)) (last_index_of_option_loop values target (+ position 1) values_len found)) found)) -(fn last_index_of_option ((values (vec string)) (target string)) -> (option i32) +(fn last_index_of_option ((values VecString) (target string)) -> (option i32) (last_index_of_option_loop values target 0 (len values) (none i32))) -(fn contains_loop ((values (vec string)) (target string) (position i32) (values_len i32)) -> bool +(fn contains_loop ((values VecString) (target string) (position i32) (values_len i32)) -> bool (if (< position values_len) (if (= (at values position) target) true (contains_loop values target (+ position 1) values_len)) false)) -(fn contains ((values (vec string)) (target string)) -> bool +(fn contains ((values VecString) (target string)) -> bool (contains_loop values target 0 (len values))) -(fn count_of_loop ((values (vec string)) (target string) (position i32) (values_len i32) (hits i32)) -> i32 +(fn count_of_loop ((values VecString) (target string) (position i32) (values_len i32) (hits i32)) -> i32 (if (< position values_len) (count_of_loop values target (+ position 1) values_len (+ hits (if (= (at values position) target) 1 0))) hits)) -(fn count_of ((values (vec string)) (target string)) -> i32 +(fn count_of ((values VecString) (target string)) -> i32 (count_of_loop values target 0 (len values) 0)) -(fn concat_loop ((built (vec string)) (right (vec string)) (position i32) (right_len i32)) -> (vec string) +(fn concat_loop ((built VecString) (right VecString) (position i32) (right_len i32)) -> VecString (if (< position right_len) (concat_loop (append built (at right position)) right (+ position 1) right_len) built)) -(fn concat ((left (vec string)) (right (vec string))) -> (vec string) +(fn concat ((left VecString) (right VecString)) -> VecString (let right_len i32 (len right)) (concat_loop left right 0 right_len)) -(fn take_loop ((values (vec string)) (position i32) (limit i32) (built (vec string))) -> (vec string) +(fn take_loop ((values VecString) (position i32) (limit i32) (built VecString)) -> VecString (if (< position limit) (take_loop values (+ position 1) limit (append built (at values position))) built)) -(fn take ((values (vec string)) (count i32)) -> (vec string) +(fn take ((values VecString) (count i32)) -> VecString (let values_len i32 (len values)) (if (< count 0) (empty) @@ -122,35 +124,35 @@ (take_loop values 0 count (empty)) values))) -(fn starts_with ((values (vec string)) (prefix (vec string))) -> bool +(fn starts_with ((values VecString) (prefix VecString)) -> bool (let prefix_len i32 (len prefix)) (if (< (len values) prefix_len) false (= (take values prefix_len) prefix))) -(fn without_prefix ((values (vec string)) (prefix (vec string))) -> (vec string) +(fn without_prefix ((values VecString) (prefix VecString)) -> VecString (if (starts_with values prefix) (drop values (len prefix)) values)) -(fn ends_with ((values (vec string)) (suffix (vec string))) -> bool +(fn ends_with ((values VecString) (suffix VecString)) -> bool (let values_len i32 (len values)) (let suffix_len i32 (len suffix)) (if (< values_len suffix_len) false (= (drop values (- values_len suffix_len)) suffix))) -(fn without_suffix ((values (vec string)) (suffix (vec string))) -> (vec string) +(fn without_suffix ((values VecString) (suffix VecString)) -> VecString (if (ends_with values suffix) (take values (- (len values) (len suffix))) values)) -(fn drop_loop ((values (vec string)) (position i32) (values_len i32) (built (vec string))) -> (vec string) +(fn drop_loop ((values VecString) (position i32) (values_len i32) (built VecString)) -> VecString (if (< position values_len) (drop_loop values (+ position 1) values_len (append built (at values position))) built)) -(fn drop ((values (vec string)) (count i32)) -> (vec string) +(fn drop ((values VecString) (count i32)) -> VecString (let values_len i32 (len values)) (if (< count 0) values @@ -158,22 +160,22 @@ (drop_loop values count values_len (empty)) (empty)))) -(fn reverse_loop ((values (vec string)) (position i32) (built (vec string))) -> (vec string) +(fn reverse_loop ((values VecString) (position i32) (built VecString)) -> VecString (if (< position 0) built (reverse_loop values (- position 1) (append built (at values position))))) -(fn reverse ((values (vec string))) -> (vec string) +(fn reverse ((values VecString)) -> VecString (reverse_loop values (- (len values) 1) (empty))) -(fn subvec ((values (vec string)) (start i32) (end_exclusive i32)) -> (vec string) +(fn subvec ((values VecString) (start i32) (end_exclusive i32)) -> VecString (if (< start 0) (empty) (if (< start end_exclusive) (take (drop values start) (- end_exclusive start)) (empty)))) -(fn insert_at ((values (vec string)) (position i32) (value string)) -> (vec string) +(fn insert_at ((values VecString) (position i32) (value string)) -> VecString (let values_len i32 (len values)) (if (< position 0) values @@ -183,7 +185,7 @@ (append values value) values)))) -(fn insert_range ((values (vec string)) (position i32) (inserted (vec string))) -> (vec string) +(fn insert_range ((values VecString) (position i32) (inserted VecString)) -> VecString (let values_len i32 (len values)) (if (< position 0) values @@ -193,14 +195,14 @@ (concat values inserted) values)))) -(fn replace_at ((values (vec string)) (position i32) (replacement string)) -> (vec string) +(fn replace_at ((values VecString) (position i32) (replacement string)) -> VecString (if (< position 0) values (if (< position (len values)) (concat (append (take values position) replacement) (drop values (+ position 1))) values))) -(fn replace_range ((values (vec string)) (start i32) (end_exclusive i32) (replacement (vec string))) -> (vec string) +(fn replace_range ((values VecString) (start i32) (end_exclusive i32) (replacement VecString)) -> VecString (let values_len i32 (len values)) (if (< start 0) values @@ -210,14 +212,14 @@ values) values))) -(fn remove_at ((values (vec string)) (position i32)) -> (vec string) +(fn remove_at ((values VecString) (position i32)) -> VecString (if (< position 0) values (if (< position (len values)) (concat (take values position) (drop values (+ position 1))) values))) -(fn remove_range ((values (vec string)) (start i32) (end_exclusive i32)) -> (vec string) +(fn remove_range ((values VecString) (start i32) (end_exclusive i32)) -> VecString (let values_len i32 (len values)) (if (< start 0) values diff --git a/tests/std-result-map-unsupported.diag b/tests/std-result-map-unsupported.diag index 1682179..179efe5 100644 --- a/tests/std-result-map-unsupported.diag +++ b/tests/std-result-map-unsupported.diag @@ -2,14 +2,14 @@ (schema slovo.diagnostic) (version 1) (severity error) - (code UnsupportedStandardLibraryCall) - (message "standard library call `std.result.map` is not supported") + (code UnsupportedGenericStandardLibraryCall) + (message "generic standard-library call `std.result.map` is reserved but not supported in beta.9") (file "") (span (bytes 38 52) (range 5 4 5 18) ) - (expected "std.io.print_i32, std.io.print_u32, std.io.print_i64, std.io.print_u64, std.io.print_f64, std.io.print_string, std.io.print_bool, std.io.eprint, std.io.read_stdin_result, std.string.len, std.string.concat, std.string.parse_i32_result, std.string.parse_u32_result, std.string.parse_i64_result, std.string.parse_u64_result, std.string.parse_f64_result, std.string.parse_bool_result, std.json.quote_string, std.process.argc, std.process.arg, std.process.arg_result, std.env.get, std.env.get_result, std.fs.read_text, std.fs.read_text_result, std.fs.write_text, std.fs.write_text_result, std.fs.exists, std.fs.is_file, std.fs.is_dir, std.fs.remove_file_result, std.fs.create_dir_result, std.fs.open_text_read_result, std.fs.read_open_text_result, std.fs.close_result, std.vec.i32.empty, std.vec.i32.append, std.vec.i32.len, std.vec.i32.index, std.vec.i64.empty, std.vec.i64.append, std.vec.i64.len, std.vec.i64.index, std.vec.f64.empty, std.vec.f64.append, std.vec.f64.len, std.vec.f64.index, std.vec.bool.empty, std.vec.bool.append, std.vec.bool.len, std.vec.bool.index, std.vec.string.empty, std.vec.string.append, std.vec.string.len, std.vec.string.index, std.time.monotonic_ms, std.time.sleep_ms, std.random.i32, std.num.i32_to_i64, std.num.i32_to_f64, std.num.i64_to_f64, std.num.i64_to_i32_result, std.num.f64_to_i32_result, std.num.f64_to_i64_result, std.num.i32_to_string, std.num.u32_to_string, std.num.i64_to_string, std.num.u64_to_string, std.num.f64_to_string, std.result.is_ok, std.result.is_err, std.result.unwrap_ok, or std.result.unwrap_err") + (expected "promoted concrete standard-library function") (found "std.result.map") - (hint "use a promoted standard-runtime name or a legacy intrinsic alias") + (hint "use current concrete families such as `std.vec.i32.empty`") ) diff --git a/tests/std-vec-empty-generic-unsupported.diag b/tests/std-vec-empty-generic-unsupported.diag new file mode 100644 index 0000000..7b9812a --- /dev/null +++ b/tests/std-vec-empty-generic-unsupported.diag @@ -0,0 +1,15 @@ +(diagnostic + (schema slovo.diagnostic) + (version 1) + (severity error) + (code UnsupportedGenericStandardLibraryCall) + (message "generic standard-library call `std.vec.empty` is reserved but not supported in beta.9") + (file "") + (span + (bytes 38 51) + (range 5 4 5 17) + ) + (expected "promoted concrete standard-library function") + (found "std.vec.empty") + (hint "use current concrete families such as `std.vec.i32.empty`") +) diff --git a/tests/unsupported-generic-function.diag b/tests/unsupported-generic-function.diag new file mode 100644 index 0000000..7401330 --- /dev/null +++ b/tests/unsupported-generic-function.diag @@ -0,0 +1,15 @@ +(diagnostic + (schema slovo.diagnostic) + (version 1) + (severity error) + (code UnsupportedGenericFunction) + (message "generic function declarations are reserved but not supported in beta.9") + (file "") + (span + (bytes 23 38) + (range 4 8 4 23) + ) + (expected "(fn name ((arg ConcreteType) ...) -> ConcreteType body...)") + (found "(type_params ...)") + (hint "write a concrete function for each currently supported type family") +) diff --git a/tests/unsupported-generic-type-alias.diag b/tests/unsupported-generic-type-alias.diag new file mode 100644 index 0000000..03c4b2e --- /dev/null +++ b/tests/unsupported-generic-type-alias.diag @@ -0,0 +1,15 @@ +(diagnostic + (schema slovo.diagnostic) + (version 1) + (severity error) + (code UnsupportedGenericTypeAlias) + (message "parameterized type aliases are reserved but not supported in beta.9") + (file "") + (span + (bytes 28 43) + (range 4 13 4 28) + ) + (expected "(type Alias ConcreteType)") + (found "(type_params ...)") + (hint "aliases remain transparent names for concrete supported target types") +) diff --git a/tests/unsupported-generic-type-parameter.diag b/tests/unsupported-generic-type-parameter.diag new file mode 100644 index 0000000..c607a33 --- /dev/null +++ b/tests/unsupported-generic-type-parameter.diag @@ -0,0 +1,15 @@ +(diagnostic + (schema slovo.diagnostic) + (version 1) + (severity error) + (code UnsupportedGenericTypeParameter) + (message "generic type parameter `T` is reserved but not supported in beta.9") + (file "") + (span + (bytes 42 44) + (range 5 8 5 10) + ) + (expected "concrete supported type") + (found "T") + (hint "use a concrete promoted type such as `i32`, `string`, or `(vec i32)`") +) diff --git a/tests/unsupported-generic-vec-type.diag b/tests/unsupported-generic-vec-type.diag index 9df613b..d0b810a 100644 --- a/tests/unsupported-generic-vec-type.diag +++ b/tests/unsupported-generic-vec-type.diag @@ -2,11 +2,14 @@ (schema slovo.diagnostic) (version 1) (severity error) - (code InvalidReturnType) - (message "invalid return type") + (code UnsupportedGenericTypeParameter) + (message "generic vector syntax is reserved but not supported in beta.9") (file "") (span (bytes 31 36) (range 4 16 4 21) ) + (expected "(vec i32), (vec i64), (vec f64), (vec bool), or (vec string)") + (found "(vec)") + (hint "choose one current concrete vector family explicitly") ) diff --git a/tests/unsupported-map-type.diag b/tests/unsupported-map-type.diag new file mode 100644 index 0000000..ee8661d --- /dev/null +++ b/tests/unsupported-map-type.diag @@ -0,0 +1,15 @@ +(diagnostic + (schema slovo.diagnostic) + (version 1) + (severity error) + (code UnsupportedMapType) + (message "`map` types are reserved but not supported in beta.9") + (file "") + (span + (bytes 31 47) + (range 4 16 4 32) + ) + (expected "supported concrete type") + (found "(map string i32)") + (hint "use current concrete arrays, vectors, option/result, structs, enums, or scalars") +) diff --git a/tests/unsupported-set-type.diag b/tests/unsupported-set-type.diag new file mode 100644 index 0000000..ec68a3f --- /dev/null +++ b/tests/unsupported-set-type.diag @@ -0,0 +1,15 @@ +(diagnostic + (schema slovo.diagnostic) + (version 1) + (severity error) + (code UnsupportedSetType) + (message "`set` types are reserved but not supported in beta.9") + (file "") + (span + (bytes 31 43) + (range 4 16 4 28) + ) + (expected "supported concrete type") + (found "(set string)") + (hint "use current concrete arrays, vectors, option/result, structs, enums, or scalars") +) diff --git a/tests/unsupported-type-alias-target.diag b/tests/unsupported-type-alias-target.diag index 5169128..cca0620 100644 --- a/tests/unsupported-type-alias-target.diag +++ b/tests/unsupported-type-alias-target.diag @@ -3,7 +3,7 @@ (version 1) (severity error) (code UnsupportedTypeAliasTarget) - (message "type alias target type is not supported in beta.8") + (message "type alias target type is not supported in the current beta") (file "") (span (bytes 50 59) @@ -19,7 +19,7 @@ (version 1) (severity error) (code UnsupportedTypeAliasTarget) - (message "type alias target type is not supported in beta.8") + (message "type alias target type is not supported in the current beta") (file "") (span (bytes 132 151) @@ -35,7 +35,7 @@ (version 1) (severity error) (code UnsupportedTypeAliasTarget) - (message "type alias target type is not supported in beta.8") + (message "type alias target type is not supported in the current beta") (file "") (span (bytes 77 88) @@ -51,7 +51,7 @@ (version 1) (severity error) (code UnsupportedTypeAliasTarget) - (message "type alias target type is not supported in beta.8") + (message "type alias target type is not supported in the current beta") (file "") (span (bytes 30 34) @@ -67,7 +67,7 @@ (version 1) (severity error) (code UnsupportedTypeAliasTarget) - (message "type alias target type is not supported in beta.8") + (message "type alias target type is not supported in the current beta") (file "") (span (bytes 104 113)