diff --git a/asm/Cumulative-Countdown.asm b/asm/Cumulative-Countdown.asm new file mode 100644 index 0000000..1f7ba8a --- /dev/null +++ b/asm/Cumulative-Countdown.asm @@ -0,0 +1,35 @@ +-- HUMAN RESOURCE MACHINE PROGRAM -- + +a: + INBOX + JUMPZ d + COPYTO 0 + COPYTO 1 +b: + BUMPDN 0 + JUMPZ c + ADD 1 + COPYTO 1 + JUMP b +c: + COPYFROM 1 +d: + OUTBOX + JUMP a + + +DEFINE LABEL 0 +eJwLZGBg8Bednn5bQDB5FbdRSgFnQl4wx73m85x6/Zw81jP28bPM/yGotsBemmU+UCkDk5pRylOV0rQ2 +lVuZbSq55Uxqim2RmpMnlWldmxKoc23KCv2ACY8MV3TdMjGru2S+Jv6SeWrHKau6Wcm2EP29rtYzClwY +WgVddmboub5P9HZbE3/cPTNWzjszFiRfGVE4cV5YbvnfsK64yohHEYsTrvmDxNmzP1dvLZzdmF06u/F5 +WUT9oYr+iuQKo5TnZV1xfiXuMXF5mbFp2YLJ3ZlLCrozefvYsx/Pbc7JXCSTv2bJpaI1S7JL3y8DmZPR +VDcro2lJQWvz+0TG1sxYsc7M2K5eo5SmCd5lDydsmTx/ouR0kLod82XV787NNbo7V88rcn5T/oZFDK0q +y1d0zVi9ogskbzC9LvTTQutgnSXfAxhGwSgYwgAAcgKCSw; + +DEFINE LABEL 1 +eJyzZGBgMJcr9JGSLfQ5LKkWvUxiZwarpFbpAynR2huyDK19iie7f2lsmTxZ++CcQJ2QVZO1d66N1JTd +WKjQtOWBVOLmFMnS1UAjGOZJF/pUyr5271Nc4fpURc/rrrp1MEg8zEw255aJVmm1yd6mahPn9u+mARNE +zH9M5bF6PHepjdqCP/ZqC744HZzzxnXLZE731z3H3SPqj7svKeB0n54O0u8RXJrWFeRd9jLIegaEn5BX +GVGatjlqerp+jH2uT+zJ7sy4k90uCbnldUkJeTqZpWkLcm9lbi18XrS2xKyOp7RuFsMoGAWjACcAAEjY +Wik; + diff --git a/asm/Mod-Module.asm b/asm/Mod-Module.asm new file mode 100644 index 0000000..5af6788 --- /dev/null +++ b/asm/Mod-Module.asm @@ -0,0 +1,38 @@ +-- HUMAN RESOURCE MACHINE PROGRAM -- + +a: + INBOX + COPYTO 0 + COPYTO 2 + INBOX + COPYTO 1 + COPYFROM 0 +b: + SUB 1 + JUMPN c + COPYTO 2 + JUMP b +c: + COPYFROM 2 + OUTBOX + JUMP a + + +DEFINE LABEL 0 +eJxTYWBg0OPi0NfjCvBexV3VAOQy9CmucJ0m99rdXnqLn5JUXai9dGasukpTfqKaVmmi2oZKF1WzuhPK +VQ2FClUNlbJmdSA9nvq3VFboOzvtNZ6evtbSrG6pTVVDhWNVg6ALRH6Djp5XmJl18AQL62AQX5CzSUuR +OdcIxJZkc27P4GFoLRFmaGUYBaNgFNAVAADvjic4; + +DEFINE LABEL 1 +eJzTZGBgKOAs9Onl4vFcxJfqbCWY6mwkwuM5UWSL30SRwonhQnWz3nAZrdTjKl2tx3Vr3Q3Zvcf7FPce +f6oScQSoleGqlmDyJ23n9kAd0VodPdmcR4aZsTImatEzTN1jis0Fk/0sE/J4rHLLeaxSO0Dqd4cv1q6M +2GtbGbGhMia8cKJH8ORJ1j6pHcfdRWs53XPLOd2b8p09S9PE/M4mdAW9T/wbJpvDMApGwSigGQAA8dM5 +lA; + +DEFINE LABEL 2 +eJyzZGBgOM4janGcx2c3kMmQIhlRryR1qWqzvFapuopWqbz6paodmnubNui87lmhn7lIxbDqqIqh85k0 +A4ZTIPV31dUWqKscnFOocHCOuZzagr/SgivmSU9fM096ydbdMv17zeVED/Upzj6WqDb72FUt0UMbdI5u +A+l7bn102xtXn90Z7lq7Wj2WbHX23LnW2TNzUYa75PQvTq97nls7t6+1rGq4ZJ5bXmy+pGCChWzOH3vB +ZJBej2BnJ7aQiPrG0Nc9lRF1swqj3ReeiHNfmJj4eC5Ifr+Xe4x9mHvM10iWqM1RB8MZRsEoGAU4AQAj +TFpS; + diff --git a/asm/Small-Divide.asm b/asm/Small-Divide.asm new file mode 100644 index 0000000..cdde6f5 --- /dev/null +++ b/asm/Small-Divide.asm @@ -0,0 +1,49 @@ +-- HUMAN RESOURCE MACHINE PROGRAM -- + +a: + COPYFROM 9 + COPYTO 3 + INBOX + COPYTO 0 + COPYTO 2 + INBOX + COPYTO 1 + COPYFROM 0 +b: + SUB 1 + JUMPN c + COPYTO 2 + BUMPUP 3 + COPYFROM 2 + JUMP b +c: + COPYFROM 3 + OUTBOX + JUMP a + + +DEFINE LABEL 0 +eJxTYWBg0OPi0NfjCvBexV3VAOQy9CmucJ0m99rdXnqLn5JUXai9dGasukpTfqKaVmmi2oZKF1WzuhPK +VQ2FClUNlbJmdSA9nvq3VFboOzvtNZ6evtbSrG6pTVVDhWNVg6ALRH6Djp5XmJl18AQL62AQX5CzSUuR +OdcIxJZkc27P4GFoLRFmaGUYBaNgFNAVAADvjic4; + +DEFINE LABEL 1 +eJzTZGBgKOAs9Onl4vFcxJfqbCWY6mwkwuM5UWSL30SRwonhQnWz3nAZrdTjKl2tx3Vr3Q3Zvcf7FPce +f6oScQSoleGqlmDyJ23n9kAd0VodPdmcR4aZsTImatEzTN1jis0Fk/0sE/J4rHLLeaxSO0Dqd4cv1q6M +2GtbGbGhMia8cKJH8ORJ1j6pHcfdRWs53XPLOd2b8p09S9PE/M4mdAW9T/wbJpvDMApGwSigGQAA8dM5 +lA; + +DEFINE LABEL 2 +eJyzZGBgOM4janGcx2c3kMmQIhlRryR1qWqzvFapuopWqbz6paodmnubNui87lmhn7lIxbDqqIqh85k0 +A4ZTIPV31dUWqKscnFOocHCOuZzagr/SgivmSU9fM096ydbdMv17zeVED/Upzj6WqDb72FUt0UMbdI5u +A+l7bn102xtXn90Z7lq7Wj2WbHX23LnW2TNzUYa75PQvTq97nls7t6+1rGq4ZJ5bXmy+pGCChWzOH3vB +ZJBej2BnJ7aQiPrG0Nc9lRF1swqj3ReeiHNfmJj4eC5Ifr+Xe4x9mHvM10iWqM1RB8MZRsEoGAU4AQAj +TFpS; + +DEFINE LABEL 3 +eJyzZWBgmCmoFv2GSy1aks0oxY6FoySa9WS3GXvMzAyec0tlBQRXuEsIrgAqYzCXk825IWtWd0HhZLe6 +ypbJZVrXpujoBUxIM2jrVDG816xieKkqzUCr1FO/KT9QZ3q6jcbZhNVKZxP+Sk9PB+kvNp8fpmmtVXrI +1qzuuqNze4Z7akerh3O7nHdEvbXP86JZPu4xtd6FPglePJ4g9TciFNt2hxulmEfOD+uL4fGUTwrw3pFy +zf9T2sHwvIw/WXkZl6pA6iYUhyhMKFZ0XFtSF9pRNj39UIVW6dyqz9Wb6mY3vmmY3QhSE1a4wjW5YoXr +rupUZ4ZRMApGARwAAOCxWdE; + diff --git a/asm/Storage-Floor.asm b/asm/Storage-Floor.asm new file mode 100644 index 0000000..e60865b --- /dev/null +++ b/asm/Storage-Floor.asm @@ -0,0 +1,10 @@ +-- HUMAN RESOURCE MACHINE PROGRAM -- + +a: + INBOX + COPYTO 12 + COPYFROM [12] + OUTBOX + JUMP a + + diff --git a/asm/The-Littlest-Number.asm b/asm/The-Littlest-Number.asm new file mode 100644 index 0000000..d2e0199 --- /dev/null +++ b/asm/The-Littlest-Number.asm @@ -0,0 +1,39 @@ +-- HUMAN RESOURCE MACHINE PROGRAM -- + +a: + INBOX + COPYTO 0 +b: +c: + INBOX + JUMPZ e + COPYTO 1 + COMMENT 0 + SUB 0 + JUMPN d + JUMP b +d: + COPYFROM 1 + COPYTO 0 + JUMP c +e: + COPYFROM 0 + OUTBOX + JUMP a + + +DEFINE COMMENT 0 +eJwrYGBg6BSvm3VbIGbmE94fU7+wv+6JZlVsm8syu9GORat0F6tsjje3WvRtgbpQoFKGQoXStEKF50Vc +ymZ18ur3mvl1GVrZDczqHhnmlj8yFExmN3CP2aBTF3pXXTLoqUpMSJ+ie8wFhbMJhQoJeSD9S20YWp9b +VzU8ty5NU7Q7GB7t8D1gk3NMCKf72YTj7iGpx90T8lo9vMtAale5qUUzel3zL/Wb7MsXKBm0PHhNfGrI +9PTUEOd2kLx6vFq0ejxv39P4c0vlky7th4j9yXJJMEq5m+Qe8ytZLfpshntMc87ODMfcpvxHORH1rzIZ +WsVT7zWD1B6qOBhuV2UdXFBfF3q8STCZsfV50f7Wz9X7WxXbrNslp4PUMLamdlyvYWhlqVBse15mPeNQ +hfvC6GrBFV9qQ1Y9aQ5ZldD6fhlI3cteo5SuXtmcl71VDan9B+coT3BfCBL36PuTpTwhJLV/+vtEjVld +cSCx5uW55dkbZjc2bKlq+LNVtHbXttK0P1uNUjQ3nk24tPZswv8VIalHl/3JOru4vyJvsVld3mLrGezL +uhYvWCG44v06wRXJmzMXgcxR+9m1mGEUjAIKAQBVe7VO; + +DEFINE LABEL 0 +eJxTZWBgqGArTatg0+s3Y1dbAOQymLG/T+TkYYly5lOLthJ8n5gjNnnSaTGW+SC5daI7M9wlMmPtpTNj +Q+QFk/UVp6e3qXCUuKhumQySbzbsims25O0DsdkNqqxB9Fz7utBdDm2dIPYf+664YOeD4a0eMSH7veaH +ffR/n5gbOD39TKDkdJC82s9b6xhGwSgYBXQDABtjLCQ; + diff --git a/asm/Three-Sort.asm b/asm/Three-Sort.asm new file mode 100644 index 0000000..9525440 --- /dev/null +++ b/asm/Three-Sort.asm @@ -0,0 +1,129 @@ +-- HUMAN RESOURCE MACHINE PROGRAM -- + +a: + INBOX + COPYTO 0 + INBOX + COPYTO 1 + INBOX + COPYTO 2 + COMMENT 2 + SUB 1 + JUMPN b + COMMENT 1 + JUMP c +b: + COMMENT 0 + COPYFROM 2 + COPYTO 3 + COPYFROM 1 + COPYTO 2 + COPYFROM 3 + COPYTO 1 +c: + COMMENT 4 + COPYFROM 2 + SUB 0 + JUMPN e + COMMENT 6 + COMMENT 7 + COPYFROM 0 + SUB 1 + JUMPN d + COPYFROM 0 + COPYTO 3 + COPYFROM 1 + COPYTO 0 + COPYFROM 3 + COPYTO 1 +d: + JUMP f +e: + COMMENT 5 + COPYFROM 0 + COPYTO 3 + COPYFROM 1 + COPYTO 0 + COPYFROM 2 + COPYTO 1 + COPYFROM 3 + COPYTO 2 +f: + COMMENT 3 + COPYFROM 0 + OUTBOX + COPYFROM 1 + OUTBOX + COPYFROM 2 + OUTBOX + JUMP a + + +DEFINE COMMENT 0 +eJzTZWBg2Cxvn6uvKJh8QK0udIPONf9qky1+YWaSQaesdmY02BVOvG/HMv+QrdHK59Z/1q+1bNriaJS7 +h19373EbjYCrHdZbbyiHHnyoH3PwIdAohrb4rjj27M/V2aWFEzXLtkzWLJOcXhj9Zz1IrqC+0Ke1+bW7 +cddJN76e1+6p/df8HSaqRc+fuKTgZW9E/faOk93zJwZMqJpcN6tq8pol0pNDVjlMtN/U1ft8+/aO3D2C +9T6751Yd3cYwCkbBKKAaAADikVFE; + +DEFINE COMMENT 1 +eJxTZWBg2Cz/KKJPMSbkl0ahD7+unle3XqGPp757TLdeSOoGnYS8q1oR9Tp6qR1HDbZMdjR6PHeBUciq +ZkPZjTp6HDufqmjtMpdbshVoDMN1R5aoVW5dcUdCnhdtjuqv4Avk7StwyVwEkptRoBbtVv494HrNNf/g +urrQTXUJeVNrtUoVK+81+5W87mnOUVvwp+r9MsZWwRUMo2AUjAK6AQCwrjs8; + +DEFINE COMMENT 2 +eJxzYGBgKFRgiTqhLBmUqLbF7676Fr8dmjEhG3Smp+fpPi/K093bZKI9eZKNxuO5Qgo717qo/lm/QefP ++u+mTVuAWhkifK2DGb0eRcy1v1S1y6GqQc+1rXO777UpIDlOd46SS0VapSD2hvS6UJ3MutDnZUYpz8v+ +ZIkUtXVaFsyfDZLrbYiwMu7SMvDo0zJQntBnPH+imaXDxC1+R/pZogK6/2TtmWSfGzpVq1R4mlndlql6 +/bGTuhZ79JWudm6Zvgakf8bqCKtLazeYLN30XNduK4f+rm0RVru2Ffq8X/e8aMK6z9V+6yPqQerC1hzd +9n31rXUT1u1c+36d7MawNUu2MoyCUTDCAQDJN2yB; + +DEFINE COMMENT 3 +eJyzYmBgSJGcPOmDCG/fD8HXPU94efvecFnP0ONSW6DHZb/p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0H5yxq +EVzR22C0Mrp6zRKGUTAKRgEcAADovW4T; + diff --git a/compile.js b/compile.js index cf84cbf..8612633 100644 --- a/compile.js +++ b/compile.js @@ -47,7 +47,8 @@ const compile = source => { if( word.startsWith( 'JUMP' ) ){ words[ 1 ] = labels[ words[ 1 ] ] } else if( words.length > 1 ){ - words[ 1 ] = Number( words[ 1 ] ) + words[ 1 ] = + words[ 1 ].startsWith( '[' ) ? words[ 1 ] : Number( words[ 1 ] ) } return words diff --git a/hrm.js b/hrm.js index da5405c..72ba7d2 100644 --- a/hrm.js +++ b/hrm.js @@ -79,7 +79,17 @@ module.exports = ( source, inbox, floor, verbose ) => { const instr = program[ i ] - cpu[ instr[ 0 ] ]( instr[ 1 ] ) + if( instr.length > 1 ){ + var arg = instr[ 1 ] + + if( ( String( arg ) ).startsWith( '[' ) ){ + arg = memory[ parseInt( arg.substr( 1 ) ) ] + } + + cpu[ instr[ 0 ] ]( arg ) + } else { + cpu[ instr[ 0 ] ]() + } steps++ diff --git a/package.json b/package.json index 57992cc..9adae9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hrm-cpu", - "version": "0.0.7", + "version": "0.1.0", "description": "Run Human Resources Machine programs in JavaScript", "main": "hrm.js", "directories": { diff --git a/readme.md b/readme.md index 81774dc..51d54e8 100644 --- a/readme.md +++ b/readme.md @@ -48,13 +48,6 @@ You can also get verbose output (for checking your size and steps): ```javascript const info = hrm( source, inbox, floor, true ) ``` - -### TODO - -* Haven't got to the levels involving strings yet so not sure how they look -* Transpile for older node? -* Browserify? -* More tests would be nice! ### License diff --git a/test/tests.json b/test/tests.json index d893278..764e237 100644 --- a/test/tests.json +++ b/test/tests.json @@ -95,5 +95,39 @@ "9": 0 }, "outbox": [ 1, 1, 2, 3, 5, 1, 1, 2, 3, 5, 8, 13 ] - } + }, + "The-Littlest-Number": { + "inbox": [ 8, 15, 2, 0, 19, 14, 8, 4, 0, 57, 47, 20, 44, 40, 0 ], + "floor": {}, + "outbox": [ 2, 4, 20 ] + }, + "Mod-Module": { + "inbox": [ 5, 2, 6, 2, 4, 6, 0, 8 ], + "floor": {}, + "outbox": [ 1, 0, 4, 0 ] + }, + "Cumulative-Countdown": { + "inbox": [ 3, 3, 0, 8 ], + "floor": { + "5": 0 + }, + "outbox": [ 6, 6, 0, 36 ] + }, + "Small-Divide": { + "inbox": [ 9, 3, 7, 3, 3, 6, 0, 9 ], + "floor": { + "9": 0 + }, + "outbox": [ 3, 2, 0, 0 ] + }, + "Three-Sort": { + "inbox": [ 8, 5, 2, 3, 5, 8, 6, -1, 3, 9, 6, -1 ], + "floor": {}, + "outbox": [ 2, 5, 8, 3, 5, 8, -1, 3, 6, -1, 6, 9 ] + }, + "Storage-Floor": { + "inbox": [ 7, 3, 3, 8, 8 ], + "floor": [ "N", "K", "A", "E", "R", "D", "O", "L", "Y", "J", null, null, 8 ], + "outbox": [ "L", "E", "E", "Y", "Y" ] + } } \ No newline at end of file