goscript 0.0.50 → 0.0.52
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 +513 -325
- package/compiler/compiler.go +39 -6
- package/compiler/expr-call-async.go +90 -23
- package/compiler/expr.go +0 -44
- package/compiler/sanitize.go +1 -2
- package/compiler/spec-struct.go +3 -3
- package/compiler/spec.go +0 -21
- package/compiler/stmt-assign.go +0 -6
- package/compiler/stmt-select.go +52 -1
- package/compiler/type-assert.go +6 -6
- package/compiler/type.go +3 -3
- 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 +5 -3
- package/dist/gs/builtin/channel.js +14 -17
- 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/runtime/runtime.d.ts +1 -1
- package/dist/gs/runtime/runtime.js +1 -1
- package/dist/gs/syscall/constants.d.ts +24 -0
- package/dist/gs/syscall/constants.js +27 -0
- package/dist/gs/syscall/constants.js.map +1 -0
- package/dist/gs/syscall/env.d.ts +6 -0
- package/dist/gs/syscall/env.js +43 -0
- package/dist/gs/syscall/env.js.map +1 -0
- package/dist/gs/syscall/errors.d.ts +111 -0
- package/dist/gs/syscall/errors.js +547 -0
- package/dist/gs/syscall/errors.js.map +1 -0
- package/dist/gs/syscall/fs.d.ts +29 -0
- package/dist/gs/syscall/fs.js +53 -0
- package/dist/gs/syscall/fs.js.map +1 -0
- package/dist/gs/syscall/index.d.ts +6 -80
- package/dist/gs/syscall/index.js +12 -168
- package/dist/gs/syscall/index.js.map +1 -1
- package/dist/gs/syscall/rawconn.d.ts +7 -0
- package/dist/gs/syscall/rawconn.js +19 -0
- package/dist/gs/syscall/rawconn.js.map +1 -0
- package/dist/gs/syscall/types.d.ts +12 -0
- package/dist/gs/syscall/types.js +2 -0
- package/dist/gs/syscall/types.js.map +1 -0
- 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 +1 -1
- package/gs/builtin/builtin.ts +0 -11
- package/gs/builtin/channel.ts +39 -17
- package/gs/context/context.ts +6 -2
- package/gs/context/meta.json +16 -0
- package/gs/runtime/runtime.ts +1 -1
- package/gs/syscall/constants.ts +29 -0
- package/gs/syscall/env.ts +47 -0
- package/gs/syscall/errors.ts +658 -0
- package/gs/syscall/fs.ts +62 -0
- package/gs/syscall/index.ts +12 -207
- package/gs/syscall/rawconn.ts +23 -0
- package/gs/syscall/types.ts +18 -0
- 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/syscall/index.ts
CHANGED
|
@@ -1,212 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
// Re-export all types
|
|
2
|
+
export * from './types.js'
|
|
2
3
|
|
|
3
|
-
//
|
|
4
|
-
export
|
|
4
|
+
// Re-export all constants
|
|
5
|
+
export * from './constants.js'
|
|
5
6
|
|
|
6
|
-
//
|
|
7
|
-
export
|
|
8
|
-
Error(): string
|
|
9
|
-
Is(target: $.GoError): boolean
|
|
10
|
-
Errno(): number
|
|
11
|
-
}
|
|
7
|
+
// Re-export environment functions
|
|
8
|
+
export * from './env.js'
|
|
12
9
|
|
|
13
|
-
//
|
|
14
|
-
export
|
|
15
|
-
export const O_WRONLY = 1
|
|
16
|
-
export const O_RDWR = 2
|
|
17
|
-
export const O_APPEND = 8
|
|
18
|
-
export const O_CREATE = 64
|
|
19
|
-
export const O_EXCL = 128
|
|
20
|
-
export const O_SYNC = 256
|
|
21
|
-
export const O_TRUNC = 512
|
|
10
|
+
// Re-export file system structures and functions
|
|
11
|
+
export * from './fs.js'
|
|
22
12
|
|
|
23
|
-
export
|
|
24
|
-
export
|
|
25
|
-
export const Stderr = 2
|
|
13
|
+
// Re-export error constants
|
|
14
|
+
export * from './errors.js'
|
|
26
15
|
|
|
27
|
-
export
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
// File mode constants
|
|
31
|
-
export const S_IFMT = 0o170000
|
|
32
|
-
export const S_IFREG = 0o100000
|
|
33
|
-
export const S_IFDIR = 0o040000
|
|
34
|
-
export const S_IFLNK = 0o120000
|
|
35
|
-
export const S_IFBLK = 0o060000
|
|
36
|
-
export const S_IFCHR = 0o020000
|
|
37
|
-
export const S_IFIFO = 0o010000
|
|
38
|
-
export const S_IFSOCK = 0o140000
|
|
39
|
-
export const S_ISUID = 0o004000
|
|
40
|
-
export const S_ISGID = 0o002000
|
|
41
|
-
export const S_ISVTX = 0o001000
|
|
42
|
-
|
|
43
|
-
// Environment variable functions using Node.js/browser APIs
|
|
44
|
-
export function Getenv(key: string): [string, boolean] {
|
|
45
|
-
if (typeof process !== 'undefined' && process.env) {
|
|
46
|
-
const value = process.env[key]
|
|
47
|
-
return value !== undefined ? [value, true] : ['', false]
|
|
48
|
-
}
|
|
49
|
-
return ['', false]
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function Setenv(key: string, value: string): $.GoError {
|
|
53
|
-
if (typeof process !== 'undefined' && process.env) {
|
|
54
|
-
process.env[key] = value
|
|
55
|
-
return null
|
|
56
|
-
}
|
|
57
|
-
return { Error: () => 'setenv not supported' }
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function Unsetenv(key: string): $.GoError {
|
|
61
|
-
if (typeof process !== 'undefined' && process.env) {
|
|
62
|
-
delete process.env[key]
|
|
63
|
-
return null
|
|
64
|
-
}
|
|
65
|
-
return { Error: () => 'unsetenv not supported' }
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function Clearenv(): void {
|
|
69
|
-
if (typeof process !== 'undefined' && process.env) {
|
|
70
|
-
for (const key in process.env) {
|
|
71
|
-
delete process.env[key]
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function Environ(): $.Slice<string> {
|
|
77
|
-
if (typeof process !== 'undefined' && process.env) {
|
|
78
|
-
const env: string[] = []
|
|
79
|
-
for (const [key, value] of Object.entries(process.env)) {
|
|
80
|
-
if (value !== undefined) {
|
|
81
|
-
env.push(`${key}=${value}`)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return $.arrayToSlice(env)
|
|
85
|
-
}
|
|
86
|
-
return $.arrayToSlice([])
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Dirent structure with Reclen field
|
|
90
|
-
export class Dirent {
|
|
91
|
-
public Name: $.Bytes = new Uint8Array(0)
|
|
92
|
-
public Reclen: number = 0
|
|
93
|
-
constructor(init?: any) {
|
|
94
|
-
if (init?.Name) this.Name = init.Name
|
|
95
|
-
if (init?.Reclen) this.Reclen = init.Reclen
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Stat_t structure stub
|
|
100
|
-
export class Stat_t {
|
|
101
|
-
public Dev: number = 0
|
|
102
|
-
public Ino: number = 0
|
|
103
|
-
public Mode: number = 0
|
|
104
|
-
public Nlink: number = 0
|
|
105
|
-
public Uid: number = 0
|
|
106
|
-
public Gid: number = 0
|
|
107
|
-
public Rdev: number = 0
|
|
108
|
-
public Size: number = 0
|
|
109
|
-
public Blksize: number = 0
|
|
110
|
-
public Blocks: number = 0
|
|
111
|
-
public Atime: number = 0
|
|
112
|
-
public Mtime: number = 0
|
|
113
|
-
public Ctime: number = 0
|
|
114
|
-
public AtimeNsec: number = 0
|
|
115
|
-
public MtimeNsec: number = 0
|
|
116
|
-
public CtimeNsec: number = 0
|
|
117
|
-
|
|
118
|
-
constructor(init?: any) {
|
|
119
|
-
if (init) {
|
|
120
|
-
Object.assign(this, init)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
public clone(): Stat_t {
|
|
125
|
-
return new Stat_t(this)
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// RawConn interface - stub implementation for JavaScript environment
|
|
130
|
-
export interface RawConn {
|
|
131
|
-
Control(f: (fd: uintptr) => void): $.GoError
|
|
132
|
-
Read(f: (fd: uintptr) => boolean): $.GoError
|
|
133
|
-
Write(f: (fd: uintptr) => boolean): $.GoError
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Stub implementation of RawConn that always returns ErrUnimplemented
|
|
137
|
-
export class StubRawConn implements RawConn {
|
|
138
|
-
Control(_f: (fd: uintptr) => void): $.GoError {
|
|
139
|
-
return {
|
|
140
|
-
Error: () => 'operation not implemented in JavaScript environment',
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
Read(_f: (fd: uintptr) => boolean): $.GoError {
|
|
145
|
-
return {
|
|
146
|
-
Error: () => 'operation not implemented in JavaScript environment',
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
Write(_f: (fd: uintptr) => boolean): $.GoError {
|
|
151
|
-
return {
|
|
152
|
-
Error: () => 'operation not implemented in JavaScript environment',
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Additional error constants - implement as Errno type
|
|
158
|
-
export const ENOSYS: Errno = {
|
|
159
|
-
Error: () => 'function not implemented',
|
|
160
|
-
Is: (target: $.GoError) => target === ENOSYS,
|
|
161
|
-
Errno: () => 38,
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export const EISDIR: Errno = {
|
|
165
|
-
Error: () => 'is a directory',
|
|
166
|
-
Is: (target: $.GoError) => target === EISDIR,
|
|
167
|
-
Errno: () => 21,
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export const ENOTDIR: Errno = {
|
|
171
|
-
Error: () => 'not a directory',
|
|
172
|
-
Is: (target: $.GoError) => target === ENOTDIR,
|
|
173
|
-
Errno: () => 20,
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export const ERANGE: Errno = {
|
|
177
|
-
Error: () => 'result too large',
|
|
178
|
-
Is: (target: $.GoError) => target === ERANGE,
|
|
179
|
-
Errno: () => 34,
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export const ENOMEM: Errno = {
|
|
183
|
-
Error: () => 'out of memory',
|
|
184
|
-
Is: (target: $.GoError) => target === ENOMEM,
|
|
185
|
-
Errno: () => 12,
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export const ESRCH: Errno = {
|
|
189
|
-
Error: () => 'no such process',
|
|
190
|
-
Is: (target: $.GoError) => target === ESRCH,
|
|
191
|
-
Errno: () => 3,
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Additional missing syscall functions
|
|
195
|
-
export function Open(
|
|
196
|
-
_path: string,
|
|
197
|
-
_flag: number,
|
|
198
|
-
_perm: number,
|
|
199
|
-
): [number, $.GoError] {
|
|
200
|
-
return [-1, ENOSYS]
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export function Sysctl(_name: string): [string, $.GoError] {
|
|
204
|
-
return ['', ENOSYS]
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Getpagesize returns the underlying system's memory page size.
|
|
208
|
-
export function Getpagesize(): number {
|
|
209
|
-
// Return a standard page size for JavaScript environment
|
|
210
|
-
// Most systems use 4096 bytes as the default page size
|
|
211
|
-
return 4096
|
|
212
|
-
}
|
|
16
|
+
// Re-export RawConn implementation
|
|
17
|
+
export * from './rawconn.js'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
import { RawConn, uintptr } from './types.js'
|
|
3
|
+
|
|
4
|
+
// Stub implementation of RawConn that always returns ErrUnimplemented
|
|
5
|
+
export class StubRawConn implements RawConn {
|
|
6
|
+
Control(_f: (fd: uintptr) => void): $.GoError {
|
|
7
|
+
return {
|
|
8
|
+
Error: () => 'operation not implemented in JavaScript environment',
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Read(_f: (fd: uintptr) => boolean): $.GoError {
|
|
13
|
+
return {
|
|
14
|
+
Error: () => 'operation not implemented in JavaScript environment',
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Write(_f: (fd: uintptr) => boolean): $.GoError {
|
|
19
|
+
return {
|
|
20
|
+
Error: () => 'operation not implemented in JavaScript environment',
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
|
|
3
|
+
// Essential type aliases
|
|
4
|
+
export type uintptr = number
|
|
5
|
+
|
|
6
|
+
// Errno type for syscall errors
|
|
7
|
+
export interface Errno {
|
|
8
|
+
Error(): string
|
|
9
|
+
Is(target: $.GoError): boolean
|
|
10
|
+
Errno(): number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// RawConn interface - stub implementation for JavaScript environment
|
|
14
|
+
export interface RawConn {
|
|
15
|
+
Control(f: (fd: uintptr) => void): $.GoError
|
|
16
|
+
Read(f: (fd: uintptr) => boolean): $.GoError
|
|
17
|
+
Write(f: (fd: uintptr) => boolean): $.GoError
|
|
18
|
+
}
|
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
|
-
)
|