From b9454659a33286f9d35ae087efca3dbac49dc742 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Sun, 31 Dec 2017 00:03:39 +0100 Subject: [PATCH] Add compiler and decompiler for .tm files --- adder.tm | 22 ++++++++++++++++++++++ cards/31 | 1 - cards/32 | 1 - cards/33 | 1 - cards/34 | 1 - cards/35 | 1 - cards/36 | 1 - compiler.py | 31 +++++++++++++++++++++++++++++++ decompiler.py | 22 ++++++++++++++++++++++ 9 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 adder.tm create mode 100755 compiler.py create mode 100755 decompiler.py diff --git a/adder.tm b/adder.tm new file mode 100644 index 0000000..8d7a68c --- /dev/null +++ b/adder.tm @@ -0,0 +1,22 @@ +1:0,1,11,0,0,0 +11:0,1,12,0,0,0 +12:0,1,13,0,0,0 +13:0,1,14,0,0,0 +14:1,0,15,0,0,0 +15:0,0,140,0,0,0 +21:1,0,22,0,0,0 +22:1,1,210,1,1,210 +30:1,1,31,0,0,0 +31:1,1,32,0,0,0, +32:1,1,33,0,0,0, +33:1,1,34,0,0,0, +34:1,1,35,0,0,0, +35:1,1,36,0,0,0, +36:1,1,37,0,0,0, +37:1,1,38,0,0,0 +38:1,1,0,0,0,0 +140:0,0,141,1,0,141 +141:0,0,142,1,0,142 +142:0,0,21,0,0,21 +210:0,1,211,1,1,211 +211:0,1,30,1,1,30 diff --git a/cards/31 b/cards/31 index f266624..fe123ec 100644 --- a/cards/31 +++ b/cards/31 @@ -4,4 +4,3 @@ 0 0 0 - diff --git a/cards/32 b/cards/32 index 737cbd8..b807e06 100644 --- a/cards/32 +++ b/cards/32 @@ -4,4 +4,3 @@ 0 0 0 - diff --git a/cards/33 b/cards/33 index 30c6f13..ce829de 100644 --- a/cards/33 +++ b/cards/33 @@ -4,4 +4,3 @@ 0 0 0 - diff --git a/cards/34 b/cards/34 index 2a0c340..b4719bc 100644 --- a/cards/34 +++ b/cards/34 @@ -4,4 +4,3 @@ 0 0 0 - diff --git a/cards/35 b/cards/35 index f0b56a6..019f089 100644 --- a/cards/35 +++ b/cards/35 @@ -4,4 +4,3 @@ 0 0 0 - diff --git a/cards/36 b/cards/36 index 9ebf576..0a2c2cf 100644 --- a/cards/36 +++ b/cards/36 @@ -4,4 +4,3 @@ 0 0 0 - diff --git a/compiler.py b/compiler.py new file mode 100755 index 0000000..47795bd --- /dev/null +++ b/compiler.py @@ -0,0 +1,31 @@ +#!/usr/bin/python3 + +import sys +import os + +filename = sys.argv[1] +dirname = sys.argv[2] +os.mkdir(dirname) + +# print("Card number: " + cardnumber + ", write zero: " + write_zero + ", move zero: " + move_zero + ", next zero: " + next_zero + ", write one: " + write_one + ", move one: " + move_one + ", next one: " + next_one ) +with open(filename, 'r') as ip: + for line in ip: + arr1 = line.split(':') + arr2 = arr1[1].split(',') + cardnumber = arr1[0] + write_zero = arr2[0] + move_zero = arr2[1] + next_zero = arr2[2] + write_one = arr2[3] + move_one = arr2[4] + next_one = arr2[5] + + + with open(dirname + "/" + cardnumber, 'a') as op: + op.write(write_zero + '\n') + op.write(move_zero + '\n') + op.write(next_zero + '\n') + op.write(write_one + '\n') + op.write(move_one + '\n') + op.write(next_one + '\n') + diff --git a/decompiler.py b/decompiler.py new file mode 100755 index 0000000..4347c06 --- /dev/null +++ b/decompiler.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 + +import sys +import os + +filename = sys.argv[1] +dirname = sys.argv[2] +temp = [] +for i in os.listdir(dirname): + temp.append(int(i)) +cards = sorted(temp) + +with open(filename, 'a') as op: + for i in cards: + card = str(i) + op.write(card + ":") + with open(dirname + "/" + card, 'r') as ip: + payload = "" + for line in ip: + payload = payload + line[:-1] + ',' + payload = payload[:-1] + op.write(payload + '\n')