functionalscript 0.0.426 → 0.0.427

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 CHANGED
@@ -5,3 +5,10 @@ version = 3
5
5
  [[package]]
6
6
  name = "nanocom"
7
7
  version = "0.1.2"
8
+
9
+ [[package]]
10
+ name = "rtest"
11
+ version = "0.1.0"
12
+ dependencies = [
13
+ "nanocom",
14
+ ]
package/Cargo.toml CHANGED
@@ -1,4 +1,5 @@
1
1
  [workspace]
2
2
  members = [
3
- "com/rust/nanocom"
3
+ "com/rust/nanocom",
4
+ "com/rust/rtest"
4
5
  ]
@@ -1,7 +1,7 @@
1
1
  const fs = require('node:fs')
2
2
  const cp = require('node:child_process')
3
3
  const os = require('node:os');
4
- const cpp = require('../testlib.f.cjs').result
4
+ const cpp = require('../test.f.cjs').result
5
5
  const { string: { join }, list: { flat } } = require('../../../types/module.f.cjs')
6
6
 
7
7
  fs.writeFileSync('_result.hpp', cpp)
File without changes
@@ -1,6 +1,6 @@
1
1
  const fs = require('node:fs')
2
2
  const cp = require('node:child_process')
3
- const cs = require('../testlib.f.cjs').result
3
+ const cs = require('../test.f.cjs').result
4
4
 
5
5
  fs.writeFileSync('_result.cs', cs)
