Skip to content

Commit

Permalink
Fixes #2
Browse files Browse the repository at this point in the history
We got to strings! Cool.
  • Loading branch information
nrkn committed Oct 21, 2015
1 parent f1587e5 commit 75f8ce8
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 11 deletions.
35 changes: 35 additions & 0 deletions asm/Cumulative-Countdown.asm
Original file line number Diff line number Diff line change
@@ -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;

38 changes: 38 additions & 0 deletions asm/Mod-Module.asm
Original file line number Diff line number Diff line change
@@ -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;

49 changes: 49 additions & 0 deletions asm/Small-Divide.asm
Original file line number Diff line number Diff line change
@@ -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;

10 changes: 10 additions & 0 deletions asm/Storage-Floor.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- HUMAN RESOURCE MACHINE PROGRAM --

a:
INBOX
COPYTO 12
COPYFROM [12]
OUTBOX
JUMP a


39 changes: 39 additions & 0 deletions asm/The-Littlest-Number.asm
Original file line number Diff line number Diff line change
@@ -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;

129 changes: 129 additions & 0 deletions asm/Three-Sort.asm
Original file line number Diff line number Diff line change
@@ -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+1bN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xWnO7coT9PqVJ2yZ3D+d
ZX73kpBVzctDVoH0Pt8422bu1g0mZjsumQbvNLMU3MXjKbhrftjUHaVpu7Y9L3LbJFr7fGNVw/ONbZ1L
NwVMAOmZu5VjJ8MoGAWjAAwAn5dk6A;

DEFINE LABEL 0
eJzjYWBg6BR/FDFPen6YuoqeV5vK47nqKu4LfZTcF1bK1s2yl54/u1JWbYG+YtdiHb1zSxlGwSgYBcMK
AABfEBDz;

DEFINE LABEL 1
eJwTZGBgCExnierOlAxSyZnsG1b42v198Wv37FLJILdy2RyWiktVS8vbOouL5s/em5e5KDFRduPq2KPb
fiUf3dZRZn5YsVL0EMMoGAWjYMgCAOEsHbE;

DEFINE LABEL 2
eJwTZWBgeOIx2TfBa4Xr8mAzywehVdYx4YqOm6MyYzdH5ZZPizSrUw5N7bjip9efGxgwYVrkmiWbo3au
DYnq37s7POLI8mCl086ezmcy3JVOb3IWPbTL4eg2hlEwCkbBkAEAtvAkow;

DEFINE LABEL 3
eJyzZWBgmChyzT9c6F7zNqF7J4BchgLOyZN6uQIm/BA82T1PekXXW0W9fpD4K73S1Y5Gt9ZpWv9Zf98u
ZFWFI8v8Csf5s3msePuqTXj7mg0LJ57VPTiHXzdz0SdtrV2ftCOObNBhOPVK7+QFRyO9K1vNAq7uctC7
AjLL2id3zx1v94VifjEz1wdcm+IRvGXy37DHc79GNm0Rik7cvDr24Jyn8Xr9v5JXdImnnuw2SSuc+Cpz
59oVWbIbj2bbbwKZYVar129X9fmAXdXJC4qVVUcPVdhvsquqm1VRs6JrU51im3OLc/udNr3+We0H5yxq
EVzR22C0Mrp6zRKGUTAKRgEcAADovW4T;

3 changes: 2 additions & 1 deletion compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion hrm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
7 changes: 0 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 35 additions & 1 deletion test/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
}

0 comments on commit 75f8ce8

Please sign in to comment.