@shd101wyy/yo 0.1.5 → 0.1.7

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.
Files changed (50) hide show
  1. package/README.md +8 -6
  2. package/out/cjs/index.cjs +691 -636
  3. package/out/cjs/yo-cli.cjs +710 -653
  4. package/out/esm/index.mjs +649 -594
  5. package/out/types/src/build-runner.d.ts +1 -1
  6. package/out/types/src/codegen/async/runtime-io-common.d.ts +2 -1
  7. package/out/types/src/codegen/async/runtime.d.ts +5 -1
  8. package/out/types/src/codegen/codegen-c.d.ts +2 -0
  9. package/out/types/src/codegen/functions/collection.d.ts +1 -1
  10. package/out/types/src/codegen/functions/context.d.ts +1 -0
  11. package/out/types/src/codegen/functions/generation.d.ts +10 -0
  12. package/out/types/src/codegen/utils/index.d.ts +4 -0
  13. package/out/types/src/env.d.ts +1 -0
  14. package/out/types/src/evaluator/builtins/build.d.ts +1 -0
  15. package/out/types/src/evaluator/builtins/comptime-index-fns.d.ts +17 -0
  16. package/out/types/src/evaluator/calls/index-trait.d.ts +17 -0
  17. package/out/types/src/evaluator/context.d.ts +19 -14
  18. package/out/types/src/evaluator/index.d.ts +3 -1
  19. package/out/types/src/evaluator/trait-checking.d.ts +1 -0
  20. package/out/types/src/evaluator/values/anonymous-module.d.ts +3 -2
  21. package/out/types/src/expr.d.ts +22 -1
  22. package/out/types/src/module-manager.d.ts +1 -0
  23. package/out/types/src/target.d.ts +1 -0
  24. package/out/types/src/value.d.ts +4 -1
  25. package/out/types/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +1 -1
  27. package/std/build.yo +2 -1
  28. package/std/collections/array_list.yo +114 -26
  29. package/std/collections/btree_map.yo +13 -3
  30. package/std/collections/deque.yo +10 -0
  31. package/std/collections/hash_map.yo +15 -0
  32. package/std/collections/priority_queue.yo +5 -5
  33. package/std/encoding/html.yo +283 -0
  34. package/std/encoding/html_char_utils.yo +36 -0
  35. package/std/encoding/html_entities.yo +2262 -0
  36. package/std/encoding/punycode.yo +366 -0
  37. package/std/encoding/toml.yo +1 -1
  38. package/std/fmt/to_string.yo +5 -4
  39. package/std/glob/index.yo +2 -2
  40. package/std/libc/wctype.yo +55 -0
  41. package/std/path.yo +6 -6
  42. package/std/prelude.yo +826 -205
  43. package/std/process.yo +1 -1
  44. package/std/regex/compiler.yo +11 -11
  45. package/std/regex/index.yo +2 -4
  46. package/std/regex/parser.yo +69 -4
  47. package/std/regex/vm.yo +53 -46
  48. package/std/string/string.yo +1424 -1339
  49. package/std/string/unicode.yo +242 -0
  50. package/out/types/src/evaluator/calls/array.d.ts +0 -14
@@ -11,7 +11,7 @@ export interface BuildOptions {
11
11
  sysroot?: string;
12
12
  summary?: boolean;
13
13
  }
14
- export declare function getArtifactOutputFileName(artifact: Pick<BuildArtifact, "kind" | "name" | "target">, targetTriple?: string): string;
14
+ export declare function getArtifactOutputFileName(artifact: Pick<BuildArtifact, "kind" | "name" | "target"> & Partial<Pick<BuildArtifact, "cFlags">>, targetTriple?: string): string;
15
15
  export declare function stageRuntimeFiles(runtimeFiles: readonly string[], outputDir: string, verbose?: boolean): string[];
16
16
  export declare function runBuild(options: BuildOptions): Promise<void>;
