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`
|
Example: `create var bool 1 true`
|
||||||
|
|
||||||
|
To set a variable to an input byte, use: `create var string 1 i[idx]`.
|
||||||
|
|
||||||
## print var
|
## print var
|
||||||
|
|
||||||
Prints the value of `var` to the console, where `var` is a variable.
|
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:
|
else:
|
||||||
error(f'Invalid bool: {value}')
|
error(f'Invalid bool: {value}')
|
||||||
elif type == 1:
|
elif type == 1:
|
||||||
variables.append(Variable(name, bytes, bytesum, type))
|
if value[0] == value[-1] == '"':
|
||||||
returnval: str = '>' * offset + '[>]' + '>' * (bytesum + 1)
|
value = value[1:-1]
|
||||||
for i in range(bytes):
|
variables.append(Variable(name, bytes, bytesum, type))
|
||||||
returnval += '+' * ord(value[i]) + '>'
|
returnval = '>' * offset + '[>]' + '>' * (bytesum + 1)
|
||||||
returnval += '<' * (bytes+bytesum+2) + '[<]' + '<' * (offset - 1)
|
for i in range(bytes):
|
||||||
return returnval
|
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:
|
elif type == 2:
|
||||||
# I hate integers
|
# I hate integers
|
||||||
error('Integers are not yet implemented')
|
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]}')
|
error(f'Could not find variable {line[1]}')
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
print(var.startByte)
|
|
||||||
if var.type == 0:
|
if var.type == 0:
|
||||||
# Create copy
|
# Create copy
|
||||||
returnval = '>' * offset + '[>]' + '>' * (var.startByte + 1) + '[' + '<' * (var.startByte+2) + '[<]<+<+>>>' + '[>]>' + '>' * var.startByte + '-]' + '<' * (var.startByte + 2) + '[<]<' + '[>>[>]' + '>' * (var.startByte + 1) + '+' + '<' * (var.startByte + 2) + '[<]<-]'
|
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:
|
else:
|
||||||
return len(str)
|
return len(str)
|
||||||
|
|
||||||
print(code)
|
|
||||||
for line in code:
|
for line in code:
|
||||||
bfcode += generateCode(line, offset)
|
bfcode += generateCode(line, offset)
|
||||||
|
|
||||||
|
|||||||
1
test.bf
1
test.bf
@@ -1 +0,0 @@
|
|||||||
>>>>>,[>,]<[<]<<<<>>>>>[>]>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++><<<<<<<[<]<<<<>>>>>[>]>>>>>>+<<<<<<<[<]<<<<>>>>>[>]>>>>>>[<<<<<<<[<]<+<+>>>[>]>>>>>>-]<<<<<<<[<]<[>>[>]>>>>>>+<<<<<<<[<]<-]+<[>-<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--.+++.----------------.[-]]>[+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-----.+++++++++++.+++++++.--------------.[-]]<<<
|
|
||||||
@@ -1,3 +1,2 @@
|
|||||||
create str string 5 Hello
|
create i3 string 1 i[3]
|
||||||
create var bool 1 true
|
print i3
|
||||||
print var
|
|
||||||
Reference in New Issue
Block a user