001 DATA1
DATA001,99999
CALL004,99999
CALL10000,0010
CALL10002
CALL002
STOP
002 DATA1
DATA002
DATA002,10001
DATA001,10001
DATA10001
CONTINUE002
004 DATA000066
CALL005,004
DATA004
CONTINUE004
005 DATA1
CALL10000,0010020002000200020002000211
006 IF005,0
CALL10000,0300
IF005,1
CALL10000,0301
IF005,2
CALL10000,0302
IF005,3
CALL10000,0303
IF005,4
CALL10000,0304
IF005,5
CALL10000,0305
IF005,6
CALL10000,0306
IF005,7
CALL10000,0307
CALL002
DATA005
CONTINUE005,006
C THIS IS A LIBRARY THAT CONVERTS 4-BIT ITEMS ENQUEUED INTO 10000 AS 2 DIGITS
C INTO 3-BIT ITEMS IN 1 DIGIT THAT ARE AVAILABLE AT 10001.
C CALL 10000 TO PROCESS ITEMS FROM 10000 INTO 10001.
C CALL 10002 TO FLUSH THE FINAL DANGLING BITS (0-2 BITS).
C IF 000002 IS A DATA STATEMENT, CALLING 10000 WILL DEQUEUE FROM IT. BEST
C NOT TO HAVE 000002 AS A LABEL (WHICH WOULD REQUIRE A CONTINUATION LINE).
10000 DATA 000002
IF 10003,11000
CALL 10100
IF 10003,11001
CALL 10110
IF 10003,11002
CALL 10120
DATA 10003
DATA 10000
CONTINUE 10000
10001 DATA 1
C FLUSH THE FINAL DANGLING BITS
10002 IF 10003,11000
CONTINUE 10002
DATA 10001,10004
DATA 10004
C REINITIALIZE 10003 TO 012
IF 10003,11001
DATA 10003
DATA 10003
DATA 10003,012
CONTINUE 10002
C 10003 HOLDS THE NUMBER OF DANGLING BITS
10003 DATA 1,012
C 10004 HOLDS THE VALUE OF THE DANGLING BITS
10004 DATA 1
C NO DANGLING BITS FROM BEFORE. LEAVES 1 DANGLING BIT FOR NEXT ITEM.
10100 IF 10000,12000
DATA 10001,11000
IF 10000,12000
DATA 10004,11000
IF 10000,12001
DATA 10001,11000
IF 10000,12001
DATA 10004,11004
IF 10000,12002
DATA 10001,11001
IF 10000,12002
DATA 10004,11000
IF 10000,12003
DATA 10001,11001
IF 10000,12003
DATA 10004,11004
IF 10000,12004
DATA 10001,11002
IF 10000,12004
DATA 10004,11000
IF 10000,12005
DATA 10001,11002
IF 10000,12005
DATA 10004,11004
IF 10000,12006
DATA 10001,11003
IF 10000,12006
DATA 10004,11000
IF 10000,12007
DATA 10001,11003
IF 10000,12007
DATA 10004,11004
IF 10000,12008
DATA 10001,11004
IF 10000,12008
DATA 10004,11000
IF 10000,12009
DATA 10001,11004
IF 10000,12009
DATA 10004,11004
IF 10000,12010
DATA 10001,11005
IF 10000,12010
DATA 10004,11000
IF 10000,12011
DATA 10001,11005
IF 10000,12011
DATA 10004,11004
IF 10000,12012
DATA 10001,11006
IF 10000,12012
DATA 10004,11000
IF 10000,12013
DATA 10001,11006
IF 10000,12013
DATA 10004,11004
IF 10000,12014
DATA 10001,11007
IF 10000,12014
DATA 10004,11000
IF 10000,12015
DATA 10001,11007
IF 10000,12015
DATA 10004,11004
CONTINUE 10100
C 1 DANGLING BIT FROM BEFORE. LEAVES 2 DANGLING BITS FOR NEXT ITEM.
10110 IF 10004,11000
CALL 10111
IF 10004,11004
CALL 10112
DATA 10004
CONTINUE 10110
C DANGLING 0 FROM BEFORE
10111 IF 10000,12000
DATA 10001,11000
IF 10000,12000
DATA 10004,11000
IF 10000,12001
DATA 10001,11000
IF 10000,12001
DATA 10004,11002
IF 10000,12002
DATA 10001,11000
IF 10000,12002
DATA 10004,11004
IF 10000,12003
DATA 10001,11000
IF 10000,12003
DATA 10004,11006
IF 10000,12004
DATA 10001,11001
IF 10000,12004
DATA 10004,11000
IF 10000,12005
DATA 10001,11001
IF 10000,12005
DATA 10004,11002
IF 10000,12006
DATA 10001,11001
IF 10000,12006
DATA 10004,11004
IF 10000,12007
DATA 10001,11001
IF 10000,12007
DATA 10004,11006
IF 10000,12008
DATA 10001,11002
IF 10000,12008
DATA 10004,11000
IF 10000,12009
DATA 10001,11002
IF 10000,12009
DATA 10004,11002
IF 10000,12010
DATA 10001,11002
IF 10000,12010
DATA 10004,11004
IF 10000,12011
DATA 10001,11002
IF 10000,12011
DATA 10004,11006
IF 10000,12012
DATA 10001,11003
IF 10000,12012
DATA 10004,11000
IF 10000,12013
DATA 10001,11003
IF 10000,12013
DATA 10004,11002
IF 10000,12014
DATA 10001,11003
IF 10000,12014
DATA 10004,11004
IF 10000,12015
DATA 10001,11003
IF 10000,12015
DATA 10004,11006
CONTINUE 10111
C DANGLING 1 FROM BEFORE
10112 IF 10000,12000
DATA 10001,11004
IF 10000,12000
DATA 10004,11000
IF 10000,12001
DATA 10001,11004
IF 10000,12001
DATA 10004,11002
IF 10000,12002
DATA 10001,11004
IF 10000,12002
DATA 10004,11004
IF 10000,12003
DATA 10001,11004
IF 10000,12003
DATA 10004,11006
IF 10000,12004
DATA 10001,11005
IF 10000,12004
DATA 10004,11000
IF 10000,12005
DATA 10001,11005
IF 10000,12005
DATA 10004,11002
IF 10000,12006
DATA 10001,11005
IF 10000,12006
DATA 10004,11004
IF 10000,12007
DATA 10001,11005
IF 10000,12007
DATA 10004,11006
IF 10000,12008
DATA 10001,11006
IF 10000,12008
DATA 10004,11000
IF 10000,12009
DATA 10001,11006
IF 10000,12009
DATA 10004,11002
IF 10000,12010
DATA 10001,11006
IF 10000,12010
DATA 10004,11004
IF 10000,12011
DATA 10001,11006
IF 10000,12011
DATA 10004,11006
IF 10000,12012
DATA 10001,11007
IF 10000,12012
DATA 10004,11000
IF 10000,12013
DATA 10001,11007
IF 10000,12013
DATA 10004,11002
IF 10000,12014
DATA 10001,11007
IF 10000,12014
DATA 10004,11004
IF 10000,12015
DATA 10001,11007
IF 10000,12015
DATA 10004,11006
CONTINUE 10112
C 2 DANGLING BITS FROM BEFORE. LEAVES NO DANGLING BITS FOR NEXT ITEM.
10120 IF 10004,11000
CALL 10121
IF 10004,11002
CALL 10122
IF 10004,11004
CALL 10123
IF 10004,11006
CALL 10124
DATA 10003,13012
DATA 10004
IF 10000,12000
DATA 10001,11000
IF 10000,12001
DATA 10001,11001
IF 10000,12002
DATA 10001,11002
IF 10000,12003
DATA 10001,11003
IF 10000,12004
DATA 10001,11004
IF 10000,12005
DATA 10001,11005
IF 10000,12006
DATA 10001,11006
IF 10000,12007
DATA 10001,11007
IF 10000,12008
DATA 10001,11000
IF 10000,12009
DATA 10001,11001
IF 10000,12010
DATA 10001,11002
IF 10000,12011
DATA 10001,11003
IF 10000,12012
DATA 10001,11004
IF 10000,12013
DATA 10001,11005
IF 10000,12014
DATA 10001,11006
IF 10000,12015
DATA 10001,11007
CONTINUE 10120
C DANGLING 00 FROM BEFORE
10121 IF 10000,12000
DATA 10001,11000
IF 10000,12001
DATA 10001,11000
IF 10000,12002
DATA 10001,11000
IF 10000,12003
DATA 10001,11000
IF 10000,12004
DATA 10001,11000
IF 10000,12005
DATA 10001,11000
IF 10000,12006
DATA 10001,11000
IF 10000,12007
DATA 10001,11000
IF 10000,12008
DATA 10001,11001
IF 10000,12009
DATA 10001,11001
IF 10000,12010
DATA 10001,11001
IF 10000,12011
DATA 10001,11001
IF 10000,12012
DATA 10001,11001
IF 10000,12013
DATA 10001,11001
IF 10000,12014
DATA 10001,11001
IF 10000,12015
DATA 10001,11001
CONTINUE 10121
C DANGLING 01 FROM BEFORE
10122 IF 10000,12000
DATA 10001,11002
IF 10000,12001
DATA 10001,11002
IF 10000,12002
DATA 10001,11002
IF 10000,12003
DATA 10001,11002
IF 10000,12004
DATA 10001,11002
IF 10000,12005
DATA 10001,11002
IF 10000,12006
DATA 10001,11002
IF 10000,12007
DATA 10001,11002
IF 10000,12008
DATA 10001,11003
IF 10000,12009
DATA 10001,11003
IF 10000,12010
DATA 10001,11003
IF 10000,12011
DATA 10001,11003
IF 10000,12012
DATA 10001,11003
IF 10000,12013
DATA 10001,11003
IF 10000,12014
DATA 10001,11003
IF 10000,12015
DATA 10001,11003
CONTINUE 10122
C DANGLING 10 FROM BEFORE
10123 IF 10000,12000
DATA 10001,11004
IF 10000,12001
DATA 10001,11004
IF 10000,12002
DATA 10001,11004
IF 10000,12003
DATA 10001,11004
IF 10000,12004
DATA 10001,11004
IF 10000,12005
DATA 10001,11004
IF 10000,12006
DATA 10001,11004
IF 10000,12007
DATA 10001,11004
IF 10000,12008
DATA 10001,11005
IF 10000,12009
DATA 10001,11005
IF 10000,12010
DATA 10001,11005
IF 10000,12011
DATA 10001,11005
IF 10000,12012
DATA 10001,11005
IF 10000,12013
DATA 10001,11005
IF 10000,12014
DATA 10001,11005
IF 10000,12015
DATA 10001,11005
CONTINUE 10123
C DANGLING 11 FROM BEFORE
10124 IF 10000,12000
DATA 10001,11006
IF 10000,12001
DATA 10001,11006
IF 10000,12002
DATA 10001,11006
IF 10000,12003
DATA 10001,11006
IF 10000,12004
DATA 10001,11006
IF 10000,12005
DATA 10001,11006
IF 10000,12006
DATA 10001,11006
IF 10000,12007
DATA 10001,11006
IF 10000,12008
DATA 10001,11007
IF 10000,12009
DATA 10001,11007
IF 10000,12010
DATA 10001,11007
IF 10000,12011
DATA 10001,11007
IF 10000,12012
DATA 10001,11007
IF 10000,12013
DATA 10001,11007
IF 10000,12014
DATA 10001,11007
IF 10000,12015
DATA 10001,11007
CONTINUE 10124
C CONSTANTS
11000 DATA 1,0
11001 DATA 1,1
11002 DATA 1,2
11003 DATA 1,3
11004 DATA 1,4
11005 DATA 1,5
11006 DATA 1,6
11007 DATA 1,7
12000 DATA 2,00
12001 DATA 2,01
12002 DATA 2,02
12003 DATA 2,03
12004 DATA 2,04
12005 DATA 2,05
12006 DATA 2,06
12007 DATA 2,07
12008 DATA 2,08
12009 DATA 2,09
12010 DATA 2,10
12011 DATA 2,11
12012 DATA 2,12
12013 DATA 2,13
12014 DATA 2,14
12015 DATA 2,15
13012 DATA 3,012
99999 DATA 40000,
+140300611002004021040524202304121002004010020040210405242023006014
+226071162344711620504010020040100201032024611414030064130344711623
+447102420040100200401004150123046061140300601402606014030460024200
+401002004010041501230460611403006014405040100200401002010320246114
+140300620242004010020040100515242365001214030062100200402104052420
+230412100200401002004021040524202300601440504010020040100201042025
+210114030062130304601403006102420040100200401004210125040460140304
+541423006014030412100200401002004021040524202304601403006102420040
+100200401004151723452111234525051403006202430060150200401004210125
+040460140300601543301210020040100200402064051423030060152260601403
+201210020040100200402104052420230060150050401002004010020103236471
+242224712521230060150050601403244010020104202521011420504010020040
+100201032024611414230060140300541403006114030062140300601443006014
+031060140300621403006014430060140310611420506014033040100201112143
+006015226060024200401002004010041501230460611403006014026060146300
+600242004010020040100445061403006513030412100200401002004020640514
+230304601403006013030063140304121002004010020040222430601403245414
+405040100200401002010320246114142300601403005414031460144050401002
+004010020111214300601522606302420040100200401004150123046061140300
+601402606014630063024200401002004010044506140300651303201210020040
+100200402064051423030460140300601303006314032012100200401002004022
+243060140324541520504010020040100201032024611414230060140300541403
+146015205040100200401002011121430060152260660242004010020040100415
+012304606114030060140260601463006602420040100200401004450614030065
+130334121002004010020040206405142303046014030060130300631403341210
+020040100200402064051423030060144050401002004010020104202521011403
+006502420040100200401004151723452111234525051403006513030060154051
+031005211022251440222514402022011422241122202511311005211020252040
+206475162544252225051440150265022225204022252105232514402124712125
+242525212420402224712423620061140300601402010124620062100421112164
+452424605103100445162504744014626502222520402225210523251440222470
+401422010422243511250201242204052410040522212201012544051123040502
+230424402025204014230060140304560244144020640514230200611403006014
+020124236201202444750321251523100445242124652310043122236464401423
+006014030040222471242362006114030060142270122062010320246114100304
+601403006210052117100431142525151010052110212201062224710123020104
+202471072304451621620102222521231002406013231040204445242462445602
+441440222430401403006014030062100445231004044021040524202201232504
+052421246505234520541004150123046111234434401423006014030040256445
+142302010421250525212525051004312223646440222520561002010221251524
+024414402344752410052117100441012544244014030060140300621004052310
+040440230405022124604012053510222415101005351725246104100511052425
+251124442440202201032364712422247125202521112364704023044516212244
+560243046014030060100421012504044014030060140300620242004010020040
+100445061003046014030063130304611403006002420040100200401004150123
+046040142300611403001210020040100200402224304014230060140314541423
+046014030412100200401002004020640514230200611403046114005040100200
+401002011121420061140300601462606114230060144050401002004010020103
+202461141003046014231060024200401002004010042101250404401423006014
+031412100200401002004021040524202200611403006014005040100200401002
+010323647124222471252122006114030060140050611403006014220104202521
+011003041220620106230525232202012422042440214445162024604021040516
+216461112344344020444524246050611403006014420111214200611403006014
+626061142300601400504010020040100201032364712422247125212200611403
+006014405040100200401002010420252101100304601403006113030460140300
+640242004010020040100421012504044014230060140320122062012221244516
+222521112024611126442440142300601403144025047440140304620242004010
+020040100445061003046014030063130304611403006102420040100200401004
+210125040440142300601403141210020040100200402104052420220061140300
+601460504010020040100201042025210110030460140300631303006114405040
+100200401002010323647124222471252122006114030060144051031003046014
+030063100441172304212310052110212201162524650221251040236430402104
+051621646111234434402044452424605061140300601462010420252101100304
+541403046202441440142300601403204022047514210514402504410510053101
+230525051004750610052110212201042024710723044516216201022225212302
+430460140300641004210125040440142051031004711710042101234435142224
+710710041111250514402145111723220102212431172444245610020114212405
+262125144014220104202471072304451621620102222520402144752210047105
+260520402225210523227012142300611403004022243040142300601403005414
+231060140300121002004010020040210405242022006114030060142260611423
+006014005040100200401002011121420061140300601402606114430060140050
+401002004010020104202521011003046014030064130304611403006002420040
+100200401004450610030460140300601303046214030061024200401002004010
+042101250404401423006014030454142304601403001210020040100200402224
+304014230060140300541423106014030412100200401002004021040524202200
+611403006015026061142300601500504010020040100201112142006114030060
+140260611443006014405040100200401002010420252101100304601403006113
+030461140300610242004010020040100445061003046014030060130304621403
+006202420040100200401004210125040440142300601403205414230460140300
+121002004010020040222430401423006014030054142310601403141210020040
+100200402104052420220061140300601422606114230060142050401002004010
+020111214200611403006014026061144300601460504010020040100201042025
+210110030460140300641303046114030064024200401002004010044506100304
+601403006013030462140300640242004010020040100421012504044014230060
+140304541423046014031012100200401002004022243040142300601403005414
+231060140320121002004010020040210405242022006114030060150260611423
+006014005040100200401002011121420061140300601402606114430060152050
+401002004010020104202521011003046014030061130304611403006202420040
+100200401004450610030460140300601303046214030065024200401002004010
+042101250404401423006014032054142304601403201210020040100200402224
+304014230060140300541423106014033012100200401002004021040524202200
+611403006014226061142300601460504010020040100201112142006114030060
+140260611443006015405040100200401002010420252101100304601403006413
+030461140300600242004010020040100445061003046014030060130304621403
+006702420040100200401004210125040440142300601403045414230460140314
+121002004010020040222430401423006014030054142310601403341210020040
+100200402104052420220061140300601502606114230060150050401002004010
+020111214200611403006014026061144300601600504010020040100201042025
+210110030460140300611303046114030064024200401002004010044506100304
+601403006013030462140300700242004010020040100421012504044014230060
+140320541423046014030012100200401002004022243040142300601403005414
+231060140344121002004010020040210405242022006114030060142260611423
+006015005040100200401002011121420061140300601402606114430060162050
+401002004010020104202521011003046014030064130304611403006402420040
+100200401004450610030460140300601303046214030460024200401002004010
+042101250404401423006014030454142304601403241210020040100200402224
+304014230060140300541423106014230012100200401002004021040524202200
+611403006015026061142300601400504010020040100201112142006114030060
+140260611443006114205040100200401002010420252101100304601403006113
+030461140300650242004010020040100445061003046014030060130304621403
+046102420040100200401004210125040440142300601403205414230460140320
+121002004010020040222430401423006014030054142310601423101210020040
+100200402104052420220061140300601422606114230060154050401002004010
+020111214200611403006014026061144300611440504010020040100201042025
+210110030460140300641303046114030060024200401002004010044506100304
+601403006013030462140304630242004010020040100421012504044014230060
+140304541423046014033012100200401002004022243040142300601403005414
+231060142314121002004010020040210405242022006114030060150260611423
+006015005040100200401002011121420061140300601402606114430061150050
+401002004010020104202521011003046014030061130304611403006702420040
+100200401004450610030460140300601303046214030464024200401002004010
+042101250404401423006014032054142304601403001210020040100200402224
+304014230060140300541423106014232412100200401002004021040524202200
+611403006014226061142300601560504010020040100201112142006114030060
+140260611443006115205040100200401002010420252101100304601403006413
+030461140300640242004010020040100415172345211123452505100304601423
+006002441440142201042024710723044516216201022225204021451117232201
+022124311724442456100201142124052621251440144201042024710723044516
+216201022225212310043117244201162125412410044524212464560243046014
+230460100445061003046014030064130304611403006002420040100200401004
+150123046040142300611423041210020040100200402224304014230060140320
+541423046014032012100200401002004020640514230200611403046114405040
+100200401002010420252101100304601403006402420040100200401004151723
+452111234525051003046014230460024414402104051621646111234434401402
+010624447515100411052144752221205061140304611422011121420061140300
+601402606114430060140050401002004010020104202521011003046014030061
+130304611403006002420040100200401004450610030460140300601303046214
+030060024200401002004010042101250404401423006014032054142304601403
+001210020040100200402224304014230060140300541423106014030412100200
+401002004021040524202200611403006014226061142300601400504010020040
+100201112142006114030060140260611443006014205040100200401002010420
+252101100304601403006413030461140300620242004010020040100445061003
+046014030060130304621403006202420040100200401004210125040440142300
+601403045414230460140300121002004010020040222430401423006014030054
+142310601403101210020040100200402104052420220061140300601502606114
+230060150050401002004010020111214200611403006014026061144300601460
+504010020040100201042025210110030460140300611303046114030060024200
+401002004010044506100304601403006013030462140300630242004010020040
+100421012504044014230060140320541423046014033012100200401002004022
+243040142300601403005414231060140320121002004010020040210405242022
+006114030060142260611423006014205040100200401002011121420061140300
+601402606114430060150050401002004010020104202521011003046014030064
+130304611403006002420040100200401004450610030460140300601303046214
+030065024200401002004010042101250404401423006014030454142304601403
+041210020040100200402224304014230060140300541423106014032412100200
+401002004021040524202200611403006015026061142300601440504010020040
+100201112142006114030060140260611443006015405040100200401002010420
+252101100304601403006113030461140300610242004010020040100445061003
+046014030060130304621403006602420040100200401004210125040440142300
+601403205414230460140320121002004010020040222430401423006014030054
+142310601403341210020040100200402104052420220061140300601422606114
+230060142050401002004010020111214200611403006014026061144300601560
+504010020040100201042025210110030460140300641303046114030066024200
+401002004010044506100304601403006013030462140300700242004010020040
+100421012504044014230060140304541423046014031012100200401002004022
+243040142300601403005414231060140340121002004010020040210405242022
+006114030060150260611423006014005040100200401002011121420061140300
+601402606114430060162050401002004010020104202521011003046014030061
+130304611403006202420040100200401004450610030460140300601303046214
+030071024200401002004010042101250404401423006014032054142304601403
+101210020040100200402224304014230060140300541423106014230012100200
+401002004021040524202200611403006014226061142300601440504010020040
+100201112142006114030060140260611443006114005040100200401002010420
+252101100304601403006413030461140300640242004010020040100445061003
+046014030060130304621403046102420040100200401004210125040440142300
+601403045414230460140310121002004010020040222430401423006014030054
+142310601423041210020040100200402104052420220061140300601502606114
+230060154050401002004010020111214200611403006014026061144300611440
+504010020040100201042025210110030460140300611303046114030063024200
+401002004010044506100304601403006013030462140304620242004010020040
+100421012504044014230060140320541423046014030012100200401002004022
+243040142300601403005414231060142314121002004010020040210405242022
+006114030060142260611423006014605040100200401002011121420061140300
+601402606114430061146050401002004010020104202521011003046014030064
+130304611403006202420040100200401004450610030460140300601303046214
+030464024200401002004010042101250404401423006014030454142304601403
+141210020040100200402224304014230060140300541423106014232012100200
+401002004021040524202200611403006015026061142300601500504010020040
+100201112142006114030060140260611443006115205040100200401002010420
+252101100304601403006113030461140300630242004010020040100445061003
+046014030060130304621403046502420040100200401004210125040440142300
+601403205414230460140330121002004010020040206475162504451625242440
+142300611423041220620104202471072304451621620061100431222364644020
+442506236511050243046014230462100445061003046014030060130304621403
+006002420040100200401004210125040440142300601403045414230460140320
+121002004010020040222430401423006014030054142310601403001210020040
+100200402104052420220061140300601502606114230060140050401002004010
+020111214200611403006014026061144300601420504010020040100201042025
+210110030460140300611303046114030064024200401002004010044506100304
+601403006013030462140300610242004010020040100421012504044014230060
+140320541423046014031012100200401002004022243040142300601403005414
+231060140310121002004010020040210405242022006114030060142260611423
+006015005040100200401002011121420061140300601402606114430060144050
+401002004010020104202521011003046014030064130304611403006402420040
+100200401004450610030460140300601303046214030063024200401002004010
+042101250404401423006014030454142304601403201210020040100200402224
+304014230060140300541423106014031412100200401002004021040524202200
+611403006015026061142300601540504010020040100201112142006114030060
+140260611443006015005040100200401002010420252101100304601403006113
+030461140300650242004010020040100445061003046014030060130304621403
+006402420040100200401004210125040440142300601403205414230460140300
+121002004010020040222430401423006014030054142310601403241210020040
+100200402104052420220061140300601422606114230060152050401002004010
+020111214200611403006014026061144300601520504010020040100201042025
+210110030460140300641303046114030062024200401002004010044506100304
+601403006013030462140300660242004010020040100421012504044014230060
+140304541423046014032412100200401002004022243040142300601403005414
+231060140330121002004010020040210405242022006114030060150260611423
+006015005040100200401002011121420061140300601402606114430060156050
+401002004010020104202521011003046014030061130304611403006502420040
+100200401004450610030460140300601303046214030067024200401002004010
+042101250404401423006014032054142304601403301210020040100200402224
+304014230060140300541423106014034012100200401002004021040524202200
+611403006014226061142300601540504010020040100201112142006114030060
+140260611443006016005040100200401002010420252101100304601403006413
+030461140300600242004010020040100445061003046014030060130304621403
+007102420040100200401004210125040440142300601403045414230460140330
+121002004010020040222430401423006014030054142310601403441210020040
+100200402104052420220061140300601502606114230060144050401002004010
+020111214200611403006014026061144300611400504010020040100201042025
+210110030460140300611303046114030066024200401002004010044506100304
+601403006013030462140304600242004010020040100421012504044014230060
+140320541423046014032012100200401002004022243040142300601403005414
+231060142304121002004010020040210405242022006114030060142260611423
+006015405040100200401002011121420061140300601402606114430061142050
+401002004010020104202521011003046014030064130304611403006602420040
+100200401004450610030460140300601303046214030462024200401002004010
+042101250404401423006014030454142304601403341210020040100200402224
+304014230060140300541423106014231012100200401002004021040524202200
+611403006015026061142300601400504010020040100201112142006114030060
+140260611443006114605040100200401002010420252101100304601403006113
+030461140300670242004010020040100445061003046014030060130304621403
+046302420040100200401004210125040440142300601403205414230460140310
+121002004010020040222430401423006014030054142310601423201210020040
+100200402104052420220061140300601422606114230060156050401002004010
+020111214200611403006014026061144300611500504010020040100201042025
+210110030460140300641303046114030064024200401002004010044506100304
+601403006013030462140304650242004010020040100421012504044014230060
+140304541423046014033412100200401002004022243040142300601403005414
+231060142324121002004010020040210405242022006114030060150260611423
+006015405040100200401002010323647124222471252122006114030461144051
+031003104021040516216461112344344020444524246201062444751510041105
+214475222122704010046105202531052462011623620104202471072304451621
+620102222521231004311724420116212541241004452421246456024304601423
+106010044506100304601403006413030461140300600242004010020040100415
+012304604014230061144304121002004010020040222430401423006014032054
+142304601403101210020040100200402064051423020061140304621440504010
+020040100201112142006114030060150260611423006015005040100200401002
+010320246114100304601423106302420040100200401004450610030460140300
+641303046114030066024200401002004010041501230460401423006114432012
+100200401002004021040524202200611403006014626061146300611440504010
+020040100201042025210110030460140300640242004010020040100445061003
+046014030060130304621403006002420040100200401004210125040440142300
+601403045414230460140300121002004010020040222430401423006014030054
+142310601403041210020040100200402104052420220061140300601422606114
+230060142050401002004010020111214200611403006014026061144300601440
+504010020040100201042025210110030460140300611303046114030062024200
+401002004010044506100304601403006013030462140300630242004010020040
+100421012504044014230060140304541423046014031412100200401002004022
+243040142300601403005414231060140320121002004010020040210405242022
+006114030060142260611423006015005040100200401002011121420061140300
+601402606114430060152050401002004010020104202521011003046014030061
+130304611403006502420040100200401004450610030460140300601303046214
+030066024200401002004010042101250404401423006014030454142304601403
+301210020040100200402224304014230060140300541423106014033412100200
+401002004021040524202200611403006014226061142300601560504010020040
+100201112142006114030060140260611443006016005040100200401002010420
+252101100304601403006113030461140300600242004010020040100445061003
+046014030060130304621403007102420040100200401004210125040440142300
+601403045414230460140304121002004010020040222430401423006014030054
+142310601423001210020040100200402104052420220061140300601422606114
+230060144050401002004010020111214200611403006014026061144300611420
+504010020040100201042025210110030460140300611303046114030063024200
+401002004010044506100304601403006013030462140304620242004010020040
+100421012504044014230060140304541423046014032012100200401002004022
+243040142300601403005414231060142314121002004010020040210405242022
+006114030060142260611423006015205040100200401002011121420061140300
+601402606114430061150050401002004010020104202521011003046014030061
+130304611403006602420040100200401004450610030460140300601303046214
+030465024200401002004010042101250404401423006014030454142304601403
+341210020040100200402064751625044516252424401423006114430012206201
+042024710723044516216200601402010624447515100411052144752221205061
+140304621422011121420061140300601402606114430060140050401002004010
+020104202521011003046014030061130304611403006002420040100200401004
+450610030460140300601303046214030061024200401002004010042101250404
+401423006014030454142304601403001210020040100200402224304014230060
+140300541423106014031012100200401002004021040524202200611403006014
+226061142300601400504010020040100201112142006114030060140260611443
+006014605040100200401002010420252101100304601403006113030461140300
+600242004010020040100445061003046014030060130304621403006402420040
+100200401004210125040440142300601403045414230460140300121002004010
+020040222430401423006014030054142310601403241210020040100200402104
+052420220061140300601422606114230060140050401002004010020111214200
+611403006014026061144300601540504010020040100201042025210110030460
+140300611303046114030060024200401002004010044506100304601403006013
+030462140300670242004010020040100421012504044014230060140304541423
+046014030012100200401002004022243040142300601403005414231060140340
+121002004010020040210405242022006114030060142260611423006014205040
+100200401002011121420061140300601402606114430060162050401002004010
+020104202521011003046014030061130304611403006102420040100200401004
+450610030460140300601303046214030460024200401002004010042101250404
+401423006014030454142304601403041210020040100200402224304014230060
+140300541423106014230412100200401002004021040524202200611403006014
+226061142300601420504010020040100201112142006114030060140260611443
+006114405040100200401002010420252101100304601403006113030461140300
+610242004010020040100445061003046014030060130304621403046302420040
+100200401004210125040440142300601403045414230460140304121002004010
+020040222430401423006014030054142310601423201210020040100200402104
+052420220061140300601422606114230060142050401002004010020111214200
+611403006014026061144300611520504010020040100201042025210110030460
+140300611303046114030061024200401002004010041517234521112345250510
+030460142310610244144021040516216461112344344014030440214511172322
+010221243117244424121423006114431040222430401423006014030054142310
+601403001210020040100200402104052420220061140300601422606114230060
+144050401002004010020111214200611403006014026061144300601420504010
+020040100201042025210110030460140300611303046114030062024200401002
+004010044506100304601403006013030462140300620242004010020040100421
+012504044014230060140304541423046014031012100200401002004022243040
+142300601403005414231060140314121002004010020040210405242022006114
+030060142260611423006014405040100200401002011121420061140300601402
+606114430060150050401002004010020104202521011003046014030061130304
+611403006202420040100200401004450610030460140300601303046214030065
+024200401002004010042101250404401423006014030454142304601403101210
+020040100200402224304014230060140300541423106014033012100200401002
+004021040524202200611403006014226061142300601440504010020040100201
+112142006114030060140260611443006015605040100200401002010420252101
+100304601403006113030461140300620242004010020040100445061003046014
+030060130304621403007002420040100200401004210125040440142300601403
+045414230460140314121002004010020040222430401423006014030054142310
+601403441210020040100200402104052420220061140300601422606114230060
+146050401002004010020111214200611403006014026061144300611400504010
+020040100201042025210110030460140300611303046114030063024200401002
+004010044506100304601403006013030462140304610242004010020040100421
+012504044014230060140304541423046014031412100200401002004022243040
+142300601403005414231060142310121002004010020040210405242022006114
+030060142260611423006014605040100200401002011121420061140300601402
+606114430061146050401002004010020104202521011003046014030061130304
+611403006302420040100200401004450610030460140300601303046214030464
+024200401002004010042101250404401423006014030454142304601403141210
+020040100200402224304014230060140300541423106014232412100200401002
+004021040524202200611403006014226061142300601460504010020040100201
+032364712422247125212200611403046214405103100421012344351422247107
+100304601004312223646440204425062365110502430460142310631004450610
+030460140300601303046214030060024200401002004010042101250404401423
+006014030454142304601403201210020040100200402224304014230060140300
+541423106014030412100200401002004021040524202200611403006014226061
+142300601500504010020040100201112142006114030060140260611443006014
+405040100200401002010420252101100304601403006113030461140300640242
+004010020040100445061003046014030060130304621403006302420040100200
+401004210125040440142300601403045414230460140320121002004010020040
+222430401423006014030054142310601403201210020040100200402104052420
+220061140300601422606114230060150050401002004010020111214200611403
+006014026061144300601520504010020040100201042025210110030460140300
+611303046114030064024200401002004010044506100304601403006013030462
+140300660242004010020040100421012504044014230060140304541423046014
+032012100200401002004022243040142300601403005414231060140334121002
+004010020040210405242022006114030060142260611423006015005040100200
+401002011121420061140300601402606114430060160050401002004010020104
+202521011003046014030061130304611403006502420040100200401004450610
+030460140300601303046214030071024200401002004010042101250404401423
+006014030454142304601403241210020040100200402224304014230060140300
+541423106014230012100200401002004021040524202200611403006014226061
+142300601520504010020040100201112142006114030060140260611443006114
+205040100200401002010420252101100304601403006113030461140300650242
+004010020040100445061003046014030060130304621403046202420040100200
+401004210125040440142300601403045414230460140324121002004010020040
+222430401423006014030054142310601423141210020040100200402104052420
+220061140300601422606114230060152050401002004010020111214200611403
+006014026061144300611500504010020040100201042025210110030460140300
+611303046114030065024200401002004010044506100304601403006013030462
+140304650242004010020040100421012504044014230060140304541423046014
+032412100200401002004020647516250445162524244014230061144314122062
+010420247107230445162162006114220106244475151004110521447522212050
+611403046215020111214200611403006014026061144300601400504010020040
+100201042025210110030460140300611303046114030066024200401002004010
+044506100304601403006013030462140300610242004010020040100421012504
+044014230060140304541423046014033012100200401002004022243040142300
+601403005414231060140310121002004010020040210405242022006114030060
+142260611423006015405040100200401002011121420061140300601402606114
+430060146050401002004010020104202521011003046014030061130304611403
+006602420040100200401004450610030460140300601303046214030064024200
+401002004010042101250404401423006014030454142304601403301210020040
+100200402224304014230060140300541423106014032412100200401002004021
+040524202200611403006014226061142300601540504010020040100201112142
+006114030060140260611443006015405040100200401002010420252101100304
+601403006113030461140300660242004010020040100445061003046014030060
+130304621403006702420040100200401004210125040440142300601403045414
+230460140330121002004010020040222430401423006014030054142310601403
+401210020040100200402104052420220061140300601422606114230060156050
+401002004010020111214200611403006014026061144300601620504010020040
+100201042025210110030460140300611303046114030067024200401002004010
+044506100304601403006013030462140304600242004010020040100421012504
+044014230060140304541423046014033412100200401002004022243040142300
+601403005414231060142304121002004010020040210405242022006114030060
+142260611423006015605040100200401002011121420061140300601402606114
+430061144050401002004010020104202521011003046014030061130304611403
+006702420040100200401004450610030460140300601303046214030463024200
+401002004010042101250404401423006014030454142304601403341210020040
+100200402224304014230060140300541423106014232012100200401002004021
+040524202200611403006014226061142300601560504010020040100201112142
+006114030060140260611443006115205040100200401002010420252101100304
+601403006113030461140300670242004010020040100415172345211123452505
+100304601423106402441440206475162465210123452123024304611403006010
+042101250404401422606002430461140300611004210125040440142260610243
+046114030062100421012504044014226062024304611403006310042101250404
+401422606302430461140300641004210125040440142260640243046114030065
+100421012504044014226065024304611403006610042101250404401422606602
+430461140300671004210125040440142260670243046214030060100421012504
+044014426060140050611443006014220104202521011003105414030412142310
+601403104021040524202200621303006202430462140300631004210125040440
+144260601460506114430060150201042025210110031054140320121423106014
+032440210405242022006213030065024304621403006610042101250404401442
+606015405061144300601562010420252101100310541403341214231060140340
+402104052420220062130300700243046214030071100421012504044014426060
+162050611443006114020104202521011003105414230012142310601423044021
+040524202200621303046102430462140304621004210125040440144260611440
+506114430061146201042025210110031054142314121423106014232040210405
+242022006213030464024304621403046510042101250404401442606115205061
+146300611442010420252101100314541403046202434471162344711004210125
+0404401503006014030054
Monday, March 29, 2010
Here is a RESOL program that prints itself.
Monday, March 22, 2010
Here is 99 bottles of beer in RESOL.
C 99 BOTTLES IN RESOL
001 DATA 000001
DATA 003,9876543210
DATA 004,9876543210
DATA 005,99
CALL 007,7
CALL 10002
CALL 002
STOP
002 DATA 000001
DATA 002
DATA 002,10001
DATA 001,10001
DATA 10001
CONTINUE 002
003 DATA 000001
004 DATA 000001
005 DATA 000002
C DECREMENT COUNTER
006 IF 003,0
DATA 003,9876543210
IF 003,0
DATA 004
DATA 003
DATA 005,004
DATA 005,003
DATA 005
CONTINUE 006
007 DATA 000001
CALL 100,005
CALL 008
CALL 10000,0200 0415 0406 0200 0402 0405 0405 0502
+ 0200 0415 0414 0200 0504 0408 0405
+ 0200 0507 0401 0412 0412 0212 0200
CALL 100,005
CALL 008
CALL 10000,0200 0415 0406 0200 0402 0405 0405 0502 0214 0010
CALL 002
IF 00,005
CONTINUE 007,009
CALL 10000,0504 0401 0411 0405 0200 0415 0414 0405
+ 0200 0404 0415 0507 0414 0200 0401 0414 0404
+ 0200 0500 0401 0503 0503 0200 0409 0504
+ 0200 0401 0502 0415 0505 0414 0404 0212 0200
CALL 006
CALL 100,005
CALL 008
CALL 10000,0200 0415 0406 0200 0402 0405 0405 0502
+ 0200 0415 0414 0200 0504 0408 0405
+ 0200 0507 0401 0412 0412 0214 0010 0010
CALL 002
CONTINUE 007
C BOTTLE(S)
008 CALL 10000,0200 0402 0415 0504 0504 0412 0405
IF 01,005
CONTINUE 008
CALL 10000,0503
CONTINUE 008
009 CALL 10000,0407 0415 0200 0504 0415 0200 0504 0408 0405
+ 0200 0503 0504 0415 0502 0405 0200 0401 0414 0404
+ 0200 0402 0505 0509 0200 0503 0415 0413 0405
+ 0200 0413 0415 0502 0405 0212 0200 0309 0309
+ 0200 0402 0415 0504 0504 0412 0405 0503
+ 0200 0415 0406 0200 0402 0405 0405 0502
+ 0200 0415 0414 0200 0504 0408 0405
+ 0200 0507 0401 0412 0412 0214 0010
DATA 007
CONTINUE 007
C OUTPUT PASSED IN COUNT OR "NO MORE" WHEN COUNT IS 00
100 DATA 000001
IF 100,0
CALL 101
CONTINUE 100,103
101 DATA 100
IF 100,0
CALL 10000,0414041502000413041505020405
IF 100,0
CONTINUE 100,102
CALL 104
102 DATA 100
CONTINUE 101
103 CALL 104
DATA 100
CALL 104
DATA 100
CONTINUE 100
104 IF 100,0
CALL 10000,0300
IF 100,1
CALL 10000,0301
IF 100,2
CALL 10000,0302
IF 100,3
CALL 10000,0303
IF 100,4
CALL 10000,0304
IF 100,5
CALL 10000,0305
IF 100,6
CALL 10000,0306
IF 100,7
CALL 10000,0307
IF 100,8
CALL 10000,0308
IF 100,9
CALL 10000,0309
CONTINUE 104
C THIS IS A LIBRARY THAT CONVERTS 4-BIT ITEMS ENQUEUED INTO 10000 AS 2 DIGITS
C INTO 3-BIT ITEMS IN 1 DIGIT THAT ARE AVAILABLE AT 10001.
C CALL 10000 TO PROCESS ITEMS FROM 10000 INTO 10001.
C CALL 10002 TO FLUSH THE FINAL DANGLING BITS (0-2 BITS).
C
C IF 000002 IS A DATA STATEMENT, CALLING 10000 WILL DEQUEUE FROM IT. BEST
C NOT TO HAVE 000002 AS A LABEL (WHICH WOULD REQUIRE A CONTINUATION LINE).
C
10000 DATA 000002
IF 10003,11000
CALL 10100
IF 10003,11001
CALL 10110
IF 10003,11002
CALL 10120
DATA 10003
DATA 10000
CONTINUE 10000
10001 DATA 1
C
C FLUSH THE FINAL DANGLING BITS
10002 IF 10003,11000
CONTINUE 10002
DATA 10001,10004
DATA 10004
C REINITIALIZE 10003 TO 012
IF 10003,11001
DATA 10003
DATA 10003
DATA 10003,012
CONTINUE 10002
C
C 10003 HOLDS THE NUMBER OF DANGLING BITS
10003 DATA 1,012
C 10004 HOLDS THE VALUE OF THE DANGLING BITS
10004 DATA 1
C
C NO DANGLING BITS FROM BEFORE. LEAVES 1 DANGLING BIT FOR NEXT ITEM.
10100 IF 10000,12000
DATA 10001,11000
IF 10000,12000
DATA 10004,11000
IF 10000,12001
DATA 10001,11000
IF 10000,12001
DATA 10004,11004
IF 10000,12002
DATA 10001,11001
IF 10000,12002
DATA 10004,11000
IF 10000,12003
DATA 10001,11001
IF 10000,12003
DATA 10004,11004
IF 10000,12004
DATA 10001,11002
IF 10000,12004
DATA 10004,11000
IF 10000,12005
DATA 10001,11002
IF 10000,12005
DATA 10004,11004
IF 10000,12006
DATA 10001,11003
IF 10000,12006
DATA 10004,11000
IF 10000,12007
DATA 10001,11003
IF 10000,12007
DATA 10004,11004
IF 10000,12008
DATA 10001,11004
IF 10000,12008
DATA 10004,11000
IF 10000,12009
DATA 10001,11004
IF 10000,12009
DATA 10004,11004
IF 10000,12010
DATA 10001,11005
IF 10000,12010
DATA 10004,11000
IF 10000,12011
DATA 10001,11005
IF 10000,12011
DATA 10004,11004
IF 10000,12012
DATA 10001,11006
IF 10000,12012
DATA 10004,11000
IF 10000,12013
DATA 10001,11006
IF 10000,12013
DATA 10004,11004
IF 10000,12014
DATA 10001,11007
IF 10000,12014
DATA 10004,11000
IF 10000,12015
DATA 10001,11007
IF 10000,12015
DATA 10004,11004
CONTINUE 10100
C
C 1 DANGLING BIT FROM BEFORE. LEAVES 2 DANGLING BITS FOR NEXT ITEM.
10110 IF 10004,11000
CALL 10111
IF 10004,11004
CALL 10112
DATA 10004
CONTINUE 10110
C DANGLING 0 FROM BEFORE
10111 IF 10000,12000
DATA 10001,11000
IF 10000,12000
DATA 10004,11000
IF 10000,12001
DATA 10001,11000
IF 10000,12001
DATA 10004,11002
IF 10000,12002
DATA 10001,11000
IF 10000,12002
DATA 10004,11004
IF 10000,12003
DATA 10001,11000
IF 10000,12003
DATA 10004,11006
IF 10000,12004
DATA 10001,11001
IF 10000,12004
DATA 10004,11000
IF 10000,12005
DATA 10001,11001
IF 10000,12005
DATA 10004,11002
IF 10000,12006
DATA 10001,11001
IF 10000,12006
DATA 10004,11004
IF 10000,12007
DATA 10001,11001
IF 10000,12007
DATA 10004,11006
IF 10000,12008
DATA 10001,11002
IF 10000,12008
DATA 10004,11000
IF 10000,12009
DATA 10001,11002
IF 10000,12009
DATA 10004,11002
IF 10000,12010
DATA 10001,11002
IF 10000,12010
DATA 10004,11004
IF 10000,12011
DATA 10001,11002
IF 10000,12011
DATA 10004,11006
IF 10000,12012
DATA 10001,11003
IF 10000,12012
DATA 10004,11000
IF 10000,12013
DATA 10001,11003
IF 10000,12013
DATA 10004,11002
IF 10000,12014
DATA 10001,11003
IF 10000,12014
DATA 10004,11004
IF 10000,12015
DATA 10001,11003
IF 10000,12015
DATA 10004,11006
CONTINUE 10111
C DANGLING 1 FROM BEFORE
10112 IF 10000,12000
DATA 10001,11004
IF 10000,12000
DATA 10004,11000
IF 10000,12001
DATA 10001,11004
IF 10000,12001
DATA 10004,11002
IF 10000,12002
DATA 10001,11004
IF 10000,12002
DATA 10004,11004
IF 10000,12003
DATA 10001,11004
IF 10000,12003
DATA 10004,11006
IF 10000,12004
DATA 10001,11005
IF 10000,12004
DATA 10004,11000
IF 10000,12005
DATA 10001,11005
IF 10000,12005
DATA 10004,11002
IF 10000,12006
DATA 10001,11005
IF 10000,12006
DATA 10004,11004
IF 10000,12007
DATA 10001,11005
IF 10000,12007
DATA 10004,11006
IF 10000,12008
DATA 10001,11006
IF 10000,12008
DATA 10004,11000
IF 10000,12009
DATA 10001,11006
IF 10000,12009
DATA 10004,11002
IF 10000,12010
DATA 10001,11006
IF 10000,12010
DATA 10004,11004
IF 10000,12011
DATA 10001,11006
IF 10000,12011
DATA 10004,11006
IF 10000,12012
DATA 10001,11007
IF 10000,12012
DATA 10004,11000
IF 10000,12013
DATA 10001,11007
IF 10000,12013
DATA 10004,11002
IF 10000,12014
DATA 10001,11007
IF 10000,12014
DATA 10004,11004
IF 10000,12015
DATA 10001,11007
IF 10000,12015
DATA 10004,11006
CONTINUE 10112
C
C 2 DANGLING BITS FROM BEFORE. LEAVES NO DANGLING BITS FOR NEXT ITEM.
10120 IF 10004,11000
CALL 10121
IF 10004,11002
CALL 10122
IF 10004,11004
CALL 10123
IF 10004,11006
CALL 10124
DATA 10003,13012
DATA 10004
IF 10000,12000
DATA 10001,11000
IF 10000,12001
DATA 10001,11001
IF 10000,12002
DATA 10001,11002
IF 10000,12003
DATA 10001,11003
IF 10000,12004
DATA 10001,11004
IF 10000,12005
DATA 10001,11005
IF 10000,12006
DATA 10001,11006
IF 10000,12007
DATA 10001,11007
IF 10000,12008
DATA 10001,11000
IF 10000,12009
DATA 10001,11001
IF 10000,12010
DATA 10001,11002
IF 10000,12011
DATA 10001,11003
IF 10000,12012
DATA 10001,11004
IF 10000,12013
DATA 10001,11005
IF 10000,12014
DATA 10001,11006
IF 10000,12015
DATA 10001,11007
CONTINUE 10120
C DANGLING 00 FROM BEFORE
10121 IF 10000,12000
DATA 10001,11000
IF 10000,12001
DATA 10001,11000
IF 10000,12002
DATA 10001,11000
IF 10000,12003
DATA 10001,11000
IF 10000,12004
DATA 10001,11000
IF 10000,12005
DATA 10001,11000
IF 10000,12006
DATA 10001,11000
IF 10000,12007
DATA 10001,11000
IF 10000,12008
DATA 10001,11001
IF 10000,12009
DATA 10001,11001
IF 10000,12010
DATA 10001,11001
IF 10000,12011
DATA 10001,11001
IF 10000,12012
DATA 10001,11001
IF 10000,12013
DATA 10001,11001
IF 10000,12014
DATA 10001,11001
IF 10000,12015
DATA 10001,11001
CONTINUE 10121
C DANGLING 01 FROM BEFORE
10122 IF 10000,12000
DATA 10001,11002
IF 10000,12001
DATA 10001,11002
IF 10000,12002
DATA 10001,11002
IF 10000,12003
DATA 10001,11002
IF 10000,12004
DATA 10001,11002
IF 10000,12005
DATA 10001,11002
IF 10000,12006
DATA 10001,11002
IF 10000,12007
DATA 10001,11002
IF 10000,12008
DATA 10001,11003
IF 10000,12009
DATA 10001,11003
IF 10000,12010
DATA 10001,11003
IF 10000,12011
DATA 10001,11003
IF 10000,12012
DATA 10001,11003
IF 10000,12013
DATA 10001,11003
IF 10000,12014
DATA 10001,11003
IF 10000,12015
DATA 10001,11003
CONTINUE 10122
C DANGLING 10 FROM BEFORE
10123 IF 10000,12000
DATA 10001,11004
IF 10000,12001
DATA 10001,11004
IF 10000,12002
DATA 10001,11004
IF 10000,12003
DATA 10001,11004
IF 10000,12004
DATA 10001,11004
IF 10000,12005
DATA 10001,11004
IF 10000,12006
DATA 10001,11004
IF 10000,12007
DATA 10001,11004
IF 10000,12008
DATA 10001,11005
IF 10000,12009
DATA 10001,11005
IF 10000,12010
DATA 10001,11005
IF 10000,12011
DATA 10001,11005
IF 10000,12012
DATA 10001,11005
IF 10000,12013
DATA 10001,11005
IF 10000,12014
DATA 10001,11005
IF 10000,12015
DATA 10001,11005
CONTINUE 10123
C DANGLING 11 FROM BEFORE
10124 IF 10000,12000
DATA 10001,11006
IF 10000,12001
DATA 10001,11006
IF 10000,12002
DATA 10001,11006
IF 10000,12003
DATA 10001,11006
IF 10000,12004
DATA 10001,11006
IF 10000,12005
DATA 10001,11006
IF 10000,12006
DATA 10001,11006
IF 10000,12007
DATA 10001,11006
IF 10000,12008
DATA 10001,11007
IF 10000,12009
DATA 10001,11007
IF 10000,12010
DATA 10001,11007
IF 10000,12011
DATA 10001,11007
IF 10000,12012
DATA 10001,11007
IF 10000,12013
DATA 10001,11007
IF 10000,12014
DATA 10001,11007
IF 10000,12015
DATA 10001,11007
CONTINUE 10124
C
C CONSTANTS
11000 DATA 1,0
11001 DATA 1,1
11002 DATA 1,2
11003 DATA 1,3
11004 DATA 1,4
11005 DATA 1,5
11006 DATA 1,6
11007 DATA 1,7
12000 DATA 2,00
12001 DATA 2,01
12002 DATA 2,02
12003 DATA 2,03
12004 DATA 2,04
12005 DATA 2,05
12006 DATA 2,06
12007 DATA 2,07
12008 DATA 2,08
12009 DATA 2,09
12010 DATA 2,10
12011 DATA 2,11
12012 DATA 2,12
12013 DATA 2,13
12014 DATA 2,14
12015 DATA 2,15
13012 DATA 3,012
Monday, March 15, 2010
After getting reacquainted with Haskell, I really like using it. However, using lots of higher-order functions and operators makes for dense APL-like code that is inaccessible to those unfamiliar with those functions and operators. And, parser combinators introduce very expressive and extensible ways to create parsers, but would also look foreign to the uninitiated. But these operators and functions also can be used to make very elegant and maintainable code.
For example, I'm writing code to deal with JVM class files. To write to a class file, I want to convert various things to a list of bytes, so I made a typeclass for that:
Then, since many objects, when converted to a list of bytes, are just the concatenation of the conversion of component objects, I defined
which is an example of dense APL-like code, using the (.) and ($) operators and the flip and concatMap higher-order functions. However, it enables this:
For most of the cases, having the ToBytes type class doesn't buy me that much. It saves having to have separate names for jvmClassToBytes, word16ToBytes, word32ToBytes, etc, but they still have to be defined. However, when there are lists of items in the class file format, it is preceded with a 16 bit count, so I can define
so the constant pool (with a hack for the off by 1 length and the double-sized long and double constants), and the lists of interfaces, fields, methods, and attributes can be taken care of by defining toBytes for single items.
For reading class files, I learned how to make a state-transformer monad, which looks like this
There are the uncurry higher-order function and the (.) operator making things hard to understand for those unfamiliar with them, not to mention the odd looking (,) constructor. However, it enables code like this:
which is very maintainable.
Using Functor and Applicative
it could be written more concisely, but with more weird operators:
readJVMClass (readWord32, readWord16, ...) doesn't return a JVMClass (Word32, Word16, ...), it returns a state transformer, which is a function that takes a state, and returns an updated state and a JVMClass (Word32, Word16, ...). readJVMClass just builds a state transformer that chains other state transformers and extracts the values that they return. To actually do the reading and building, one must use runST.
For example, I'm writing code to deal with JVM class files. To write to a class file, I want to convert various things to a list of bytes, so I made a typeclass for that:
class ToBytes a where
toBytes :: a -> [Word8]
Then, since many objects, when converted to a list of bytes, are just the concatenation of the conversion of component objects, I defined
concatAccessors :: [a -> [b]] -> a -> [b]
concatAccessors = flip (.) (flip ($)) . flip concatMap
which is an example of dense APL-like code, using the (.) and ($) operators and the flip and concatMap higher-order functions. However, it enables this:
instance ToBytes JVMClass where
toBytes = concatAccessors [
toBytes . jvmClassMagic,
toBytes . jvmClassMinorVersion,
toBytes . jvmClassMajorVersion,
toBytes . jvmClassConstantPool,
toBytes . jvmClassAccessFlags,
toBytes . jvmClassThisClass,
toBytes . jvmClassSuperClass,
toBytes . jvmClassInterfaces,
toBytes . jvmClassFields,
toBytes . jvmClassMethods,
toBytes . jvmClassAttributes
]
For most of the cases, having the ToBytes type class doesn't buy me that much. It saves having to have separate names for jvmClassToBytes, word16ToBytes, word32ToBytes, etc, but they still have to be defined. However, when there are lists of items in the class file format, it is preceded with a 16 bit count, so I can define
instance ToBytes a => ToBytes [a] where
toBytes l = toBytes (fromIntegral (length l) :: Word16) ++ concatMap toBytes l
so the constant pool (with a hack for the off by 1 length and the double-sized long and double constants), and the lists of interfaces, fields, methods, and attributes can be taken care of by defining toBytes for single items.
For reading class files, I learned how to make a state-transformer monad, which looks like this
newtype ST st a = ST (st -> (a,st))
instance Monad (ST st) where
p >>= q = ST (uncurry (s . q) . s p) where s (ST t) = t
return = ST . (,)
runST :: ST st a -> st -> a
runST (ST t) = fst . t
There are the uncurry higher-order function and the (.) operator making things hard to understand for those unfamiliar with them, not to mention the odd looking (,) constructor. However, it enables code like this:
readJVMClass :: ST State JVMClass
readJVMClass = do
magic <- readWord32
minorVersion <- readWord16
majorVersion <- readWord16
constantPool <- readConstantPool
accessFlags <- readWord16
thisClass <- readWord16
superClass <- readWord16
interfaces <- readList readWord16
fields <- readList readField
methods <- readList readMethod
attributes <- readList readAttribute
return (JVMClass magic minorVersion majorVersion constantPool accessFlags
thisClass superClass interfaces fields methods attributes)
which is very maintainable.
Using Functor and Applicative
instance Functor (ST st) where
fmap f p = do { a <- p; return (f a) }
instance Applicative (ST st) where
pure = return
p <*> q = do { f <- p; a <- q; return (f a) }
it could be written more concisely, but with more weird operators:
readJVMClass = JVMClass <$> readWord32
<*> readWord16
<*> readWord16
<*> readConstantPool
<*> readWord16
<*> readWord16
<*> readWord16
<*> readList readWord16
<*> readList readField
<*> readList readMethod
<*> readList readAttribute
readJVMClass (readWord32, readWord16, ...) doesn't return a JVMClass (Word32, Word16, ...), it returns a state transformer, which is a function that takes a state, and returns an updated state and a JVMClass (Word32, Word16, ...). readJVMClass just builds a state transformer that chains other state transformers and extracts the values that they return. To actually do the reading and building, one must use runST.
Monday, March 8, 2010
There was some feature that, due to changes in an external service, stopped working. The trunk was fixed to work with the new version of the external service, but the release branch was not. The bug report classified it as a regression, but it wasn't a regression, as the feature had stopped working in the same manner in production. It was decided that it was too risky to copy the fix from the trunk to the release branch.
Now, this new release also included the launch of a new virtual host, where having the non-working feature was not an option, so it was decided that the feature had to be disabled for that virtual host, so an ugly hack got put in to disable that feature for one set of use cases. Then, I got called in to review the hack and was told that it needed to be extended to some other use cases. It turned out that I had added a general mechanism to do per-virtual host configuration 8 or 9 months earlier for another feature, so the ugly hack was reverted, and per-virtual host configuration was changed to disable that feature for all the use cases on that virtual host.
Now, this new release also included the launch of a new virtual host, where having the non-working feature was not an option, so it was decided that the feature had to be disabled for that virtual host, so an ugly hack got put in to disable that feature for one set of use cases. Then, I got called in to review the hack and was told that it needed to be extended to some other use cases. It turned out that I had added a general mechanism to do per-virtual host configuration 8 or 9 months earlier for another feature, so the ugly hack was reverted, and per-virtual host configuration was changed to disable that feature for all the use cases on that virtual host.
Monday, March 1, 2010
I got a 3am call because of some problem when a new version went out to production. It turned out to be some code using an external hostname that was invisible to the internal host. I wasn't involved in figuring out the problem, because I was looking at the pieces that I had worked on. When it was figured out, I went back to sleep. These problems keep turning up because there are no distinct internal and external hostnames in the testing and development environments, and anyone new to the project hasn't gotten lots of these late-night calls.
Monday, February 22, 2010
Here is an interpreter for 01_ that I wrote in 01_. It compiles the 01_ source code into a bit code, and then interprets that bit code.
One limitation is that the top-level function evaluated is the first function defined in the source, instead of the function specified on the command line or inferred from the filename. This could easily be coded to be, in a fashion, specified from the command line. This would be somewhat awkward, since the 01_ code does not get the actual command line data, but rather, the contents of the file named in the command line, so the name of the function to be evaluated would have to be put into a file or piped into stdin to be received by the interpreter.
Another limitation is that it can only pass in a maximum of 9 arguments to the top level function. (Any additional arguments will be given nil.) This limit can be easily changed by changing the arglist function (and the interp and bitcode functions) to take a different number of arguments.
Here is the bit code format used by my 01_ interpreter.
Parenthesis indicates a list. Ellipses indicates zero or more of the
preceding item. A vertical bar indicates alternatives.
The program has the name of the function to apply, the number of arguments that function takes, a pair of lists forming an association list of names to functions.
A push op pushes its value onto the local stack to be used as an argument to a function call. A concat op concatenates its result to the value that is returned by the current function.
A binding value has an index to the bound parameters of the function. Let n = the number of bound parameters, then 0 is the last parameter, and n - 1 is the first parameter.
A funcall value has the name of the function and the number of arguments that function takes.
All the counts, the binding index and the number of arguments taken by a function, are in base 1.
Since I've implemented multiple 01_ interpreters, here's a comparison of the source code sizes:
One limitation is that the top-level function evaluated is the first function defined in the source, instead of the function specified on the command line or inferred from the filename. This could easily be coded to be, in a fashion, specified from the command line. This would be somewhat awkward, since the 01_ code does not get the actual command line data, but rather, the contents of the file named in the command line, so the name of the function to be evaluated would have to be put into a file or piped into stdin to be received by the interpreter.
Another limitation is that it can only pass in a maximum of 9 arguments to the top level function. (Any additional arguments will be given nil.) This limit can be easily changed by changing the arglist function (and the interp and bitcode functions) to take a different number of arguments.
Bit code format
Here is the bit code format used by my 01_ interpreter.
Parenthesis indicates a list. Ellipses indicates zero or more of the
preceding item. A vertical bar indicates alternatives.
program = (name ones names functions)
names = (name name ...)
functions = (definitions definitions ...)
definitions = (definition definition ...)
definition = (patterns body)
patterns = (pattern ...)
pattern = bound-pattern | literal-pattern | wild-pattern
bound-pattern = 0 bits
literal-pattern = 1 0 bits
wild-pattern = 1 1 bits
bits = bit ...
bit = 0 | 1
ones = 1 ...
body = op op ...
op = push | concat
push = 0 value
concat = 1 value
value = literal | binding | funcall
binding = 0 ones
literal = 1 0 bits
funcall = 1 1 (bits ones)
The program has the name of the function to apply, the number of arguments that function takes, a pair of lists forming an association list of names to functions.
A push op pushes its value onto the local stack to be used as an argument to a function call. A concat op concatenates its result to the value that is returned by the current function.
A binding value has an index to the bound parameters of the function. Let n = the number of bound parameters, then 0 is the last parameter, and n - 1 is the first parameter.
A funcall value has the name of the function and the number of arguments that function takes.
All the counts, the binding index and the number of arguments taken by a function, are in base 1.
Library functions
== library
== force a pattern match failure
error 0 = error _.
concat a b = a b.
== lists
== first item in the list
head 0. = _.
head 11rest = 1 head rest.
head 10rest = 0 head rest.
head _ = _.
== the list with the first item removed
tail 0rest = rest.
tail 11rest = tail rest.
tail 10rest = tail rest.
tail _ = _.
list-encode _ = 0.
list-encode 1x = 11 list-encode x.
list-encode 0x = 10 list-encode x.
== association lists
== association list lookup
alist-lookup key klist dlist =
if-equal key head klist
head dlist
alist-lookup key tail klist tail dlist.
alist-lookup . _ . = _.
== association list update
alist-update key data klist dlist =
if-equal key head klist
concat list-encode data
tail dlist
concat list-encode head dlist
alist-update key data
tail klist
tail dlist.
alist-append key data klist dlist =
if-equal key head klist
concat list-encode concat head dlist
list-encode data
tail dlist
concat list-encode head dlist
alist-append key data
tail klist
tail dlist.
== stacks
== new empty stack
empty-stack = 0_.
== number of items in the stack (in base 1)
stack-count 0stack = _.
stack-count 1stack = 1 stack-count stack.
drop-stack-count 0stack = stack.
drop-stack-count 1stack = drop-stack-count stack.
== top of the stack
top 0. = _. == stack underflow
top stack = top' decrement-count stack-count stack drop-stack-count stack.
top' count 0stack-data = _.
top' count 10stack-data = 0 top' count drop-stack-bit count stack-data.
top' count 11stack-data = 1 top' count drop-stack-bit count stack-data.
decrement-count 1count = count.
drop-stack-bit _ stack-data = stack-data.
drop-stack-bit 1count 0stack-data = drop-stack-bit count stack-data.
drop-stack-bit 1count 10stack-data = drop-stack-bit count stack-data.
drop-stack-bit 1count 11stack-data = drop-stack-bit count stack-data.
== returns stack with data pushed on top
push data stack =
1 stack-count stack 0 push' data stack-count stack drop-stack-count stack.
push' _ count stack-data =
0 take-stack-bit count stack-data
push' _ count drop-stack-bit count stack-data.
push' 0data count stack-data =
10 take-stack-bit count stack-data
push' data count drop-stack-bit count stack-data.
push' 1data count stack-data =
11 take-stack-bit count stack-data
push' data count drop-stack-bit count stack-data.
take-stack-bit _ . = _.
take-stack-bit 1count 0stack-data = 0 take-stack-bit count stack-data.
take-stack-bit 1count 10stack-data = 10 take-stack-bit count stack-data.
take-stack-bit 1count 11stack-data = 11 take-stack-bit count stack-data.
== returns stack with the top item popped
pop 0. = 0_. == stack underflow
pop 10. = 0_. == 1 item optimization
pop 1stack = stack-count stack 0 pop' stack-count stack drop-stack-count stack.
pop' count 0stack-data =
take-stack-bit count stack-data
pop' count drop-stack-bit count stack-data.
pop' count 10stack-data =
take-stack-bit count stack-data
pop' count drop-stack-bit count stack-data.
pop' count 11stack-data =
take-stack-bit count stack-data
pop' count drop-stack-bit count stack-data.
== conditional
if-equal 0x 0y true false = if-equal x y true false.
if-equal 1x 1y true false = if-equal x y true false.
if-equal _ _ true . = true.
if-equal . . . false = false.
==
take-bits _ . = _.
take-bits . _ = _.
take-bits 0bits 0data = 0 take-bits bits data.
take-bits 1bits 0data = 0 take-bits bits data.
take-bits 0bits 1data = 1 take-bits bits data.
take-bits 1bits 1data = 1 take-bits bits data.
drop-bits _ data = data.
drop-bits . _ = _.
drop-bits 0bits 0data = drop-bits bits data.
drop-bits 1bits 0data = drop-bits bits data.
drop-bits 0bits 1data = drop-bits bits data.
drop-bits 1bits 1data = drop-bits bits data.
Tokenizer
== 01_ tokenizer
== token tokenized
== 0 0
== 1 1
== _ 00
== . 01
== = 10
== input stream to list of tokens
tokenize in = tokenize' in _.
tokenize' _ . = _.
== comment
tokenize' 00111101 00111101in flag = end-symbol flag
drop-comment in.
== 0
tokenize' 00110000in flag = end-symbol flag
100 tokenize' in _.
== 1
tokenize' 00110001in flag = end-symbol flag
110 tokenize' in _.
== _
tokenize' 01011111in flag = end-symbol flag
10100 tokenize' in _.
== .
tokenize' 00101110in flag = end-symbol flag
10110 tokenize' in _.
== =
tokenize' 00111101in flag = end-symbol flag
11100 tokenize' in _.
== whitespace
tokenize' 00100000in flag = end-symbol flag tokenize' in _. == SPC
tokenize' 00001001in flag = end-symbol flag tokenize' in _. == TAB
tokenize' 00001010in flag = end-symbol flag tokenize' in _. == LF
tokenize' 00001101in flag = end-symbol flag tokenize' in _. == CR
== symbol
tokenize' in . = take-symbol 00000000 in.
end-symbol _ = _.
end-symbol . = 0.
take-symbol _ in = tokenize' in 0.
take-symbol 0bits 0in = 10 take-symbol bits in.
take-symbol 0bits 1in = 11 take-symbol bits in.
== comment
drop-comment _ = _.
drop-comment 00001010in = tokenize' in _.
drop-comment in = drop-comment drop-bits 00000000 in.
==
test-tokenize in = test-tokenize-out tokenize in _.
test-tokenize-out _ . = _.
test-tokenize-out list flag = test-tokenize-out-one head list tail list flag.
test-tokenize-out-one 0_ list . = 00110000 test-tokenize-out list _.
test-tokenize-out-one 1_ list . = 00110001 test-tokenize-out list _.
test-tokenize-out-one 00_ list . = 01011111 test-tokenize-out list _.
test-tokenize-out-one 01_ list . = 00101110 test-tokenize-out list _.
test-tokenize-out-one 10_ list . = 00111101 test-tokenize-out list _.
test-tokenize-out-one one list flag = test-tokenize-out-sep flag one test-tokenize-out list 0.
test-tokenize-out-sep _ = _.
test-tokenize-out-sep . = 00100000.
Parser
== parse a list of 01_ tokens into a list of function names
parse-names tokens = parse-names' head tokens tail tokens _.
parse-names' _ . list = list.
parse-names' 0_ . . = error _. == expecting symbol
parse-names' 1_ . . = error _. == expecting symbol
parse-names' 00_ . . = error _. == expecting symbol
parse-names' 01_ . . = error _. == expecting symbol
parse-names' 10_ . . = error _. == expecting symbol
parse-names' name tokens list =
parse-names' head parse-drop-def head tokens tail tokens
tail parse-drop-def head tokens tail tokens
add-unique name list.
add-unique item _ = list-encode item.
add-unique item list = list-encode head list
if-equal item head list
tail list
add-unique item
tail list.
parse-drop-def 10_ tokens = parse-drop-def-body head tokens tail tokens.
parse-drop-def . tokens = parse-drop-def head tokens tail tokens.
parse-drop-def-body 01_ tokens = tokens.
parse-drop-def-body . tokens = parse-drop-def-body head tokens tail tokens.
test-parse-names in = test-tokenize-out parse-names tokenize in _.
== given a list of items, return a list of empty lists of equal length
== this can be used to initialize association lists
== keys cannot be nil
alist-empty-values keys = alist-empty-values' head keys tail keys.
alist-empty-values' _ . = _.
alist-empty-values' . keys = 0 alist-empty-values' head keys tail keys.
== collect arities from list of 01_ tokens
parse-arities names tokens = parse-arities' names
alist-empty-values names
head tokens
tail tokens.
parse-arities' names arities _ . = arities.
parse-arities' names arities name tokens =
parse-arities-count-args names arities name _
head tokens
tail tokens
_.
parse-arities-count-args names arities name count _ tokens flag = error _.
== unexpected EOF
parse-arities-count-args names arities name count 10_ tokens _ =
== got = without any bits
parse-arities' names
alist-update name count names arities
head parse-drop-def-body head tokens tail tokens
tail parse-drop-def-body head tokens tail tokens.
parse-arities-count-args names arities name count 10_ tokens . =
== got = with leading bits
parse-arities' names
alist-update name
concat 1 count
names arities
head parse-drop-def-body head tokens tail tokens
tail parse-drop-def-body head tokens tail tokens.
parse-arities-count-args names arities name count 0_ tokens . =
parse-arities-count-args names arities name count
head tokens
tail tokens
0.
parse-arities-count-args names arities name count 1_ tokens . =
parse-arities-count-args names arities name count
head tokens
tail tokens
0.
parse-arities-count-args names arities name count . tokens . =
parse-arities-count-args names arities name
concat 1 count
head tokens
tail tokens
_.
test-parse-arities in = test-parse-arities' parse-names tokenize in
tokenize in.
test-parse-arities' names tokens =
test-alist-out names parse-arities names tokens.
test-alist-out _ . = _.
test-alist-out klist dlist =
head klist
00111101
test-bits-out head dlist
00001010
test-alist-out tail klist tail dlist.
test-bits-out _ = _.
test-bits-out 0b = 00110000 test-bits-out b.
test-bits-out 1b = 00110001 test-bits-out b.
== parse
parse tokens = parse' parse-names tokens tokens.
parse' names tokens = parse'' names parse-arities names tokens tokens.
parse'' names arities tokens =
list-encode head names
list-encode head arities
list-encode names
list-encode parse-functions names arities
alist-empty-values names
tokens.
parse-functions names arities functions _ = functions.
parse-functions names arities functions tokens =
parse-functions names arities
alist-append head tokens
parse-def-args names arities _ _ _
head tail tokens
tail tail tokens
names
functions
parse-drop-def head tokens tail tokens.
parse-def-args names arities bindings bits patterns 10_ tokens = == =
if-equal bits _
list-encode patterns
list-encode concat patterns
list-encode concat 10 bits == literal pattern
parse-def-body names arities bindings _ _ _ head tokens tail tokens.
parse-def-args names arities bindings bits patterns 0_ tokens = == 0
parse-def-args names arities bindings
concat bits 0
patterns
head tokens
tail tokens.
parse-def-args names arities bindings bits patterns 1_ tokens = == 1
parse-def-args names arities bindings
concat bits 1
patterns
head tokens
tail tokens.
parse-def-args names arities bindings bits patterns 00_ tokens = == _
== literal pattern
parse-def-args names arities bindings
_
concat patterns
list-encode concat 10 bits
head tokens
tail tokens.
parse-def-args names arities bindings bits patterns 01_ tokens = == .
== wild pattern
parse-def-args names arities bindings
_
concat patterns
list-encode concat 11 bits
head tokens
tail tokens.
parse-def-args names arities bindings bits patterns arg tokens =
== bound pattern
parse-def-args names arities
concat list-encode arg
bindings
_
concat patterns
list-encode concat 0 bits
head tokens
tail tokens.
parse-def-body names arities bindings argcounts funcalls bits _ . = error _.
parse-def-body names arities bindings argcounts funcalls bits 0_ tokens =
parse-def-body names arities bindings
argcounts funcalls
concat bits 0
head tokens
tail tokens.
parse-def-body names arities bindings argcounts funcalls bits 1_ tokens =
parse-def-body names arities bindings
argcounts funcalls
concat bits 1
head tokens
tail tokens.
parse-def-body names arities bindings argcounts funcalls _ 01_ . = _.
== . end of definition
parse-def-body names arities bindings argcounts funcalls _ 00_ tokens =
== _ nil constant
list-encode if-equal argcounts _
110_ == concat nil
010 == push nil
check-argcounts argcounts funcalls
head argcounts
parse-def-body names arities bindings
decrement-argcounts argcounts head argcounts
decrement-funcalls argcounts funcalls head argcounts
_
head tokens
tail tokens.
parse-def-body names arities bindings argcounts funcalls _ token tokens =
== symbol: either binding or funcall
parse-def-try-binding names arities bindings argcounts funcalls tokens
token bindings _
alist-lookup token names arities.
parse-def-body names arities bindings argcounts funcalls _ token tokens =
== symbol: either binding or funcall
parse-def-try-binding names arities bindings argcounts funcalls
tokens
token bindings _
alist-lookup token names arities.
parse-def-body names arities bindings argcounts funcalls bits 00_ tokens =
== _ terminated constant
list-encode if-equal argcounts _
concat 110 bits == concat nil
concat 010 bits == push nil
check-argcounts argcounts funcalls
head argcounts
parse-def-body names arities bindings
decrement-argcounts argcounts head argcounts
decrement-funcalls argcounts funcalls head argcounts
_
head tokens
tail tokens.
parse-def-body names arities bindings argcounts funcalls bits token tokens =
== end of constant
list-encode if-equal argcounts _
concat 110 bits == concat nil
concat 010 bits == push nil
check-argcounts argcounts funcalls
head argcounts
parse-def-body names arities bindings
decrement-argcounts argcounts head argcounts
decrement-funcalls argcounts funcalls head argcounts
_
token
tokens.
parse-def-try-binding names arities bindings argcounts funcalls tokens
name _ . _ =
== not in bindings, nullary funcall
list-encode if-equal _ argcounts
concat 111 concat list-encode name 0
concat 011 concat list-encode name 0
check-argcounts argcounts funcalls
head argcounts
parse-def-body names arities bindings
decrement-argcounts argcounts head argcounts
decrement-funcalls argcounts funcalls head argcounts
_
head tokens
tail tokens.
parse-def-try-binding names arities bindings argcounts funcalls tokens
name _ . arity =
== not in bindings, push funcall
parse-def-body names arities bindings
concat list-encode arity
argcounts
concat list-encode concat list-encode name
list-encode arity
funcalls
_
head tokens
tail tokens.
parse-def-try-binding names arities bindings argcounts funcalls tokens
name bind-list bind-index arity =
if-equal name head bind-list
parse-def-emit-bound names arities bindings
argcounts funcalls tokens
bind-index
parse-def-try-binding names arities bindings
argcounts funcalls tokens
name
tail bind-list
concat 1 bind-index
arity.
parse-def-emit-bound names arities bindings argcounts funcalls tokens
bind-index =
list-encode if-equal _ argcounts
concat 10 bind-index == concat
concat 00 bind-index == push
check-argcounts argcounts funcalls
head argcounts
parse-def-body names arities bindings
decrement-argcounts argcounts head argcounts
decrement-funcalls argcounts funcalls head argcounts
_
head tokens
tail tokens.
end-constant argcounts _ = _.
end-constant argcounts bits =
list-encode if-equal argcounts _
concat 110 bits == concat constant
concat 010 bits. == push constant
check-argcounts _ . . = _.
check-argcounts argcounts funcalls _ =
list-encode concat if-equal _ tail argcounts
111_ == concat funcall
011 == push funcall
head funcalls
check-argcounts tail argcounts tail funcalls
head tail argcounts.
check-argcounts argcounts funcalls 1_ =
list-encode concat if-equal _ tail argcounts
111_ == concat funcall
011 == push funcall
head funcalls
check-argcounts tail argcounts tail funcalls
head tail argcounts.
check-argcounts . . . = _.
decrement-argcounts _ . = _.
decrement-argcounts argcounts _ =
decrement-argcounts tail argcounts head tail argcounts.
decrement-argcounts argcounts 1_ =
decrement-argcounts tail argcounts head tail argcounts.
decrement-argcounts argcounts 1argcount =
list-encode argcount
tail argcounts.
decrement-funcalls _ . . = _.
decrement-funcalls argcounts funcalls _ =
decrement-funcalls tail argcounts tail funcalls head tail argcounts.
decrement-funcalls argcounts funcalls 1_ =
decrement-funcalls tail argcounts tail funcalls head tail argcounts.
decrement-funcalls . funcalls . = funcalls.
Bit code interpreter
== 01_ bitcode interpreter
bitcode bitcode arg arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 =
interpret-bitcode bitcode
arglist arg arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9.
interpret-bitcode bitcode args =
apply head tail tail bitcode == list of function names
head tail tail tail bitcode == list of functions
alist-lookup head bitcode == main function name
head tail tail bitcode == list of function names
head tail tail tail bitcode == list of functions
push-arguments head tail bitcode == main function arity
args
empty-stack.
arglist arg arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 =
list-encode arg list-encode arg2 list-encode arg3
list-encode arg4 list-encode arg5 list-encode arg6
list-encode arg7 list-encode arg8 list-encode arg9.
push-arguments _ . stack = stack.
push-arguments 1count args stack =
push-arguments count
tail args
push head args
stack.
apply fnames functions function args =
match fnames functions args
head function
tail function.
match fnames functions args _ defs = error _. == pattern match failed
match fnames functions args def defs =
match2 fnames functions args defs
head head def == first pattern
tail head def == remaining patterns
tail def == body
empty-stack == bindings
args.
match2 fnames functions saved-args defs
_ patterns body bindings args
= eval fnames functions bindings
head body
tail body
empty-stack.
== binding
match2 fnames functions saved-args defs
0pattern-bits patterns body bindings args =
if-match pattern-bits
top args
match2 fnames functions saved-args defs
head patterns
tail patterns
body
push drop-head pattern-bits
top args
bindings
pop args
match fnames functions saved-args
head defs
tail defs.
== literal
match2 fnames functions saved-args defs
10pattern-bits patterns body bindings args =
if-equal pattern-bits
top args
match2 fnames functions saved-args defs
head patterns
tail patterns
body
bindings
pop args
match fnames functions saved-args
head defs
tail defs.
== wild
match2 fnames functions saved-args defs
11pattern-bits patterns body bindings args =
if-match pattern-bits
top args
match2 fnames functions saved-args defs
head patterns
tail patterns
body
bindings
pop args
match fnames functions saved-args
head defs
tail defs.
eval fnames functions bindings _ ops stack = _.
== push bound expr
eval fnames functions bindings
00index ops stack =
eval fnames functions bindings
head ops
tail ops
push get-binding index bindings
stack.
== concat bound expr
eval fnames functions bindings
10index ops 0. =
get-binding index bindings
eval fnames functions bindings
head ops
tail ops
empty-stack.
get-binding _ bindings = top bindings.
get-binding 1index bindings = get-binding index pop bindings.
== push literal expr
eval fnames functions bindings
010bits ops stack =
eval fnames functions bindings
head ops
tail ops
push bits stack.
== concat literal expr
eval fnames functions bindings
110bits ops 0. =
bits
eval fnames functions bindings
head ops
tail ops
empty-stack.
== push funcall expr
eval fnames functions bindings
011funcall ops stack =
eval fnames functions bindings
head ops
tail ops
push apply fnames functions
alist-lookup head funcall
fnames functions
pull-args head tail funcall
stack empty-stack
pop-args head tail funcall
stack.
== concat funcall expr
eval fnames functions bindings
111funcall ops stack =
apply fnames functions
alist-lookup head funcall
fnames functions
pull-args head tail funcall
stack empty-stack
eval fnames functions bindings
head ops
tail ops
pop-args head tail funcall
stack.
pull-args _ . args = args.
pull-args 1count stack args =
pull-args count
pop stack
push top stack
args.
pop-args _ stack = stack.
pop-args 1count stack =
pop-args count
pop stack.
if-match 0x 0y true false = if-match x y true false.
if-match 1x 1y true false = if-match x y true false.
if-match _ . true . = true.
if-match . . . false = false.
drop-head 0x 0y = drop-head x y.
drop-head 1x 1y = drop-head x y.
drop-head _ y = y.
Top-level
interp in arg arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 =
interpret-bitcode parse tokenize in
arglist arg arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9.
compile in = parse tokenize in 0000000. == pad to at least an even byte
Code size comparisons
Since I've implemented multiple 01_ interpreters, here's a comparison of the source code sizes:
- Haskell - 216 lines, 9k
- Python - 424 lines, 12k
- 01_ - 746 lines, 25k
- Java (slow original version) - 782 lines, 25k
- Java (fast new version including compiler to Java) - 1188 lines, 34k
- C - 1527 lines, 37k
Subscribe to:
Posts (Atom)