-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from 2graphic/types-to-interfaces
Types to interfaces
- Loading branch information
Showing
22 changed files
with
903 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
export type Error = { error: string }; | ||
export type Error = { | ||
kind: "sinap-error", | ||
message: string, | ||
stack?: string, | ||
}; | ||
export type Result = { states: any[], result: any }; | ||
|
||
export interface PluginProgram { | ||
run(a: any): Result | Error; | ||
run(a: any): Result; | ||
validate(): string[]; | ||
} | ||
|
||
export function isError(e: { states: any[], result: any } | { error: any } | null): e is Error { | ||
return e != null && (e as any).error !== undefined; | ||
export function isError(e: any): e is Error { | ||
return e != null && typeof (e.message) === "string" && (e.stack === undefined || typeof (e.stack) === "string") && e.kind === "sinap-error"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,77 @@ | ||
export interface Type { | ||
readonly name: string; | ||
export interface TypeEnvironment { | ||
kind: "SinapTypeEnvironment"; | ||
|
||
getAnyType(): Type; | ||
getStringType(): Type; | ||
getNumberType(): Type; | ||
getBooleanType(): Type; | ||
getVoidType(): Type; | ||
getUndefinedType(): Type; | ||
getNullType(): Type; | ||
getESSymbolType(): Type; | ||
getNeverType(): Type; | ||
getUnknownType(): Type; | ||
getStringLiteralType(text: string): Type; | ||
getNumberLiteralType(text: string): Type; | ||
getFalseType(): Type; | ||
getTrueType(): Type; | ||
lookupGlobalType(name: string): Type; | ||
} | ||
|
||
export interface TypeComparisons { | ||
/** | ||
* Return true if this type is assignable to that type | ||
*/ | ||
isAssignableTo(that: Type, alreadyFlipped?: boolean): boolean; | ||
|
||
/** | ||
* Return if this type is assignable to that type | ||
* Return true if this type is assignable to that type | ||
*/ | ||
isAssignableTo(that: Type): boolean; | ||
isAssignableFrom(that: Type, alreadyFlipped?: boolean): boolean; | ||
|
||
/** | ||
* Return true if this type is identical to that type | ||
*/ | ||
isIdenticalTo(that: Type): boolean; | ||
} | ||
|
||
export interface UnionType { | ||
types: Type[]; | ||
export interface Type extends TypeComparisons { | ||
readonly name: string; | ||
readonly env: TypeEnvironment; | ||
} | ||
|
||
export interface IntersectionType { | ||
export interface UnionType extends Type { | ||
types: Set<Type>; | ||
kind: "SinapUnionType"; | ||
} | ||
|
||
export interface IntersectionType extends Type { | ||
types: Type[]; | ||
kind: "SinapIntersectionType"; | ||
} | ||
|
||
export interface ObjectType { | ||
export interface ObjectType extends Type { | ||
readonly members: Map<string, Type>; | ||
kind: "SinapObjectType"; | ||
isArray(): this is ArrayType; | ||
} | ||
|
||
export interface ArrayType extends ObjectType { | ||
typeArguments: Type[]; | ||
} | ||
|
||
export function isObjectType(t: Type): t is ObjectType { | ||
return t && (t as any).kind === "SinapObjectType"; | ||
} | ||
|
||
export function isUnionType(t: Type): t is UnionType { | ||
return t && (t as any).kind === "SinapUnionType"; | ||
} | ||
|
||
export function isIntersectionType(t: Type): t is IntersectionType { | ||
return t && (t as any).kind === "SinapIntersectionType"; | ||
} | ||
|
||
export function isTypeEnvironment(t: any): t is TypeEnvironment { | ||
return t && t.kind === "SinapTypeEnvironment"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
export * from "./types"; | ||
export * from "./plugin-loader"; | ||
export * from "./value"; | ||
export * from "./element"; | ||
export * from "./plugin"; | ||
export * from "./files"; | ||
export * from "./program" | ||
export * from "./program"; | ||
export * from "../sinap-includes/types-interfaces"; | ||
export * from "./typecheck-json"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.