Skip to content

Commit

Permalink
path functions
Browse files Browse the repository at this point in the history
  • Loading branch information
michele-nuzzi committed Feb 6, 2025
1 parent 5cdabc6 commit fb3c245
Show file tree
Hide file tree
Showing 26 changed files with 380 additions and 197 deletions.
6 changes: 3 additions & 3 deletions src/ast/PebbleAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { isVarDecl, VarDecl } from "./nodes/statements/declarations/VarDecl/VarD
import { Identifier } from "./nodes/common/Identifier";
import { isPebbleExpr, PebbleExpr } from "./nodes/expr/PebbleExpr";
import { isPebbleStmt, PebbleStmt } from "./nodes/statements/PebbleStmt";
import { isPebbleType, PebbleType } from "./nodes/types/PebbleType";
import { isPebbleAstType, PebbleAstType } from "./nodes/types/PebbleAstType";
import { isPebbleDecl, PebbleDecl } from "./nodes/statements/declarations/PebbleDecl";


export type PebbleAst
= VarDecl
| PebbleStmt
| PebbleExpr
| PebbleType
| PebbleAstType
| Identifier
| PebbleDecl
;
Expand All @@ -22,7 +22,7 @@ export function isPebbleAst( thing: any ): thing is PebbleAst
|| isVarDecl( thing )
|| isPebbleStmt( thing )
|| isPebbleExpr( thing )
|| isPebbleType( thing )
|| isPebbleAstType( thing )
|| isPebbleDecl( thing )
);
}
2 changes: 1 addition & 1 deletion src/ast/Source/Source.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LIBRARY_PREFIX, PATH_DELIMITER, LIBRARY_SUBST } from "../../common";
import { CharCode } from "../../utils/CharCode";
import { mangleInternalPath } from "../../utils/mangleInternalPath";
import { mangleInternalPath } from "../../compiler/path/mangleInternalPath";
import { PebbleStmt } from "../nodes/statements/PebbleStmt";
import { PebbleAst } from "../PebbleAst";
import { SourceRange } from "./SourceRange";
Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/expr/ElemAccessExpr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SourceRange } from "../../Source/SourceRange";
import { HasSourceRange } from "../HasSourceRange";
import { PebbleType } from "../types/PebbleType";
import { PebbleAstType } from "../types/PebbleAstType";
import { PebbleExpr } from "./PebbleExpr";


Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/expr/InstanceOfExpr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SourceRange } from "../../Source/SourceRange";
import { HasSourceRange } from "../HasSourceRange";
import { PebbleType } from "../types/PebbleType";
import { PebbleAstType } from "../types/PebbleAstType";
import { PebbleExpr } from "./PebbleExpr";


Expand All @@ -9,7 +9,7 @@ export class InstanceOfExpr
{
constructor(
readonly instanceExpr: PebbleExpr,
readonly ofType: PebbleType,
readonly ofType: PebbleAstType,
readonly range: SourceRange
) {}
}
2 changes: 1 addition & 1 deletion src/ast/nodes/expr/NonNullExpr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SourceRange } from "../../Source/SourceRange";
import { HasSourceRange } from "../HasSourceRange";
import { PebbleType } from "../types/PebbleType";
import { PebbleAstType } from "../types/PebbleAstType";
import { PebbleExpr } from "./PebbleExpr";


Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/expr/TypeConversionExpr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SourceRange } from "../../Source/SourceRange";
import { HasSourceRange } from "../HasSourceRange";
import { PebbleType } from "../types/PebbleType";
import { PebbleAstType } from "../types/PebbleAstType";
import { PebbleExpr } from "./PebbleExpr";


