goscript 0.0.51 → 0.0.53
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/compiler/analysis.go +633 -340
- package/compiler/compiler.go +35 -6
- package/compiler/expr-call-async.go +82 -209
- package/compiler/expr.go +0 -44
- package/compiler/stmt-assign.go +0 -6
- package/compiler/stmt-select.go +5 -5
- package/compiler/type-assert.go +6 -6
- package/dist/gs/builtin/builtin.d.ts +0 -1
- package/dist/gs/builtin/builtin.js +0 -9
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/channel.d.ts +3 -1
- package/dist/gs/builtin/channel.js +2 -10
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/context/context.js +2 -2
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/reflect/index.d.ts +8 -8
- package/dist/gs/reflect/index.js +6 -6
- package/dist/gs/reflect/index.js.map +1 -1
- package/dist/gs/reflect/iter.d.ts +1 -1
- package/dist/gs/reflect/iter.js +1 -1
- package/dist/gs/reflect/iter.js.map +1 -1
- package/dist/gs/reflect/swapper.d.ts +1 -1
- package/dist/gs/reflect/value.d.ts +1 -2
- package/dist/gs/reflect/value.js +1 -3
- package/dist/gs/reflect/value.js.map +1 -1
- package/dist/gs/runtime/runtime.d.ts +1 -1
- package/dist/gs/runtime/runtime.js +1 -1
- package/dist/gs/sort/index.d.ts +4 -4
- package/dist/gs/sort/index.js +3 -3
- package/dist/gs/sort/index.js.map +1 -1
- package/dist/gs/strings/index.js +0 -1
- package/dist/gs/strings/index.js.map +1 -1
- package/dist/gs/time/time.d.ts +2 -2
- package/dist/gs/time/time.js +12 -9
- package/dist/gs/time/time.js.map +1 -1
- package/go.mod +4 -4
- package/go.sum +6 -6
- package/gs/builtin/builtin.ts +0 -11
- package/gs/builtin/channel.ts +23 -7
- package/gs/context/context.ts +6 -2
- package/gs/context/meta.json +16 -0
- package/gs/reflect/index.ts +8 -8
- package/gs/reflect/iter.ts +1 -11
- package/gs/reflect/swapper.ts +1 -1
- package/gs/reflect/value.ts +1 -4
- package/gs/runtime/runtime.ts +1 -1
- package/gs/sort/index.ts +4 -4
- package/gs/strings/index.ts +0 -1
- package/gs/syscall/constants.ts +1 -1
- package/gs/syscall/env.ts +1 -1
- package/gs/syscall/errors.ts +1 -1
- package/gs/syscall/fs.ts +1 -1
- package/gs/syscall/rawconn.ts +1 -1
- package/gs/syscall/types.ts +1 -1
- package/gs/time/meta.json +6 -0
- package/gs/time/time.ts +16 -13
- package/gs/unicode/meta.json +24 -0
- package/package.json +1 -1
- package/gs/unicode/unicode.go +0 -38
package/gs/builtin/channel.ts
CHANGED
|
@@ -99,7 +99,7 @@ export interface SelectCase<T> {
|
|
|
99
99
|
* @param hasDefault Whether there is a default case
|
|
100
100
|
* @returns A promise that resolves with the result of the selected case
|
|
101
101
|
*/
|
|
102
|
-
export async function selectStatement<T, V=void>(
|
|
102
|
+
export async function selectStatement<T, V = void>(
|
|
103
103
|
cases: SelectCase<T>[],
|
|
104
104
|
hasDefault: boolean = false,
|
|
105
105
|
): Promise<[boolean, V]> {
|
|
@@ -143,7 +143,9 @@ export async function selectStatement<T, V=void>(
|
|
|
143
143
|
selectedCase.id,
|
|
144
144
|
)
|
|
145
145
|
if (selectedCase.onSelected) {
|
|
146
|
-
const handlerResult = await selectedCase.onSelected(
|
|
146
|
+
const handlerResult = await selectedCase.onSelected(
|
|
147
|
+
result as SelectResult<T>,
|
|
148
|
+
)
|
|
147
149
|
return [handlerResult !== undefined, handlerResult as V]
|
|
148
150
|
}
|
|
149
151
|
} else {
|
|
@@ -265,18 +267,32 @@ export async function chanRecvWithOk<T>(
|
|
|
265
267
|
* @param direction Optional direction for the channel. Default is 'both' (bidirectional).
|
|
266
268
|
* @returns A new channel instance or channel reference.
|
|
267
269
|
*/
|
|
268
|
-
export
|
|
270
|
+
export function makeChannel<T>(
|
|
271
|
+
bufferSize: number,
|
|
272
|
+
zeroValue: T,
|
|
273
|
+
direction: 'send',
|
|
274
|
+
): SendOnlyChannelRef<T>
|
|
275
|
+
export function makeChannel<T>(
|
|
276
|
+
bufferSize: number,
|
|
277
|
+
zeroValue: T,
|
|
278
|
+
direction: 'receive',
|
|
279
|
+
): ReceiveOnlyChannelRef<T>
|
|
280
|
+
export function makeChannel<T>(
|
|
281
|
+
bufferSize: number,
|
|
282
|
+
zeroValue: T,
|
|
283
|
+
direction?: 'both',
|
|
284
|
+
): Channel<T>
|
|
285
|
+
export function makeChannel<T>(
|
|
269
286
|
bufferSize: number,
|
|
270
287
|
zeroValue: T,
|
|
271
288
|
direction: 'send' | 'receive' | 'both' = 'both',
|
|
272
|
-
): Channel<T> | ChannelRef<T>
|
|
289
|
+
): Channel<T> | ChannelRef<T> {
|
|
273
290
|
const channel = new BufferedChannel<T>(bufferSize, zeroValue)
|
|
274
291
|
|
|
275
|
-
// Wrap the channel with the appropriate ChannelRef based on direction
|
|
276
292
|
if (direction === 'send') {
|
|
277
|
-
return new SendOnlyChannelRef<T>(channel)
|
|
293
|
+
return new SendOnlyChannelRef<T>(channel)
|
|
278
294
|
} else if (direction === 'receive') {
|
|
279
|
-
return new ReceiveOnlyChannelRef<T>(channel)
|
|
295
|
+
return new ReceiveOnlyChannelRef<T>(channel)
|
|
280
296
|
} else {
|
|
281
297
|
return channel
|
|
282
298
|
}
|
package/gs/context/context.ts
CHANGED
|
@@ -343,7 +343,7 @@ export function WithTimeout(
|
|
|
343
343
|
parent: Context,
|
|
344
344
|
timeout: number,
|
|
345
345
|
): [ContextNonNil, CancelFunc] {
|
|
346
|
-
return WithDeadline(parent, new Date(Date.now() + timeout))
|
|
346
|
+
return WithDeadline(parent, new Date(Date.now() + timeout / 1000000))
|
|
347
347
|
}
|
|
348
348
|
|
|
349
349
|
// WithTimeoutCause is like WithTimeout but also sets the cause
|
|
@@ -352,7 +352,11 @@ export function WithTimeoutCause(
|
|
|
352
352
|
timeout: number,
|
|
353
353
|
cause: $.GoError,
|
|
354
354
|
): [ContextNonNil, CancelFunc] {
|
|
355
|
-
return WithDeadlineCause(
|
|
355
|
+
return WithDeadlineCause(
|
|
356
|
+
parent,
|
|
357
|
+
new Date(Date.now() + timeout / 1000000),
|
|
358
|
+
cause,
|
|
359
|
+
)
|
|
356
360
|
}
|
|
357
361
|
|
|
358
362
|
// WithValue returns a copy of parent with the value associated with key
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"asyncMethods": {
|
|
3
|
+
"Background": false,
|
|
4
|
+
"TODO": false,
|
|
5
|
+
"WithCancel": false,
|
|
6
|
+
"WithCancelCause": false,
|
|
7
|
+
"WithDeadline": false,
|
|
8
|
+
"WithDeadlineCause": false,
|
|
9
|
+
"WithTimeout": false,
|
|
10
|
+
"WithTimeoutCause": false,
|
|
11
|
+
"WithValue": false,
|
|
12
|
+
"WithoutCancel": false,
|
|
13
|
+
"Cause": false,
|
|
14
|
+
"AfterFunc": false
|
|
15
|
+
}
|
|
16
|
+
}
|
package/gs/reflect/index.ts
CHANGED
|
@@ -14,9 +14,9 @@ export {
|
|
|
14
14
|
RecvDir,
|
|
15
15
|
SendDir,
|
|
16
16
|
BothDir,
|
|
17
|
-
} from './type'
|
|
18
|
-
export type { Type, ChanDir, Kind } from './type'
|
|
19
|
-
export { DeepEqual } from './deepequal'
|
|
17
|
+
} from './type.js'
|
|
18
|
+
export type { Type, ChanDir, Kind } from './type.js'
|
|
19
|
+
export { DeepEqual } from './deepequal.js'
|
|
20
20
|
export {
|
|
21
21
|
Zero,
|
|
22
22
|
Copy,
|
|
@@ -27,8 +27,8 @@ export {
|
|
|
27
27
|
Append,
|
|
28
28
|
MakeChan,
|
|
29
29
|
Select,
|
|
30
|
-
} from './value'
|
|
31
|
-
export { Swapper } from './swapper'
|
|
30
|
+
} from './value.js'
|
|
31
|
+
export { Swapper } from './swapper.js'
|
|
32
32
|
|
|
33
33
|
// Export new types and constants
|
|
34
34
|
export {
|
|
@@ -39,7 +39,7 @@ export {
|
|
|
39
39
|
SelectRecv,
|
|
40
40
|
SelectDefault,
|
|
41
41
|
bitVector,
|
|
42
|
-
} from './types'
|
|
42
|
+
} from './types.js'
|
|
43
43
|
export type {
|
|
44
44
|
uintptr,
|
|
45
45
|
Pointer,
|
|
@@ -49,7 +49,7 @@ export type {
|
|
|
49
49
|
SliceHeader,
|
|
50
50
|
StringHeader,
|
|
51
51
|
MapIter,
|
|
52
|
-
} from './types'
|
|
52
|
+
} from './types.js'
|
|
53
53
|
|
|
54
54
|
// Export kind constants
|
|
55
55
|
export {
|
|
@@ -80,4 +80,4 @@ export {
|
|
|
80
80
|
String,
|
|
81
81
|
Struct,
|
|
82
82
|
UnsafePointer,
|
|
83
|
-
} from './type'
|
|
83
|
+
} from './type.js'
|
package/gs/reflect/iter.ts
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import { Type, Value } from './type.js'
|
|
1
|
+
import { Type, Value, ValueOf } from './type.js'
|
|
2
2
|
import { uintptr } from './types.js'
|
|
3
|
-
import { ValueOf } from './value.js'
|
|
4
3
|
|
|
5
4
|
import * as iter from '@goscript/iter/index.js'
|
|
6
5
|
|
|
7
6
|
export function rangeNum<
|
|
8
7
|
T extends
|
|
9
|
-
| number
|
|
10
|
-
| number
|
|
11
|
-
| number
|
|
12
|
-
| number
|
|
13
|
-
| number
|
|
14
|
-
| number
|
|
15
|
-
| number
|
|
16
|
-
| number
|
|
17
|
-
| number
|
|
18
8
|
| number
|
|
19
9
|
| uintptr,
|
|
20
10
|
N extends number | number,
|
package/gs/reflect/swapper.ts
CHANGED
package/gs/reflect/value.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
1
2
|
import {
|
|
2
3
|
Array,
|
|
3
4
|
Bool,
|
|
@@ -26,16 +27,12 @@ import {
|
|
|
26
27
|
Invalid,
|
|
27
28
|
} from './type.js'
|
|
28
29
|
import { ReflectValue, SelectCase, SelectRecv, SelectDefault } from './types.js'
|
|
29
|
-
import * as $ from '@goscript/builtin/index.js'
|
|
30
30
|
|
|
31
31
|
interface ChannelObject {
|
|
32
32
|
_sendQueue?: unknown[]
|
|
33
33
|
send?: (value: unknown) => void
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
// Re-export ValueOf from type.ts for compatibility
|
|
37
|
-
export { ValueOf } from './type'
|
|
38
|
-
|
|
39
36
|
// Zero returns a Value representing the zero value for the specified type.
|
|
40
37
|
export function Zero(typ: Type): Value {
|
|
41
38
|
let zeroValue: ReflectValue
|
package/gs/runtime/runtime.ts
CHANGED
package/gs/sort/index.ts
CHANGED
|
@@ -4,8 +4,8 @@ export {
|
|
|
4
4
|
SearchFloat64s,
|
|
5
5
|
SearchInts,
|
|
6
6
|
SearchStrings,
|
|
7
|
-
} from './search.gs'
|
|
8
|
-
export { Slice, SliceIsSorted, SliceStable } from './slice.gs'
|
|
7
|
+
} from './search.gs.js'
|
|
8
|
+
export { Slice, SliceIsSorted, SliceStable } from './slice.gs.js'
|
|
9
9
|
export {
|
|
10
10
|
Float64Slice,
|
|
11
11
|
Float64s,
|
|
@@ -20,5 +20,5 @@ export {
|
|
|
20
20
|
StringSlice,
|
|
21
21
|
Strings,
|
|
22
22
|
StringsAreSorted,
|
|
23
|
-
} from './sort.gs'
|
|
24
|
-
export type { Interface } from './sort.gs'
|
|
23
|
+
} from './sort.gs.js'
|
|
24
|
+
export type { Interface } from './sort.gs.js'
|
package/gs/strings/index.ts
CHANGED
package/gs/syscall/constants.ts
CHANGED
package/gs/syscall/env.ts
CHANGED
package/gs/syscall/errors.ts
CHANGED
package/gs/syscall/fs.ts
CHANGED
package/gs/syscall/rawconn.ts
CHANGED
package/gs/syscall/types.ts
CHANGED
package/gs/time/time.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { makeChannel, ChannelRef, makeChannelRef } from '../builtin/channel.js'
|
|
2
|
+
|
|
1
3
|
// Time represents a time instant with nanosecond precision
|
|
2
4
|
export class Time {
|
|
3
5
|
private _date: globalThis.Date
|
|
@@ -590,14 +592,6 @@ export function Duration_multiply(
|
|
|
590
592
|
return receiver * multiplier
|
|
591
593
|
}
|
|
592
594
|
|
|
593
|
-
// Override multiplication operator for Duration * number
|
|
594
|
-
export function multiplyDuration(
|
|
595
|
-
duration: Duration,
|
|
596
|
-
multiplier: number,
|
|
597
|
-
): Duration {
|
|
598
|
-
return duration * multiplier
|
|
599
|
-
}
|
|
600
|
-
|
|
601
595
|
// Location represents a time zone
|
|
602
596
|
export class Location {
|
|
603
597
|
private _name: string
|
|
@@ -1010,10 +1004,19 @@ export function ParseInLocation(
|
|
|
1010
1004
|
return Time.create(date, 0, undefined, loc)
|
|
1011
1005
|
}
|
|
1012
1006
|
|
|
1013
|
-
// After waits for the duration to elapse and then
|
|
1014
|
-
export
|
|
1015
|
-
|
|
1016
|
-
|
|
1007
|
+
// After waits for the duration to elapse and then sends the current time on the returned channel
|
|
1008
|
+
export function After(d: Duration): ChannelRef<Time> {
|
|
1009
|
+
const ms = d / 1000000 // Convert nanoseconds to milliseconds
|
|
1010
|
+
|
|
1011
|
+
// Create a buffered channel with capacity 1
|
|
1012
|
+
const channel = makeChannel(1, new Time(), 'both')
|
|
1013
|
+
|
|
1014
|
+
// Start a timer that will send the current time after the duration
|
|
1015
|
+
setTimeout(async () => {
|
|
1016
|
+
channel.send(Now()).catch(() => {})
|
|
1017
|
+
}, ms)
|
|
1018
|
+
|
|
1019
|
+
return makeChannelRef(channel, 'receive')
|
|
1017
1020
|
}
|
|
1018
1021
|
|
|
1019
1022
|
// AfterFunc waits for the duration to elapse and then calls f
|
|
@@ -1056,6 +1059,6 @@ export function LoadLocationFromTZData(
|
|
|
1056
1059
|
name: string,
|
|
1057
1060
|
_data: Uint8Array,
|
|
1058
1061
|
): Location {
|
|
1059
|
-
//
|
|
1062
|
+
// TODO: parse the timezone data
|
|
1060
1063
|
return new Location(name)
|
|
1061
1064
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"asyncMethods": {
|
|
3
|
+
"IsControl": false,
|
|
4
|
+
"IsDigit": false,
|
|
5
|
+
"IsGraphic": false,
|
|
6
|
+
"IsLetter": false,
|
|
7
|
+
"IsLower": false,
|
|
8
|
+
"IsMark": false,
|
|
9
|
+
"IsNumber": false,
|
|
10
|
+
"IsPrint": false,
|
|
11
|
+
"IsPunct": false,
|
|
12
|
+
"IsSpace": false,
|
|
13
|
+
"IsSymbol": false,
|
|
14
|
+
"IsTitle": false,
|
|
15
|
+
"IsUpper": false,
|
|
16
|
+
"ToLower": false,
|
|
17
|
+
"ToTitle": false,
|
|
18
|
+
"ToUpper": false,
|
|
19
|
+
"SimpleFold": false,
|
|
20
|
+
"In": false,
|
|
21
|
+
"Is": false,
|
|
22
|
+
"IsOneOf": false
|
|
23
|
+
}
|
|
24
|
+
}
|
package/package.json
CHANGED
package/gs/unicode/unicode.go
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
package unicode
|
|
2
|
-
|
|
3
|
-
import "github.com/aperturerobotics/goscript/compiler"
|
|
4
|
-
|
|
5
|
-
// Metadata for unicode package functions
|
|
6
|
-
// Most unicode functions are synchronous character operations
|
|
7
|
-
|
|
8
|
-
// Character classification functions
|
|
9
|
-
var (
|
|
10
|
-
IsControlInfo = compiler.FunctionInfo{IsAsync: false}
|
|
11
|
-
IsDigitInfo = compiler.FunctionInfo{IsAsync: false}
|
|
12
|
-
IsGraphicInfo = compiler.FunctionInfo{IsAsync: false}
|
|
13
|
-
IsLetterInfo = compiler.FunctionInfo{IsAsync: false}
|
|
14
|
-
IsLowerInfo = compiler.FunctionInfo{IsAsync: false}
|
|
15
|
-
IsMarkInfo = compiler.FunctionInfo{IsAsync: false}
|
|
16
|
-
IsNumberInfo = compiler.FunctionInfo{IsAsync: false}
|
|
17
|
-
IsPrintInfo = compiler.FunctionInfo{IsAsync: false}
|
|
18
|
-
IsPunctInfo = compiler.FunctionInfo{IsAsync: false}
|
|
19
|
-
IsSpaceInfo = compiler.FunctionInfo{IsAsync: false}
|
|
20
|
-
IsSymbolInfo = compiler.FunctionInfo{IsAsync: false}
|
|
21
|
-
IsTitleInfo = compiler.FunctionInfo{IsAsync: false}
|
|
22
|
-
IsUpperInfo = compiler.FunctionInfo{IsAsync: false}
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
// Case conversion functions
|
|
26
|
-
var (
|
|
27
|
-
ToLowerInfo = compiler.FunctionInfo{IsAsync: false}
|
|
28
|
-
ToTitleInfo = compiler.FunctionInfo{IsAsync: false}
|
|
29
|
-
ToUpperInfo = compiler.FunctionInfo{IsAsync: false}
|
|
30
|
-
SimpleFoldInfo = compiler.FunctionInfo{IsAsync: false}
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
// Category functions
|
|
34
|
-
var (
|
|
35
|
-
InInfo = compiler.FunctionInfo{IsAsync: false}
|
|
36
|
-
IsInfo = compiler.FunctionInfo{IsAsync: false}
|
|
37
|
-
IsOneOfInfo = compiler.FunctionInfo{IsAsync: false}
|
|
38
|
-
)
|