Skip to content

Commit

Permalink
- ir lib upgrade
Browse files Browse the repository at this point in the history
- prerelease version bump
- implemented Value.from_flat
- refactored some unit-test suites
  • Loading branch information
christianschmitz committed Aug 8, 2024
1 parent 4dd7be3 commit 99bf004
Show file tree
Hide file tree
Showing 10 changed files with 1,399 additions and 1,005 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@helios-lang/compiler",
"version": "0.17.0-28",
"version": "0.17.0-29",
"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": "src/index.js",
"types": "types/index.d.ts",
Expand Down Expand Up @@ -53,7 +53,7 @@
"dependencies": {
"@helios-lang/codec-utils": "^0.1.32",
"@helios-lang/compiler-utils": "^0.1.53",
"@helios-lang/ir": "^0.1.12",
"@helios-lang/ir": "^0.1.13",
"@helios-lang/type-utils": "^0.1.20",
"@helios-lang/uplc": "^0.1.35"
}
Expand Down
202 changes: 202 additions & 0 deletions src/codegen/makeRawFuncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9506,6 +9506,14 @@ export function makeRawFunctions(simplify, isTestnet) {
}`
)
)
add(
new RawFunc(
"__helios__assetclass__mph_data",
`(self) -> {
__helios__common__enum_field_0(self)
}`
)
)
add(
new RawFunc(
"__helios__assetclass__token_name",
Expand All @@ -9514,6 +9522,14 @@ export function makeRawFunctions(simplify, isTestnet) {
}`
)
)
add(
new RawFunc(
"__helios__assetclass__token_name_data",
`(self) -> {
__helios__common__enum_field_1(self)
}`
)
)
add(
new RawFunc(
"__helios__assetclass__show",
Expand Down Expand Up @@ -10672,6 +10688,192 @@ export function makeRawFunctions(simplify, isTestnet) {
}`
)
)
add(
new RawFunc(
`__helios__value__from_flat`,
`(flat_map) -> {
__core__chooseList(
flat_map,
() -> {
__core__mkNilPairData(())
},
() -> {
sorted_map = __helios__map[__helios__assetclass@__helios__int]__sort(flat_map)((keya, _, keyb, _) -> {
__helios__assetclass____lt(keya, keyb)
});
recurse_outer = (flat_map, this_mph_data, this_token_name_data, this_qty_data) -> {
__core__chooseList(
flat_map,
() -> {
__core__mkCons(
__core__mkPairData(
this_mph_data,
__core__mapData(
__core__mkCons(
__core__mkPairData(
this_token_name_data,
this_qty_data
),
__core__mkNilPairData(())
)
)
),
__core__mkNilPairData(())
)
},
() -> {
head = __core__headList(flat_map);
tail = __core__tailList(flat_map);
next_assetclass = __helios__assetclass__from_data(__core__fstPair(head));
next_mph_data = __helios__assetclass__mph_data(next_assetclass);
next_token_name_data = __helios__assetclass__token_name_data(next_assetclass);
next_qty_data = __core__sndPair(head);
__core__ifThenElse(
__core__equalsData(this_mph_data, next_mph_data),
() -> {
__core__ifThenElse(
__core__equalsData(this_token_name_data, next_token_name_data),
() -> {
__helios__error("duplicate assetclass in flat map (outer)")
},
() -> {
// recurse_inner keeps inner and outer map separate
recurse_inner = (flat_map, this_mph_data, this_token_name_data, this_qty_data) -> {
__core__chooseList(
flat_map,
() -> {
(callback) -> {
callback(
__core__mkCons(
__core__mkPairData(
this_token_name_data,
this_qty_data
),
__core__mkNilPairData(())
),
__core__mkNilPairData(())
)
}
},
() -> {
head = __core__headList(flat_map);
tail = __core__tailList(flat_map);
next_assetclass = __helios__assetclass__from_data(__core__fstPair(head));
next_mph_data = __helios__assetclass__mph_data(next_assetclass);
next_token_name_data = __helios__assetclass__token_name_data(next_assetclass);
next_qty_data = __core__sndPair(head);
__core__ifThenElse(
__core__equalsData(this_mph_data, next_mph_data),
() -> {
__core__ifThenElse(
__core__equalsData(this_token_name_data, next_token_name_data),
() -> {
__helios__error("duplicate assetclass in flat map (inner)")
},
() -> {
callback_tail = recurse_inner(tail, next_mph_data, next_token_name_data, next_qty_data);
callback_tail((inner_tail, outer_tail) -> {
(callback) -> {
callback(
__core__mkCons(
__core__mkPairData(
this_token_name_data,
this_qty_data
),
inner_tail
),
outer_tail
)
}
})
}
)()
},
() -> {
outer_tail = recurse_outer(tail, next_mph_data, next_token_name_data, next_qty_data);
(callback) -> {
callback(
__core__mkCons(
__core__mkPairData(
this_token_name_data,
this_qty_data
),
__core__mkNilPairData(())
),
outer_tail
)
}
}
)()
}
)()
};
callback = recurse_inner(tail, next_mph_data, next_token_name_data, next_qty_data);
callback((inner_tail, outer_tail) -> {
inner = __core__mkCons(
__core__mkPairData(
this_token_name_data,
this_qty_data
),
inner_tail
);
__core__mkCons(
__core__mkPairData(
this_mph_data,
__core__mapData(inner)
),
outer_tail
)
})
}
)()
},
() -> {
outer_tail = recurse_outer(__core__tailList(flat_map), next_mph_data, next_token_name_data, next_qty_data);
__core__mkCons(
__core__mkPairData(
this_mph_data,
__core__mapData(
__core__mkCons(
__core__mkPairData(
this_token_name_data,
this_qty_data
),
__core__mkNilPairData(())
)
)
),
outer_tail
)
}
)()
}
)()
};
head = __core__headList(sorted_map);
head_assetclass = __helios__assetclass__from_data(__core__fstPair(head));
recurse_outer(
__core__tailList(sorted_map),
__helios__assetclass__mph_data(head_assetclass),
__helios__assetclass__token_name_data(head_assetclass),
__core__sndPair(head)
)
}
)()
}`
)
)

// Cip67 namespace
add(new RawFunc(`__helios__cip67__fungible_token_label`, "#0014df10"))
Expand Down
2 changes: 1 addition & 1 deletion src/program/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = "0.17.0-28"
export const VERSION = "0.17.0-29"
2 changes: 2 additions & 0 deletions src/typecheck/money.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export const ValueType = new GenericType({
],
self
),
from_flat: new FuncType([MapType$(AssetClassType, IntType)], self),
// TODO: should be getter
lovelace: new FuncType([IntType], self),
new: new FuncType([AssetClassType, IntType], self),
sum: (() => {
Expand Down
34 changes: 15 additions & 19 deletions test/mintingpolicyhash.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { describe, it } from "node:test"
import { True, bytes, compileAndRunMany } from "./utils.js"
import { True, bytes, compileForRun } from "./utils.js"

describe("MintingPolicyHash", () => {
compileAndRunMany([
{
description: "can be converted to ScriptHash and back",
main: `
testing mph_to_from_script_hash
func main(mph: MintingPolicyHash) -> Bool {
sh = mph.to_script_hash();
mph_ = MintingPolicyHash::from_script_hash(sh);
mph == mph_
}`,
inputs: [
bytes(
"00112233445566778899aabbccddeeff00112233445566778899aabb"
)
],
output: True
}
])
it("can be converted to ScriptHash and back", () => {
const runner = compileForRun(`
testing mph_to_from_script_hash
func main(mph: MintingPolicyHash) -> Bool {
sh = mph.to_script_hash();
mph_ = MintingPolicyHash::from_script_hash(sh);
mph == mph_
}`)

runner(
[bytes("00112233445566778899aabbccddeeff00112233445566778899aabb")],
True
)
})
})
Loading

0 comments on commit 99bf004

Please sign in to comment.