Set variables to inputs
This commit is contained in:
@@ -9,6 +9,8 @@ Creates the variable "var" with a set number of bytes allocated to it, and initi
|
||||
|
||||
Example: `create var bool 1 true`
|
||||
|
||||
To set a variable to an input byte, use: `create var string 1 i[idx]`.
|
||||
|
||||
## print var
|
||||
|
||||
Prints the value of `var` to the console, where `var` is a variable.
|
||||
|
||||
@@ -51,12 +51,31 @@ def generateCode(line: list[str], offset: int) -> str:
|
||||
else:
|
||||
error(f'Invalid bool: {value}')
|
||||
elif type == 1:
|
||||
if value[0] == value[-1] == '"':
|
||||
value = value[1:-1]
|
||||
variables.append(Variable(name, bytes, bytesum, type))
|
||||
returnval: str = '>' * offset + '[>]' + '>' * (bytesum + 1)
|
||||
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)
|
||||
|
||||
|
||||
1
test.bf
1
test.bf
@@ -1 +0,0 @@
|
||||
>>>>>,[>,]<[<]<<<<>>>>>[>]>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++><<<<<<<[<]<<<<>>>>>[>]>>>>>>+<<<<<<<[<]<<<<>>>>>[>]>>>>>>[<<<<<<<[<]<+<+>>>[>]>>>>>>-]<<<<<<<[<]<[>>[>]>>>>>>+<<<<<<<[<]<-]+<[>-<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--.+++.----------------.[-]]>[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----.+++++++++++.+++++++.--------------.[-]]<<<
|
||||
@@ -1,3 +1,2 @@
|
||||
create str string 5 Hello
|
||||
create var bool 1 true
|
||||
print var
|
||||
create i3 string 1 i[3]
|
||||
print i3
|
||||
Reference in New Issue
Block a user