Skip to content

Commit 16dbcbd

Browse files
committed
centralize literals
1 parent fbe3659 commit 16dbcbd

16 files changed

Lines changed: 362 additions & 112 deletions

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ especially the [Rust flavour](https://doc.rust-lang.org/cargo/reference/semver.h
1616

1717
### Removed
1818

19+
## [0.1.1] - 2025-07-29
20+
21+
### Added
22+
- Usage eample in README
23+
- build profiles
24+
25+
### Changed
26+
- centralized literales
27+
- updated dependencies
28+
29+
### Fixed
30+
- links to documentation
31+
1932
## [0.1.0] - 2025-07-19
2033

2134
Version 0.1.0 focussed on implementation of the core language.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
[package]
44
name = "tinyscript"
5-
version = "0.1.0"
5+
version = "0.1.1"
66
authors = ["stepkun <stephan.kunz@kabelbw.de>"]
77
license = "MIT OR Apache-2.0"
88
description = "Tiny, C-like scripting language"
99
edition = "2024"
1010
rust-version = "1.86.0"
1111
repository = "https://github.com/stepkun/tinyscript"
12-
documentation = "https://docs.rs/tinyscript/latest/tinyscript/"
12+
documentation = "https://docs.rs/tinyscript"
1313
readme = "README.md"
1414
exclude = [
1515
"benches/**",
@@ -47,7 +47,7 @@ harness = false
4747
workspace = true
4848

4949
[dependencies]
50-
tinyscript-derive = { path = "derive", version = "0.1.0"}
50+
tinyscript-derive = { path = "derive", version = "0.1.1"}
5151
parking_lot = "0.12.4"
5252
thiserror = "2.0.12"
5353

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
__tinyscript__ is considered to ba a superset of the scripting language
44
defined in [BehviorTree.CPP](https://www.behaviortree.dev/docs/guides/scripting).
55

6+
## Usage
7+
8+
```rust
9+
use tinyscript::{Runtime, DefaultEnvironment};
10+
11+
fn main() -> Result<(), Box<dyn std::error::Error>> {
12+
let mut runtime = Runtime::default();
13+
let mut env = DefaultEnvironment::default();
14+
let value = runtime.run("2 * 2 == 4", &mut env)?;
15+
Ok(())
16+
}
17+
```
18+
619
## License
720

821
Licensed under either of

benches/comparison.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use std::time::Duration;
77

88
use criterion::{Criterion, criterion_group, criterion_main};
9-
use tinyscript::{DefaultEnvironment, Runtime};
9+
use tinyscript::{DefaultEnvironment, Runtime, SHOULD_NOT_HAPPEN};
1010

1111
const SAMPLES: usize = 100;
1212
const ITERATIONS: usize = 100;
@@ -21,35 +21,35 @@ fn comparison(c: &mut Criterion) {
2121

2222
let chunk = runtime
2323
.parse("1<1; 3.1475<4.99999; -3.00987654321234>-3.00987654321234; 4>3.00987654321234;")
24-
.expect("snh");
24+
.expect(SHOULD_NOT_HAPPEN);
2525
group.bench_function("double", |b| {
2626
b.iter(|| {
2727
for _ in 1..=ITERATIONS {
28-
runtime.execute(&chunk, &mut env).expect("snh");
28+
runtime.execute(&chunk, &mut env).expect(SHOULD_NOT_HAPPEN);
2929
}
3030
std::hint::black_box(());
3131
});
3232
});
3333

3434
let chunk = runtime
3535
.parse("0x1<0x1; 0x1<0x2; 0x1>0x1; 0x2>0x1;")
36-
.expect("snh");
36+
.expect(SHOULD_NOT_HAPPEN);
3737
group.bench_function("integer", |b| {
3838
b.iter(|| {
3939
for _ in 1..=ITERATIONS {
40-
runtime.execute(&chunk, &mut env).expect("snh");
40+
runtime.execute(&chunk, &mut env).expect(SHOULD_NOT_HAPPEN);
4141
}
4242
std::hint::black_box(());
4343
});
4444
});
4545

4646
let chunk = runtime
4747
.parse("0x1<0x1; 3.1475<4.99999; 4>3.00987654321234; 0x2>1;")
48-
.expect("snh");
48+
.expect(SHOULD_NOT_HAPPEN);
4949
group.bench_function("mixed", |b| {
5050
b.iter(|| {
5151
for _ in 1..=ITERATIONS {
52-
runtime.execute(&chunk, &mut env).expect("snh");
52+
runtime.execute(&chunk, &mut env).expect(SHOULD_NOT_HAPPEN);
5353
}
5454
std::hint::black_box(());
5555
});

benches/equality.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use std::time::Duration;
77

88
use criterion::{Criterion, criterion_group, criterion_main};
9-
use tinyscript::{DefaultEnvironment, Runtime};
9+
use tinyscript::{DefaultEnvironment, Runtime, SHOULD_NOT_HAPPEN};
1010

1111
const SAMPLES: usize = 100;
1212
const ITERATIONS: usize = 100;
@@ -21,57 +21,57 @@ fn equality(c: &mut Criterion) {
2121

2222
let chunk = runtime
2323
.parse("true==true; true==false; false==true; false==false;")
24-
.expect("snh");
24+
.expect(SHOULD_NOT_HAPPEN);
2525
group.bench_function("boolean", |b| {
2626
b.iter(|| {
2727
for _ in 1..=ITERATIONS {
28-
runtime.execute(&chunk, &mut env).expect("snh");
28+
runtime.execute(&chunk, &mut env).expect(SHOULD_NOT_HAPPEN);
2929
}
3030
std::hint::black_box(());
3131
});
3232
});
3333

3434
let chunk = runtime
3535
.parse("1==1; 3.1475==4.99999; -3.00987654321234==-3.00987654321234; 3.00987654321234==4;")
36-
.expect("snh");
36+
.expect(SHOULD_NOT_HAPPEN);
3737
group.bench_function("double", |b| {
3838
b.iter(|| {
3939
for _ in 1..=ITERATIONS {
40-
runtime.execute(&chunk, &mut env).expect("snh");
40+
runtime.execute(&chunk, &mut env).expect(SHOULD_NOT_HAPPEN);
4141
}
4242
std::hint::black_box(());
4343
});
4444
});
4545

4646
let chunk = runtime
4747
.parse("0x1==0x1; 0xFF321==0x56adf; -0x34==-0x34; 0xabcdef==0x1;")
48-
.expect("snh");
48+
.expect(SHOULD_NOT_HAPPEN);
4949
group.bench_function("integer", |b| {
5050
b.iter(|| {
5151
for _ in 1..=ITERATIONS {
52-
runtime.execute(&chunk, &mut env).expect("snh");
52+
runtime.execute(&chunk, &mut env).expect(SHOULD_NOT_HAPPEN);
5353
}
5454
std::hint::black_box(());
5555
});
5656
});
5757

58-
let chunk = runtime.parse("'short'=='short'; 'short'=='sho'; 'medium'=='this is a little bit longer'; 'this is a little bit longer'=='this is a little bit longer';").expect("snh");
58+
let chunk = runtime.parse("'short'=='short'; 'short'=='sho'; 'medium'=='this is a little bit longer'; 'this is a little bit longer'=='this is a little bit longer';").expect(SHOULD_NOT_HAPPEN);
5959
group.bench_function("string", |b| {
6060
b.iter(|| {
6161
for _ in 1..=ITERATIONS {
62-
runtime.execute(&chunk, &mut env).expect("snh");
62+
runtime.execute(&chunk, &mut env).expect(SHOULD_NOT_HAPPEN);
6363
}
6464
std::hint::black_box(());
6565
});
6666
});
6767

6868
let chunk = runtime
6969
.parse("'short'==true; 'short'==1; 'medium'==nil; 'this is a little bit longer'==0x15;")
70-
.expect("snh");
70+
.expect(SHOULD_NOT_HAPPEN);
7171
group.bench_function("mixed", |b| {
7272
b.iter(|| {
7373
for _ in 1..=ITERATIONS {
74-
runtime.execute(&chunk, &mut env).expect("snh");
74+
runtime.execute(&chunk, &mut env).expect(SHOULD_NOT_HAPPEN);
7575
}
7676
std::hint::black_box(());
7777
});

benches/expression.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use std::time::Duration;
77

88
use criterion::{Criterion, criterion_group, criterion_main};
9-
use tinyscript::{DefaultEnvironment, Runtime};
9+
use tinyscript::{DefaultEnvironment, Runtime, SHOULD_NOT_HAPPEN};
1010

1111
const SAMPLES: usize = 100;
1212
const ITERATIONS: usize = 100;
@@ -19,31 +19,37 @@ fn expression(c: &mut Criterion) {
1919
let mut env = DefaultEnvironment::default();
2020
let mut runtime = Runtime::default();
2121

22-
let chunk = runtime.parse("(3 + 2) * (4 - 1);").expect("snh");
22+
let chunk = runtime
23+
.parse("(3 + 2) * (4 - 1);")
24+
.expect(SHOULD_NOT_HAPPEN);
2325
group.bench_function("simple", |b| {
2426
b.iter(|| {
2527
for _ in 1..=ITERATIONS {
26-
runtime.execute(&chunk, &mut env).expect("snh");
28+
runtime.execute(&chunk, &mut env).expect(SHOULD_NOT_HAPPEN);
2729
}
2830
std::hint::black_box(());
2931
});
3032
});
3133

32-
let chunk = runtime.parse("!(5 - 4 > 3 * 2 == !nil);").expect("snh");
34+
let chunk = runtime
35+
.parse("!(5 - 4 > 3 * 2 == !nil);")
36+
.expect(SHOULD_NOT_HAPPEN);
3337
group.bench_function("moderate", |b| {
3438
b.iter(|| {
3539
for _ in 1..=ITERATIONS {
36-
runtime.execute(&chunk, &mut env).expect("snh");
40+
runtime.execute(&chunk, &mut env).expect(SHOULD_NOT_HAPPEN);
3741
}
3842
std::hint::black_box(());
3943
});
4044
});
4145

42-
let chunk = runtime.parse("'this is a ' + 'test string';").expect("snh");
46+
let chunk = runtime
47+
.parse("'this is a ' + 'test string';")
48+
.expect(SHOULD_NOT_HAPPEN);
4349
group.bench_function("strings", |b| {
4450
b.iter(|| {
4551
for _ in 1..=ITERATIONS {
46-
runtime.execute(&chunk, &mut env).expect("snh");
52+
runtime.execute(&chunk, &mut env).expect(SHOULD_NOT_HAPPEN);
4753
}
4854
std::hint::black_box(());
4955
});

derive/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
[package]
44
name = "tinyscript-derive"
5-
version = "0.1.0"
5+
version = "0.1.1"
66
authors = ["stepkun <stephan.kunz@kabelbw.de>"]
77
license = "MIT OR Apache-2.0"
88
edition = "2024"
99
rust-version = "1.86.0"
1010
description = "Procedural macros for tinyscript"
11-
documentation = "https://docs.rs/tinyscript-derive/latest/tinyscript-derive/"
11+
documentation = "https://docs.rs/tinyscript-derive"
1212
repository = "https://github.com/stepkun/tinyscript"
1313
readme = "../README.md"
1414
exclude = [

derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn derive_scripting_enum(input: &DeriveInput) -> TokenStream {
108108
///
109109
/// # Panics
110110
/// - if used on structs or unions
111-
#[proc_macro_derive(ScriptEnum, attributes(tinyscript))]
111+
#[proc_macro_derive(ScriptEnum, attributes(tscript))]
112112
pub fn derive_script_enum(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
113113
// Construct a representation of Rust code as a syntax tree
114114
let input: DeriveInput = syn::parse(input).expect("could not parse input");

src/execution/chunk.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,20 @@ impl Chunk {
152152
/// constant instruction
153153
#[cfg(feature = "std")]
154154
fn jump_instruction(&self, name: &str, offset: usize) -> usize {
155-
let target = (usize::from(self.code.get(offset + 1).expect("snh").to_owned()) << 8)
156-
+ usize::from(self.code.get(offset + 2).expect("snh").to_owned());
155+
use crate::SHOULD_NOT_HAPPEN;
156+
157+
let target = (usize::from(
158+
self.code
159+
.get(offset + 1)
160+
.expect(SHOULD_NOT_HAPPEN)
161+
.to_owned(),
162+
) << 8)
163+
+ usize::from(
164+
self.code
165+
.get(offset + 2)
166+
.expect(SHOULD_NOT_HAPPEN)
167+
.to_owned(),
168+
);
157169

158170
std::println!("{name:16} {offset:05} {target:05}");
159171
offset + 3

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ use execution::ScriptingValue;
3232
use parking_lot::RwLock;
3333
// endregion: --- modules
3434

35+
/// Global constant for expect statements that should never happen
36+
pub const SHOULD_NOT_HAPPEN: &str = "should not happen";
37+
3538
// region --- types
3639
/// An immutable thread safe `String` type
3740
/// see: [Logan Smith](https://www.youtube.com/watch?v=A4cKi7PTJSs).

0 commit comments

Comments
 (0)