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 ;
|
func main { mega | with args ;
|
||||||
[ "sudo" "mkdir" "/usr/lib/spl" ] command-wait;
|
[ "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;
|
[ "cargo" "build" "--release" ] command-wait;
|
||||||
[ "sudo" "rm" "/bin/spl" ] command-wait;
|
[ "sudo" "rm" "/bin/spl" ] command-wait;
|
||||||
[ "sudo" "cp" "target/release/spl" "/bin" ] 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 {
|
construct messaging namespace {
|
||||||
Message
|
Message
|
|
@ -53,7 +53,7 @@ construct net:server:ServerStream {
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
accept { Stream | with this ;
|
accept { Stream | with this ;
|
||||||
def stream null Stream settype =stream
|
def stream Stream:mkinstance =stream
|
||||||
this:id accept-server-stream stream:=id
|
this:id accept-server-stream stream:=id
|
||||||
stream
|
stream
|
||||||
}
|
}
|
|
@ -30,55 +30,77 @@ construct FrameInfo {
|
||||||
|
|
||||||
construct _str_ext {
|
construct _str_ext {
|
||||||
;
|
;
|
||||||
new { any | with this ;
|
new { any | :mkinstance:construct }
|
||||||
null clone this settype:construct
|
mkinstance { any | with this ;
|
||||||
|
null clone this settype
|
||||||
}
|
}
|
||||||
to-bytes { [int] | str-to-bytes }
|
to-bytes { [int] | str-to-bytes }
|
||||||
split { str | with splitter this ;
|
split { str | with splitter this ;
|
||||||
def bytes splitter:to-bytes =bytes
|
splitter:to-bytes =splitter
|
||||||
def iter this:to-bytes:iter =iter
|
def bytes this:to-bytes =bytes
|
||||||
def item 0 =item
|
def i 0 =i
|
||||||
[ while { item null eq not } {
|
[ [ while { i bytes:len lt } {
|
||||||
def match 0 =match
|
def match 0 =match
|
||||||
[
|
while { match i + bytes:len lt match splitter:len lt and } {
|
||||||
while { match bytes:len eq not } {
|
i match + bytes:get (match splitter:get) eq dup if {
|
||||||
iter:next =item
|
|
||||||
item null eq if {
|
|
||||||
3 stop
|
|
||||||
}
|
|
||||||
item dup (match bytes:get) eq dup if {
|
|
||||||
match ++ =match
|
match ++ =match
|
||||||
} not if {
|
} not if {
|
||||||
0 =match
|
0 =match
|
||||||
|
3 stop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{ | pop pop } match:foreach
|
i bytes:get
|
||||||
] _str
|
match splitter:len eq if {
|
||||||
} ]
|
pop ] _str [
|
||||||
|
i match + 1 - =i
|
||||||
|
}
|
||||||
|
i ++ =i
|
||||||
|
} ] _str ]
|
||||||
}
|
}
|
||||||
replace { str | with replacee replacement this ;
|
replace { str | with replacee replacement this ;
|
||||||
def bytes replacee:to-bytes =bytes
|
replacee:to-bytes =replacee
|
||||||
def iter this:to-bytes:iter =iter
|
def bytes this:to-bytes =bytes
|
||||||
def item 0 =item
|
def i 0 =i
|
||||||
[ while { item null eq not } {
|
[ while { i bytes:len lt } {
|
||||||
def match 0 =match
|
def match 0 =match
|
||||||
while { match bytes:len eq not } {
|
while { match i + bytes:len lt match replacee:len lt and } {
|
||||||
iter:next =item
|
i match + bytes:get (match replacee:get) eq dup if {
|
||||||
item null eq if {
|
|
||||||
3 stop
|
|
||||||
}
|
|
||||||
item dup (match bytes:get) eq dup if {
|
|
||||||
match ++ =match
|
match ++ =match
|
||||||
} not if {
|
} not if {
|
||||||
0 =match
|
0 =match
|
||||||
|
3 stop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{ | pop pop } match:foreach
|
i bytes:get
|
||||||
match bytes:len eq if {
|
match replacee:len eq if {
|
||||||
replacement _array :to-stack
|
pop replacement:to-bytes:to-stack
|
||||||
|
i match + 1 - =i
|
||||||
}
|
}
|
||||||
|
i ++ =i
|
||||||
} ] _str
|
} ] _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 ;
|
starts-with { bool | with beginning this ;
|
||||||
beginning:to-bytes this:to-bytes:starts-with
|
beginning:to-bytes this:to-bytes:starts-with
|
||||||
}
|
}
|
|
@ -35,7 +35,7 @@ construct Stream {
|
||||||
def read
|
def read
|
||||||
while { buf this:id read-stream pop _mega dup =read } {
|
while { buf this:id read-stream pop _mega dup =read } {
|
||||||
full (0 read buf:sub) aadd =full
|
full (0 read buf:sub) aadd =full
|
||||||
}
|
} pop
|
||||||
full
|
full
|
||||||
}
|
}
|
||||||
write { mega | with buf this ;
|
write { mega | with buf this ;
|
|
@ -1,17 +1,18 @@
|
||||||
use crate::Runtime;
|
use crate::Runtime;
|
||||||
use multicall::multicall;
|
use multicall::multicall;
|
||||||
|
|
||||||
pub const STD: &str = include_str!("../std.spl");
|
pub const STD: &str = include_str!("../spl/std.spl");
|
||||||
pub const NET: &str = include_str!("../net.spl");
|
pub const NET: &str = include_str!("../spl/net.spl");
|
||||||
pub const ITER: &str = include_str!("../iter.spl");
|
pub const ITER: &str = include_str!("../spl/iter.spl");
|
||||||
pub const HTTP: &str = include_str!("../http.spl");
|
pub const HTTP: &str = include_str!("../spl/http.spl");
|
||||||
pub const STREAM: &str = include_str!("../stream.spl");
|
pub const STREAM: &str = include_str!("../spl/stream.spl");
|
||||||
pub const MESSAGING: &str = include_str!("../messaging.spl");
|
pub const MESSAGING: &str = include_str!("../spl/messaging.spl");
|
||||||
pub const ASSEMBLE: &str = include_str!("../assemble.spl");
|
pub const ASSEMBLE: &str = include_str!("../spl/assemble.spl");
|
||||||
pub const ISBPL: &str = include_str!("../isbpl.spl");
|
pub const ISBPL: &str = include_str!("../spl/isbpl.spl");
|
||||||
pub const REPL: &str = include_str!("../repl.spl");
|
pub const REPL: &str = include_str!("../spl/repl.spl");
|
||||||
pub const PURE: &str = include_str!("../pure.spl");
|
pub const PURE: &str = include_str!("../spl/pure.spl");
|
||||||
pub const TIME: &str = include_str!("../time.spl");
|
pub const TIME: &str = include_str!("../spl/time.spl");
|
||||||
|
pub const SERVER: &str = include_str!("../spl/server.spl");
|
||||||
pub const NOP: &str = "";
|
pub const NOP: &str = "";
|
||||||
|
|
||||||
pub fn register(runtime: &mut Runtime) {
|
pub fn register(runtime: &mut Runtime) {
|
||||||
|
@ -28,6 +29,7 @@ pub fn register(runtime: &mut Runtime) {
|
||||||
insert("repl.spl", REPL);
|
insert("repl.spl", REPL);
|
||||||
insert("pure.spl", PURE);
|
insert("pure.spl", PURE);
|
||||||
insert("time.spl", TIME);
|
insert("time.spl", TIME);
|
||||||
|
insert("server.spl", SERVER);
|
||||||
insert("nop.spl", NOP);
|
insert("nop.spl", NOP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use std::{
|
use std::{
|
||||||
borrow::BorrowMut,
|
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
hint::black_box,
|
hint::black_box,
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
|
|
41
test.spl
41
test.spl
|
@ -1,4 +1,4 @@
|
||||||
|
[
|
||||||
"#stream.spl" import
|
"#stream.spl" import
|
||||||
"#http.spl" import
|
"#http.spl" import
|
||||||
"#messaging.spl" import
|
"#messaging.spl" import
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
"SPL tester" =program-name
|
"SPL tester" =program-name
|
||||||
|
|
||||||
func main { int | with args ;
|
func main { int | with args ;
|
||||||
|
|
||||||
def thing
|
def thing
|
||||||
|
|
||||||
1 anew =thing
|
1 anew =thing
|
||||||
|
@ -110,7 +111,7 @@ func main { int | with args ;
|
||||||
|
|
||||||
def file "test.txt" 1 StreamTypes:file:create =file
|
def file "test.txt" 1 StreamTypes:file:create =file
|
||||||
"hi\n" :to-bytes file:write-exact;
|
"hi\n" :to-bytes file:write-exact;
|
||||||
file:close null =file
|
file:close; null =file
|
||||||
|
|
||||||
"" println
|
"" println
|
||||||
"testing split" println
|
"testing split" println
|
||||||
|
@ -119,9 +120,9 @@ func main { int | with args ;
|
||||||
|
|
||||||
catch {
|
catch {
|
||||||
use net:http:Request
|
use net:http:Request
|
||||||
"testing http" println
|
"testing http" println;
|
||||||
def req "data.tudbut.de" 80 "GET" "/spltest" Request:new =req
|
def req "data.tudbut.de" 80 "GET" "/spltest" Request:new =req
|
||||||
req:send:body _str println
|
req:send:body _str println;
|
||||||
} { with e ;
|
} { with e ;
|
||||||
e:message println
|
e:message println
|
||||||
"it seems the internet is not available" 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
|
def client "localhost" 4075 StreamTypes:tcp:create =client
|
||||||
1024 client:read-to-end:to-str println;
|
1024 client:read-to-end:to-str println;
|
||||||
" ^ this should say 'Hello!'" println;
|
" ^ this should say 'Hello!'" println;
|
||||||
"you now have a chance to connect too: localhost:4075 - continuing in 5 seconds..." println;
|
"you now have a chance to connect too: localhost:4075 - continuing in 2 seconds..." println;
|
||||||
5000 time:sleep;
|
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
|
100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue