Commit 54060ecd authored by yann300's avatar yann300

fix struct type

parent 5a833953
...@@ -165,26 +165,41 @@ function getEnum (type, stateDefinitions) { ...@@ -165,26 +165,41 @@ function getEnum (type, stateDefinitions) {
*/ */
function getStructMembers (typeName, stateDefinitions) { function getStructMembers (typeName, stateDefinitions) {
var members = [] var members = []
var storageBytes = 0
for (var k in stateDefinitions) { for (var k in stateDefinitions) {
var dec = stateDefinitions[k] var dec = stateDefinitions[k]
if (dec.name === 'StructDefinition' && typeName === dec.attributes.name) { if (dec.name === 'StructDefinition' && typeName === dec.attributes.name) {
var location = {
offset: 0,
slot: 0
}
for (var i in dec.children) { for (var i in dec.children) {
var member = dec.children[i] var member = dec.children[i]
var decoded = parseType(member.attributes.type, stateDefinitions) var type = parseType(member.attributes.type, stateDefinitions)
if (!decoded) { if (location.offset + type.storageBytes > 32) {
location.slot++
location.offset = 0
}
if (!type) {
console.log('unable to retrieve decode info of ' + member.attributes.type) console.log('unable to retrieve decode info of ' + member.attributes.type)
return null return null
} }
members.push(decoded) members.push(type)
storageBytes += decoded.storageBytes if (type.storageSlots === 1 && location.offset + type.storageBytes <= 32) {
location.offset += type.storageBytes
} else {
location.slot += type.storageSlots
location.offset = 0
}
}
if (location.offset > 0) {
location.slot++
} }
break break
} }
} }
return { return {
members: members, members: members,
storageBytes: storageBytes storageBytes: location.slot
} }
} }
......
'use strict' 'use strict'
function Struct (memberDetails) { function Struct (memberDetails) {
this.storageSlots = Math.ceil(memberDetails.storageBytes / 32) this.storageSlots = memberDetails.storageBytes
this.storageBytes = 32 this.storageBytes = 32
this.members = memberDetails.members this.members = memberDetails.members
this.typeName = 'struct' this.typeName = 'struct'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment