Constructed a HashMap for the Arithmetic Commands
This commit is contained in:
+39
-1
@@ -8,6 +8,38 @@ class VirtualMachineCompiler:
|
|||||||
if ".vm" in file_path:
|
if ".vm" in file_path:
|
||||||
self.is_folder=False
|
self.is_folder=False
|
||||||
self.files.append(file_path)
|
self.files.append(file_path)
|
||||||
|
self.assembly_commands={
|
||||||
|
None:"",
|
||||||
|
"add":"@SP\nA=M\nD=M\n@SP\nM=M-1\nA=M\nM=D+M\n",
|
||||||
|
"sub":"@SP\nA=M\nD=M\n@SP\nM=M-1\nA=M\nM=M-D\n",
|
||||||
|
"neg":"@SP\nA=M\nM=-M\n",
|
||||||
|
"eq":"@SP\nA=M\nD=M\n@SP\nAM=M-1\nD=M-D\nM=-1\n@LABEL{number}\nD;JEQ\n@SP\nA=M\nM=0\n(LABLE{number})\n",
|
||||||
|
"gt":"@SP\nA=M\nD=M\n@SP\nAM=M-1\nD=M-D\nM=-1\n@LABEL{number}\nD;JGT\n@SP\nA=M\nM=0\n(LABLE{number})\n",
|
||||||
|
"lt":"@SP\nA=M\nD=M\n@SP\nAM=M-1\nD=M-D\nM=-1\n@LABEL{number}\nD;JLT\n@SP\nA=M\nM=0\n(LABLE{number})\n",
|
||||||
|
"and":"@SP\nA=M\nD=M\n@SP\nM=M-1\nA=M\nM=D&M\n",
|
||||||
|
"or":"@SP\nA=M\nD=M\n@SP\nM=M-1\nA=M\nM=D|M\n",
|
||||||
|
"not":"@SP\nA=M\nM=!M\n",
|
||||||
|
"push":"",
|
||||||
|
"pop":"",
|
||||||
|
"label":"",
|
||||||
|
"goto":"",
|
||||||
|
"if-goto":"",
|
||||||
|
"function":"",
|
||||||
|
"call":"",
|
||||||
|
"return":""
|
||||||
|
}
|
||||||
|
self.arguments={
|
||||||
|
None:"",
|
||||||
|
"argument":"ARG",
|
||||||
|
"local":"LCL",
|
||||||
|
"static":"",
|
||||||
|
"constant":"",
|
||||||
|
"this":"",
|
||||||
|
"that":"",
|
||||||
|
"pointer":"",
|
||||||
|
"temp":""
|
||||||
|
}
|
||||||
|
self.label_number=0
|
||||||
def folder_search(self):
|
def folder_search(self):
|
||||||
for item in listdir(self.file_path):
|
for item in listdir(self.file_path):
|
||||||
if ".vm" in item:
|
if ".vm" in item:
|
||||||
@@ -29,4 +61,10 @@ class VirtualMachineCompiler:
|
|||||||
self.files_content.append(command)
|
self.files_content.append(command)
|
||||||
file_content.close()
|
file_content.close()
|
||||||
def code_writer_module(self):
|
def code_writer_module(self):
|
||||||
pass
|
file_path=self.file_path
|
||||||
|
if not self.is_folder:
|
||||||
|
file_path=file_path[:file_path.find(".")]
|
||||||
|
assembly_file=open(file_path,"w")
|
||||||
|
for line in self.files_content:
|
||||||
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user