fix string ops, add string find, fix server.spl not being embedded, move stdlib to spl/, fix a null identity loss
This commit is contained in:
parent
bb4d163b40
commit
15ae8622e1
16 changed files with 111 additions and 59 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
func main { mega | with args ;
|
||||
[ "sudo" "mkdir" "/usr/lib/spl" ] command-wait;
|
||||
[ "sh" "-c" "sudo cp *.spl /usr/lib/spl" ] command-wait;
|
||||
[ "sh" "-c" "sudo cp -r spl/* /usr/lib/spl" ] command-wait;
|
||||
[ "cargo" "build" "--release" ] command-wait;
|
||||
[ "sudo" "rm" "/bin/spl" ] command-wait;
|
||||
[ "sudo" "cp" "target/release/spl" "/bin" ] command-wait;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"messaging bus, aka event bus"
|
||||
"messaging bus, aka event bus";
|
||||
|
||||
construct messaging namespace {
|
||||
Message
|
|
@ -53,7 +53,7 @@ construct net:server:ServerStream {
|
|||
this
|
||||
}
|
||||
accept { Stream | with this ;
|
||||
def stream null Stream settype =stream
|
||||
def stream Stream:mkinstance =stream
|
||||
this:id accept-server-stream stream:=id
|
||||
stream
|
||||
}
|
|
@ -30,55 +30,77 @@ construct FrameInfo {
|
|||
|
||||
construct _str_ext {
|
||||
;
|
||||
new { any | with this ;
|
||||
null clone this settype:construct
|
||||
new { any | :mkinstance:construct }
|
||||
mkinstance { any | with this ;
|
||||
null clone this settype
|
||||
}
|
||||
to-bytes { [int] | str-to-bytes }
|
||||
split { str | with splitter this ;
|
||||
def bytes splitter:to-bytes =bytes
|
||||
def iter this:to-bytes:iter =iter
|
||||
def item 0 =item
|
||||
[ while { item null eq not } {
|
||||
splitter:to-bytes =splitter
|
||||
def bytes this:to-bytes =bytes
|
||||
def i 0 =i
|
||||
[ [ while { i bytes:len lt } {
|
||||
def match 0 =match
|
||||
[
|
||||
while { match bytes:len eq not } {
|
||||
iter:next =item
|
||||
item null eq if {
|
||||
3 stop
|
||||
}
|
||||
item dup (match bytes:get) eq dup if {
|
||||
while { match i + bytes:len lt match splitter:len lt and } {
|
||||
i match + bytes:get (match splitter:get) eq dup if {
|
||||
match ++ =match
|
||||
} not if {
|
||||
0 =match
|
||||
3 stop
|
||||
}
|
||||
}
|
||||
{ | pop pop } match:foreach
|
||||
] _str
|
||||
} ]
|
||||
i bytes:get
|
||||
match splitter:len eq if {
|
||||
pop ] _str [
|
||||
i match + 1 - =i
|
||||
}
|
||||
i ++ =i
|
||||
} ] _str ]
|
||||
}
|
||||
replace { str | with replacee replacement this ;
|
||||
def bytes replacee:to-bytes =bytes
|
||||
def iter this:to-bytes:iter =iter
|
||||
def item 0 =item
|
||||
[ while { item null eq not } {
|
||||
replacee:to-bytes =replacee
|
||||
def bytes this:to-bytes =bytes
|
||||
def i 0 =i
|
||||
[ while { i bytes:len lt } {
|
||||
def match 0 =match
|
||||
while { match bytes:len eq not } {
|
||||
iter:next =item
|
||||
item null eq if {
|
||||
3 stop
|
||||
}
|
||||
item dup (match bytes:get) eq dup if {
|
||||
while { match i + bytes:len lt match replacee:len lt and } {
|
||||
i match + bytes:get (match replacee:get) eq dup if {
|
||||
match ++ =match
|
||||
} not if {
|
||||
0 =match
|
||||
3 stop
|
||||
}
|
||||
}
|
||||
{ | pop pop } match:foreach
|
||||
match bytes:len eq if {
|
||||
replacement _array :to-stack
|
||||
i bytes:get
|
||||
match replacee:len eq if {
|
||||
pop replacement:to-bytes:to-stack
|
||||
i match + 1 - =i
|
||||
}
|
||||
i ++ =i
|
||||
} ] _str
|
||||
}
|
||||
find { idx | with search this ;
|
||||
search:to-bytes =search
|
||||
def bytes this:to-bytes =bytes
|
||||
def i 0 =i
|
||||
while { i bytes:len lt } {
|
||||
def match 0 =match
|
||||
while { match i + bytes:len lt match search:len lt and } {
|
||||
i match + bytes:get (match search:get) eq dup if {
|
||||
match ++ =match
|
||||
} not if {
|
||||
0 =match
|
||||
3 stop
|
||||
}
|
||||
}
|
||||
match search:len eq if {
|
||||
i
|
||||
4 stop
|
||||
}
|
||||
i ++ =i
|
||||
}
|
||||
null
|
||||
}
|
||||
starts-with { bool | with beginning this ;
|
||||
beginning:to-bytes this:to-bytes:starts-with
|
||||
}
|
|
@ -35,7 +35,7 @@ construct Stream {
|
|||
def read
|
||||
while { buf this:id read-stream pop _mega dup =read } {
|
||||
full (0 read buf:sub) aadd =full
|
||||
}
|
||||
} pop
|
||||
full
|
||||
}
|
||||
write { mega | with buf this ;
|
|
@ -1,17 +1,18 @@
|
|||
use crate::Runtime;
|
||||
use multicall::multicall;
|
||||
|
||||
pub const STD: &str = include_str!("../std.spl");
|
||||
pub const NET: &str = include_str!("../net.spl");
|
||||
pub const ITER: &str = include_str!("../iter.spl");
|
||||
pub const HTTP: &str = include_str!("../http.spl");
|
||||
pub const STREAM: &str = include_str!("../stream.spl");
|
||||
pub const MESSAGING: &str = include_str!("../messaging.spl");
|
||||
pub const ASSEMBLE: &str = include_str!("../assemble.spl");
|
||||
pub const ISBPL: &str = include_str!("../isbpl.spl");
|
||||
pub const REPL: &str = include_str!("../repl.spl");
|
||||
pub const PURE: &str = include_str!("../pure.spl");
|
||||
pub const TIME: &str = include_str!("../time.spl");
|
||||
pub const STD: &str = include_str!("../spl/std.spl");
|
||||
pub const NET: &str = include_str!("../spl/net.spl");
|
||||
pub const ITER: &str = include_str!("../spl/iter.spl");
|
||||
pub const HTTP: &str = include_str!("../spl/http.spl");
|
||||
pub const STREAM: &str = include_str!("../spl/stream.spl");
|
||||
pub const MESSAGING: &str = include_str!("../spl/messaging.spl");
|
||||
pub const ASSEMBLE: &str = include_str!("../spl/assemble.spl");
|
||||
pub const ISBPL: &str = include_str!("../spl/isbpl.spl");
|
||||
pub const REPL: &str = include_str!("../spl/repl.spl");
|
||||
pub const PURE: &str = include_str!("../spl/pure.spl");
|
||||
pub const TIME: &str = include_str!("../spl/time.spl");
|
||||
pub const SERVER: &str = include_str!("../spl/server.spl");
|
||||
pub const NOP: &str = "";
|
||||
|
||||
pub fn register(runtime: &mut Runtime) {
|
||||
|
@ -28,6 +29,7 @@ pub fn register(runtime: &mut Runtime) {
|
|||
insert("repl.spl", REPL);
|
||||
insert("pure.spl", PURE);
|
||||
insert("time.spl", TIME);
|
||||
insert("server.spl", SERVER);
|
||||
insert("nop.spl", NOP);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use std::{
|
||||
borrow::BorrowMut,
|
||||
collections::HashMap,
|
||||
hint::black_box,
|
||||
io::{Read, Write},
|
||||
|
|
41
test.spl
41
test.spl
|
@ -1,4 +1,4 @@
|
|||
|
||||
[
|
||||
"#stream.spl" import
|
||||
"#http.spl" import
|
||||
"#messaging.spl" import
|
||||
|
@ -8,6 +8,7 @@
|
|||
"SPL tester" =program-name
|
||||
|
||||
func main { int | with args ;
|
||||
|
||||
def thing
|
||||
|
||||
1 anew =thing
|
||||
|
@ -110,7 +111,7 @@ func main { int | with args ;
|
|||
|
||||
def file "test.txt" 1 StreamTypes:file:create =file
|
||||
"hi\n" :to-bytes file:write-exact;
|
||||
file:close null =file
|
||||
file:close; null =file
|
||||
|
||||
"" println
|
||||
"testing split" println
|
||||
|
@ -119,9 +120,9 @@ func main { int | with args ;
|
|||
|
||||
catch {
|
||||
use net:http:Request
|
||||
"testing http" println
|
||||
"testing http" println;
|
||||
def req "data.tudbut.de" 80 "GET" "/spltest" Request:new =req
|
||||
req:send:body _str println
|
||||
req:send:body _str println;
|
||||
} { with e ;
|
||||
e:message println
|
||||
"it seems the internet is not available" println
|
||||
|
@ -180,9 +181,37 @@ func main { int | with args ;
|
|||
def client "localhost" 4075 StreamTypes:tcp:create =client
|
||||
1024 client:read-to-end:to-str println;
|
||||
" ^ this should say 'Hello!'" println;
|
||||
"you now have a chance to connect too: localhost:4075 - continuing in 5 seconds..." println;
|
||||
5000 time:sleep;
|
||||
"you now have a chance to connect too: localhost:4075 - continuing in 2 seconds..." println;
|
||||
2000 time:sleep;
|
||||
|
||||
"" println
|
||||
"testing string replace" println;
|
||||
|
||||
"aba" "!!" "ababab" :replace println;
|
||||
" ^ should be !!bab." println;
|
||||
"aba" "!!" "aababab" :replace println;
|
||||
" ^ should be a!!bab." println;
|
||||
|
||||
"" println;
|
||||
"testing string split" println;
|
||||
|
||||
"ba" "abaabaabaa" :split:iter:join<", "> println;
|
||||
" ^ should be a, a, a, a" println;
|
||||
"ba" "abbaabbaababaa" :split:iter:join<", "> println;
|
||||
" ^ should be ab, ab, a, , a" println;
|
||||
|
||||
"" println;
|
||||
"testing string find" println;
|
||||
|
||||
"abba" "ababba" :find println;
|
||||
"^ should be 2" println;
|
||||
|
||||
|
||||
] dup :len 0 eq not if {
|
||||
"" println
|
||||
"!! something went wrong somewhere. the stack is not empty." println
|
||||
dyn-__dump
|
||||
}
|
||||
100
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue