예제 #1
0
    def testEncode(self):
        obj = arith_ast.Const(99)
        print('Encoding into binary:')
        print(obj)

        enc = encode.Params()
        f = io.BytesIO()
        out = encode.BinOutput(f)
        encode.EncodeRoot(obj, enc, out)
        e = f.getvalue()

        #print(repr(e))
        #print(e[0:4], e[4:8], e[8:])

        # Header is OHP version 1
        self.assertEqual(b'OHP\x01', e[0:4])

        self.assertEqual(b'\x04', e[4:5])  # alignment 4

        # TODO: Fix after spids
        return
        self.assertEqual(b'\x02\x00\x00', e[5:8])  # root ref 2

        self.assertEqual(b'\x01', e[8:9])  # tag 1 is const
        self.assertEqual(b'\x63\x00\x00', e[9:12])  # 0x63 = 99
예제 #2
0
def NullConstant(p, token, bp):
    if token.type == 'number':
        return arith_ast.Const(token.val)
    # We have to wrap a string in some kind of variant.
    if token.type == 'name':
        return arith_ast.ArithVar(token.val)

    raise AssertionError(token.type)