17
17
  export interface DAGNode {
@@ -1,4 +1,5 @@
1
1
  import { Emitter } from "../../emitter";
2
2
  import type { TargetInfo } from "../../target";
3
+ import type { AsyncRuntimeOptions } from "./runtime";
3
4
  export declare function generateSysRuntime(emitter: Emitter, targetInfo: TargetInfo): void;
4
- export declare function generateAsyncRuntimeIOCommon(emitter: Emitter, targetInfo: TargetInfo): void;
5
+ export declare function generateAsyncRuntimeIOCommon(emitter: Emitter, targetInfo: TargetInfo, options: AsyncRuntimeOptions): void;
@@ -1,3 +1,7 @@
1
1
  import { Emitter } from "../../emitter";
2
2
  import type { TargetInfo } from "../../target";
3
- export declare function generateAsyncRuntime(emitter: Emitter, targetInfo: TargetInfo, _debugAsyncAwait: boolean): void;
3
+ export interface AsyncRuntimeOptions {
4
+ needsCycleGC: boolean;
5
+ registerDisposeTypeId?: (disposeFnName: string) => number;
6
+ }
7
+ export declare function generateAsyncRuntime(emitter: Emitter, targetInfo: TargetInfo, _debugAsyncAwait: boolean, options: AsyncRuntimeOptions): void;
@@ -1,3 +1,4 @@
1
+ import type { Expr } from "../expr";
1
2
  import type { ModuleValue } from "../value";
2
3
  export declare class CodeGeneratorC {
3
4
  private emitter;
@@ -11,6 +12,7 @@ export declare class CodeGeneratorC {
11
12
  debugAsyncAwait?: boolean;
12
13
  allocator?: "mimalloc" | "libc";
13
14
  isLibrary?: boolean;
15
+ allModuleLevelInitExprs?: Expr[];
14
16
  }): void;
15
17
  print(): string;
16
18
  getExportedFunctionNames(): Set<string>;
@@ -1,6 +1,6 @@
1
1
  import { type Expr } from "../../expr";
2
2
  import { type ModuleValue, type TraitValue } from "../../value";
3
3
  import { type CodeGenContext } from "../utils";
4
- export declare function collectRequiredFunctions(moduleValue: ModuleValue | TraitValue, context: CodeGenContext): void;
4
+ export declare function collectRequiredFunctions(moduleValue: ModuleValue | TraitValue, context: CodeGenContext, isTopLevelExport?: boolean): void;
5
5
  export declare function findFunctionCallsInExpr(expr: Expr, context: CodeGenContext): void;
6
6
  export declare function collectDisposeMethodsFromGenericImpls(context: CodeGenContext): void;
@@ -107,6 +107,7 @@ export interface FunctionGenerationContext extends CodeGenContext {
107
107
  };
108
108
  smWhileBodyDrops?: Expr[];
109
109
  shortCircuitHandledDropVarNames?: Set<string>;
110
+ declaredTempVars?: Set<string>;
110
111
  effectHandlerParamDrops?: string[];
111
112
  effectSmConsumedArgCNames?: Set<string>;
112
113
  loopBodyDropsBaselineCount?: number;
@@ -4,6 +4,16 @@ import type { FunctionType } from "../../types/definitions";
4
4
  import { type CodeGenContext } from "../utils";
5
5
  import type { FunctionGenerationContext } from "./context";
6
6
  export declare function generateAllFunctions(context: FunctionGenerationContext): void;
7
+ export declare function emitModuleLevelVariableDeclarations(context: FunctionGenerationContext): Array<{
8
+ cVarName: string;
9
+ cTypeStr: string;
10
+ rhs: Expr;
11
+ }>;
12
+ export declare function generateLibraryInitFunction(context: FunctionGenerationContext, moduleLevelVars: Array<{
13
+ cVarName: string;
14
+ cTypeStr: string;
15
+ rhs: Expr;
16
+ }>): void;
7
17
  export declare function generateMainWrapper(context: FunctionGenerationContext): void;
8
18
  export declare function preRegisterEffectfulFunctions(context: FunctionGenerationContext): void;
9
19
  export declare function generateFunction(functionValue: FunctionValue, cFunctionName: string, context: FunctionGenerationContext): void;
@@ -80,8 +80,12 @@ export interface CodeGenContext {
80
80
  currentContinueLabel?: string;
81
81
  insideMatch?: boolean;
82
82
  typeIdStatics?: Map<string, string>;
83
+ needsCycleGC?: boolean;
84
+ disposeTypeIds?: Map<string, number>;
85
+ nextDisposeTypeId?: number;
83
86
  isLibrary?: boolean;
84
87
  needsIntelAsmSyntax?: boolean;
88
+ moduleLevelInitExprs?: Expr[];
85
89
  currentModuleId?: string;
86
90
  exportedFunctionLabels?: Map<FuncValueId, string>;
87
91
  }
@@ -20,6 +20,7 @@ export interface Variable {
20
20
  isImplicit?: boolean;
21
21
  isFromEffectSpread?: boolean;
22
22
  isEffectParam?: boolean;
23
+ isModuleLevel?: boolean;
23
24
  }
24
25
  export type WhereClauseConstraints = {
25
26
  someType: SomeType;
@@ -109,6 +109,7 @@ export declare class BuildRegistry {
109
109
  findTest(name: string): BuildTestSuite | undefined;
110
110
  findRunStep(name: string): BuildRunStep | undefined;
111
111
  findStep(name: string): BuildStep | undefined;
112
+ private checkDuplicateArtifactName;
112
113
  findDependency(name: string): BuildGitDependency | undefined;
113
114
  findPathDependency(name: string): BuildPathDependency | undefined;
114
115
  findSystemLibrary(name: string): BuildSystemLibrary | undefined;
@@ -0,0 +1,17 @@
1
+ import type { Environment } from "../../env";
2
+ import { type FnCallExpr } from "../../expr";
3
+ import type { Token } from "../../token";
4
+ import { type Value } from "../../value";
5
+ import type { EvaluatorContext } from "../context";
6
+ export declare function evaluateYoComptimeIndexFunctions({ expr, env, context, }: {
7
+ expr: FnCallExpr;
8
+ env: Environment;
9
+ context: EvaluatorContext;
10
+ }): FnCallExpr;
11
+ export declare function computeComptimeStringIndex({ strValue, argValue, token, isRange, isInclusive, }: {
12
+ strValue: string;
13
+ argValue: Value;
14
+ token: Token;
15
+ isRange: boolean;
16
+ isInclusive: boolean;
17
+ }): Value;
@@ -0,0 +1,17 @@
1
+ import type { Environment } from "../../env";
2
+ import { type Expr, type FnCallExpr } from "../../expr";
3
+ import type { Type } from "../../types/definitions";
4
+ import type { EvaluatorContext, IndexCallResult } from "../context";
5
+ export declare function tryToCallWithIndexTrait({ expr, valueType, argExprs, callerEnv, context, }: {
6
+ expr: FnCallExpr;
7
+ valueType: Type;
8
+ argExprs: Expr[];
9
+ callerEnv: Environment;
10
+ context: EvaluatorContext;
11
+ }): IndexCallResult;
12
+ export declare function hasIndexImpl({ concreteType, argExprs, callerEnv, _context, }: {
13
+ concreteType: Type;
14
+ argExprs: Expr[];
15
+ callerEnv: Environment;
16
+ _context: EvaluatorContext;
17
+ }): boolean;
@@ -36,6 +36,7 @@ export interface EvaluatorContext {
36
36
  env: Environment;
37
37
  };
38
38
  isEvaluatingFunctionBodyOrAsyncBlock?: FunctionEvaluationContext | AsyncBlockEvaluationContext | TestBlockEvaluationContext;
39
+ isInsideImplBlock?: boolean;
39
40
  capturedVariables?: Map<string, CapturedVariableInfo>;
40
41
  isEvaluatingLoopBody?: {
41
42
  kind: "while" | "for";
@@ -67,6 +68,7 @@ export interface EvaluatorContext {
67
68
  isInFunctionCallCheckingPhase?: boolean;
68
69
  isInsideIoAsyncCall?: boolean;
69
70
  isInsideGivenHandler?: boolean;
71
+ isEvaluatingGenericImplSpecialization?: boolean;
70
72
  }
71
73
  export interface ArgValues {
72
74
  forallArgs: {
@@ -118,16 +120,6 @@ export interface TraitSpecializationResult {
118
120
  specializedTraitType: TraitType;
119
121
  callerEnv: Environment;
120
122
  }
121
- export interface ArrayCallResult {
122
- value: Value | undefined;
123
- index?: number;
124
- arrayElementRef?: {
125
- arrayValue: ArrayValue;
126
- index: number;
127
- };
128
- type: Type;
129
- callerEnv: Environment;
130
- }
131
123
  export interface MacroFunctionCallResult {
132
124
  calleeEnv: Environment;
133
125
  callerEnv: Environment;
@@ -141,6 +133,19 @@ export interface PointerTypeCallResult {
141
133
  expr: Expr;
142
134
  env: Environment;
143
135
  }
136
+ export interface IndexCallResult {
137
+ value: Value | undefined;
138
+ type: Type;
139
+ ptrType: Type;
140
+ indexMethodType: FunctionType | undefined;
141
+ indexMethodValue: Value | undefined;
142
+ callerEnv: Environment;
143
+ index?: number;
144
+ arrayElementRef?: {
145
+ arrayValue: ArrayValue;
146
+ index: number;
147
+ };
148
+ }
144
149
  export interface FunctionToCall {
145
150
  type: Type;
146
151
  args?: Expr[];
@@ -166,9 +171,6 @@ export interface FunctionToCall {
166
171
  } | {
167
172
  kind: "trait-specialization";
168
173
  result: TraitSpecializationResult;
169
- } | {
170
- kind: "array";
171
- result: ArrayCallResult;
172
174
  } | {
173
175
  kind: "numeric-type";
174
176
  result: NumericTypeCallResult;
@@ -181,6 +183,9 @@ export interface FunctionToCall {
181
183
  } | {
182
184
  kind: "arc-value";
183
185
  result: FnCallExpr;
186
+ } | {
187
+ kind: "index";
188
+ result: IndexCallResult;
184
189
  } | {
185
190
  kind: "error";
186
191
  error: Error | YoError;
@@ -190,7 +195,7 @@ export declare function getFunctionCallResult(functionToCall: FunctionToCall): F
190
195
  export declare function getTypeCallResult(functionToCall: FunctionToCall): TypeCallResult;
191
196
  export declare function getModuleTypeCallResult(functionToCall: FunctionToCall): ModuleTypeCallResult;
192
197
  export declare function getTraitTypeCallResult(functionToCall: FunctionToCall): TraitTypeCallResult;
193
- export declare function getArrayCallResult(functionToCall: FunctionToCall): ArrayCallResult;
198
+ export declare function getIndexCallResult(functionToCall: FunctionToCall): IndexCallResult;
194
199
  export declare function getPointerTypeCallResult(functionToCall: FunctionToCall): PointerTypeCallResult;
195
200
  export type EvaluateExpression = ({ expr, env, context, }: {
196
201
  expr: Expr;
@@ -13,12 +13,14 @@ export default class Evaluator {
13
13
  private moduleValue;
14
14
  private moduleError;
15
15
  private allowPartialModule;
16
- constructor({ modulePath, stdPath, loadModule, inputString, allowPartialModule, }: {
16
+ private registerPartialModule;
17
+ constructor({ modulePath, stdPath, loadModule, inputString, allowPartialModule, registerPartialModule, }: {
17
18
  modulePath: string;
18
19
  stdPath: string;
19
20
  loadModule: LoadModuleFn;
20
21
  inputString?: string;
21
22
  allowPartialModule?: boolean;
23
+ registerPartialModule?: (mv: ModuleValue) => void;
22
24
  });
23
25
  getProgram(): Expr[];
24
26
  getTokens(): Token[];
@@ -14,6 +14,7 @@ export declare function checkTypeImplementsSelfConstraints({ targetType, traitTy
14
14
  errorToken: Token;
15
15
  }): void;
16
16
  export declare function typeImplementsComptime(type: Type, env: Environment): boolean;
17
+ export declare function findSomeTypeMissingComptimeConstraint(type: Type, env: Environment): SomeType | undefined;
17
18
  export declare function typeImplementsRuntime(type: Type, env: Environment): boolean;
18
19
  export declare function typeImplementsSend(type: Type | undefined, env: Environment): boolean;
19
20
  export declare function typeImplementsDispose(type: Type | undefined, env: Environment): boolean;
@@ -1,13 +1,14 @@
1
1
  import { type Environment } from "../../env";
2
2
  import { type Expr } from "../../expr";
3
3
  import type { ModuleType } from "../../types/definitions";
4
- import { type ModuleValue } from "../../value";
4
+ import type { ModuleValue } from "../../value";
5
5
  import type { EvaluatorContext } from "../context";
6
- export declare function evaluateAnonymousModuleBeginExprs({ beginExprs, env, context, allowPartialModule, }: {
6
+ export declare function evaluateAnonymousModuleBeginExprs({ beginExprs, env, context, allowPartialModule, registerPartialModule, }: {
7
7
  beginExprs: Expr[];
8
8
  env: Environment;
9
9
  context: EvaluatorContext;
10
10
  allowPartialModule?: boolean;
11
+ registerPartialModule?: (mv: ModuleValue) => void;
11
12
  }): {
12
13
  moduleValue: ModuleValue;
13
14
  moduleType: ModuleType;
@@ -3,7 +3,7 @@ import type { AwaitAnalysisResult } from "./evaluator/async/await-analysis-types
3
3
  import type { EvaluatorContext } from "./evaluator/context";
4
4
  import type { EffectAnalysisResult } from "./evaluator/effects/effect-analysis-types";
5
5
  import { type Token } from "./token";
6
- import type { StructType, Type } from "./types/definitions";
6
+ import type { FunctionType, StructType, Type } from "./types/definitions";
7
7
  import { type ArrayValue, type TraitValue, type Value } from "./value";
8
8
  import { ValueTag } from "./value-tag";
9
9
  export type Path = string[];
@@ -67,6 +67,10 @@ export interface EvaluatedExprData {
67
67
  arrayValue: ArrayValue;
68
68
  index: number;
69
69
  };
70
+ indexTraitPtrType?: Type;
71
+ indexMethodType?: FunctionType;
72
+ indexMethodValue?: Value;
73
+ isIndexTraitAddressOf?: boolean;
70
74
  isCompileTimeOnlyAssignment?: boolean;
71
75
  isAnonymousFunctionDefinition?: boolean;
72
76
  comptimeUnrolledBodies?: Expr[];
@@ -195,6 +199,19 @@ export declare const BuiltinFunctions: {
195
199
  __yo_ptr_set: string[];
196
200
  __yo_slice_len: string[];
197
201
  __yo_slice_new: string[];
202
+ __yo_slice_ptr: string[];
203
+ __yo_array_index: string[];
204
+ __yo_slice_index: string[];
205
+ __yo_array_index_range: string[];
206
+ __yo_array_index_range_inclusive: string[];
207
+ __yo_slice_index_range: string[];
208
+ __yo_slice_index_range_inclusive: string[];
209
+ __yo_comptime_array_index: string[];
210
+ __yo_comptime_slice_index: string[];
211
+ __yo_comptime_array_index_range: string[];
212
+ __yo_comptime_array_index_range_inclusive: string[];
213
+ __yo_comptime_slice_index_range: string[];
214
+ __yo_comptime_slice_index_range_inclusive: string[];
198
215
  __yo_as: string[];
199
216
  __yo_expr_is_atom: string[];
200
217
  __yo_expr_is_fn_call: string[];
@@ -470,6 +487,9 @@ export declare const BuiltinFunctions: {
470
487
  __yo_comptime_string_to_upper: string[];
471
488
  __yo_comptime_string_to_lower: string[];
472
489
  __yo_comptime_string_slice: string[];
490
+ __yo_comptime_string_index: string[];
491
+ __yo_comptime_string_index_range: string[];
492
+ __yo_comptime_string_index_range_inclusive: string[];
473
493
  __yo_type_to_comptime_string: string[];
474
494
  __yo_type_contains_rc_type: string[];
475
495
  __yo_type_can_form_rc_cycle: string[];
@@ -565,6 +585,7 @@ export interface ExprToStringConfig {
565
585
  indentLevel?: number;
566
586
  }
567
587
  export declare function exprToString(expr: Expr, config?: ExprToStringConfig): string;
588
+ export declare function consumeCaseBodyTempVar(evaluatedBody: Expr, env: Environment): Environment;
568
589
  export declare function attachTempVariableToExpr(expr: Expr, isOwningTheRcValue: boolean, isOwningTheSameRcValueAs?: Variable): void;
569
590
  export declare function mergeAndCheckEnvs(env: Environment, bodies: Expr[]): Environment;
570
591
  export declare function replaceFuncCallExprWithFuncCallExpr(funcExpr: FnCallExpr, newFuncExpr: FnCallExpr): void;
@@ -8,6 +8,7 @@ export declare class ModuleManager {
8
8
  }>;
9
9
  private dependencies;
10
10
  private dependents;
11
+ private loadingModules;
11
12
  stdPath: string;
12
13
  private codeGenratorC;
13
14
  private allowPartialModule;
@@ -28,4 +28,5 @@ export declare function isTargetMSVC(target: TargetInfo): boolean;
28
28
  export declare function isTargetWasm(target: TargetInfo): boolean;
29
29
  export declare function isTargetEmscripten(target: TargetInfo): boolean;
30
30
  export declare function isTargetStandaloneWasi(target: TargetInfo): boolean;
31
+ export declare function isTargetMusl(target: TargetInfo): boolean;
31
32
  export declare function isTargetPosix(target: TargetInfo): boolean;
@@ -41,6 +41,8 @@ export type ModuleValue = {
41
41
  tag: ValueTag.Module;
42
42
  type: ModuleType;
43
43
  fields: (Value | undefined)[];
44
+ moduleLevelInitExprs?: Expr[];
45
+ isLoading?: boolean;
44
46
  };
45
47
  export type TraitValue = {
46
48
  tag: ValueTag.Trait;
@@ -73,6 +75,7 @@ export type UnknownValue = {
73
75
  tag: ValueTag.Unknown;
74
76
  type: Type;
75
77
  variableName?: string;
78
+ isRuntimeOnly?: boolean;
76
79
  };
77
80
  export type PtrValue = {
78
81
  tag: ValueTag.Ptr;
@@ -123,7 +126,7 @@ export declare function createUnknownValue(type: Type, { variableName, recursive
123
126
  context: EvaluatorContext;
124
127
  }): UnknownValue | TypeValue;
125
128
  export declare function createStructValue(type: StructType, fields: Value[]): StructValue;
126
- export declare function createModuleValue(type: ModuleType, fields: (Value | undefined)[]): ModuleValue;
129
+ export declare function createModuleValue(type: ModuleType, fields: (Value | undefined)[], moduleLevelInitExprs?: Expr[]): ModuleValue;
127
130
  export declare function createTraitValue(type: TraitType, fields: (Value | undefined)[]): TraitValue;
128
131
  export declare function createTupleValue(type: TupleType, fields: Value[]): TupleValue;
129
132
  export declare function createEnumValue(type: EnumType, variantName: string, fields: Value[]): EnumValue;