functionalscript 0.0.455 → 0.0.457
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1 -1
- package/com/rust/module.f.cjs +2 -2
- package/com/rust/nanocom/Cargo.toml +1 -1
- package/com/rust/nanocom/src/class.rs +1 -9
- package/com/rust/nanocom/src/cobject.rs +35 -18
- package/com/rust/nanocom/src/lib.rs +8 -2
- package/com/rust/nanocom/src/object.rs +3 -0
- package/com/rust/nanocom/tests/it.rs +12 -12
- package/com/rust/nanocom/tests/itmod.rs +14 -12
- package/com/rust/test.f.cjs +8 -8
- package/com/test/rust/src/lib.rs +1 -1
- package/fsm/README.md +3 -1
- package/package.json +1 -1
package/Cargo.lock
CHANGED
package/com/rust/module.f.cjs
CHANGED
|
@@ -196,7 +196,7 @@ const rust = library => {
|
|
|
196
196
|
const type = virtualFnType(` ${n}`)(p)
|
|
197
197
|
return [
|
|
198
198
|
`${type} {`,
|
|
199
|
-
[`unsafe {
|
|
199
|
+
[`unsafe { nanocom::CObject::from_object_unchecked(this) }.${n}(${call(p)})`],
|
|
200
200
|
'}'
|
|
201
201
|
]
|
|
202
202
|
}
|
|
@@ -231,7 +231,7 @@ const rust = library => {
|
|
|
231
231
|
pub: true,
|
|
232
232
|
type: 'ClassEx',
|
|
233
233
|
content: ['const VMT: Vmt = Vmt {',
|
|
234
|
-
[ 'iunknown: Self
|
|
234
|
+
[ 'iunknown: nanocom::CObject::<Self>::IUNKNOWN,',
|
|
235
235
|
'interface: Interface {',
|
|
236
236
|
mapAssign(e),
|
|
237
237
|
'},',
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
use crate::{
|
|
1
|
+
use crate::{Interface, Vmt};
|
|
2
2
|
|
|
3
3
|
pub trait Class: Sized {
|
|
4
4
|
type Interface: Interface;
|
|
5
5
|
fn static_vmt() -> &'static Vmt<Self::Interface>;
|
|
6
|
-
const IUNKNOWN: IUnknown<Self::Interface> = CObject::<Self>::IUNKNOWN;
|
|
7
|
-
fn cobject_new(self) -> Ref<Self::Interface> {
|
|
8
|
-
CObject::new(self)
|
|
9
|
-
}
|
|
10
|
-
unsafe fn to_cobject(this: &Object<Self::Interface>) -> &CObject<Self> {
|
|
11
|
-
let p = this as *const Object<Self::Interface> as *const CObject<Self>;
|
|
12
|
-
&*p
|
|
13
|
-
}
|
|
14
6
|
}
|
|
@@ -7,33 +7,23 @@ use crate::{hresult::HRESULT, iunknown::IUnknown, Class, Interface, Object, Ref,
|
|
|
7
7
|
|
|
8
8
|
#[repr(C)]
|
|
9
9
|
pub struct CObject<T: Class> {
|
|
10
|
-
|
|
10
|
+
object: Object<T::Interface>,
|
|
11
11
|
counter: AtomicU32,
|
|
12
12
|
pub value: T,
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
impl<T: Class> CObject<T> {
|
|
16
|
-
pub fn new(value: T) -> Ref<T::Interface> {
|
|
17
|
-
let c = CObject {
|
|
18
|
-
vmt: T::static_vmt(),
|
|
19
|
-
counter: Default::default(),
|
|
20
|
-
value,
|
|
21
|
-
};
|
|
22
|
-
let p = Box::into_raw(Box::new(c));
|
|
23
|
-
unsafe { &*p }.to_interface().into()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
pub fn to_interface(&self) -> &Object<T::Interface> {
|
|
27
|
-
let p = self as *const Self as *const Object<T::Interface>;
|
|
28
|
-
unsafe { &*p }
|
|
29
|
-
}
|
|
30
|
-
|
|
31
16
|
pub const IUNKNOWN: IUnknown<T::Interface> = IUnknown {
|
|
32
17
|
QueryInterface: Self::QueryInterface,
|
|
33
18
|
AddRef: Self::AddRef,
|
|
34
19
|
Release: Self::Release,
|
|
35
20
|
};
|
|
36
21
|
|
|
22
|
+
pub unsafe fn from_object_unchecked(this: &Object<T::Interface>) -> &CObject<T> {
|
|
23
|
+
let p = this as *const Object<T::Interface> as *const CObject<T>;
|
|
24
|
+
&*p
|
|
25
|
+
}
|
|
26
|
+
|
|
37
27
|
#[allow(non_snake_case)]
|
|
38
28
|
extern "system" fn QueryInterface(
|
|
39
29
|
this: &Object<T::Interface>,
|
|
@@ -52,7 +42,7 @@ impl<T: Class> CObject<T> {
|
|
|
52
42
|
|
|
53
43
|
#[allow(non_snake_case)]
|
|
54
44
|
extern "system" fn AddRef(this: &Object<T::Interface>) -> u32 {
|
|
55
|
-
unsafe {
|
|
45
|
+
unsafe { Self::from_object_unchecked(this) }
|
|
56
46
|
.counter
|
|
57
47
|
.fetch_add(1, Ordering::Relaxed)
|
|
58
48
|
+ 1
|
|
@@ -60,7 +50,7 @@ impl<T: Class> CObject<T> {
|
|
|
60
50
|
|
|
61
51
|
#[allow(non_snake_case)]
|
|
62
52
|
extern "system" fn Release(this: &Object<T::Interface>) -> u32 {
|
|
63
|
-
let t = unsafe {
|
|
53
|
+
let t = unsafe { Self::from_object_unchecked(this) };
|
|
64
54
|
match t.counter.fetch_sub(1, Ordering::Relaxed) {
|
|
65
55
|
1 => {
|
|
66
56
|
let m = t as *const CObject<T> as *mut CObject<T>;
|
|
@@ -71,3 +61,30 @@ impl<T: Class> CObject<T> {
|
|
|
71
61
|
}
|
|
72
62
|
}
|
|
73
63
|
}
|
|
64
|
+
|
|
65
|
+
pub trait CObjectEx: Class {
|
|
66
|
+
fn to_cobject(self) -> Ref<Self::Interface> {
|
|
67
|
+
let c = CObject {
|
|
68
|
+
object: Object::new(Self::static_vmt()),
|
|
69
|
+
counter: Default::default(),
|
|
70
|
+
value: self,
|
|
71
|
+
};
|
|
72
|
+
let p = Box::into_raw(Box::new(c));
|
|
73
|
+
let o = &unsafe { &*p }.object;
|
|
74
|
+
o.into()
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
impl<T: Class> CObjectEx for T {}
|
|
79
|
+
|
|
80
|
+
impl<'a, T: Class> From<&'a CObject<T>> for &'a Object<T::Interface> {
|
|
81
|
+
fn from(this: &'a CObject<T>) -> Self {
|
|
82
|
+
&this.object
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
impl<T: Class> From<&CObject<T>> for Ref<T::Interface> {
|
|
87
|
+
fn from(this: &CObject<T>) -> Self {
|
|
88
|
+
(&this.object).into()
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -9,6 +9,12 @@ mod r#ref;
|
|
|
9
9
|
mod vmt;
|
|
10
10
|
|
|
11
11
|
pub use crate::{
|
|
12
|
-
class::Class,
|
|
13
|
-
|
|
12
|
+
class::Class,
|
|
13
|
+
cobject::{CObject, CObjectEx},
|
|
14
|
+
guid::GUID,
|
|
15
|
+
interface::Interface,
|
|
16
|
+
iunknown::IUnknown,
|
|
17
|
+
object::Object,
|
|
18
|
+
r#ref::Ref,
|
|
19
|
+
vmt::Vmt,
|
|
14
20
|
};
|
|
@@ -46,10 +46,10 @@ mod library {
|
|
|
46
46
|
CObject<Self>: IMyEx,
|
|
47
47
|
{
|
|
48
48
|
extern "system" fn A(this: &Object<IMy>) -> Ref<IMy> {
|
|
49
|
-
unsafe {
|
|
49
|
+
unsafe { CObject::from_object_unchecked(this) }.A()
|
|
50
50
|
}
|
|
51
51
|
extern "system" fn B(this: &Object<IMy>) -> u32 {
|
|
52
|
-
unsafe {
|
|
52
|
+
unsafe { CObject::from_object_unchecked(this) }.B()
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -68,7 +68,7 @@ mod number {
|
|
|
68
68
|
type Interface = IMy;
|
|
69
69
|
fn static_vmt() -> &'static Vmt<Self::Interface> {
|
|
70
70
|
static V: Vmt<IMy> = Vmt {
|
|
71
|
-
iunknown: X
|
|
71
|
+
iunknown: CObject::<X>::IUNKNOWN,
|
|
72
72
|
interface: X::INTERFACE,
|
|
73
73
|
};
|
|
74
74
|
&V
|
|
@@ -78,7 +78,7 @@ mod number {
|
|
|
78
78
|
#[allow(non_snake_case)]
|
|
79
79
|
impl IMyEx for CObject<X> {
|
|
80
80
|
fn A(&self) -> Ref<IMy> {
|
|
81
|
-
self.
|
|
81
|
+
self.into()
|
|
82
82
|
}
|
|
83
83
|
fn B(&self) -> u32 {
|
|
84
84
|
self.value.0
|
|
@@ -87,17 +87,17 @@ mod number {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
mod use_number {
|
|
90
|
-
use nanocom::Class;
|
|
90
|
+
use nanocom::{CObjectEx, Class};
|
|
91
91
|
|
|
92
92
|
use super::{library::IMyEx, number::X};
|
|
93
93
|
|
|
94
94
|
#[test]
|
|
95
95
|
fn test() {
|
|
96
|
-
let a = X(42).
|
|
96
|
+
let a = X(42).to_cobject();
|
|
97
97
|
let a1 = a.A();
|
|
98
98
|
assert_eq!(a, a1);
|
|
99
99
|
assert_eq!(a.B(), 42);
|
|
100
|
-
let b = X(43).
|
|
100
|
+
let b = X(43).to_cobject();
|
|
101
101
|
assert_ne!(a, b);
|
|
102
102
|
assert_eq!(b.B(), 43);
|
|
103
103
|
}
|
|
@@ -134,7 +134,7 @@ mod destructor {
|
|
|
134
134
|
type Interface = IMy;
|
|
135
135
|
fn static_vmt() -> &'static Vmt<Self::Interface> {
|
|
136
136
|
static V: Vmt<IMy> = Vmt {
|
|
137
|
-
iunknown: X
|
|
137
|
+
iunknown: CObject::<X>::IUNKNOWN,
|
|
138
138
|
interface: X::INTERFACE,
|
|
139
139
|
};
|
|
140
140
|
&V
|
|
@@ -144,7 +144,7 @@ mod destructor {
|
|
|
144
144
|
#[allow(non_snake_case)]
|
|
145
145
|
impl IMyEx for CObject<X> {
|
|
146
146
|
fn A(&self) -> Ref<IMy> {
|
|
147
|
-
self.
|
|
147
|
+
self.into()
|
|
148
148
|
}
|
|
149
149
|
fn B(&self) -> u32 {
|
|
150
150
|
self.value.p.load(Ordering::Relaxed)
|
|
@@ -158,7 +158,7 @@ mod use_destructor {
|
|
|
158
158
|
sync::atomic::{AtomicU32, Ordering},
|
|
159
159
|
};
|
|
160
160
|
|
|
161
|
-
use nanocom::
|
|
161
|
+
use nanocom::CObjectEx;
|
|
162
162
|
|
|
163
163
|
use super::{destructor::X, library::IMyEx};
|
|
164
164
|
|
|
@@ -167,14 +167,14 @@ mod use_destructor {
|
|
|
167
167
|
let p = Rc::new(AtomicU32::default());
|
|
168
168
|
{
|
|
169
169
|
assert_eq!(p.load(Ordering::Relaxed), 0);
|
|
170
|
-
let a = X::new(p.clone()).
|
|
170
|
+
let a = X::new(p.clone()).to_cobject();
|
|
171
171
|
assert_eq!(p.load(Ordering::Relaxed), 1);
|
|
172
172
|
let a1 = a.A();
|
|
173
173
|
assert_eq!(p.load(Ordering::Relaxed), 1);
|
|
174
174
|
assert_eq!(a, a1);
|
|
175
175
|
assert_eq!(a.B(), 1);
|
|
176
176
|
{
|
|
177
|
-
let b = X::new(p.clone()).
|
|
177
|
+
let b = X::new(p.clone()).to_cobject();
|
|
178
178
|
assert_eq!(p.load(Ordering::Relaxed), 2);
|
|
179
179
|
assert_ne!(a, b);
|
|
180
180
|
assert_eq!(b.B(), 2);
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
mod library {
|
|
6
6
|
pub mod IMy {
|
|
7
|
+
use nanocom::CObject;
|
|
8
|
+
|
|
7
9
|
pub type Object = nanocom::Object<Interface>;
|
|
8
10
|
pub type Ref = nanocom::Ref<Interface>;
|
|
9
11
|
pub type Vmt = nanocom::Vmt<Interface>;
|
|
@@ -37,11 +39,11 @@ mod library {
|
|
|
37
39
|
nanocom::CObject<Self>: Ex,
|
|
38
40
|
{
|
|
39
41
|
const VMT: Vmt = Vmt {
|
|
40
|
-
iunknown: Self
|
|
42
|
+
iunknown: CObject::<Self>::IUNKNOWN,
|
|
41
43
|
interface: Interface {
|
|
42
44
|
A: Self::A,
|
|
43
45
|
B: Self::B,
|
|
44
|
-
}
|
|
46
|
+
},
|
|
45
47
|
};
|
|
46
48
|
}
|
|
47
49
|
|
|
@@ -52,10 +54,10 @@ mod library {
|
|
|
52
54
|
nanocom::CObject<Self>: Ex,
|
|
53
55
|
{
|
|
54
56
|
extern "system" fn A(this: &Object) -> Ref {
|
|
55
|
-
unsafe {
|
|
57
|
+
unsafe { CObject::from_object_unchecked(this) }.A()
|
|
56
58
|
}
|
|
57
59
|
extern "system" fn B(this: &Object) -> u32 {
|
|
58
|
-
unsafe {
|
|
60
|
+
unsafe { CObject::from_object_unchecked(this) }.B()
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
|
|
@@ -83,7 +85,7 @@ mod number {
|
|
|
83
85
|
|
|
84
86
|
impl IMy::Ex for CObject<X> {
|
|
85
87
|
fn A(&self) -> IMy::Ref {
|
|
86
|
-
self.
|
|
88
|
+
self.into()
|
|
87
89
|
}
|
|
88
90
|
fn B(&self) -> u32 {
|
|
89
91
|
self.value.0
|
|
@@ -92,7 +94,7 @@ mod number {
|
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
mod use_number {
|
|
95
|
-
use nanocom::
|
|
97
|
+
use nanocom::CObjectEx;
|
|
96
98
|
|
|
97
99
|
use crate::library::IMy::Ex;
|
|
98
100
|
|
|
@@ -100,11 +102,11 @@ mod use_number {
|
|
|
100
102
|
|
|
101
103
|
#[test]
|
|
102
104
|
fn test() {
|
|
103
|
-
let a = X(42).
|
|
105
|
+
let a = X(42).to_cobject();
|
|
104
106
|
let a1 = a.A();
|
|
105
107
|
assert_eq!(a, a1);
|
|
106
108
|
assert_eq!(a.B(), 42);
|
|
107
|
-
let b = X(43).
|
|
109
|
+
let b = X(43).to_cobject();
|
|
108
110
|
assert_ne!(a, b);
|
|
109
111
|
assert_eq!(b.B(), 43);
|
|
110
112
|
}
|
|
@@ -149,7 +151,7 @@ mod destructor {
|
|
|
149
151
|
|
|
150
152
|
impl IMy::Ex for CObject<X> {
|
|
151
153
|
fn A(&self) -> IMy::Ref {
|
|
152
|
-
self.
|
|
154
|
+
self.into()
|
|
153
155
|
}
|
|
154
156
|
fn B(&self) -> u32 {
|
|
155
157
|
self.value.p.load(Ordering::Relaxed)
|
|
@@ -163,7 +165,7 @@ mod use_destructor {
|
|
|
163
165
|
sync::atomic::{AtomicU32, Ordering},
|
|
164
166
|
};
|
|
165
167
|
|
|
166
|
-
use nanocom::
|
|
168
|
+
use nanocom::CObjectEx;
|
|
167
169
|
|
|
168
170
|
use crate::library::IMy::Ex;
|
|
169
171
|
|
|
@@ -174,14 +176,14 @@ mod use_destructor {
|
|
|
174
176
|
let p = Rc::new(AtomicU32::default());
|
|
175
177
|
{
|
|
176
178
|
assert_eq!(p.load(Ordering::Relaxed), 0);
|
|
177
|
-
let a = X::new(p.clone()).
|
|
179
|
+
let a = X::new(p.clone()).to_cobject();
|
|
178
180
|
assert_eq!(p.load(Ordering::Relaxed), 1);
|
|
179
181
|
let a1 = a.A();
|
|
180
182
|
assert_eq!(p.load(Ordering::Relaxed), 1);
|
|
181
183
|
assert_eq!(a, a1);
|
|
182
184
|
assert_eq!(a.B(), 1);
|
|
183
185
|
{
|
|
184
|
-
let b = X::new(p.clone()).
|
|
186
|
+
let b = X::new(p.clone()).to_cobject();
|
|
185
187
|
assert_eq!(p.load(Ordering::Relaxed), 2);
|
|
186
188
|
assert_ne!(a, b);
|
|
187
189
|
assert_eq!(b.B(), 2);
|
package/com/rust/test.f.cjs
CHANGED
|
@@ -67,7 +67,7 @@ module.exports = () => {
|
|
|
67
67
|
' nanocom::CObject<Self>: Ex,\n' +
|
|
68
68
|
' {\n' +
|
|
69
69
|
' const VMT: Vmt = Vmt {\n' +
|
|
70
|
-
' iunknown: Self
|
|
70
|
+
' iunknown: nanocom::CObject::<Self>::IUNKNOWN,\n' +
|
|
71
71
|
' interface: Interface {\n' +
|
|
72
72
|
' GetSlice: Self::GetSlice,\n' +
|
|
73
73
|
' SetSlice: Self::SetSlice,\n' +
|
|
@@ -91,25 +91,25 @@ module.exports = () => {
|
|
|
91
91
|
' nanocom::CObject<Self>: Ex,\n' +
|
|
92
92
|
' {\n' +
|
|
93
93
|
' extern "system" fn GetSlice(this: &Object) -> super::Slice {\n' +
|
|
94
|
-
' unsafe {
|
|
94
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetSlice()\n' +
|
|
95
95
|
' }\n' +
|
|
96
96
|
' extern "system" fn SetSlice(this: &Object, slice: super::Slice) {\n' +
|
|
97
|
-
' unsafe {
|
|
97
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetSlice(slice)\n' +
|
|
98
98
|
' }\n' +
|
|
99
99
|
' extern "system" fn GetUnsafe(this: &Object) -> *const bool {\n' +
|
|
100
|
-
' unsafe {
|
|
100
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetUnsafe()\n' +
|
|
101
101
|
' }\n' +
|
|
102
102
|
' extern "system" fn SetUnsafe(this: &Object, p: *const super::Slice, size: u32) {\n' +
|
|
103
|
-
' unsafe {
|
|
103
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetUnsafe(p, size)\n' +
|
|
104
104
|
' }\n' +
|
|
105
105
|
' extern "system" fn Some(this: &Object, p: &super::IMy::Object) -> bool {\n' +
|
|
106
|
-
' unsafe {
|
|
106
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.Some(p)\n' +
|
|
107
107
|
' }\n' +
|
|
108
108
|
' extern "system" fn GetIMy(this: &Object) -> super::IMy::Ref {\n' +
|
|
109
|
-
' unsafe {
|
|
109
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetIMy()\n' +
|
|
110
110
|
' }\n' +
|
|
111
111
|
' extern "system" fn SetManagedStruct(this: &Object, a: super::ManagedStruct) {\n' +
|
|
112
|
-
' unsafe {
|
|
112
|
+
' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetManagedStruct(a)\n' +
|
|
113
113
|
' }\n' +
|
|
114
114
|
' }\n' +
|
|
115
115
|
' impl<T> PrivateClassEx for T\n' +
|
package/com/test/rust/src/lib.rs
CHANGED
package/fsm/README.md
CHANGED
|
@@ -41,11 +41,13 @@ const dot = byteSet('.')
|
|
|
41
41
|
const grammar = [
|
|
42
42
|
['init', digit, 'int'],
|
|
43
43
|
['int', digit, 'int'],
|
|
44
|
+
//
|
|
44
45
|
['init', digit, 'floatBegin'],
|
|
45
46
|
['floatBegin', digit, 'floatBegin'],
|
|
46
47
|
['floatBegin', dot, 'floatDot'],
|
|
47
48
|
['floatDot', digit, 'float'],
|
|
48
|
-
['float',
|
|
49
|
+
['float', digit, 'float'],
|
|
50
|
+
//
|
|
49
51
|
['init', idBegin, 'id'],
|
|
50
52
|
['id', idNext, 'id'],
|
|
51
53
|
]
|