Set variables to inputs
This commit is contained in:
@@ -51,12 +51,31 @@ def generateCode(line: list[str], offset: int) -> str:
|
||||
else:
|
||||
error(f'Invalid bool: {value}')
|
||||
elif type == 1:
|
||||
variables.append(Variable(name, bytes, bytesum, type))
|
||||
returnval: str = '>' * offset + '[>]' + '>' * (bytesum + 1)
|
||||
for i in range(bytes):
|
||||
returnval += '+' * ord(value[i]) + '>'
|
||||
returnval += '<' * (bytes+bytesum+2) + '[<]' + '<' * (offset - 1)
|
||||
return returnval
|
||||
if value[0] == value[-1] == '"':
|
||||
value = value[1:-1]
|
||||
variables.append(Variable(name, bytes, bytesum, type))
|
||||
returnval = '>' * offset + '[>]' + '>' * (bytesum + 1)
|
||||
for i in range(bytes):
|
||||
try:
|
||||
returnval += '+' * ord(value[i]) + '>'
|
||||
except IndexError:
|
||||
returnval += '>'
|
||||
returnval += '<' * (bytes+bytesum+2) + '[<]' + '<' * (offset - 1)
|
||||
return returnval
|
||||
elif (value[:2] == 'i[') & (value[-1] == ']'):
|
||||
try:
|
||||
validx: int = int(value[2:-1])
|
||||
except ValueError:
|
||||
error(f'Invalid input index: {value[2:-1]}')
|
||||
quit()
|
||||
variables.append(Variable(name, bytes, bytesum, type))
|
||||
returnval = '>' * (offset + validx)
|
||||
returnval += '[[>]' + '>' * (bytesum+1) + '+' + '<' * (bytesum+2) + '[<]<+' + '>' * (validx+2) + '-]'
|
||||
returnval += '<[<]<[' + '>' * (validx+2) + '+<[<]<-]<<<'
|
||||
|
||||
return returnval
|
||||
else:
|
||||
error(f"Invalid string: {value}")
|
||||
elif type == 2:
|
||||
# I hate integers
|
||||
error('Integers are not yet implemented')
|
||||
@@ -79,7 +98,6 @@ def generateCode(line: list[str], offset: int) -> str:
|
||||
error(f'Could not find variable {line[1]}')
|
||||
quit()
|
||||
|
||||
print(var.startByte)
|
||||
if var.type == 0:
|
||||
# Create copy
|
||||
returnval = '>' * offset + '[>]' + '>' * (var.startByte + 1) + '[' + '<' * (var.startByte+2) + '[<]<+<+>>>' + '[>]>' + '>' * var.startByte + '-]' + '<' * (var.startByte + 2) + '[<]<' + '[>>[>]' + '>' * (var.startByte + 1) + '+' + '<' * (var.startByte + 2) + '[<]<-]'
|
||||
|
||||
@@ -37,7 +37,6 @@ def find(str: str, char: str):
|
||||
else:
|
||||
return len(str)
|
||||
|
||||
print(code)
|
||||
for line in code:
|
||||
bfcode += generateCode(line, offset)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user