@tsonic/core 0.2.0 → 0.4.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/package.json +1 -1
- package/types.d.ts +89 -3
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -52,6 +52,92 @@ export type char = string; // System.Char (single UTF-16 code unit)
|
|
|
52
52
|
// Erases to unknown for type safety - requires explicit handling
|
|
53
53
|
export type ptr<T> = unknown;
|
|
54
54
|
|
|
55
|
-
//
|
|
56
|
-
// Parameter
|
|
57
|
-
//
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// Parameter Passing Modifiers
|
|
57
|
+
// ============================================================================
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Marks a parameter as `out` - callee sets the value.
|
|
61
|
+
* Use with `as out<T>` at call sites.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { int, out } from "@tsonic/core/types.js";
|
|
66
|
+
*
|
|
67
|
+
* let value: int = 0;
|
|
68
|
+
* dict.tryGetValue("key", value as out<int>);
|
|
69
|
+
* // value now contains the result
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export type out<T> = T;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Marks a parameter as `ref` - callee can read and modify.
|
|
76
|
+
* Use with `as ref<T>` at call sites.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* import { int, ref } from "@tsonic/core/types.js";
|
|
81
|
+
*
|
|
82
|
+
* let count: int = 10;
|
|
83
|
+
* increment(count as ref<int>);
|
|
84
|
+
* // count is now modified
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export type ref<T> = T;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Marks a parameter as `in` - read-only reference (optimization for large structs).
|
|
91
|
+
* Use with `as inref<T>` at call sites.
|
|
92
|
+
* Named `inref` because `in` is a TypeScript reserved keyword.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { inref } from "@tsonic/core/types.js";
|
|
97
|
+
*
|
|
98
|
+
* const data: LargeStruct = { ... };
|
|
99
|
+
* process(data as inref<LargeStruct>);
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export type inref<T> = T;
|
|
103
|
+
|
|
104
|
+
// ============================================================================
|
|
105
|
+
// Value Type Markers
|
|
106
|
+
// ============================================================================
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Marker interface for C# struct types.
|
|
110
|
+
*
|
|
111
|
+
* Types that extend `struct` will be emitted as C# structs instead of classes.
|
|
112
|
+
* This enables value semantics and stack allocation in the generated code.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* import { struct } from "@tsonic/core/types.js";
|
|
117
|
+
*
|
|
118
|
+
* // This becomes a C# struct
|
|
119
|
+
* export interface Point extends struct {
|
|
120
|
+
* x: number;
|
|
121
|
+
* y: number;
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* // Use as generic constraint for nullable value types
|
|
125
|
+
* function wrap<T extends struct>(value: T | null): T | null {
|
|
126
|
+
* return value;
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* In C#, this emits:
|
|
131
|
+
* ```csharp
|
|
132
|
+
* public struct Point {
|
|
133
|
+
* public double x { get; set; }
|
|
134
|
+
* public double y { get; set; }
|
|
135
|
+
* }
|
|
136
|
+
*
|
|
137
|
+
* // With constraint: where T : struct
|
|
138
|
+
* T? Wrap<T>(T? value) where T : struct => value;
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export interface struct {
|
|
142
|
+
readonly __brand: unique symbol;
|
|
143
|
+
}
|