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