]> rethought.computer Git - sorel-lang.git/commitdiff
add new string stdlib module keep/9674970ee4895400c02b66b3616cb46c87fb5881
authorBryan English <bryan@rethought.computer>
Fri, 6 Feb 2026 03:35:42 +0000 (22:35 -0500)
committerBryan English <bryan@rethought.computer>
Tue, 10 Feb 2026 04:08:54 +0000 (04:08 +0000)
rel-lang/sorelc/src/ir.rs
rel-lang/stdlib/out.sorel
rel-lang/stdlib/string.sorel [new file with mode: 0644]

index 7d31d1a4370043e7d87a4d0efa816f13ff3730f4..d38d7f783c04a9e423f6c33dfb8f406a2993a098 100644 (file)
@@ -63,6 +63,7 @@ fn std_import(specifier: &str) -> Result<&str> {
     match specifier {
         "std:mem" => Ok(include_str!("../../stdlib/mem.sorel")),
         "std:out" => Ok(include_str!("../../stdlib/out.sorel")),
+        "std:string" => Ok(include_str!("../../stdlib/string.sorel")),
         _ => bail!("{} is not a standard library module", specifier),
     }
 }
index 000b32042160bd1387297c1a487e39d38d9dec0e..5704f999c9826acdf975d64eefcff4541be79d5a 100644 (file)
@@ -5,17 +5,7 @@
   sys3
 ;
 
-: strlen ( addr -- len )
-  dup dup \ ( addr addr addr )
-  @:8 \ ( addr addr byte )
-  loop \ ( addr addr )
-    1 + \ ( addr addr+1 )
-    dup \ ( addr addr+1 addr+1)
-    @:8 \ ( addr addr+1 byte )
-  endloop \ ( addr addr+len )
-  swap \ ( addr+len addr )
-  - \ ( len )
-;
+import "std:string"
 
 export puts
 
diff --git a/rel-lang/stdlib/string.sorel b/rel-lang/stdlib/string.sorel
new file mode 100644 (file)
index 0000000..b0c76a8
--- /dev/null
@@ -0,0 +1,15 @@
+\ vim: filetype=forth
+
+: strlen ( addr -- len )
+  dup dup \ ( addr addr addr )
+  @:8 \ ( addr addr byte )
+  loop \ ( addr addr )
+    1 + \ ( addr addr+1 )
+    dup \ ( addr addr+1 addr+1)
+    @:8 \ ( addr addr+1 byte )
+  endloop \ ( addr addr+len )
+  swap \ ( addr+len addr )
+  - \ ( len )
+;
+
+export strlen