UNPKG

@helios-lang/compiler

Version:

Helios is a Domain Specific Language that compiles to Plutus-Core (i.e. Cardano on-chain validator scripts). Helios is a non-Haskell alternative to Plutus. With this library you can compile Helios scripts and build Cardano transactions, all you need to bu

76 lines (68 loc) 1.97 kB
import { $ } from "@helios-lang/ir" import { ToIRContext } from "../codegen/index.js" import { Scope } from "../scopes/index.js" import { DataEntity } from "../typecheck/index.js" import { Expr } from "./Expr.js" import { PathExpr } from "./PathExpr.js" /** * @import { Site, Word } from "@helios-lang/compiler-utils" * @import { SourceMappedStringI } from "@helios-lang/ir" * @import { TypeCheckContext } from "../index.js" * @typedef {import("../typecheck/index.js").EvalEntity} EvalEntity */ /** * Name::Member expression which can instantiate zero field structs and enum members */ export class ValuePathExpr extends PathExpr { /** * @param {Site} site * @param {Expr} baseExpr * @param {Word} memberName */ constructor(site, baseExpr, memberName) { super(site, baseExpr, memberName) } /** * @param {TypeCheckContext} ctx * @param {Scope} scope * @returns {EvalEntity} */ evalInternal(ctx, scope) { const member = super.evalInternal(ctx, scope, false) if ( member.asEnumMemberType && member.asEnumMemberType.fieldNames.length == 0 ) { return new DataEntity(member.asEnumMemberType) } else { return member } } /** * @returns {boolean} */ isLiteral() { return ( (this.cache?.asTyped?.type.asEnumMemberType?.fieldNames?.length ?? -1) == 0 ) } /** * @param {ToIRContext} ctx * @returns {SourceMappedStringI} */ toIR(ctx) { const v = this.cache if ( v?.asTyped?.type?.asEnumMemberType && v.asTyped.type.asEnumMemberType.fieldNames.length == 0 ) { return $([ $(`${v.asTyped.type.asEnumMemberType.path}____new`, this.site), $("()") ]) } else { return super.toIR(ctx) } } }