From: chaoskagami Date: Sun, 12 Jun 2016 20:49:02 +0000 (-0400) Subject: Add string/utf16le string support to assembler X-Git-Tag: v0.0.10~23 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=9c0443bf056f878615241d8d35fdefb88e759eb1;p=corbenik%2Fcorbenik.git Add string/utf16le string support to assembler --- diff --git a/host/bytecode_asm.py b/host/bytecode_asm.py index eef5c18..18463ce 100755 --- a/host/bytecode_asm.py +++ b/host/bytecode_asm.py @@ -134,8 +134,15 @@ def parse_op(token_list, instr_offs): if s != 2: syn_err("invalid number of arguments") - # We cut corners and calculate stuff manually. - return bytearray.fromhex("02") + bytearray([len(token_list[1]) / 2]) + bytearray.fromhex(token_list[1]) + if token_list[1][:1] == "\"": # Quoted string. + data = bytearray(eval(token_list[1]).encode('utf-8')) + return bytearray.fromhex("02") + bytearray([len(data)]) + data + elif token_list[1][:2] == "u\"": # Wide quoted string. + data = bytearray(eval(token_list[1]).encode('utf-16le')) + return bytearray.fromhex("02") + bytearray([len(data)]) + data + else: + # We cut corners and calculate stuff manually. + return bytearray.fromhex("02") + bytearray([len(token_list[1]) / 2]) + bytearray.fromhex(token_list[1]) elif token_list[0] == "back": if s != 2: syn_err("invalid number of arguments") @@ -150,14 +157,28 @@ def parse_op(token_list, instr_offs): if s != 2: syn_err("invalid number of arguments") - # We cut corners and calculate stuff manually. - return bytearray.fromhex("05") + bytearray([len(token_list[1]) / 2]) + bytearray.fromhex(token_list[1]) + if token_list[1][:1] == "\"": # Quoted string. + data = bytearray(eval(token_list[1]).encode('utf-8')) + return bytearray.fromhex("05") + bytearray([len(data)]) + data + elif token_list[1][:2] == "u\"": # Wide quoted string. + data = bytearray(eval(token_list[1]).encode('utf-16le')) + return bytearray.fromhex("05") + bytearray([len(data)]) + data + else: + # We cut corners and calculate stuff manually. + return bytearray.fromhex("05") + bytearray([len(token_list[1]) / 2]) + bytearray.fromhex(token_list[1]) elif token_list[0] == "test": if s != 2: syn_err("invalid number of arguments") - # We cut corners and calculate stuff manually. - return bytearray.fromhex("06") + bytearray([len(token_list[1]) / 2]) + bytearray.fromhex(token_list[1]) + if token_list[1][:1] == "\"": # Quoted string. + data = bytearray(eval(token_list[1]).encode('utf-8')) + return bytearray.fromhex("06") + bytearray([len(data)]) + data + elif token_list[1][:2] == "u\"": # Wide quoted string. + data = bytearray(eval(token_list[1]).encode('utf-16le')) + return bytearray.fromhex("06") + bytearray([len(data)]) + data + else: + # We cut corners and calculate stuff manually. + return bytearray.fromhex("06") + bytearray([len(token_list[1]) / 2]) + bytearray.fromhex(token_list[1]) elif token_list[0] == "jmp": if s != 2: syn_err("invalid number of arguments") diff --git a/patch/mset_str.pco b/patch/mset_str.pco index c001f5d..e0b051c 100644 --- a/patch/mset_str.pco +++ b/patch/mset_str.pco @@ -9,9 +9,9 @@ rel exe_text # Status: needs loader # u"Ver." -find 5600650072002e00 +find u"Ver." abortnf # u".hax" -set 2e006800610078 +set u".hax"