seq_runtime/
lib.rs

1//! Seq Runtime: A clean concatenative language foundation
2//!
3//! Key design principles:
4//! - Value: What the language talks about (Int, Bool, Variant, etc.)
5//! - StackValue: 40-byte tagged stack entry (discriminant + 4 payload slots)
6//! - Stack: Contiguous array of StackValue entries for efficient operations
7
8// Re-export core modules from seq-core (foundation for stack-based languages)
9pub use seq_core::arena;
10pub use seq_core::error;
11pub use seq_core::memory_stats;
12pub use seq_core::seqstring;
13pub use seq_core::son;
14pub use seq_core::stack;
15pub use seq_core::tagged_stack;
16pub use seq_core::value;
17
18// Seq-specific modules
19pub mod args;
20pub mod arithmetic;
21pub mod channel;
22pub mod closures;
23pub mod cond;
24pub mod crypto;
25pub mod diagnostics;
26pub mod encoding;
27pub mod file;
28pub mod float_ops;
29pub mod http_client;
30pub mod io;
31pub mod list_ops;
32pub mod map_ops;
33pub mod os;
34pub mod quotations;
35pub mod scheduler;
36pub mod serialize;
37pub mod string_ops;
38pub mod tcp;
39pub mod tcp_test;
40pub mod test;
41pub mod time_ops;
42pub mod variant_ops;
43pub mod watchdog;
44pub mod weave;
45
46// Re-export key types and functions from seq-core
47pub use seq_core::{ChannelData, MapKey, Value, VariantData, WeaveChannelData, WeaveMessage};
48pub use seq_core::{
49    DISC_BOOL, DISC_CHANNEL, DISC_CLOSURE, DISC_FLOAT, DISC_INT, DISC_MAP, DISC_QUOTATION,
50    DISC_STRING, DISC_SYMBOL, DISC_VARIANT, DISC_WEAVECTX, Stack, alloc_stack, alloc_test_stack,
51    clone_stack, clone_stack_segment, clone_stack_value, clone_value, drop_op, drop_stack_value,
52    drop_top, dup, is_empty, nip, over, peek, peek_sv, pick_op, pop, pop_sv, push, push_sv,
53    push_value, roll, rot, set_stack_base, stack_dump, stack_value_to_value, swap, three_drop,
54    tuck, two_dup, value_to_stack_value,
55};
56
57// SON serialization (from seq-core)
58pub use seq_core::{son_dump, son_dump_pretty};
59
60// Error handling (from seq-core)
61pub use seq_core::{
62    clear_error, clear_runtime_error, get_error, has_error, has_runtime_error, set_runtime_error,
63    take_error, take_runtime_error,
64};
65
66// Serialization types (for persistence/exchange with external systems)
67pub use serialize::{SerializeError, TypedMapKey, TypedValue, ValueSerialize};
68
69// Arithmetic operations (exported for LLVM linking)
70pub use arithmetic::{
71    patch_seq_add as add, patch_seq_divide as divide, patch_seq_eq as eq, patch_seq_gt as gt,
72    patch_seq_gte as gte, patch_seq_lt as lt, patch_seq_lte as lte, patch_seq_multiply as multiply,
73    patch_seq_neq as neq, patch_seq_push_bool as push_bool, patch_seq_push_int as push_int,
74    patch_seq_subtract as subtract,
75};
76
77// Float operations (exported for LLVM linking)
78pub use float_ops::{
79    patch_seq_f_add as f_add, patch_seq_f_divide as f_divide, patch_seq_f_eq as f_eq,
80    patch_seq_f_gt as f_gt, patch_seq_f_gte as f_gte, patch_seq_f_lt as f_lt,
81    patch_seq_f_lte as f_lte, patch_seq_f_multiply as f_multiply, patch_seq_f_neq as f_neq,
82    patch_seq_f_subtract as f_subtract, patch_seq_float_to_int as float_to_int,
83    patch_seq_float_to_string as float_to_string, patch_seq_int_to_float as int_to_float,
84    patch_seq_push_float as push_float,
85};
86
87// I/O operations (exported for LLVM linking)
88pub use io::{
89    patch_seq_exit_op as exit_op, patch_seq_push_interned_symbol as push_interned_symbol,
90    patch_seq_push_string as push_string, patch_seq_push_symbol as push_symbol,
91    patch_seq_read_line as read_line, patch_seq_read_line_plus as read_line_plus,
92    patch_seq_read_n as read_n, patch_seq_string_to_symbol as string_to_symbol,
93    patch_seq_symbol_to_string as symbol_to_string, patch_seq_write_line as write_line,
94};
95
96// Scheduler operations (exported for LLVM linking)
97pub use scheduler::{
98    patch_seq_maybe_yield as maybe_yield, patch_seq_scheduler_init as scheduler_init,
99    patch_seq_scheduler_run as scheduler_run, patch_seq_scheduler_shutdown as scheduler_shutdown,
100    patch_seq_spawn_strand as spawn_strand, patch_seq_strand_spawn as strand_spawn,
101    patch_seq_wait_all_strands as wait_all_strands, patch_seq_yield_strand as yield_strand,
102};
103
104// Channel operations (exported for LLVM linking)
105// Note: All channel ops now return success flags (errors are values, not crashes)
106pub use channel::{
107    patch_seq_chan_receive as receive, patch_seq_chan_send as send,
108    patch_seq_close_channel as close_channel, patch_seq_make_channel as make_channel,
109};
110
111// Weave operations (generators/coroutines with yield/resume)
112pub use weave::{
113    patch_seq_resume as weave_resume, patch_seq_weave as weave_make,
114    patch_seq_weave_cancel as weave_cancel, patch_seq_yield as weave_yield,
115};
116
117// String operations (exported for LLVM linking)
118pub use io::patch_seq_int_to_string as int_to_string;
119pub use string_ops::{
120    patch_seq_json_escape as json_escape, patch_seq_string_chomp as string_chomp,
121    patch_seq_string_concat as string_concat, patch_seq_string_contains as string_contains,
122    patch_seq_string_empty as string_empty, patch_seq_string_length as string_length,
123    patch_seq_string_split as string_split, patch_seq_string_starts_with as string_starts_with,
124    patch_seq_string_to_int as string_to_int, patch_seq_string_to_lower as string_to_lower,
125    patch_seq_string_to_upper as string_to_upper, patch_seq_string_trim as string_trim,
126};
127
128// Encoding operations (exported for LLVM linking)
129pub use encoding::{
130    patch_seq_base64_decode as base64_decode, patch_seq_base64_encode as base64_encode,
131    patch_seq_base64url_decode as base64url_decode, patch_seq_base64url_encode as base64url_encode,
132    patch_seq_hex_decode as hex_decode, patch_seq_hex_encode as hex_encode,
133};
134
135// Crypto operations (exported for LLVM linking)
136pub use crypto::{
137    patch_seq_constant_time_eq as constant_time_eq, patch_seq_hmac_sha256 as hmac_sha256,
138    patch_seq_random_bytes as random_bytes, patch_seq_sha256 as sha256, patch_seq_uuid4 as uuid4,
139};
140
141// Quotation operations (exported for LLVM linking)
142pub use quotations::{
143    patch_seq_call as call, patch_seq_peek_is_quotation as peek_is_quotation,
144    patch_seq_peek_quotation_fn_ptr as peek_quotation_fn_ptr,
145    patch_seq_push_quotation as push_quotation, patch_seq_spawn as spawn, patch_seq_times as times,
146    patch_seq_until_loop as until_loop, patch_seq_while_loop as while_loop,
147};
148
149// Closure operations (exported for LLVM linking)
150pub use closures::{
151    patch_seq_create_env as create_env, patch_seq_env_get as env_get,
152    patch_seq_env_get_int as env_get_int, patch_seq_env_set as env_set,
153    patch_seq_make_closure as make_closure, patch_seq_push_closure as push_closure,
154};
155
156// Conditional combinator (exported for LLVM linking)
157pub use cond::patch_seq_cond as cond;
158
159// TCP operations (exported for LLVM linking)
160pub use tcp::{
161    patch_seq_tcp_accept as tcp_accept, patch_seq_tcp_close as tcp_close,
162    patch_seq_tcp_listen as tcp_listen, patch_seq_tcp_read as tcp_read,
163    patch_seq_tcp_write as tcp_write,
164};
165
166// OS operations (exported for LLVM linking)
167pub use os::{
168    patch_seq_current_dir as current_dir, patch_seq_exit as exit, patch_seq_getenv as getenv,
169    patch_seq_home_dir as home_dir, patch_seq_os_arch as os_arch, patch_seq_os_name as os_name,
170    patch_seq_path_exists as path_exists, patch_seq_path_filename as path_filename,
171    patch_seq_path_is_dir as path_is_dir, patch_seq_path_is_file as path_is_file,
172    patch_seq_path_join as path_join, patch_seq_path_parent as path_parent,
173};
174
175// Variant operations (exported for LLVM linking)
176pub use variant_ops::{
177    patch_seq_make_variant_0 as make_variant_0, patch_seq_make_variant_1 as make_variant_1,
178    patch_seq_make_variant_2 as make_variant_2, patch_seq_make_variant_3 as make_variant_3,
179    patch_seq_make_variant_4 as make_variant_4, patch_seq_unpack_variant as unpack_variant,
180    patch_seq_variant_field_at as variant_field_at,
181    patch_seq_variant_field_count as variant_field_count, patch_seq_variant_tag as variant_tag,
182};
183
184// Command-line argument operations (exported for LLVM linking)
185pub use args::{
186    patch_seq_arg_at as arg_at, patch_seq_arg_count as arg_count, patch_seq_args_init as args_init,
187};
188
189// File operations (exported for LLVM linking)
190pub use file::{
191    patch_seq_file_exists as file_exists,
192    patch_seq_file_for_each_line_plus as file_for_each_line_plus,
193    patch_seq_file_slurp as file_slurp,
194};
195
196// List operations (exported for LLVM linking)
197pub use list_ops::{
198    patch_seq_list_each as list_each, patch_seq_list_empty as list_empty,
199    patch_seq_list_filter as list_filter, patch_seq_list_fold as list_fold,
200    patch_seq_list_get as list_get, patch_seq_list_length as list_length,
201    patch_seq_list_make as list_make, patch_seq_list_map as list_map,
202    patch_seq_list_push as list_push, patch_seq_list_set as list_set,
203};
204
205// Map operations (exported for LLVM linking)
206pub use map_ops::{
207    patch_seq_make_map as make_map, patch_seq_map_empty as map_empty, patch_seq_map_get as map_get,
208    patch_seq_map_has as map_has, patch_seq_map_keys as map_keys,
209    patch_seq_map_remove as map_remove, patch_seq_map_set as map_set,
210    patch_seq_map_size as map_size, patch_seq_map_values as map_values,
211};
212
213// Test framework operations (exported for LLVM linking)
214pub use test::{
215    patch_seq_test_assert as test_assert, patch_seq_test_assert_eq as test_assert_eq,
216    patch_seq_test_assert_eq_str as test_assert_eq_str,
217    patch_seq_test_assert_not as test_assert_not, patch_seq_test_fail as test_fail,
218    patch_seq_test_fail_count as test_fail_count, patch_seq_test_finish as test_finish,
219    patch_seq_test_has_failures as test_has_failures, patch_seq_test_init as test_init,
220    patch_seq_test_pass_count as test_pass_count,
221};
222
223// Time operations (exported for LLVM linking)
224pub use time_ops::{
225    patch_seq_time_nanos as time_nanos, patch_seq_time_now as time_now,
226    patch_seq_time_sleep_ms as time_sleep_ms,
227};
228
229// HTTP client operations (exported for LLVM linking)
230pub use http_client::{
231    patch_seq_http_delete as http_delete, patch_seq_http_get as http_get,
232    patch_seq_http_post as http_post, patch_seq_http_put as http_put,
233};