@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
60 lines (52 loc) • 1.24 kB
JavaScript
import { $ } from "@helios-lang/ir"
import { ToIRContext } from "../codegen/index.js"
import { Scope } from "../scopes/index.js"
import { Expr } from "./Expr.js"
/**
* @import { Word } from "@helios-lang/compiler-utils"
* @typedef {import("@helios-lang/ir").SourceMappedStringI} SourceMappedStringI
* @typedef {import("../typecheck/index.js").EvalEntity} EvalEntity
*/
/**
* Simple reference class (i.e. using a Word)
*/
export class RefExpr extends Expr {
/**
* @readonly
* @type {Word}
*/
name
/**
* @param {Word} name
*/
constructor(name) {
super(name.site)
this.name = name
}
/**
* @param {Scope} scope
* @returns {EvalEntity}
*/
evalInternal(scope) {
if (this.name.value == "Some") {
throw new Error("unexpected")
}
return scope.get(this.name)
}
/**
* @param {ToIRContext} _ctx
* @returns {SourceMappedStringI}
*/
toIR(_ctx) {
const path = this.cache?.asNamed
? this.cache.asNamed.path
: this.name.value
return $(path, this.site)
}
/**
* @returns {string}
*/
toString() {
return this.name.toString()
}
}