Skip to content

[WIP] compiler: extern fn #8119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ words:
- lzutf
- MACVMIMAGE
- MACVMIMAGEM
- marshal
- mday
- mgmt
- mgmtplane
Expand Down Expand Up @@ -257,6 +258,7 @@ words:
- Ungroup
- uninstantiated
- unioned
- unmarshal
- unparented
- unprefixed
- unprojected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import type { TypeSpecPrototypesDecorators } from "./TypeSpec.Prototypes.js";
/**
* An error here would mean that the exported decorator is not using the same signature. Make sure to have export const $decName: DecNameDecorator = (...) => ...
*/
const _: TypeSpecPrototypesDecorators = $decorators["TypeSpec.Prototypes"];
const _decs: TypeSpecPrototypesDecorators = $decorators["TypeSpec.Prototypes"];
2 changes: 1 addition & 1 deletion packages/compiler/generated-defs/TypeSpec.ts-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import type { TypeSpecDecorators } from "./TypeSpec.js";
/**
* An error here would mean that the exported decorator is not using the same signature. Make sure to have export const $decName: DecNameDecorator = (...) => ...
*/
const _: TypeSpecDecorators = $decorators["TypeSpec"];
const _decs: TypeSpecDecorators = $decorators["TypeSpec"];
1 change: 1 addition & 0 deletions packages/compiler/lib/std/reflection.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ model Scalar {}
model Union {}
model UnionVariant {}
model StringTemplate {}
model Type {}
16 changes: 15 additions & 1 deletion packages/compiler/src/core/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EnumStatementNode,
FileLibraryMetadata,
FunctionDeclarationStatementNode,
FunctionImplementations,
FunctionParameterNode,
InterfaceStatementNode,
IntersectionExpressionNode,
Expand Down Expand Up @@ -133,7 +134,7 @@ export function createBinder(program: Program): Binder {

for (const [key, member] of Object.entries(sourceFile.esmExports)) {
let name: string;
let kind: "decorator" | "function";
let kind: "decorator" | "function" | "template";
if (key === "$flags") {
const context = getLocationContext(program, sourceFile);
if (context.type === "library" || context.type === "project") {
Expand All @@ -152,6 +153,19 @@ export function createBinder(program: Program): Binder {
);
}
}
} else if (key === "$functions") {
const value: FunctionImplementations = member as any;
for (const [namespaceName, functions] of Object.entries(value)) {
for (const [functionName, fn] of Object.entries(functions)) {
bindFunctionImplementation(
namespaceName === "" ? [] : namespaceName.split("."),
"function",
functionName,
fn,
sourceFile,
);
}
}
} else if (typeof member === "function") {
// lots of 'any' casts here because control flow narrowing `member` to Function
// isn't particularly useful it turns out.
Expand Down
Loading
Loading