Set variables to inputs

This commit is contained in:
2025-10-20 10:38:15 +11:00
parent 0710369871
commit 1ceecbb99e
5 changed files with 29 additions and 12 deletions

View File

@@ -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) + '[<]<-]'