def KNamedList(klabel, empty_klabel, items): tail = KApply(empty_klabel, []) while not items == []: last = items.pop() tail = KApply(klabel, [last, tail]) return tail
def I64_STORE8(offset: int): return KApply('aStore', [i64, KApply('storeOpStore8', []), KInt(offset)])
def I64_STORE32(offset: int): return KApply('aStore', [i32, KApply('storeOpStore32', []), KInt(offset)])
def I32_CONST(i: int): return (KApply('aIConst', [i32, KInt(i)]))
def F32_STORE(offset: int): return KApply('aStore', [f32, KApply('storeOpStore', []), KInt(offset)])
def CALL(function_idx: int): return KApply('aCall', [KInt(function_idx)])
def F32_CONST(f: float): return KApply('aFConst', [f32, KFloat(f)])
def val_types(items): return KNamedList(VAL_TYPES, VAL_TYPES_NIL, items) def ints(iis: [int]): kis = [KInt(x) for x in iis] return KNamedList(INTS, INTS_NIL, kis) ########### # Empties # ########### EMPTY_ID = KApply(EMPTY_ID, []) EMPTY_DEFNS = KApply(EMPTY_STMTS, []) EMPTY_MODULE_METADATA = KApply(MODULE_METADATA, [EMPTY_ID, KApply(EMPTY_MAP, [])]) EMPTY_FUNC_METADATA = KApply(FUNC_METADATA, [EMPTY_ID, KApply(EMPTY_MAP, [])]) ######### # Types # ######### i32 = KApply('i32', []) i64 = KApply('i64', []) f32 = KApply('f32', [])
def vec_type(valtypes): return KApply(VEC_TYPE, [valtypes])
def get_steps_validator_reward(step): tx = mandos_to_validator_reward_tx(step['tx']) return [KApply('validatorReward', [tx])]
def KList_aux(lis): if lis == []: return KApply(".List", []) head = lis[0] tail = KList_aux(lis[1:]) return KApply("_List_", [head, tail])
def get_steps_transfer(step): tx = mandos_to_transfer_tx(step['tx']) return [KApply('transfer', [tx])]
def register(with_name: str): return KApply('register', [KString(with_name)])
def mandos_to_validator_reward_tx(tx): to = mandos_argument_to_kbytes(tx['to']) value = mandos_int_to_kint(tx['value']) rewardTx = KApply('validatorRewardTx', [to, value]) return rewardTx
def BR_IF(idx: int): return KApply('aBr_if', [KInt(idx)])
def func_type(params, results): return KApply(FUNC_TYPE, [params, results])
def BR_TABLE(idxs: [int], default): return KApply('aBr_table', [ints(idxs + (default, ))])
def limits(tup): i = tup[0] j = tup[1] if j is None: return KApply('limitsMin', [KInt(i)]) return KApply('limitsMinMax', [KInt(i), KInt(j)])
def CALL_INDIRECT(type_idx: int): return KApply('aCall_indirect', [KInt(type_idx)])
def global_type(mut, valtype): return KApply(GLOBAL_TYPE, [mut, valtype])
def F64_CONST(f: float): return KApply('aFConst', [f64, KFloat(f)])
def BLOCK(vec_type, instrs): return KApply('aBlock', [vec_type, instrs])
def I64_CONST(i: int): return (KApply('aIConst', [i64, KInt(i)]))
def IF(vec_type, then_instrs, else_instrs): return KApply('aIf', [vec_type, then_instrs, else_instrs])
def F64_STORE(offset: int): return KApply('aStore', [f64, KApply('storeOpStore', []), KInt(offset)])
def LOOP(vec_type, instrs): return KApply('aLoop', [vec_type, instrs])
def I32_STORE16(offset: int): return KApply('aStore', [i32, KApply('storeOpStore16', []), KInt(offset)])
def BR(idx: int): return KApply('aBr', [KInt(idx)])
def F32_LOAD(offset: int): return KApply('aLoad', [f32, KApply('loadOpLoad', []), KInt(offset)])
def module_metadata(mid=None, fids=None, filename=None): # TODO: Implement module id and function ids metadata transformation. kfilename = EMPTY_OPT_STRING if filename is None else KString(filename) return KApply(MODULE_METADATA, [EMPTY_ID, EMPTY_MAP, kfilename])