Reduce a lot the size of the forth_floppy.lua file

This commit is contained in:
Novatux 2015-02-12 12:46:52 +01:00
parent aaed258432
commit a906826a24
2 changed files with 18 additions and 3 deletions

17
f.py
View File

@ -415,8 +415,23 @@ def getc(i):
#f.close()
f = open('forth_floppy.lua','w')
f.write("function create_forth_floppy()\n\treturn \"")
for i in range(2**14):
#for i in range(2**14):
i = 0
N = 2 ** 14
while i < N:
j = i
while j < N and memory[j] == 0:
j += 1
if j - i >= 9: # Minimum number to save characters: costs 34 characters instead of 36
f.write('"..string.rep(string.char(0),%d).."' % (j - i))
i = j
else:
c = memory[i]
if 32 <= c and c != ord('"') and c != ord("\\") and c <= 126:
f.write(chr(c))
else:
f.write("\\%03d"%memory[i])
i += 1
f.write("\"\nend")
f.close()

File diff suppressed because one or more lines are too long