Skip to content

Commit

Permalink
correct implemented of cip68 struct eq and neq operators
Browse files Browse the repository at this point in the history
  • Loading branch information
christianschmitz committed Sep 17, 2024
1 parent 3154e7c commit 62f580f
Show file tree
Hide file tree
Showing 6 changed files with 470 additions and 159 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@helios-lang/compiler",
"version": "0.17.0-85",
"version": "0.17.0-86",
"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
12 changes: 10 additions & 2 deletions src/codegen/makeRawFuncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,13 +683,21 @@ export function makeRawFunctions(simplify, isTestnet) {
}`
)
)
// TODO: inline __core__sndPair(head)
add(
new RawFunc(
"__helios__common__cip68_field",
`(self, name) -> {
name_data = __core__bData(name);
map = __core__unMapData(__core__headList(__core__sndPair(__core__unConstrData(self))));
__helios__common__cip68_field_internal(map, name)
}`
)
)
// map is expected to already have been extracted
add(
new RawFunc(
"__helios__common__cip68_field_internal",
`(map, name) -> {
name_data = __core__bData(name);
recurse = (recurse, map) -> {
__core__chooseList(
map,
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-85"
export const VERSION = "0.17.0-86"
82 changes: 75 additions & 7 deletions src/statements/DataDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ export class DataDefinition {
return this.#fields.slice()
}

/**
* @type {string[]}
*/
get fieldNames() {
return this.#fields.map((f) => f.name.value)
}

hasTags() {
return this.#fields.some((f) => f.hasTag())
}
Expand All @@ -88,13 +95,6 @@ export class DataDefinition {
return found
}

/**
* @type {string[]}
*/
get fieldNames() {
return this.#fields.map((f) => f.name.value)
}

/**
* @param {Word} name
* @returns {boolean}
Expand Down Expand Up @@ -598,6 +598,74 @@ export class DataDefinition {
}
}

/**
* @param {Site} site
* @returns {SourceMappedString}
*/
toIR_withTagsEq(site) {
// the expected fields must exist in both
let irInner = $`true`

for (let i = 0; i < this.#fields.length; i++) {
const f = this.#fields[i]

irInner = $`__core__ifThenElse(
__core__equalsData(
__helios__common__cip68_field_internal(aFields, #${bytesToHex(encodeUtf8(f.tag))}),
__helios__common__cip68_field_internal(bFields, #${bytesToHex(encodeUtf8(f.tag))})
),
() -> {${irInner}},
() -> {false}
)()`
}

let irOuter = $(
`(a, b) -> {
aFields = __core__unMapData(__core__headList(__core__sndPair(__core__unConstrData(a))));
bFields = __core__unMapData(__core__headList(__core__sndPair(__core__unConstrData(b))));
${irInner}
}`,
site
)

return irOuter
}

/**
* @param {Site} site
* @returns {SourceMappedString}
*/
toIR_withTagsNeq(site) {
// the expected fields must exist in both
let irInner = $`false`

for (let i = 0; i < this.#fields.length; i++) {
const f = this.#fields[i]

irInner = $`__core__ifThenElse(
__core__equalsData(
__helios__common__cip68_field_internal(aFields, #${bytesToHex(encodeUtf8(f.tag))}),
__helios__common__cip68_field_internal(bFields, #${bytesToHex(encodeUtf8(f.tag))})
),
() -> {${irInner}},
() -> {true}
)()`
}

let irOuter = $(
`(a, b) -> {
aFields = __core__unMapData(__core__headList(__core__sndPair(__core__unConstrData(a))));
bFields = __core__unMapData(__core__headList(__core__sndPair(__core__unConstrData(b))));
${irInner}
}`,
site
)

return irOuter
}

/**
* @param {string} path
* @returns {SourceMappedString}
Expand Down
Loading

0 comments on commit 62f580f

Please sign in to comment.