diff --git a/package-lock.json b/package-lock.json index 89509376..42f9443c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { - "name": "@harmoniclabs/plu-ts", - "version": "0.10.0", + "name": "@harmoniclabs/pebble", + "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@harmoniclabs/plu-ts", - "version": "0.10.0", + "name": "@harmoniclabs/pebble", + "version": "0.1.0", "license": "Apache-2.0", "dependencies": { "@harmoniclabs/bigint-utils": "^1.0.0", diff --git a/src/ast/nodes/expr/functions/CallExpr.ts b/src/ast/nodes/expr/functions/CallExpr.ts index 75101f80..2b38b28b 100644 --- a/src/ast/nodes/expr/functions/CallExpr.ts +++ b/src/ast/nodes/expr/functions/CallExpr.ts @@ -1,4 +1,5 @@ import { SourceRange } from "../../../Source/SourceRange"; +import { Identifier } from "../../common/Identifier"; import { HasSourceRange } from "../../HasSourceRange"; import { PebbleAstType } from "../../types/PebbleAstType"; import { PebbleExpr } from "../PebbleExpr"; diff --git a/src/compiler/AstCompiler/AstCompiler.ts b/src/compiler/AstCompiler/AstCompiler.ts index dc5fc1c0..0b9790ab 100644 --- a/src/compiler/AstCompiler/AstCompiler.ts +++ b/src/compiler/AstCompiler/AstCompiler.ts @@ -85,8 +85,8 @@ export class AstCompiler extends DiagnosticEmitter super( diagnostics ); } - readonly depGraph = new DependencyGraph(); - readonly exportedSymbols = new Map(); + // readonly depGraph = new DependencyGraph(); + // readonly exportedSymbols = new Map(); async compileFile( path: string, @@ -115,11 +115,24 @@ export class AstCompiler extends DiagnosticEmitter async compileSource( src: Source ) { - await this._typeCheck( src ); + await this._checkCircularDependencies( src ); return this.diagnostics; } + async checkCircularDependencies( src: Source | Path ): Promise + { + if(!( src instanceof Source )) + { + src = src.toString(); + src = mangleInternalPath( removeSingleDotDirsFromPath( src ) ); + src = (await this.sourceFromInternalPath( src ))!; + if( !src ) return this.diagnostics; + } + await this._checkCircularDependencies( src ); + return this.diagnostics; + } + /** MUST NOT be used as a "seen" log */ private readonly _sourceCache = new Map(); async sourceFromInternalPath( @@ -154,24 +167,11 @@ export class AstCompiler extends DiagnosticEmitter return this._sourceCache.get( internalPath ); } - async typeCheck( src: Source | Path ): Promise - { - if(!( src instanceof Source )) - { - src = src.toString(); - src = mangleInternalPath( removeSingleDotDirsFromPath( src ) ); - src = (await this.sourceFromInternalPath( src ))!; - if( !src ) return this.diagnostics; - } - await this._typeCheck( src ); - return this.diagnostics; - } - /** * * @returns `true` if there were no errors. `false` otherwise. */ - private async _typeCheck( + private async _checkCircularDependencies( source: Source | ResolveStackNode ): Promise { @@ -254,13 +254,11 @@ export class AstCompiler extends DiagnosticEmitter const imports = stmts.filter( isImportStmtLike ); - const srcPath = src.internalPath; - - const importPaths = this.importPathsFromStmts( imports, srcPath ); - - this.depGraph.addDependencies( srcPath, importPaths ); + // const srcPath = src.internalPath; + // const importPaths = this.importPathsFromStmts( imports, srcPath ); + // this.depGraph.addDependencies( srcPath, importPaths ); - return await this.typeCheckDependencies( + return await this.checkCircularDependenciesDependencies( imports, resolveStack ); @@ -290,7 +288,7 @@ export class AstCompiler extends DiagnosticEmitter .filter( path => path !== "" ); } - async typeCheckDependencies( + async checkCircularDependenciesDependencies( imports: ImportStmtLike[], dependent: ResolveStackNode ): Promise @@ -306,7 +304,7 @@ export class AstCompiler extends DiagnosticEmitter if( !src ) continue; // error already reported parsing import const resolveStack = new ResolveStackNode( dependent, src ); - if( !await this._typeCheck( resolveStack ) ) return false; + if( !await this._checkCircularDependencies( resolveStack ) ) return false; } return true; diff --git a/src/compiler/AstCompiler/__test__/compiler.ast.depGraph.test.ts b/src/compiler/AstCompiler/__test__/compiler.ast.depGraph.test.ts index 16455552..9a56e7e5 100644 --- a/src/compiler/AstCompiler/__test__/compiler.ast.depGraph.test.ts +++ b/src/compiler/AstCompiler/__test__/compiler.ast.depGraph.test.ts @@ -57,7 +57,7 @@ const complier = new AstCompiler( ); test("type check", async () => { - const diagnostics = await complier.typeCheck("a.pebble"); + const diagnostics = await complier.checkCircularDependencies("a.pebble"); expect( diagnostics.length ) // at least the 3 files in the cycle diff --git a/src/compiler/path/path.ts b/src/compiler/path/path.ts index 4eed52d6..ae8c2406 100644 --- a/src/compiler/path/path.ts +++ b/src/compiler/path/path.ts @@ -145,8 +145,8 @@ export function resolveAsRootPath( toResolve: string, fromPath: string ): string result = result === "." || result.endsWith( fromDirname.slice( 0, fromDirname.length - 1 ) ) ? result + PATH_DELIMITER : result; - result = result.startsWith("/") ? result : "/" + result; - + // result = result.startsWith("/") ? result : "/" + result; + return result; } diff --git a/src/parser/Parser.ts b/src/parser/Parser.ts index a54f3f4d..54da1159 100644 --- a/src/parser/Parser.ts +++ b/src/parser/Parser.ts @@ -2083,7 +2083,7 @@ export class Parser extends DiagnosticEmitter const inner = this.joinPropertyCall( startPos, expr, - callee + callee as CallExpr ); if( !inner ) return undefined; call = new CallExpr( diff --git a/src/pluts/API/V2/ScriptContext/PTxInfo/__tests__/PTxInfo.pmatch.extract.input.value.test.ts b/src/pluts/API/V2/ScriptContext/PTxInfo/__tests__/PTxInfo.pmatch.extract.input.value.test.ts deleted file mode 100644 index be23014a..00000000 --- a/src/pluts/API/V2/ScriptContext/PTxInfo/__tests__/PTxInfo.pmatch.extract.input.value.test.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { Machine } from "@harmoniclabs/plutus-machine"; -import { PValue } from "../../../../V1/Value/PValue"; -import { pBool, punMapData, toData } from "../../../../../lib"; -import { tx_v2, beef32 } from "../../../../../../utils/test_utils"; - -describe.skip("input value extraction", () => { - - test("extract tx_v2.inputs", () => { - - expect( - () => tx_v2.extract("inputs").in( ({ inputs }) => inputs ).toUPLC(0) - ).not.toThrow() - - }) - - test("extracts input value", () => { - - const uplc = tx_v2.extract("inputs").in( ({ inputs }) => - inputs.head.extract("resolved").in( ({ resolved: input }) => - input.extract("value").in( ({ value }) => value - ))).toUPLC(0); - - // console.log( showUPLC( uplc ) ) - - const res = Machine.evalSimple( - uplc - ); - - // console.log( res ); - - const expected = Machine.evalSimple( - punMapData.$( toData( PValue.type )( beef32 ) ) - ); - - // console.log( expected ) - - expect( - res - ).toEqual( - expected - ); - - }); - - test("extracts signatories", () => { - - const term = tx_v2.signatories.head.eq("deadbeef"); - const uplc = term.toUPLC(0); - const res = Machine.evalSimple( - uplc - ); - - expect( - res - ).toEqual( - Machine.evalSimple( - pBool( true ) - ) - ) - }) - -}) \ No newline at end of file diff --git a/src/pluts/API/V2/index.ts b/src/pluts/API/V2/index.ts index 57c7b73f..468eed16 100644 --- a/src/pluts/API/V2/index.ts +++ b/src/pluts/API/V2/index.ts @@ -11,7 +11,7 @@ import { POutputDatum } from "./Tx/POutputDatum"; import { PTxOut } from "./Tx/PTxOut"; import { PTxInInfo } from "./Tx/PTxInInfo"; -export const V2 = Object.freeze({ +export const V2: typeof V1 = Object.freeze({ ...V1, PScriptContext, @@ -20,4 +20,4 @@ export const V2 = Object.freeze({ POutputDatum, PTxInInfo, PTxOut -} as const); \ No newline at end of file +} as any); \ No newline at end of file diff --git a/src/type_system/ts-pluts-conversion.ts b/src/type_system/ts-pluts-conversion.ts index 84f33d54..62329086 100644 --- a/src/type_system/ts-pluts-conversion.ts +++ b/src/type_system/ts-pluts-conversion.ts @@ -1,9 +1,7 @@ -import { PType } from "../PType"; -import { PInt, PByteString, PString, PUnit, PBool, PList, PPair, PDelayed, PLam, PAlias, PStruct, PData, PAsData } from "../PTypes"; -import { PBlsG1 } from "../PTypes/PBlsG1"; -import { PBlsG2 } from "../PTypes/PBlsG2"; -import { PBlsMlRes } from "../PTypes/PBlsMlRes"; -import { PSop } from "../PTypes/PSoP/psop"; +import { PAlias, PAsData, PBool, PByteString, PData, PDelayed, PInt, PLam, PList, PPair, PSop, PString, PStruct, PType, PUnit } from "../pluts"; +import { PBlsG1 } from "../pluts/PTypes/PBlsG1"; +import { PBlsG2 } from "../pluts/PTypes/PBlsG2"; +import { PBlsMlRes } from "../pluts/PTypes/PBlsMlRes"; import { AliasT, GenericTermType, Methods, NonAliasTermType, PrimType, SopDefinition, StructDefinition, TermType } from "./types"; export type ToPType = diff --git a/src/utils/test_utils.ts b/src/utils/test_utils.ts deleted file mode 100644 index 6220b742..00000000 --- a/src/utils/test_utils.ts +++ /dev/null @@ -1,188 +0,0 @@ -import { - pByteString, - pList, - toData, - pDataI, - pPair, - pInt, - V1, - V2, - pBool, - addUtilityForType, - PMaybe, -} from "../pluts"; -import { bs, bool, data, list, map, pair, int } from "../type_system"; - -export const unitDatumHash = V2.PDatumHash.from( pByteString("923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec") ); -export const emptyValue = V2.PValue.from( pList( V2.PValueEntry.type )([]) as any ); - -export const emptyValueAsData = toData( V2.PValue.type )( emptyValue ); - -export const validatorSpendingUtxo = V2.PTxOutRef.PTxOutRef({ - id: toData( V2.PTxId.type )( - V2.PTxId.PTxId({ - txId: toData( bs )( pByteString("deadbeef") ) - }) - ), - index: pDataI( 0 ) -}); - -export const validatorSpendingUtxoAsData = toData( V2.PTxOutRef.type )( validatorSpendingUtxo ); - -export const beef32 = V2.PValue.from( - pList( V2.PValueEntry.type )([ - V2.PValueEntry.from([ - V2.PCurrencySymbol.from( pByteString("deadbeef") ), - pList( V2.PAssetsEntry.type )([ - V2.PAssetsEntry.from([ - V2.PTokenName.from( pByteString("beef") ), - pInt( 32 ) - ]) - ]) - ]) - ]) -); - -export const beef32AsData = toData( V2.PValue.type )( beef32 ); - -export const datums = toData( map( V2.PDatumHash.type, data ) ) -( - pList( pair( V2.PDatumHash.type, data ) )([]) -); - -export const dCertificates = toData( list( V2.PDCert.type ) ) -( - pList( V2.PDCert.type )([]) -); - -export const txId = toData( V2.PTxId.type )( - V2.PTxId.PTxId({ - txId: toData( bs )( pByteString("deadbeef") ) - }) -); - -export const interval = toData( V2.PPOSIXTimeRange.type )( - V2.PPOSIXTimeRange.PInterval({ - from: toData( V2.PBound.type )( - V2.PBound.PBound({ - bound: toData( V2.PExtended.type )( V2.PExtended.PFinite({ n: pDataI(1) }) ), - inclusive: toData( bool )( pBool( false ) ) - }) - ), - to: toData( V2.PBound.type )( - V2.PBound.PBound({ - bound: toData( V2.PExtended.type )( V2.PExtended.PPosInf({}) ), - inclusive: toData( bool )( pBool( false ) ) - }) - ) - }) -); - -export const signatories = toData( list( V2.PPubKeyHash.type ) )( pList( V2.PPubKeyHash.type )([ - V2.PPubKeyHash.from("deadbeef") -]) ); - -export const withdrawals = - toData( map( V2.PStakingCredential.type,int ) )( - pList( pair( V2.PStakingCredential.type, int ) )([]) - ); - -export const address = toData( V2.PAddress.type )( - V2.PAddress.PAddress({ - credential: V2.PCredential.PScriptCredential({ - valHash: toData( V2.PValidatorHash.type )( V2.PValidatorHash.from( pByteString("caffee") ) ) - }) as any, - stakingCredential: PMaybe( V2.PStakingCredential.type ).Nothing({}) as any - }) -); - -export const inputs = toData( list( V1.PTxInInfo.type ) )( - pList( V1.PTxInInfo.type )([ - V1.PTxInInfo.PTxInInfo({ - utxoRef: validatorSpendingUtxoAsData, - resolved: toData( V1.PTxOut.type )( - V1.PTxOut.PTxOut({ - address, - datumHash: PMaybe( V2.PDatumHash.type ).Just({ val: toData( V2.PDatumHash.type )(unitDatumHash) }) as any, - value: beef32AsData as any - }) - ) - }) - ]) -) - -export const outputs = toData( list( V1.PTxOut.type ) )( - pList( V1.PTxOut.type )([]) -); - -export const txInfo_v1 = V1.PTxInfo.PTxInfo({ - datums, - dCertificates, - fee: emptyValueAsData as any, - mint: emptyValueAsData as any, - id: txId, - interval, - signatories, - withdrawals, - inputs, - outputs -}); - -export const _purp = V2.PScriptPurpose.Spending({ - utxoRef: validatorSpendingUtxoAsData -}); - -export const ctx = V1.PScriptContext.PScriptContext({ - tx: toData( V1.PTxInfo.type )( txInfo_v1 ), - purpose: toData( V2.PScriptPurpose.type )( _purp ) -}); - -export const v2_out = toData( V2.PTxOut.type ) -( - V2.PTxOut.PTxOut({ - address, - value: beef32AsData as any, - datum: V2.POutputDatum.NoDatum({}) as any, - refScrpt: PMaybe( V2.PValidatorHash.type ).Nothing({}) as any - }) -) - -export const v2_inputs = toData( list( V2.PTxInInfo.type ) ) -( - pList( V2.PTxInInfo.type )([ - V2.PTxInInfo.PTxInInfo({ - utxoRef: validatorSpendingUtxoAsData, - resolved: v2_out - }) - ]) -) - -export const empty_v2_outs = toData( list(V2.PTxOut.type) )( - pList( V2.PTxOut.type )([]) -); - -export const empty_redeemers = toData( map( V2.PScriptPurpose.type, data ) )( - pList( pair( V2.PScriptPurpose.type, data ) )([]) -); - -export const empty_refInputs = toData( list( V2.PTxInInfo.type ) )( - pList( V2.PTxInInfo.type )([]) -) - -export const tx_v2 = addUtilityForType( V2.PTxInfo.type )( - - V2.PTxInfo.PTxInfo({ - datums, - dCertificates, - fee: emptyValueAsData as any, - mint: emptyValueAsData as any, - id: txId, - interval, - signatories, - withdrawals, - inputs: v2_inputs, - outputs: empty_v2_outs, - redeemers: empty_redeemers, - refInputs: empty_refInputs - }) -); \ No newline at end of file