Skip to content

Commit

Permalink
Fixed some flaws in the python backend
Browse files Browse the repository at this point in the history
  • Loading branch information
EgonOlsen71 committed Jul 29, 2024
1 parent 54bfd4a commit b105c92
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
Binary file modified dist/basicv2.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class AndPy extends CalculationPy {

public AndPy() {
super("AND", "int({to}) and int({from})");
super("AND", "int({to}) & int({from})");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ public void generateCode(GeneratorContext context, String line, List<String> nCo
private void indexedTargetWithConstant(List<String> nCode, Operand source, Operand target) {
String from = getOpName(source);
String to = getOpName(target);
nCode.add("_memory[int(" + to + ")]=int(" + from + ") and 255");
nCode.add("_memory[int(" + to + ")]=int(" + from + ") & 255");
}

private void indexedSource(List<String> nCode, Operand source, Operand target) {
String from = getOpName(source);
String to = getOpName(target);
nCode.add(to + "=_memory[int(" + from + ") and 65535];");
nCode.add(to + "=_memory[int(" + from + ") & 65535];");
}

private void indexedTarget(List<String> nCode, Operand source, Operand target) {
Expand Down Expand Up @@ -101,6 +101,6 @@ private void fillMemory(List<String> nCode, Operand target, String from) {
if (isNumber(to)) {
to = "_memory[" + to + "]";
}
nCode.add(to + "=int(" + from + ") and 255;");
nCode.add(to + "=int(" + from + ") & 255;");
}
}
35 changes: 22 additions & 13 deletions src/main/resources/subroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ def RETURN():
while True:
val = _forstack.pop()
if val == 1:
forstack.pop()
forstack.pop()
forstack.pop()
forstack.pop()
_forstack.pop()
_forstack.pop()
_forstack.pop()
_forstack.pop()
if val==0:
break
val = _forstack.pop()
Expand Down Expand Up @@ -613,7 +613,10 @@ def OPEN():
fileHandle = _files.get(key)
if fileHandle != None:
throw("File already open error!")
fileHandle = open(fileName, mode, encoding="ascii")
if mode=="r":
fileHandle = open(fileName, mode+"b")
else:
fileHandle = open(fileName, mode, encoding="ascii")
_files[key]=fileHandle

def CLOSE():
Expand All @@ -636,15 +639,17 @@ def readChar(fileHandle):
global status
status = 0
char = fileHandle.read(1)
if char=="":
if not char:
status = 64
return ""
# determine, if we reached the end...whichm, or course, doesn't work ... because ... python ...
#chs = fileHandle.read(1)
#if chs=="":
# status = 64
#fileHandle.seek(-1, 1)
# determine, if we reached the end...
chs = fileHandle.read(1)
#print(":",chs,":")
if not chs:
status = 64
fileHandle.seek(-1, 1)
# convert...
char = char.decode("ascii")
if ord(char)==10:
char = chr(13)
return char
Expand Down Expand Up @@ -680,8 +685,11 @@ def INTOUTCHANNEL():

def INPUTNUMBERCHANNEL():
global X_REG
out("[INPUT# not supported for PY, call ignored]")
global A_REG
INPUTSTRCHANNEL()
X_REG=0
if A_REG!="":
X_REG=float(A_REG)

def openFile(number):
key = "file"+str(int(number))
Expand All @@ -694,12 +702,13 @@ def INPUTSTRCHANNEL():
global A_REG
global C_REG
global _files
global status
fileHandle = openFile(C_REG)
A_REG=""
stops = "\n\r:,"
while True:
char = readChar(fileHandle)
if char=="" or char in stops:
if char=="" or char in stops or status==64:
return
A_REG+=char

Expand Down

0 comments on commit b105c92

Please sign in to comment.