mirror of
https://github.com/zorp-corp/jock-lang.git
synced 2024-11-30 10:59:43 +03:00
jock: all files
This commit is contained in:
parent
4a9483f339
commit
2984f070c2
20
.gitignore
vendored
Normal file
20
.gitignore
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
# Compilation artifacts
|
||||
target
|
||||
bin/
|
||||
|
||||
.data.crown
|
||||
**/.data.crown
|
||||
|
||||
# Dev config
|
||||
.vscode/settings.json
|
||||
|
||||
# Junk
|
||||
.unikraft
|
||||
.DS_Store
|
||||
|
||||
*.swp
|
||||
**/*.swp
|
||||
.DS_Store
|
||||
._.DS_Store
|
||||
**/.DS_store
|
||||
**/._.DS_store
|
2534
Cargo.lock
generated
Normal file
2534
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
Cargo.toml
Normal file
17
Cargo.toml
Normal file
@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "jock-testing"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
crown = { git = "https://github.com/zorp-corp/nockapp", rev="503a5afd0a969fb1d2c240ffc1793a694407072b" }
|
||||
sword = { git = "https://github.com/zorp-corp/sword.git", rev="92f4f40cf7af714538b8766de6f7792eaa103cbd" }
|
||||
sword_macros = { git = "https://github.com/zorp-corp/sword.git", rev="92f4f40cf7af714538b8766de6f7792eaa103cbd" }
|
||||
assert_no_alloc = { git = "https://github.com/zorp-corp/sword.git", rev="92f4f40cf7af714538b8766de6f7792eaa103cbd" }
|
||||
clap = { version = "4.4.4", features = ["derive", "cargo", "color", "env"]}
|
||||
tokio = { version = "1.32", features = ["rt", "rt-multi-thread", "net", "macros", "io-util", "fs", "sync", "time"] }
|
||||
tracing = "0.1.40"
|
||||
|
||||
[[bin]]
|
||||
name = "jock-testing"
|
||||
path = "main.rs"
|
0
assets/jocktest.jam
Normal file
0
assets/jocktest.jam
Normal file
1254
hoon/lib/jock.hoon
Normal file
1254
hoon/lib/jock.hoon
Normal file
File diff suppressed because it is too large
Load Diff
97
hoon/lib/test-jock.hoon
Normal file
97
hoon/lib/test-jock.hoon
Normal file
@ -0,0 +1,97 @@
|
||||
/+ jock
|
||||
::/* let-edit %jock /lib/tests/let-edit/jock
|
||||
::/* let-inner-exp %jock /lib/tests/let-inner-exp/jock
|
||||
::/* call %jock /lib/tests/call/jock
|
||||
::/* axis-call %jock /lib/tests/axis-call/jock
|
||||
::/* inline-lambda-call %jock /lib/tests/inline-lambda-call/jock
|
||||
::/* in-subj-call %jock /lib/tests/in-subj-call/jock
|
||||
::/* if-else %jock /lib/tests/if-else/jock
|
||||
::/* assert %jock /lib/tests/assert/jock
|
||||
::/* call-let-edit %jock /lib/tests/call-let-edit/jock
|
||||
::/* inline-point %jock /lib/tests/inline-point/jock
|
||||
::/* inline-lambda-no-arg %jock /lib/tests/inline-lambda-no-arg/jock
|
||||
::/* dec-jock %jock /lib/tests/dec/jock
|
||||
::/* eval %jock /lib/tests/eval/jock
|
||||
::/* multi-limb %jock /lib/tests/multi-limb/jock
|
||||
::/* compose %jock /lib/tests/compose/jock
|
||||
::/* compose-cores %jock /lib/tests/compose-cores/jock
|
||||
::/* baby %jock /lib/tests/baby/jock
|
||||
::/* comparator %jock /lib/tests/comparator/jock
|
||||
|%
|
||||
::
|
||||
++ list-jocks
|
||||
^- (list [term @t])
|
||||
:~ ex+''
|
||||
==
|
||||
:: :~ let-edit+let-edit
|
||||
:: let-inner-exp+let-inner-exp
|
||||
:: call+call
|
||||
:: axis-call+axis-call
|
||||
:: inline-lambda-call+inline-lambda-call
|
||||
:: in-subj-call+in-subj-call
|
||||
:: if-else+if-else
|
||||
:: assert+assert
|
||||
:: call-let-edit+call-let-edit
|
||||
:: inline-point+inline-point
|
||||
:: inline-lambda-no-arg+inline-lambda-no-arg
|
||||
:: dec-jock+dec-jock
|
||||
:: eval+eval
|
||||
:: multi-limb+multi-limb
|
||||
:: compose+compose
|
||||
:: compose-cores+compose-cores
|
||||
:: baby+baby
|
||||
:: ::comparator+comparator
|
||||
:: ==
|
||||
::
|
||||
++ jeam
|
||||
|= i=@
|
||||
^- jock:jock
|
||||
=/ p (snag i list-jocks)
|
||||
~| -.p
|
||||
(jeam:jock +.p)
|
||||
::
|
||||
++ jeam-all
|
||||
^- (list jock:jock)
|
||||
%+ turn list-jocks
|
||||
|= [=term t=@t]
|
||||
~| term
|
||||
(jeam:jock t)
|
||||
::
|
||||
++ mint-all
|
||||
^- (list *)
|
||||
%+ turn list-jocks
|
||||
|= [=term t=@t]
|
||||
~| term
|
||||
(mint:jock t)
|
||||
::
|
||||
++ mint
|
||||
|= i=@
|
||||
^- [term *]
|
||||
=/ p (snag i list-jocks)
|
||||
:- -.p
|
||||
(mint:jock +.p)
|
||||
::
|
||||
++ exec
|
||||
|= i=@
|
||||
^- *
|
||||
=/ nok (mint i)
|
||||
~& nok
|
||||
.*(%jock +.nok)
|
||||
::
|
||||
++ exec-all
|
||||
^- (list ?)
|
||||
=| i=@
|
||||
=/ len (lent list-jocks)
|
||||
=| lis=(list ?)
|
||||
|-
|
||||
?: =(i len)
|
||||
(flop lis)
|
||||
=/ res=(unit *)
|
||||
%- mole
|
||||
|.
|
||||
=/ nok (mint i)
|
||||
.*(%jock +.nok)
|
||||
=. lis
|
||||
[?=(^ res) lis]
|
||||
$(i +(i))
|
||||
--
|
14
hoon/lib/tests/assert.jock
Normal file
14
hoon/lib/tests/assert.jock
Normal file
@ -0,0 +1,14 @@
|
||||
let a: @ = 5;
|
||||
let b: @ = 0;
|
||||
|
||||
assert a != 0;
|
||||
let c = ?([a a]);
|
||||
loop;
|
||||
|
||||
if a == +(b) {
|
||||
b
|
||||
} else {
|
||||
b = +(b);
|
||||
recur
|
||||
}
|
||||
|
5
hoon/lib/tests/axis-call.jock
Normal file
5
hoon/lib/tests/axis-call.jock
Normal file
@ -0,0 +1,5 @@
|
||||
let a: (c: @ -> @) = (b:@ -> @) {
|
||||
+(b)
|
||||
};
|
||||
|
||||
&2(17)
|
10
hoon/lib/tests/baby.jock
Normal file
10
hoon/lib/tests/baby.jock
Normal file
@ -0,0 +1,10 @@
|
||||
compose with 0; object {
|
||||
load = crash
|
||||
peek = crash
|
||||
poke = (a:* -> [* &1]) {
|
||||
[a &1]
|
||||
}
|
||||
wish = crash
|
||||
};
|
||||
|
||||
poke(3)
|
10
hoon/lib/tests/call-let-edit.jock
Normal file
10
hoon/lib/tests/call-let-edit.jock
Normal file
@ -0,0 +1,10 @@
|
||||
let a = (c:@ -> @) {
|
||||
+(c)
|
||||
};
|
||||
|
||||
let b: @ = 42;
|
||||
|
||||
b = a(23);
|
||||
|
||||
b
|
||||
|
6
hoon/lib/tests/call.jock
Normal file
6
hoon/lib/tests/call.jock
Normal file
@ -0,0 +1,6 @@
|
||||
let a: (@ -> @) = (b:@ -> @) {
|
||||
+(b)
|
||||
};
|
||||
|
||||
a(23)
|
||||
|
10
hoon/lib/tests/comparator.jock
Normal file
10
hoon/lib/tests/comparator.jock
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
let a = true;
|
||||
let b = a == true;
|
||||
let c = a < 1;
|
||||
let d = a > 2;
|
||||
let e = b != true;
|
||||
let f = a <= 1;
|
||||
let g = a >= 2;
|
||||
|
||||
g
|
13
hoon/lib/tests/compose-cores.jock
Normal file
13
hoon/lib/tests/compose-cores.jock
Normal file
@ -0,0 +1,13 @@
|
||||
let g = (a:@ -> @) {
|
||||
29
|
||||
};
|
||||
|
||||
compose
|
||||
with this; object {
|
||||
b = (c:@ -> @) {
|
||||
g(5)
|
||||
}
|
||||
c = 89
|
||||
};
|
||||
|
||||
b(3)
|
9
hoon/lib/tests/compose.jock
Normal file
9
hoon/lib/tests/compose.jock
Normal file
@ -0,0 +1,9 @@
|
||||
compose
|
||||
object {
|
||||
b = 5
|
||||
a = (c: @ -> @) {
|
||||
+(c)
|
||||
}
|
||||
};
|
||||
a(b)
|
||||
|
13
hoon/lib/tests/dec.jock
Normal file
13
hoon/lib/tests/dec.jock
Normal file
@ -0,0 +1,13 @@
|
||||
let dec = (a:@ -> @) {
|
||||
let b = 0;
|
||||
loop;
|
||||
if a == +(b) {
|
||||
b
|
||||
} else {
|
||||
b = +(b);
|
||||
recur
|
||||
}
|
||||
};
|
||||
|
||||
dec(5)
|
||||
|
7
hoon/lib/tests/eval.jock
Normal file
7
hoon/lib/tests/eval.jock
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
let a = {
|
||||
eval [42 55] [0 2]
|
||||
};
|
||||
|
||||
a
|
||||
|
7
hoon/lib/tests/if-else.jock
Normal file
7
hoon/lib/tests/if-else.jock
Normal file
@ -0,0 +1,7 @@
|
||||
let a: @ = 3;
|
||||
|
||||
if a == 3 {
|
||||
72
|
||||
} else {
|
||||
17
|
||||
}
|
12
hoon/lib/tests/in-subj-call.jock
Normal file
12
hoon/lib/tests/in-subj-call.jock
Normal file
@ -0,0 +1,12 @@
|
||||
let a = 17;
|
||||
|
||||
let b = ([b:@ c:&1] -> @) {
|
||||
if c == 18 {
|
||||
+(b)
|
||||
} else {
|
||||
b
|
||||
}
|
||||
}([23 &1]);
|
||||
|
||||
&1
|
||||
|
4
hoon/lib/tests/inline-lambda-call.jock
Normal file
4
hoon/lib/tests/inline-lambda-call.jock
Normal file
@ -0,0 +1,4 @@
|
||||
(b:@ -> @) {
|
||||
+(b)
|
||||
}(23)
|
||||
|
4
hoon/lib/tests/inline-lambda-no-arg.jock
Normal file
4
hoon/lib/tests/inline-lambda-no-arg.jock
Normal file
@ -0,0 +1,4 @@
|
||||
(b:@ -> @) {
|
||||
+(b)
|
||||
}()
|
||||
|
10
hoon/lib/tests/inline-point.jock
Normal file
10
hoon/lib/tests/inline-point.jock
Normal file
@ -0,0 +1,10 @@
|
||||
let a: @ = 5;
|
||||
let b: @ = 0;
|
||||
loop;
|
||||
if a == +(b) {
|
||||
b
|
||||
} else {
|
||||
b = +(b);
|
||||
$
|
||||
}
|
||||
|
6
hoon/lib/tests/let-edit.jock
Normal file
6
hoon/lib/tests/let-edit.jock
Normal file
@ -0,0 +1,6 @@
|
||||
let a: ? = true;
|
||||
|
||||
a = false;
|
||||
|
||||
a
|
||||
|
6
hoon/lib/tests/let-inner-exp.jock
Normal file
6
hoon/lib/tests/let-inner-exp.jock
Normal file
@ -0,0 +1,6 @@
|
||||
let a = {
|
||||
let b = 3;
|
||||
3
|
||||
};
|
||||
|
||||
a
|
4
hoon/lib/tests/multi-limb.jock
Normal file
4
hoon/lib/tests/multi-limb.jock
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
let a: [p:@ q:[k:@ v:@]] = [52 30 45];
|
||||
|
||||
v.q.a
|
89
hoon/lib/wrapper.hoon
Normal file
89
hoon/lib/wrapper.hoon
Normal file
@ -0,0 +1,89 @@
|
||||
|%
|
||||
+$ goof [mote=term =tang]
|
||||
+$ wire path
|
||||
+$ ovum [=wire =input]
|
||||
+$ crud [=goof =input]
|
||||
+$ input [eny=@ our=@ux now=@da cause=*]
|
||||
::
|
||||
++ keep
|
||||
|* inner=mold
|
||||
=>
|
||||
|%
|
||||
+$ inner-state inner
|
||||
+$ outer-state [desk-hash=(unit @uvI) internal=inner]
|
||||
+$ outer-fort
|
||||
$_ ^|
|
||||
|_ outer-state
|
||||
++ load
|
||||
|~ arg=*
|
||||
[*(list *) **]
|
||||
++ peek
|
||||
|~ arg=path
|
||||
*(unit (unit *))
|
||||
++ poke
|
||||
|* [num=@ ovum=*]
|
||||
[*(list *) *outer-state]
|
||||
++ wish
|
||||
|~ txt=@
|
||||
**
|
||||
--
|
||||
::
|
||||
+$ fort
|
||||
$_ ^|
|
||||
|_ state=inner-state
|
||||
++ load
|
||||
|~ arg=*
|
||||
[*(list *) **]
|
||||
++ peek
|
||||
|~ arg=path
|
||||
*(unit (unit *))
|
||||
++ poke
|
||||
|~ arg=input
|
||||
[*(list *) *inner-state]
|
||||
--
|
||||
--
|
||||
::
|
||||
|= inner=fort
|
||||
|= hash=@uvI
|
||||
=< .(desk-hash.outer `hash)
|
||||
|_ outer=outer-state
|
||||
++ load
|
||||
|= arg=*
|
||||
^- [(list *) *]
|
||||
(load:inner arg)
|
||||
::
|
||||
++ peek
|
||||
|= arg=path
|
||||
^- (unit (unit *))
|
||||
(peek:inner arg)
|
||||
::
|
||||
++ wish
|
||||
|= txt=@
|
||||
^- *
|
||||
(slap !>(~) (ream txt))
|
||||
::
|
||||
++ poke
|
||||
|= [num=@ ovum=*]
|
||||
^- [(list *) _..poke]
|
||||
?+ ovum ~&("invalid arg: {<ovum>}" ~^..poke)
|
||||
[[%$ %arvo ~] *]
|
||||
=/ g ((soft crud) +.ovum)
|
||||
?~ g ~&(%invalid-goof ~^..poke)
|
||||
=- [~ ..poke]
|
||||
(slog tang.goof.u.g)
|
||||
::
|
||||
[[%poke ~] *]
|
||||
=/ ovum ((soft ^ovum) ovum)
|
||||
?~ ovum ~&("invalid arg: {<ovum>}" ~^..poke)
|
||||
=/ o ((soft input) input.u.ovum)
|
||||
?~ o
|
||||
~& "could not mold poke type: {<ovum>}"
|
||||
=+ (road |.(;;(^^ovum ovum)))
|
||||
~^..poke
|
||||
=^ effects internal.outer
|
||||
(poke:inner input.u.ovum)
|
||||
=. state.inner internal.outer
|
||||
[effects ..poke(internal.outer internal.outer)]
|
||||
==
|
||||
--
|
||||
--
|
44
hoon/main.hoon
Normal file
44
hoon/main.hoon
Normal file
@ -0,0 +1,44 @@
|
||||
/+ *wrapper, test-jock
|
||||
=>
|
||||
|%
|
||||
+$ test-state ~
|
||||
++ moat (keep test-state)
|
||||
+$ cause
|
||||
$% [%test-n n=@]
|
||||
[%test-all ~]
|
||||
==
|
||||
+$ effect ~
|
||||
--
|
||||
%- moat
|
||||
^- fort:moat
|
||||
|_ k=test-state
|
||||
::
|
||||
:: +load: upgrade from previous state
|
||||
::
|
||||
++ load
|
||||
|= arg=*
|
||||
^- [(list *) *]
|
||||
!!
|
||||
::
|
||||
:: +peek: external inspect
|
||||
::
|
||||
++ peek
|
||||
|= =path
|
||||
~
|
||||
::
|
||||
:: +poke: external apply
|
||||
::
|
||||
++ poke
|
||||
|= [eny=@ our=@ux now=@da dat=*]
|
||||
^- [(list effect) test-state]
|
||||
~& "poked at {<now^dat>}"
|
||||
=/ soft-cau ((soft cause) dat)
|
||||
?~ soft-cau
|
||||
~& "could not mold poke type: {<dat>}" !!
|
||||
=/ c=cause u.soft-cau
|
||||
?- -.c
|
||||
%test-n [~ k]
|
||||
%test-all [~ k]
|
||||
==
|
||||
--
|
||||
|
69
main.rs
Normal file
69
main.rs
Normal file
@ -0,0 +1,69 @@
|
||||
use crown::kernel::boot;
|
||||
use crown::kernel::form::Kernel;
|
||||
use crown::utils::make_tas;
|
||||
use crown::Noun;
|
||||
use sword::noun::{D, T};
|
||||
use sword_macros::tas;
|
||||
use tracing::debug;
|
||||
|
||||
use clap::{arg, command, ColorChoice, Parser};
|
||||
static KERNEL_JAM: &[u8] = include_bytes!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/assets/jocktest.jam"
|
||||
));
|
||||
|
||||
use crown::kernel::boot::Cli as BootCli;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(about = "Tests various poke types for the kernel", author = "zorp", version, color = ColorChoice::Auto)]
|
||||
struct TestCli {
|
||||
#[command(flatten)]
|
||||
boot: BootCli,
|
||||
|
||||
#[command(subcommand)]
|
||||
command: Command,
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
enum Command {
|
||||
#[command(about = "Test n with optional override")]
|
||||
TestN {
|
||||
#[arg(help = "The number to test")]
|
||||
n: Option<u64>,
|
||||
},
|
||||
#[command(about = "Test all with optional override")]
|
||||
TestAll {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let cli = TestCli::parse();
|
||||
let mut kernel = boot::setup(KERNEL_JAM, Some(cli.boot), &[])?;
|
||||
|
||||
let poke = match cli.command {
|
||||
Command::TestN { n } => {
|
||||
let n = n.unwrap_or(0); // Default to 0 if not provided
|
||||
create_poke(&mut kernel, &[D(tas!(b"test-n")), D(n)])
|
||||
}
|
||||
Command::TestAll { } => {
|
||||
let tas = make_tas(kernel.serf.stack(), "test-all");
|
||||
create_poke(&mut kernel, &[tas.as_noun(), D(0)])
|
||||
}
|
||||
};
|
||||
|
||||
debug!("Sending poke: {:?}", poke);
|
||||
let poke_result = kernel.poke(poke)?;
|
||||
debug!("Poke response: {:?}", poke_result);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_poke(kernel: &mut Kernel, args: &[Noun]) -> Noun {
|
||||
// error if args is less than 2 elements
|
||||
if args.len() < 2 {
|
||||
panic!("args must have at least 2 elements");
|
||||
}
|
||||
T(kernel.serf.stack(), args)
|
||||
}
|
||||
|
6
rust-toolchain.toml
Normal file
6
rust-toolchain.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[toolchain]
|
||||
# Generally latest stable.
|
||||
# If we need to change to nightly please
|
||||
# note the reason why in this comment.
|
||||
# channel = "1.77.0"
|
||||
channel = "nightly-2024-04-19"
|
Loading…
Reference in New Issue
Block a user