Expand All @@ -9,7 +9,7 @@ export class TypeConversionExpr
{
constructor(
readonly expr: PebbleExpr,
readonly asType: PebbleType,
readonly asType: PebbleAstType,
readonly range: SourceRange = SourceRange.join( expr.range, asType.range )
) {}
}
4 changes: 2 additions & 2 deletions src/ast/nodes/expr/functions/CallExpr.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { SourceRange } from "../../../Source/SourceRange";
import { HasSourceRange } from "../../HasSourceRange";
import { PebbleType } from "../../types/PebbleType";
import { PebbleAstType } from "../../types/PebbleAstType";
import { PebbleExpr } from "../PebbleExpr";

export class CallExpr implements HasSourceRange
{
constructor(
readonly func: PebbleExpr,
/** if the function is generic */
readonly genericTypeArgs: PebbleType[] | undefined,
readonly genericTypeArgs: PebbleAstType[] | undefined,
readonly args: PebbleExpr[],
readonly range: SourceRange
) {}
Expand Down
8 changes: 4 additions & 4 deletions src/ast/nodes/statements/TypeImplementsStmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { Identifier } from "../common/Identifier";
import { HasSourceRange } from "../HasSourceRange";
import { NamedType } from "../types/NamedType";
import { FuncType } from "../types/NativeType";
import { PebbleType } from "../types/PebbleType";
import { PebbleAstType } from "../types/PebbleAstType";
import { BlockStmt } from "./BlockStmt";


export class TypeImplementsStmt
implements HasSourceRange
{
constructor(
readonly typeIdentifier: PebbleType,
readonly interfaceType: PebbleType | undefined,
readonly typeIdentifier: PebbleAstType,
readonly interfaceType: PebbleAstType | undefined,
readonly methodImplementations: InterfaceMethodImpl[],
readonly range: SourceRange,
) {}
Expand All @@ -23,7 +23,7 @@ export class InterfaceMethodImpl
{
constructor(
readonly methodName: Identifier,
readonly typeParameters: PebbleType[],
readonly typeParameters: PebbleAstType[],
readonly signature: FuncType,
readonly body: BlockStmt,
readonly range: SourceRange,
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/statements/declarations/FuncDecl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { HasSourceRange } from "../../HasSourceRange";
import { BlockStmt } from "../BlockStmt";
import { NamedType } from "../../types/NamedType";
import { FuncType } from "../../types/NativeType";
import { PebbleType } from "../../types/PebbleType";
import { PebbleAstType } from "../../types/PebbleAstType";

export class FuncDecl
implements HasSourceRange
{
constructor(
readonly name: Identifier,
readonly flags: CommonFlags,
readonly typeParams: PebbleType[],
readonly typeParams: PebbleAstType[],
readonly signature: FuncType,
readonly body: BlockStmt | PebbleExpr,
readonly arrowKind: ArrowKind,
Expand Down
6 changes: 3 additions & 3 deletions src/ast/nodes/statements/declarations/InterfaceDecl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { HasSourceRange } from "../../HasSourceRange";
import { BlockStmt } from "../BlockStmt";
import { NamedType } from "../../types/NamedType";
import { FuncType } from "../../types/NativeType";
import { PebbleType } from "../../types/PebbleType";
import { PebbleAstType } from "../../types/PebbleAstType";

export class InterfaceDecl
implements HasSourceRange
{
constructor(
readonly name: Identifier,
readonly typeParams: PebbleType[],
readonly typeParams: PebbleAstType[],
readonly methods: InterfaceDeclMethod[],
readonly range: SourceRange
) {}
Expand All @@ -22,7 +22,7 @@ export class InterfaceDeclMethod
{
constructor(
readonly name: Identifier,
readonly typeParams: PebbleType[],
readonly typeParams: PebbleAstType[],
readonly signature: FuncType,
readonly body: BlockStmt | undefined,
readonly range: SourceRange
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/statements/declarations/StructDecl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SourceRange } from "../../../Source/SourceRange";
import { Identifier } from "../../common/Identifier";
import { HasSourceRange } from "../../HasSourceRange";
import { PebbleType } from "../../types/PebbleType";
import { PebbleAstType } from "../../types/PebbleAstType";
import { VarDecl } from "./VarDecl/VarDecl";


Expand All @@ -10,7 +10,7 @@ export class StructDecl
{
constructor(
readonly name: Identifier,
readonly typeParams: PebbleType[],
readonly typeParams: PebbleAstType[],
readonly constrs: StructConstrDecl[],
readonly range: SourceRange
) {}
Expand Down
6 changes: 3 additions & 3 deletions src/ast/nodes/statements/declarations/TypeAliasDecl.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { SourceRange } from "../../../Source/SourceRange";
import { HasSourceRange } from "../../HasSourceRange";
import { PebbleType } from "../../types/PebbleType";
import { PebbleAstType } from "../../types/PebbleAstType";


export class TypeAliasDecl
implements HasSourceRange
{
constructor(
readonly typeIdentifier: PebbleType,
readonly aliasedType: PebbleType,
readonly typeIdentifier: PebbleAstType,
readonly aliasedType: PebbleAstType,
readonly range: SourceRange,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SourceRange } from "../../../../Source/SourceRange";
import { Identifier } from "../../../common/Identifier";
import { PebbleExpr } from "../../../expr/PebbleExpr";
import { HasSourceRange } from "../../../HasSourceRange";
import { PebbleType } from "../../../types/PebbleType";
import { PebbleAstType } from "../../../types/PebbleAstType";
import { HasInitExpr } from "./HasInit";
import { VarDecl } from "./VarDecl";

Expand All @@ -12,7 +12,7 @@ export class ArrayLikeDeconstr
constructor(
readonly elements: VarDecl[],
readonly rest: Identifier | undefined,
readonly type: PebbleType | undefined, // just for the type checker, ususally this is inferred
readonly type: PebbleAstType | undefined, // just for the type checker, ususally this is inferred
readonly initExpr: PebbleExpr | undefined,
readonly range: SourceRange,
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SourceRange } from "../../../../Source/SourceRange";
import { Identifier } from "../../../common/Identifier";
import { PebbleExpr } from "../../../expr/PebbleExpr";
import { HasSourceRange } from "../../../HasSourceRange";
import { PebbleType } from "../../../types/PebbleType";
import { PebbleAstType } from "../../../types/PebbleAstType";
import { ISingleDeconstructVarDecl, SingleDeconstructVarDecl } from "./SingleDeconstructVarDecl";
import { VarDecl } from "./VarDecl";

Expand All @@ -13,7 +13,7 @@ export class NamedDeconstructVarDecl
readonly name: Identifier,
readonly fields: Map<string, VarDecl>,
readonly rest: Identifier | undefined,
readonly type: PebbleType | undefined, // can be undefined when use ad function parameter
readonly type: PebbleAstType | undefined, // can be undefined when use ad function parameter
readonly initExpr: PebbleExpr | undefined, // can be undefined when use ad function parameter
readonly range: SourceRange,
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { SourceRange } from "../../../../Source/SourceRange";
import { Identifier } from "../../../common/Identifier";
import { PebbleExpr } from "../../../expr/PebbleExpr";
import { HasSourceRange } from "../../../HasSourceRange";
import { PebbleType } from "../../../types/PebbleType";
import { PebbleAstType } from "../../../types/PebbleAstType";
import { HasInitExpr } from "./HasInit";

export class SimpleVarDecl
implements HasSourceRange, HasInitExpr
{
constructor(
readonly name: Identifier,
readonly type: PebbleType | undefined,
readonly type: PebbleAstType | undefined,
readonly initExpr: PebbleExpr | undefined,
readonly range: SourceRange,
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { SourceRange } from "../../../../Source/SourceRange";
import { Identifier } from "../../../common/Identifier";
import { PebbleExpr } from "../../../expr/PebbleExpr";
import { HasSourceRange } from "../../../HasSourceRange";
import { PebbleType } from "../../../types/PebbleType";
import { PebbleAstType } from "../../../types/PebbleAstType";
import { HasInitExpr } from "./HasInit";
import { VarDecl } from "./VarDecl";

export interface ISingleDeconstructVarDecl extends HasInitExpr {
fields: Map<string, VarDecl>;
rest: Identifier | undefined;
type: PebbleType | undefined; // could turn useful in generic types (even with one constr)
type: PebbleAstType | undefined; // could turn useful in generic types (even with one constr)
initExpr: PebbleExpr | undefined; // can be undefined when use ad function parameter
}

Expand All @@ -19,7 +19,7 @@ export class SingleDeconstructVarDecl
constructor(
readonly fields: Map<string, VarDecl>,
readonly rest: Identifier | undefined,
readonly type: PebbleType | undefined,
readonly type: PebbleAstType | undefined,
readonly initExpr: PebbleExpr | undefined,
readonly range: SourceRange
) {}
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/types/NamedType.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { SourceRange } from "../../Source/SourceRange";
import { Identifier } from "../common/Identifier";
import { HasSourceRange } from "../HasSourceRange";
import { PebbleType } from "./PebbleType";
import { PebbleAstType } from "./PebbleAstType";

export class NamedType implements HasSourceRange
{
constructor(
readonly name: Identifier,
readonly tyArgs: PebbleType[],
readonly tyArgs: PebbleAstType[],
readonly range: SourceRange
) {}
}
16 changes: 8 additions & 8 deletions src/ast/nodes/types/NativeType.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { SourceRange } from "../../Source/SourceRange";
import { HasSourceRange } from "../HasSourceRange";
import { VarDecl } from "../statements/declarations/VarDecl/VarDecl";
import { PebbleType } from "./PebbleType";
import { PebbleAstType } from "./PebbleAstType";

export type NativeType
= VoidType
| BooleanType
| NumberType
| BytesType
| NativeOptionalType<PebbleType>
| ListType<PebbleType>
| LinearMapType<PebbleType,PebbleType>
| NativeOptionalType<PebbleAstType>
| ListType<PebbleAstType>
| LinearMapType<PebbleAstType,PebbleAstType>
| FuncType
;

Expand Down Expand Up @@ -56,23 +56,23 @@ export class BytesType implements HasSourceRange
) {}
}

export class NativeOptionalType<TArg extends PebbleType> implements HasSourceRange
export class NativeOptionalType<TArg extends PebbleAstType> implements HasSourceRange
{
constructor(
readonly typeArg: TArg,
readonly range: SourceRange
) {}
}

export class ListType<TArg extends PebbleType> implements HasSourceRange
export class ListType<TArg extends PebbleAstType> implements HasSourceRange
{
constructor(
readonly typeArg: TArg,
readonly range: SourceRange
) {}
}

export class LinearMapType<KT extends PebbleType, VT extends PebbleType> implements HasSourceRange
export class LinearMapType<KT extends PebbleAstType, VT extends PebbleAstType> implements HasSourceRange
{
constructor(
readonly keyTypeArg: KT,
Expand All @@ -85,7 +85,7 @@ export class FuncType implements HasSourceRange
{
constructor(
readonly params: VarDecl[],
readonly returnType: PebbleType | undefined,
readonly returnType: PebbleAstType | undefined,
readonly range: SourceRange
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { isObject } from "@harmoniclabs/obj-utils";
import { isNativeType, NativeType } from "./NativeType";
import { NamedType } from "./NamedType";

export type PebbleType
export type PebbleAstType
= NativeType
| NamedType
;

export function isPebbleType( obj: any ): obj is PebbleType
export function isPebbleAstType( obj: any ): obj is PebbleAstType
{
return isObject( obj ) && (
isNativeType( obj ) ||
Expand Down
Loading

0 comments on commit fb3c245

Please sign in to comment.