6
6
  try {
File without changes
@@ -29,15 +29,23 @@ const self = ['&self']
29
29
  /** @type {(p: types.Field) => string} */
30
30
  const paramName = ([n]) => n
31
31
 
32
+ /** @type {(p: types.FieldArray) => list.Thunk<string>} */
33
+ const callList = p => map(paramName)(paramList(p))
34
+
35
+ /** @type {(p: types.FieldArray) => string} */
36
+ const call = p => commaJoin(callList(p))
37
+
32
38
  /** @type {(p: types.FieldArray) => string} */
33
- const call = p => commaJoin(flat([['self'], map(paramName)(paramList(p))]))
39
+ const virtualCall = p => commaJoin(flat([['self'], callList(p)]))
40
+
41
+ const super_ = 'super::'
34
42
 
35
43
  /** @type {(m: types.Method) => string} */
36
44
  const assign = ([n]) => `${n}: Self::${n},`
37
45
 
38
46
  const mapAssign = map(assign)
39
47
 
40
- const super_ = 'super::'
48
+ const this_ = ['this: &Object']
41
49
 
42
50
  /** @type {(library: types.Library) => text.Block} */
43
51
  const rust = library => {
@@ -78,6 +86,14 @@ const rust = library => {
78
86
  return `(${params})${resultStr}`
79
87
  }
80
88
 
89
+ /** @type {(n: string) => (p: types.FieldArray) => string} */
90
+ const virtualFnType = n => p => `extern "system" fn${n}${func(this_)(p)}`
91
+
92
+ /** @type {(m: types.Method) => string} */
93
+ const virtualFn = ([n, p]) => `${n}: unsafe ${virtualFnType('')(p)}`
94
+
95
+ const mapVirtualFn = map(virtualFn)
96
+
81
97
  /** @type {(m: types.Method) => string} */
82
98
  const headerFn = ([n, p]) => `fn ${n}${func(self)(p)}`
83
99
 
@@ -91,35 +107,38 @@ const rust = library => {
91
107
  const [n, p] = m
92
108
  return [
93
109
  `${headerFn(m)} {`,
94
- [`unsafe { (self.interface().${n})(${call(p)}) }`],
110
+ [`unsafe { (self.interface().${n})(${virtualCall(p)}) }`],
95
111
  '}'
96
112
  ]
97
113
  }
98
114
 
99
115
  const flatMapImplFn = flatMap(implFn)
100
116
 
101
- /** @type {(i: types.Interface) => (name: string) => text.Block} */
102
- const interface_ = ({ interface: i, guid }) => name => {
117
+ /** @type {(m: types.Method) => text.Block} */
118
+ const impl = ([n, p]) => {
119
+ const type = virtualFnType(` ${n}`)(p)
120
+ return [
121
+ `${type} {`,
122
+ [`unsafe { Self::to_cobject(this) }.${n}(${call(p)})`],
123
+ '}'
124
+ ]
125
+ }
103
126
 
104
- const this_ = ['this: &Object']
127
+ const flatMapImpl = flatMap(impl)
105
128
 
106
- /** @type {(m: types.Method) => string} */
107
- const virtualFn = ([n, p]) => `${n}: unsafe extern "system" fn${func(this_)(p)}`
129
+ /** @type {(i: types.Interface) => (name: string) => text.Block} */
130
+ const interface_ = ({ interface: i, guid }) => name => {
108
131
 
109
132
  const e = entries(i)
110
133
 
111
- const nameEx = `${name}Ex`
112
-
113
- const nameVmt = `${name}Vmt`
114
-
115
134
  return [
116
135
  `pub mod ${name} {`,
117
136
  [
118
- 'type Object = nanocom::Object<Interface>;',
119
- 'type Ref = nanocom::Ref<Interface>;',
120
- 'type Vmt = nanocom::Vmt<Interface>;',
137
+ 'pub type Object = nanocom::Object<Interface>;',
138
+ 'pub type Ref = nanocom::Ref<Interface>;',
139
+ 'pub type Vmt = nanocom::Vmt<Interface>;',
121
140
  ],
122
- rustStruct(map(virtualFn)(e))('Interface'),
141
+ rustStruct(mapVirtualFn(e))('Interface'),
123
142
  [ 'impl nanocom::Interface for Interface {',
124
143
  [ `const GUID: nanocom::GUID = 0x${guid.replaceAll('-', '_')};`],
125
144
  '}',
@@ -139,6 +158,13 @@ const rust = library => {
139
158
  ],
140
159
  '}',
141
160
  'impl<T: nanocom::Class<Interface = Interface>> ClassEx for T where nanocom::CObject<T>: Ex {}',
161
+ 'trait PrivateClassEx: nanocom::Class<Interface = Interface>',
162
+ 'where',
163
+ [ 'nanocom::CObject<Self>: Ex'],
164
+ `{`,
165
+ flatMapImpl(e),
166
+ `}`,
167
+ 'impl<T: nanocom::Class<Interface = Interface>> PrivateClassEx for T where nanocom::CObject<T>: Ex {}',
142
168
  ],
143
169
  '}'
144
170
  ]
@@ -3,74 +3,101 @@ const { flat } = require('../../text/module.f.cjs')
3
3
  const { join } = require('../../types/string/module.f.cjs')
4
4
  const library = require('../types/testlib.f.cjs')
5
5
 
6
- module.exports = () => {
7
- const e =
8
- '#![allow(non_snake_case)]\n' +
9
- '#[repr(C)]\n' +
10
- 'pub struct Slice {\n' +
11
- ' pub Start: *const u8,\n' +
12
- ' pub Size: usize,\n' +
13
- ' pub M: IMy::Ref,\n' +
14
- '}\n' +
15
- 'pub mod IMy {\n' +
16
- ' type Object = nanocom::Object<Interface>;\n' +
17
- ' type Ref = nanocom::Ref<Interface>;\n' +
18
- ' type Vmt = nanocom::Vmt<Interface>;\n' +
19
- ' #[repr(C)]\n' +
20
- ' pub struct Interface {\n' +
21
- ' pub GetSlice: unsafe extern "system" fn(this: &Object) -> super::Slice,\n' +
22
- ' pub SetSlice: unsafe extern "system" fn(this: &Object, slice: super::Slice),\n' +
23
- ' pub GetUnsafe: unsafe extern "system" fn(this: &Object) -> *const bool,\n' +
24
- ' pub SetUnsafe: unsafe extern "system" fn(this: &Object, p: *const super::Slice, size: u32),\n' +
25
- ' pub Some: unsafe extern "system" fn(this: &Object, p: &super::IMy::Object) -> bool,\n' +
26
- ' pub GetIMy: unsafe extern "system" fn(this: &Object) -> super::IMy::Ref,\n' +
27
- ' }\n' +
28
- ' impl nanocom::Interface for Interface {\n' +
29
- ' const GUID: nanocom::GUID = 0xC66FB270_2D80_49AD_BB6E_88C1F90B805D;\n' +
30
- ' }\n' +
31
- ' pub trait Ex {\n' +
32
- ' fn GetSlice(&self) -> super::Slice;\n' +
33
- ' fn SetSlice(&self, slice: super::Slice);\n' +
34
- ' fn GetUnsafe(&self) -> *const bool;\n' +
35
- ' fn SetUnsafe(&self, p: *const super::Slice, size: u32);\n' +
36
- ' fn Some(&self, p: &super::IMy::Object) -> bool;\n' +
37
- ' fn GetIMy(&self) -> super::IMy::Ref;\n' +
38
- ' }\n' +
39
- ' impl Ex for Object {\n' +
40
- ' fn GetSlice(&self) -> super::Slice {\n' +
41
- ' unsafe { (self.interface().GetSlice)(self) }\n' +
42
- ' }\n' +
43
- ' fn SetSlice(&self, slice: super::Slice) {\n' +
44
- ' unsafe { (self.interface().SetSlice)(self, slice) }\n' +
45
- ' }\n' +
46
- ' fn GetUnsafe(&self) -> *const bool {\n' +
47
- ' unsafe { (self.interface().GetUnsafe)(self) }\n' +
48
- ' }\n' +
49
- ' fn SetUnsafe(&self, p: *const super::Slice, size: u32) {\n' +
50
- ' unsafe { (self.interface().SetUnsafe)(self, p, size) }\n' +
51
- ' }\n' +
52
- ' fn Some(&self, p: &super::IMy::Object) -> bool {\n' +
53
- ' unsafe { (self.interface().Some)(self, p) }\n' +
54
- ' }\n' +
55
- ' fn GetIMy(&self) -> super::IMy::Ref {\n' +
56
- ' unsafe { (self.interface().GetIMy)(self) }\n' +
57
- ' }\n' +
58
- ' }\n' +
59
- ' pub trait ClassEx: nanocom::Class<Interface = Interface>\n' +
60
- ' where\n' +
61
- ' nanocom::CObject<Self>: Ex,\n' +
62
- ' {\n' +
63
- ' const INTERFACE: Interface = Interface {\n' +
64
- ' GetSlice: Self::GetSlice,\n' +
65
- ' SetSlice: Self::SetSlice,\n' +
66
- ' GetUnsafe: Self::GetUnsafe,\n' +
67
- ' SetUnsafe: Self::SetUnsafe,\n' +
68
- ' Some: Self::Some,\n' +
69
- ' GetIMy: Self::GetIMy,\n' +
70
- ' };\n' +
71
- ' }\n' +
72
- ' impl<T: nanocom::Class<Interface = Interface>> ClassEx for T where nanocom::CObject<T>: Ex {}\n' +
73
- '}'
74
- const r = join('\n')(flat(' ')(rust(library)))
75
- if (r !== e) { throw [e, r] }
76
- }
6
+ module.exports = {
7
+ result: () => {
8
+ const e =
9
+ '#![allow(non_snake_case)]\n' +
10
+ '#[repr(C)]\n' +
11
+ 'pub struct Slice {\n' +
12
+ ' pub Start: *const u8,\n' +
13
+ ' pub Size: usize,\n' +
14
+ ' pub M: IMy::Ref,\n' +
15
+ '}\n' +
16
+ 'pub mod IMy {\n' +
17
+ ' pub type Object = nanocom::Object<Interface>;\n' +
18
+ ' pub type Ref = nanocom::Ref<Interface>;\n' +
19
+ ' pub type Vmt = nanocom::Vmt<Interface>;\n' +
20
+ ' #[repr(C)]\n' +
21
+ ' pub struct Interface {\n' +
22
+ ' pub GetSlice: unsafe extern "system" fn(this: &Object) -> super::Slice,\n' +
23
+ ' pub SetSlice: unsafe extern "system" fn(this: &Object, slice: super::Slice),\n' +
24
+ ' pub GetUnsafe: unsafe extern "system" fn(this: &Object) -> *const bool,\n' +
25
+ ' pub SetUnsafe: unsafe extern "system" fn(this: &Object, p: *const super::Slice, size: u32),\n' +
26
+ ' pub Some: unsafe extern "system" fn(this: &Object, p: &super::IMy::Object) -> bool,\n' +
27
+ ' pub GetIMy: unsafe extern "system" fn(this: &Object) -> super::IMy::Ref,\n' +
28
+ ' }\n' +
29
+ ' impl nanocom::Interface for Interface {\n' +
30
+ ' const GUID: nanocom::GUID = 0xC66FB270_2D80_49AD_BB6E_88C1F90B805D;\n' +
31
+ ' }\n' +
32
+ ' pub trait Ex {\n' +
33
+ ' fn GetSlice(&self) -> super::Slice;\n' +
34
+ ' fn SetSlice(&self, slice: super::Slice);\n' +
35
+ ' fn GetUnsafe(&self) -> *const bool;\n' +
36
+ ' fn SetUnsafe(&self, p: *const super::Slice, size: u32);\n' +
37
+ ' fn Some(&self, p: &super::IMy::Object) -> bool;\n' +
38
+ ' fn GetIMy(&self) -> super::IMy::Ref;\n' +
39
+ ' }\n' +
40
+ ' impl Ex for Object {\n' +
41
+ ' fn GetSlice(&self) -> super::Slice {\n' +
42
+ ' unsafe { (self.interface().GetSlice)(self) }\n' +
43
+ ' }\n' +
44
+ ' fn SetSlice(&self, slice: super::Slice) {\n' +
45
+ ' unsafe { (self.interface().SetSlice)(self, slice) }\n' +
46
+ ' }\n' +
47
+ ' fn GetUnsafe(&self) -> *const bool {\n' +
48
+ ' unsafe { (self.interface().GetUnsafe)(self) }\n' +
49
+ ' }\n' +
50
+ ' fn SetUnsafe(&self, p: *const super::Slice, size: u32) {\n' +
51
+ ' unsafe { (self.interface().SetUnsafe)(self, p, size) }\n' +
52
+ ' }\n' +
53
+ ' fn Some(&self, p: &super::IMy::Object) -> bool {\n' +
54
+ ' unsafe { (self.interface().Some)(self, p) }\n' +
55
+ ' }\n' +
56
+ ' fn GetIMy(&self) -> super::IMy::Ref {\n' +
57
+ ' unsafe { (self.interface().GetIMy)(self) }\n' +
58
+ ' }\n' +
59
+ ' }\n' +
60
+ ' pub trait ClassEx: nanocom::Class<Interface = Interface>\n' +
61
+ ' where\n' +
62
+ ' nanocom::CObject<Self>: Ex,\n' +
63
+ ' {\n' +
64
+ ' const INTERFACE: Interface = Interface {\n' +
65
+ ' GetSlice: Self::GetSlice,\n' +
66
+ ' SetSlice: Self::SetSlice,\n' +
67
+ ' GetUnsafe: Self::GetUnsafe,\n' +
68
+ ' SetUnsafe: Self::SetUnsafe,\n' +
69
+ ' Some: Self::Some,\n' +
70
+ ' GetIMy: Self::GetIMy,\n' +
71
+ ' };\n' +
72
+ ' }\n' +
73
+ ' impl<T: nanocom::Class<Interface = Interface>> ClassEx for T where nanocom::CObject<T>: Ex {}\n' +
74
+ ' trait PrivateClassEx: nanocom::Class<Interface = Interface>\n' +
75
+ ' where\n' +
76
+ ' nanocom::CObject<Self>: Ex\n' +
77
+ ' {\n' +
78
+ ' extern "system" fn GetSlice(this: &Object) -> super::Slice {\n' +
79
+ ' unsafe { Self::to_cobject(this) }.GetSlice()\n' +
80
+ ' }\n' +
81
+ ' extern "system" fn SetSlice(this: &Object, slice: super::Slice) {\n' +
82
+ ' unsafe { Self::to_cobject(this) }.SetSlice(slice)\n' +
83
+ ' }\n' +
84
+ ' extern "system" fn GetUnsafe(this: &Object) -> *const bool {\n' +
85
+ ' unsafe { Self::to_cobject(this) }.GetUnsafe()\n' +
86
+ ' }\n' +
87
+ ' extern "system" fn SetUnsafe(this: &Object, p: *const super::Slice, size: u32) {\n' +
88
+ ' unsafe { Self::to_cobject(this) }.SetUnsafe(p, size)\n' +
89
+ ' }\n' +
90
+ ' extern "system" fn Some(this: &Object, p: &super::IMy::Object) -> bool {\n' +
91
+ ' unsafe { Self::to_cobject(this) }.Some(p)\n' +
92
+ ' }\n' +
93
+ ' extern "system" fn GetIMy(this: &Object) -> super::IMy::Ref {\n' +
94
+ ' unsafe { Self::to_cobject(this) }.GetIMy()\n' +
95
+ ' }\n' +
96
+ ' }\n' +
97
+ ' impl<T: nanocom::Class<Interface = Interface>> PrivateClassEx for T where nanocom::CObject<T>: Ex {}\n' +
98
+ '}'
99
+ const r = join('\n')(flat(' ')(rust(library)))
100
+ if (r !== e) { throw [e, r] }
101
+ return r
102
+ }
103
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.426",
3
+ "version": "0.0.427",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
package/test.mjs CHANGED
@@ -65,7 +65,7 @@ const load = async () => {
65
65
  await f(file)
66
66
  }
67
67
  } else if (name.endsWith('.f.cjs')) {
68
- console.log(`loading ${file}`)
68
+ // console.log(`loading ${file}`)
69
69
  const source = await readFile(file, 'utf8')
70
70
  map.push([file, Function('module', 'require', `"use strict";${source}`)])
71
71
  }
@@ -107,7 +107,7 @@ const build = async () => {
107
107
  const module = {
108
108
  dependencies: {}
109
109
  }
110
- console.log(`${i}building ${pathStr}`)
110
+ // console.log(`${i}building ${pathStr}`)
111
111
  const getModule = req(newBase)(`${i}| `)
112
112
  const newReq = s => {
113
113
  const [p, result] = getModule(s)
@@ -130,10 +130,12 @@ const modules = await build()
130
130
 
131
131
  // graph
132
132
 
133
+ /*
133
134
  for (const [k, v] of Object.entries(modules)) {
134
135
  console.log(`: ${k}`)
135
136
  console.log(Object.keys(v.dependencies))
136
137
  }
138
+ */
137
139
 
138
140
  // test runner.
139
141