Skip to content

Commit

Permalink
outputdatum constructors can be called anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
christianschmitz committed Mar 27, 2023
1 parent ac82fc6 commit db43db3
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 38 deletions.
2 changes: 1 addition & 1 deletion helios.d.ts
Expand Up @@ -185,7 +185,7 @@ export function highlight(src: string): Uint8Array;
/**
* Version of the Helios library.
*/
export const VERSION: "0.13.5";
export const VERSION: "0.13.6";
/**
* Modifiable config vars
* @type {{
Expand Down
43 changes: 25 additions & 18 deletions helios.js
Expand Up @@ -7,7 +7,7 @@
// Email: cschmitz398@gmail.com
// Website: https://www.hyperion-bt.org
// Repository: https://github.com/hyperion-bt/helios
// Version: 0.13.5
// Version: 0.13.6
// Last update: March 2023
// License: Unlicense
//
Expand Down Expand Up @@ -219,7 +219,7 @@
/**
* Version of the Helios library.
*/
export const VERSION = "0.13.5";
export const VERSION = "0.13.6";

/**
* A tab used for indenting of the IR.
Expand Down Expand Up @@ -16783,23 +16783,26 @@ class OutputDatumType extends BuiltinType {
getTypeMember(name) {
switch (name.value) {
case "new_none":
if (this.macrosAllowed) {
return Instance.new(new FuncType([], new NoOutputDatumType()));
} else {
throw name.referenceError("'OutputDatum::new_none' only allowed after 'main'");
}
return Instance.new(new FuncType([], new NoOutputDatumType()));
case "new_hash":
if (this.macrosAllowed) {
return Instance.new(new FuncType([new DatumHashType()], new HashedOutputDatumType()));
} else {
throw name.referenceError("'OutputDatum::new_hash' only allowed after 'main'");
}
case "new_inline":
if (this.macrosAllowed) {
return Instance.new(new FuncType([new AnyDataType()], new InlineOutputDatumType()));
} else {
throw name.referenceError("'OutputDatum::new_inline' only allowed after 'main'");
}
return Instance.new(new FuncType([new DatumHashType()], new HashedOutputDatumType()));
case "new_inline": {
let a = new ParamType("a");
return new ParamFuncValue([a], new FuncType([a], new InlineOutputDatumType()), () => {
let type = a.type;
if (type === null) {
throw new Error("should've been inferred by now");
} else {
if (a.type instanceof FuncType) {
throw name.site.typeError("can't use function as argument to OutputDatum::new_inline()");
} else if ((new BoolType()).isBaseOf(Site.dummy(), type)) {
return "new_inline_from_bool";
} else {
return "new_inline";
}
}
});
}
case "None":
return new NoOutputDatumType();
case "Hash":
Expand Down Expand Up @@ -28062,6 +28065,10 @@ function makeRawFunctions() {
`(data) -> {
__core__constrData(2, __helios__common__list_1(data))
}`));
add(new RawFunc("__helios__outputdatum__new_inline_from_bool",
`(b) -> {
__helios__outputdatum__new_inline(_helios__common__boolData(b))
}`));
add(new RawFunc("__helios__outputdatum__get_inline_data",
`(self) -> {
() -> {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "@hyperionbt/helios",
"type": "module",
"version": "0.13.5",
"version": "0.13.6",
"description": "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 build 100% client-side DApps for Cardano.",
"main": "helios.js",
"types": "helios.d.ts",
Expand Down
35 changes: 19 additions & 16 deletions src/helios-eval-entities.js
Expand Up @@ -4379,23 +4379,26 @@ export class OutputDatumType extends BuiltinType {
getTypeMember(name) {
switch (name.value) {
case "new_none":
if (this.macrosAllowed) {
return Instance.new(new FuncType([], new NoOutputDatumType()));
} else {
throw name.referenceError("'OutputDatum::new_none' only allowed after 'main'");
}
return Instance.new(new FuncType([], new NoOutputDatumType()));
case "new_hash":
if (this.macrosAllowed) {
return Instance.new(new FuncType([new DatumHashType()], new HashedOutputDatumType()));
} else {
throw name.referenceError("'OutputDatum::new_hash' only allowed after 'main'");
}
case "new_inline":
if (this.macrosAllowed) {
return Instance.new(new FuncType([new AnyDataType()], new InlineOutputDatumType()));
} else {
throw name.referenceError("'OutputDatum::new_inline' only allowed after 'main'");
}
return Instance.new(new FuncType([new DatumHashType()], new HashedOutputDatumType()));
case "new_inline": {
let a = new ParamType("a");
return new ParamFuncValue([a], new FuncType([a], new InlineOutputDatumType()), () => {
let type = a.type;
if (type === null) {
throw new Error("should've been inferred by now");
} else {
if (a.type instanceof FuncType) {
throw name.site.typeError("can't use function as argument to OutputDatum::new_inline()");
} else if ((new BoolType()).isBaseOf(Site.dummy(), type)) {
return "new_inline_from_bool";
} else {
return "new_inline";
}
}
});
}
case "None":
return new NoOutputDatumType();
case "Hash":
Expand Down
4 changes: 4 additions & 0 deletions src/ir-defs.js
Expand Up @@ -2912,6 +2912,10 @@ function makeRawFunctions() {
`(data) -> {
__core__constrData(2, __helios__common__list_1(data))
}`));
add(new RawFunc("__helios__outputdatum__new_inline_from_bool",
`(b) -> {
__helios__outputdatum__new_inline(_helios__common__boolData(b))
}`));
add(new RawFunc("__helios__outputdatum__get_inline_data",
`(self) -> {
() -> {
Expand Down

0 comments on commit db43db3

Please sign in to comment.