Ignore:
Timestamp:
Sep 20, 2009, 4:41:10 AM (10 years ago)
Author:
cameron
Message:

Copyright; u8u16 test case

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/Compiler/bitstream_compiler.py

    r305 r306  
    11#
     2# bitstream_compiler.py - compile unbounded bitstreams code into
     3#   equivalent block-by-block code in C.
     4#
     5# (c) 2009 Robert D. Cameron and Ehsan Amiri
     6# All rights reserved.
     7# Licensed to International Characters, Inc. under Academic Free License 3.0
     8#
     9
    210import ast, bitexpr, py2bitexpr
    311
     
    256264
    257265if __name__ == '__main__':
    258         s=ast.parse(r"""def u8_streams(u8bit):
    259         Ref2 = bitutil.Advance(lex.RefStart &~ CtCDPI_mask)
    260         NumRef2 = Ref2 & lex.Hash
    261         GenRef2 = Ref2 & ~lex.Hash
    262         NumRef3 = bitutil.Advance(NumRef2)
    263         HexRef3 = NumRef3 & lex.x
    264         DecRef3 = NumRef3 &~ lex.x
    265         HexRef4 = bitutil.Advance(HexRef3)
    266         GenRefEnds = bitutil.ScanThru(GenRef2, lex.NameScan)
    267         DecRefEnds = bitutil.ScanThru(DecRef3, lex.Digit)
    268         HexRefEnds = bitutil.ScanThru(HexRef4, lex.Hex)
    269         # Error checks
    270         # At least one digit required for DecRef, one hex digit for HexRef.
    271         Error = DecRef3 &~ lex.Digit
    272         Error |= HexRef4 &~ lex.Hex
    273         # Semicolon terminator required (also covers unterminated at EOF).
    274         Error |= (GenRefEnds | DecRefEnds | HexRefEnds) &~ lex.Semicolon
    275         CallOuts.GenRefs = GenRefEnds - GenRef2
    276         CallOuts.DecRefs = DecRefEnds - DecRef3
    277         CallOuts.HexRefs = HexRefEnds - HexRef4
    278         # Mark references for deletion, but leave the trailing semicolon as
    279         # the point for insertion of the "expansion" text (most often a
    280         # single character).
    281         CallOuts.delmask = (GenRefEnds | DecRefEnds | HexRefEnds) - lex.RefStart
    282         CallOuts.error = Error
     266        s=ast.parse(r"""def u8u16(u8, u8bit):
     267        u8.unibyte = (~u8bit[0]);
     268        u8.prefix = (u8bit[0] & u8bit[1]);
     269        u8.prefix2 = (u8.prefix &~ u8bit[2]);
     270        temp1 = (u8bit[2] &~ u8bit[3]);
     271        u8.prefix3 = (u8.prefix & temp1);
     272        temp2 = (u8bit[2] & u8bit[3]);
     273        u8.prefix4 = (u8.prefix & temp2);
     274        u8.suffix = (u8bit[0] &~ u8bit[1]);
     275        temp3 = (u8bit[2] | u8bit[3]);
     276        temp4 = (u8.prefix &~ temp3);
     277        temp5 = (u8bit[4] | u8bit[5]);
     278        temp6 = (temp5 | u8bit[6]);
     279        temp7 = (temp4 &~ temp6);
     280        temp8 = (u8bit[6] | u8bit[7]);
     281        temp9 = (u8bit[5] & temp8);
     282        temp10 = (u8bit[4] | temp9);
     283        temp11 = (u8.prefix4 & temp10);
     284        u8.badprefix = (temp7 | temp11);
     285        temp12 = (temp5 | temp8);
     286        u8.xE0 = (u8.prefix3 &~ temp12);
     287        temp13 = (u8bit[4] & u8bit[5]);
     288        temp14 = (u8bit[7] &~ u8bit[6]);
     289        temp15 = (temp13 & temp14);
     290        u8.xED = (u8.prefix3 & temp15);
     291        u8.xF0 = (u8.prefix4 &~ temp12);
     292        temp16 = (u8bit[5] &~ u8bit[4]);
     293        temp17 = (temp16 &~ temp8);
     294        u8.xF4 = (u8.prefix4 & temp17);
     295        u8.xA0_xBF = (u8.suffix & u8bit[2]);
     296        u8.x80_x9F = (u8.suffix &~ u8bit[2]);
     297        u8.x90_xBF = (u8.suffix & temp3);
     298        u8.x80_x8F = (u8.suffix &~ temp3);
     299       
     300        u8.scope22 = bitutil.Advance(u8.prefix2)
     301        u8.scope32 = bitutil.Advance(u8.prefix3)
     302        u8.scope33 = bitutil.Advance(u8.scope32)
     303        u8.scope42 = bitutil.Advance(u8.prefix4)
     304        u8.scope43 = bitutil.Advance(u8.scope42)
     305        u8.scope44 = bitutil.Advance(u8.scope43)
     306        u8lastscope = u8.scope22 | u8.scope33 | u8.scope44
     307        u8anyscope = u8lastscope | u8.scope32 | u8.scope42 | u8.scope43
     308       
     309        # C0-C1 and F5-FF are illegal
     310        error_mask = u8.badprefix
     311       
     312        error_mask |= bitutil.Advance(u8.xE0) & u8.x80_x9F
     313        error_mask |= bitutil.Advance(u8.xED) & u8.xA0_xBF
     314        error_mask |= bitutil.Advance(u8.xF0) & u8.x80_x8F
     315        error_mask |= bitutil.Advance(u8.xF4) & u8.x90_xBF
     316       
     317        error_mask |= u8anyscope ^ u8.suffix
     318        u8.error = error_mask
     319       
     320        u8lastscope = u8.scope22 | u8.scope33 | u8.scope44
     321        u8lastbyte = u8.unibyte | u8lastscope
     322        u16lo[2] = u8lastbyte & u8bit[2]
     323        u16lo[3] = u8lastbyte & u8bit[3]
     324        u16lo[4] = u8lastbyte & u8bit[4]
     325        u16lo[5] = u8lastbyte & u8bit[5]
     326        u16lo[6] = u8lastbyte & u8bit[6]
     327        u16lo[7] = u8lastbyte & u8bit[7]
     328        u16lo[1] = (u8.unibyte & u8bit[1]) | (u8lastscope & bitutil.Advance(u8bit[7]))
     329        u16lo[0] = u8lastscope & bitutil.Advance(u8bit[6])
     330       
     331        u16hi[5] = u8lastscope & bitutil.Advance(u8bit[3])
     332        u16hi[6] = u8lastscope & bitutil.Advance(u8bit[4])
     333        u16hi[7] = u8lastscope & bitutil.Advance(u8bit[5])
     334        u16hi[0] = u8.scope33 & bitutil.Advance(bitutil.Advance(u8bit[4]))
     335        u16hi[1] = u8.scope33 & bitutil.Advance(bitutil.Advance(u8bit[5]))
     336        u16hi[2] = u8.scope33 & bitutil.Advance(bitutil.Advance(u8bit[6]))
     337        u16hi[3] = u8.scope33 & bitutil.Advance(bitutil.Advance(u8bit[7]))
     338        u16hi[4] = u8.scope33 & bitutil.Advance(u8bit[2])
     339
     340        u8surrogate = u8.scope43 | u8.scope44
     341        u16hi[0] = u16hi[0] | u8surrogate       
     342        u16hi[1] = u16hi[1] | u8surrogate       
     343        u16hi[3] = u16hi[3] | u8surrogate       
     344        u16hi[4] = u16hi[4] | u8surrogate       
     345        u16hi[5] = u16hi[5] | u8.scope44
     346
     347
     348        s42lo1 = ~u8bit[3] # subtract 1
     349        u16lo[1] = u16lo[1] | (u8.scope43 & bitutil.Advance(s42lo1))
     350        s42lo0 = u8bit[2] ^ s42lo1 # borrow *
     351        u16lo[0] = u16lo[0] | (u8.scope43 & bitutil.Advance(s42lo0))
     352        borrow1 = s42lo1 & ~u8bit[2]
     353        bitutil.Advance_bit7 = bitutil.Advance(u8bit[7])
     354        s42hi7 = bitutil.Advance_bit7 ^ borrow1
     355        u16hi[7]= u16hi[7] | (u8.scope43 & bitutil.Advance(s42hi7))
     356        borrow2 = borrow1 & ~bitutil.Advance_bit7
     357        s42hi6 = bitutil.Advance(u8bit[6]) ^ borrow2
     358        u16hi[6] = u16hi[6] | (u8.scope43 & bitutil.Advance(s42hi6))
     359
     360        u16lo[2] = u16lo[2] | (u8.scope43 & bitutil.Advance(u8bit[4]))
     361        u16lo[3] = u16lo[3] | (u8.scope43 & bitutil.Advance(u8bit[5]))
     362        u16lo[4] = u16lo[4] | (u8.scope43 & bitutil.Advance(u8bit[6]))
     363        u16lo[5] = u16lo[5] | (u8.scope43 & bitutil.Advance(u8bit[7]))
     364        u16lo[6] = u16lo[6] | (u8.scope43 & u8bit[2])
     365        u16lo[7] = u16lo[7] | (u8.scope43 & u8bit[3])
     366
     367        delmask = u8.prefix | u8.scope32 | u8.scope42
    283368""")
    284369        s=s.body[0].body
Note: See TracChangeset for help on using the changeset viewer.