@tsonic/core 0.5.0 → 0.6.0
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/__build/scripts/generate.sh +99 -0
- package/families.json +9 -0
- package/lang.d.ts +183 -0
- package/package.json +1 -1
- package/runtime/bindings.json +5343 -0
- package/runtime/internal/index.d.ts +346 -0
- package/runtime/internal/metadata.json +3696 -0
- package/runtime.d.ts +41 -0
- package/runtime.js +9 -0
- package/types.d.ts +0 -32
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Generate TypeScript declarations for Tsonic.Runtime in @tsonic/core
|
|
3
|
+
#
|
|
4
|
+
# This script regenerates TypeScript type declarations from the
|
|
5
|
+
# Tsonic.Runtime.dll assembly using tsbindgen.
|
|
6
|
+
#
|
|
7
|
+
# Prerequisites:
|
|
8
|
+
# - .NET 10 SDK installed
|
|
9
|
+
# - tsbindgen repository cloned at ../tsbindgen (sibling directory)
|
|
10
|
+
# - runtime repository cloned at ../runtime (sibling directory)
|
|
11
|
+
#
|
|
12
|
+
# Usage:
|
|
13
|
+
# ./__build/scripts/generate.sh
|
|
14
|
+
|
|
15
|
+
set -e
|
|
16
|
+
|
|
17
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
18
|
+
PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
19
|
+
TSBINDGEN_DIR="$PROJECT_DIR/../tsbindgen"
|
|
20
|
+
RUNTIME_DIR="$PROJECT_DIR/../runtime"
|
|
21
|
+
DOTNET_LIB="$PROJECT_DIR/../dotnet"
|
|
22
|
+
|
|
23
|
+
# .NET runtime path (needed for BCL type resolution)
|
|
24
|
+
DOTNET_VERSION="${DOTNET_VERSION:-10.0.0}"
|
|
25
|
+
DOTNET_HOME="${DOTNET_HOME:-$HOME/.dotnet}"
|
|
26
|
+
DOTNET_RUNTIME_PATH="$DOTNET_HOME/shared/Microsoft.NETCore.App/$DOTNET_VERSION"
|
|
27
|
+
|
|
28
|
+
# Tsonic.Runtime.dll path
|
|
29
|
+
RUNTIME_DLL="$RUNTIME_DIR/artifacts/bin/Tsonic.Runtime/Release/net10.0/Tsonic.Runtime.dll"
|
|
30
|
+
|
|
31
|
+
echo "================================================================"
|
|
32
|
+
echo "Generating Tsonic.Runtime TypeScript Declarations for @tsonic/core"
|
|
33
|
+
echo "================================================================"
|
|
34
|
+
echo ""
|
|
35
|
+
echo "Configuration:"
|
|
36
|
+
echo " Runtime.dll: $RUNTIME_DLL"
|
|
37
|
+
echo " .NET Runtime: $DOTNET_RUNTIME_PATH"
|
|
38
|
+
echo " BCL Library: $DOTNET_LIB (external reference)"
|
|
39
|
+
echo " tsbindgen: $TSBINDGEN_DIR"
|
|
40
|
+
echo " Output: $PROJECT_DIR"
|
|
41
|
+
echo " Naming: JS (camelCase)"
|
|
42
|
+
echo ""
|
|
43
|
+
|
|
44
|
+
# Verify prerequisites
|
|
45
|
+
if [ ! -f "$RUNTIME_DLL" ]; then
|
|
46
|
+
echo "ERROR: Tsonic.Runtime.dll not found at $RUNTIME_DLL"
|
|
47
|
+
echo "Build it first: cd ../runtime && dotnet build -c Release"
|
|
48
|
+
exit 1
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
if [ ! -d "$DOTNET_RUNTIME_PATH" ]; then
|
|
52
|
+
echo "ERROR: .NET runtime not found at $DOTNET_RUNTIME_PATH"
|
|
53
|
+
echo "Set DOTNET_HOME or DOTNET_VERSION environment variables"
|
|
54
|
+
exit 1
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
if [ ! -d "$TSBINDGEN_DIR" ]; then
|
|
58
|
+
echo "ERROR: tsbindgen not found at $TSBINDGEN_DIR"
|
|
59
|
+
echo "Clone it: git clone https://github.com/tsoniclang/tsbindgen ../tsbindgen"
|
|
60
|
+
exit 1
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
if [ ! -d "$DOTNET_LIB" ]; then
|
|
64
|
+
echo "ERROR: @tsonic/dotnet not found at $DOTNET_LIB"
|
|
65
|
+
echo "Clone it: git clone https://github.com/tsoniclang/dotnet ../dotnet"
|
|
66
|
+
exit 1
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
# Clean only generated runtime files (keep hand-written types.d.ts, attributes.d.ts)
|
|
70
|
+
echo "[1/3] Cleaning generated runtime files..."
|
|
71
|
+
cd "$PROJECT_DIR"
|
|
72
|
+
|
|
73
|
+
# Remove only the generated runtime directory and facade files
|
|
74
|
+
rm -rf Tsonic.Runtime/ runtime/ 2>/dev/null || true
|
|
75
|
+
rm -f Tsonic.Runtime.d.ts Tsonic.Runtime.js runtime.d.ts runtime.js 2>/dev/null || true
|
|
76
|
+
rm -f families.json 2>/dev/null || true
|
|
77
|
+
|
|
78
|
+
echo " Done"
|
|
79
|
+
|
|
80
|
+
# Build tsbindgen
|
|
81
|
+
echo "[2/3] Building tsbindgen..."
|
|
82
|
+
cd "$TSBINDGEN_DIR"
|
|
83
|
+
dotnet build src/tsbindgen/tsbindgen.csproj -c Release --verbosity quiet
|
|
84
|
+
echo " Done"
|
|
85
|
+
|
|
86
|
+
# Generate types with JavaScript-style naming
|
|
87
|
+
# Uses --lib to reference BCL types from @tsonic/dotnet instead of regenerating them
|
|
88
|
+
# Uses --namespace-map to emit as runtime.d.ts/runtime.js for cleaner imports
|
|
89
|
+
echo "[3/3] Generating TypeScript declarations..."
|
|
90
|
+
dotnet run --project src/tsbindgen/tsbindgen.csproj --no-build -c Release -- \
|
|
91
|
+
generate -a "$RUNTIME_DLL" -d "$DOTNET_RUNTIME_PATH" -o "$PROJECT_DIR" \
|
|
92
|
+
--lib "$DOTNET_LIB" \
|
|
93
|
+
--naming js \
|
|
94
|
+
--namespace-map "Tsonic.Runtime=runtime"
|
|
95
|
+
|
|
96
|
+
echo ""
|
|
97
|
+
echo "================================================================"
|
|
98
|
+
echo "Generation Complete"
|
|
99
|
+
echo "================================================================"
|
package/families.json
ADDED
package/lang.d.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tsonic/core - Language Intrinsics
|
|
3
|
+
*
|
|
4
|
+
* TypeScript declarations for C# language-level intrinsics.
|
|
5
|
+
* These compile to C# keywords and special syntax.
|
|
6
|
+
*
|
|
7
|
+
* All intrinsics are lowercase to match C# keyword style.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { stackalloc, sizeof, nameof, defaultof, trycast } from "@tsonic/core/lang.js";
|
|
12
|
+
* import { int, Span } from "@tsonic/core/types.js";
|
|
13
|
+
*
|
|
14
|
+
* const buffer: Span<int> = stackalloc<int>(100);
|
|
15
|
+
* const size: int = sizeof<int>();
|
|
16
|
+
* const name: string = nameof(myVariable);
|
|
17
|
+
* const zero: int = defaultof<int>();
|
|
18
|
+
* const person = trycast<Person>(obj);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { int } from "./types.js";
|
|
23
|
+
|
|
24
|
+
// ============================================================================
|
|
25
|
+
// Memory Intrinsics
|
|
26
|
+
// ============================================================================
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Allocates memory on the stack.
|
|
30
|
+
*
|
|
31
|
+
* TypeScript: `stackalloc<int>(100)`
|
|
32
|
+
* C#: `stackalloc int[100]`
|
|
33
|
+
*
|
|
34
|
+
* Returns a Span<T> pointing to stack-allocated memory.
|
|
35
|
+
* The memory is automatically freed when the scope exits.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { stackalloc } from "@tsonic/core/lang.js";
|
|
40
|
+
* import { int, Span } from "@tsonic/core/types.js";
|
|
41
|
+
*
|
|
42
|
+
* const buffer: Span<int> = stackalloc<int>(256);
|
|
43
|
+
* buffer[0] = 42;
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* In C#, this emits:
|
|
47
|
+
* ```csharp
|
|
48
|
+
* Span<int> buffer = stackalloc int[256];
|
|
49
|
+
* buffer[0] = 42;
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function stackalloc<T>(size: int): Span<T>;
|
|
53
|
+
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// Type Intrinsics
|
|
56
|
+
// ============================================================================
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns the size in bytes of a type.
|
|
60
|
+
*
|
|
61
|
+
* TypeScript: `sizeof<int>()`
|
|
62
|
+
* C#: `sizeof(int)`
|
|
63
|
+
*
|
|
64
|
+
* Only valid for unmanaged types (primitives, structs with no reference fields).
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* import { sizeof } from "@tsonic/core/lang.js";
|
|
69
|
+
* import { int, long } from "@tsonic/core/types.js";
|
|
70
|
+
*
|
|
71
|
+
* const intSize: int = sizeof<int>(); // 4
|
|
72
|
+
* const longSize: int = sizeof<long>(); // 8
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* In C#, this emits:
|
|
76
|
+
* ```csharp
|
|
77
|
+
* int intSize = sizeof(int); // 4
|
|
78
|
+
* int longSize = sizeof(long); // 8
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function sizeof<T>(): int;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns the default value for a type.
|
|
85
|
+
*
|
|
86
|
+
* TypeScript: `defaultof<int>()`
|
|
87
|
+
* C#: `default(int)`
|
|
88
|
+
*
|
|
89
|
+
* For value types, returns the zero value.
|
|
90
|
+
* For reference types, returns null.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* import { defaultof } from "@tsonic/core/lang.js";
|
|
95
|
+
* import { int, bool } from "@tsonic/core/types.js";
|
|
96
|
+
*
|
|
97
|
+
* const zero: int = defaultof<int>(); // 0
|
|
98
|
+
* const falseBool: bool = defaultof<bool>(); // false
|
|
99
|
+
* const nullRef = defaultof<Person>(); // null
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* In C#, this emits:
|
|
103
|
+
* ```csharp
|
|
104
|
+
* int zero = default(int); // 0
|
|
105
|
+
* bool falseBool = default(bool); // false
|
|
106
|
+
* Person? nullRef = default; // null
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare function defaultof<T>(): T;
|
|
110
|
+
|
|
111
|
+
// ============================================================================
|
|
112
|
+
// Symbol Intrinsics
|
|
113
|
+
// ============================================================================
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Returns the name of a symbol as a string.
|
|
117
|
+
*
|
|
118
|
+
* TypeScript: `nameof(myVariable)`
|
|
119
|
+
* C#: `nameof(myVariable)`
|
|
120
|
+
*
|
|
121
|
+
* Useful for refactoring-safe string literals.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* import { nameof } from "@tsonic/core/lang.js";
|
|
126
|
+
*
|
|
127
|
+
* const name = nameof(myVariable); // "myVariable"
|
|
128
|
+
* const prop = nameof(person.name); // "name"
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* In C#, this emits:
|
|
132
|
+
* ```csharp
|
|
133
|
+
* string name = nameof(myVariable); // "myVariable"
|
|
134
|
+
* string prop = nameof(person.name); // "name"
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function nameof(expression: unknown): string;
|
|
138
|
+
|
|
139
|
+
// ============================================================================
|
|
140
|
+
// Cast Intrinsics
|
|
141
|
+
// ============================================================================
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Safe cast - returns T or null if cast fails.
|
|
145
|
+
*
|
|
146
|
+
* TypeScript: `trycast<Person>(obj)`
|
|
147
|
+
* C#: `obj as Person`
|
|
148
|
+
*
|
|
149
|
+
* Unlike `x as T` type assertion which throws on failure (C# `(T)x`),
|
|
150
|
+
* this returns null if the cast is not valid.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* import { trycast } from "@tsonic/core/lang.js";
|
|
155
|
+
*
|
|
156
|
+
* const person = trycast<Person>(unknownObj);
|
|
157
|
+
* if (person !== null) {
|
|
158
|
+
* console.log(person.name);
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* In C#, this emits:
|
|
163
|
+
* ```csharp
|
|
164
|
+
* Person? person = unknownObj as Person;
|
|
165
|
+
* if (person != null) {
|
|
166
|
+
* Console.WriteLine(person.name);
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function trycast<T>(value: unknown): T | null;
|
|
171
|
+
|
|
172
|
+
// ============================================================================
|
|
173
|
+
// Span type (for stackalloc return type)
|
|
174
|
+
// ============================================================================
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A contiguous region of memory.
|
|
178
|
+
* Used as the return type of stackalloc.
|
|
179
|
+
*/
|
|
180
|
+
export interface Span<T> {
|
|
181
|
+
readonly length: int;
|
|
182
|
+
[index: number]: T;
|
|
183
|
+
}
|