From 74afe0dceb05b584832ddfacfe09d9f516e6bb4c Mon Sep 17 00:00:00 2001 From: Joshua Wright Date: Wed, 14 Feb 2018 18:50:52 -0800 Subject: [PATCH 1/7] =?UTF-8?q?(=E0=B8=87=20=E0=B8=B7=E2=96=BF=20=E0=B8=B7?= =?UTF-8?q?)=E0=B8=A7=20number=201=20of=20many?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aspen VM.py | 69 ++++++++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/Aspen VM.py b/Aspen VM.py index 95df93b..fb3edec 100644 --- a/Aspen VM.py +++ b/Aspen VM.py @@ -1,19 +1,5 @@ -#Alright, finally started on the python VM for Aspen. it is the 8th of february (only 7 days til' my birthday!) and I am... pretty ready. -# I didnt actually write out as much pre-planning as I usually do, that has me worried. -#lmao python doesnt have switch statements - so the solution is a little funky. -#I always thought switch statements existed in python, I just never wanted to use them so I never found out they didn't exist. -#anyways I've got a pretty solid foundation done, I'm gonna go take a shower, my eyes are really itchy and I smell bad. -#yeah, I should've planned this out on paper. I'll do that in the morning. - -#came back, its just the next day, and I've finished iconst! thats where everything starts babyyy -#I'm on a goddamn roll, all the arithmetic works smooth as hell -#I might want to consider breaking the code up into separate files -#maybe if I ever become a goddamned PUSSY I'll consider it - - - -class VM(): #Where the magic happens - def __init__(self, args): #args is an array of: code, ip, sp, fp, data, datasize +class VM(): # Where the magic happens + def __init__(self, args): # args is an array of: code, ip, sp, fp, data, datasize self.ip = args[1] self.sp = args[2] self.fp = args[3] @@ -31,7 +17,7 @@ def halt(): return def pop(): - self.stack.pop(self.sp) + self.stack.pop() self.sp -= 1 def iConst(): @@ -40,16 +26,10 @@ def iConst(): self.sp += 1 def iAdd(): - sum = int(self.stack[-1]) + int(self.stack[-2]) - pop() - pop() - self.stack.append(sum) - - def iMult(): - product = int(self.stack[-1]) * int(self.stack[-2]) + summation = int(self.stack[-1]) + int(self.stack[-2]) pop() pop() - self.stack.append(product) + self.stack.append(summation) def iMult(): product = int(self.stack[-1]) * int(self.stack[-2]) @@ -64,14 +44,25 @@ def iDiv(): self.stack.append(quotient) def iSub(): - difference = int(self.stack[-1]) - int(self.stack[-2]) #subtract the lower item in the stack from the higher item! + difference = int(self.stack[-1]) - int( + self.stack[-2]) # subtract the lower item in the stack from the higher item! pop() pop() self.stack.append(difference) def cout(): print(self.stack[-1]) + + def iMod(): + mod = int(self.stack[-1]) % int(self.stack[-2]) pop() + pop() + self.stack.append(mod) + + def branch(): + self.ip += 1 + addr = int(self.code[self.ip]) + self.ip = addr - 1 decoder = { "HALT": halt, @@ -81,7 +72,10 @@ def cout(): "ISUB": iSub, "IMULT": iMult, "IDIV": iDiv, + "IMOD": iMod, "PRINT": cout, + + "BR": branch, } # Ending the operations list ==================== @@ -89,33 +83,22 @@ def cout(): def picker(codeName): decoder[codeName]() - while self.ip < len(self.code) - 1: #Ok, all that other stuff was just buildup, this is where the REAL magic happens + while self.ip < len( + self.code) - 1: # Ok, all that other stuff was just buildup, this is where the REAL magic happens self.ip += 1 - op = self.code[self.ip] - #print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack)) - picker(self.code[self.ip]) + print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack)) + picker(op) aspenVM = VM([ - ["ICONST", "12", "ICONST", "60", "IDIV", "PRINT", "HALT"], + ["ICONST", "5", "PRINT", "POP", "BR", "0"], - - -1, -1, 4, 12, 2]) #code, IP, SP, FP, data, datasize + -1, -1, 4, 12, 2]) # code, IP, SP, FP, data, datasize aspenVM.cpu() - - - - - - - - - - From 7139612a546f0f2ac8156539bb4f5db16195787c Mon Sep 17 00:00:00 2001 From: Joshua Wright Date: Sat, 17 Feb 2018 15:13:10 -0800 Subject: [PATCH 2/7] =?UTF-8?q?(=E0=B8=87=20=E0=B8=B7=E2=96=BF=20=E0=B8=B7?= =?UTF-8?q?)=E0=B8=A7=20number=201=20of=20many?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aspen VM.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/Aspen VM.py b/Aspen VM.py index fb3edec..027678f 100644 --- a/Aspen VM.py +++ b/Aspen VM.py @@ -1,3 +1,13 @@ +#Its the seventeenth of february, all my notes are gone ;( +#I wanted to work on branching at school, and copied the github code into repl.it +#but I took it from the organization repo, so the notes werent there +#and when I pasted it back into my personal file the notes were gone and I didnt notice until it was too late to ctrl-z it all back +#oh, farewell, two days of comments, you will be missed +#anyway I have if statements now +#branch if true and branch if false +#pretty snazzy if I do say so myself + + class VM(): # Where the magic happens def __init__(self, args): # args is an array of: code, ip, sp, fp, data, datasize self.ip = args[1] @@ -9,6 +19,7 @@ def __init__(self, args): # args is an array of: code, ip, sp, fp, data, datasi self.code = args[0] self.stack = [] + self.memory = [None] * self.datasize def cpu(self): # Starting the list of all the operations ============= @@ -44,8 +55,7 @@ def iDiv(): self.stack.append(quotient) def iSub(): - difference = int(self.stack[-1]) - int( - self.stack[-2]) # subtract the lower item in the stack from the higher item! + difference = int(self.stack[-1]) - int(self.stack[-2]) # subtract the lower item in the stack from the higher item! pop() pop() self.stack.append(difference) @@ -64,6 +74,31 @@ def branch(): addr = int(self.code[self.ip]) self.ip = addr - 1 + def isLessThan(): + bul = self.stack[-1] < self.stack[-2] + self.stack.append(bul) + + def isEqualTo(): + bul = self.stack[-1]==self.stack[-2] + self.stack.append(bul) + + def isGreaterThan(): + bul = self.stack[-1] > self.stack[-2] + self.stack.append(bul) + + def branchIfTrue(): + if self.stack[-1]: + branch() + else: + self.ip += 1 + + def branchIfFalse(): + if not self.stack[-1]: + branch() + else: + self.ip += 1 + + decoder = { "HALT": halt, "POP": pop, @@ -74,8 +109,12 @@ def branch(): "IDIV": iDiv, "IMOD": iMod, "PRINT": cout, - "BR": branch, + "IL": isLessThan, + "IQ": isEqualTo, + "IG": isGreaterThan, + "BRT": branchIfTrue, + "BRF": branchIfFalse, } # Ending the operations list ==================== @@ -88,13 +127,15 @@ def picker(codeName): self.ip += 1 op = self.code[self.ip] - print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack)) + #print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n ---") picker(op) + #print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n ---------------") + aspenVM = VM([ - ["ICONST", "5", "PRINT", "POP", "BR", "0"], + ["ICONST", "5", "ICONST", "4", "IL", "BRT", "0"], -1, -1, 4, 12, 2]) # code, IP, SP, FP, data, datasize From 41a1aca5225a1a81c217495ec9ac31daee005ec9 Mon Sep 17 00:00:00 2001 From: Joshua Wright Date: Sat, 17 Feb 2018 15:34:11 -0800 Subject: [PATCH 3/7] If statements and variables! --- Aspen VM.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Aspen VM.py b/Aspen VM.py index 027678f..a8b9bad 100644 --- a/Aspen VM.py +++ b/Aspen VM.py @@ -6,7 +6,10 @@ #anyway I have if statements now #branch if true and branch if false #pretty snazzy if I do say so myself - +#OOOO BABY +#are those variables I see? +#Memory? In the distance? +#Why yes they are, young traveller. class VM(): # Where the magic happens def __init__(self, args): # args is an array of: code, ip, sp, fp, data, datasize @@ -98,6 +101,15 @@ def branchIfFalse(): else: self.ip += 1 + def gStore(): + self.ip += 1 + addr = int(self.code[self.ip]) + self.memory[addr] = self.stack[-1] + + def gLoad(): + self.ip += 1 + addr = int(self.code[self.ip]) + self.stack.append(self.memory[addr]) decoder = { "HALT": halt, @@ -115,6 +127,8 @@ def branchIfFalse(): "IG": isGreaterThan, "BRT": branchIfTrue, "BRF": branchIfFalse, + "GSTORE": gStore, + "GLOAD": gLoad, } # Ending the operations list ==================== @@ -127,17 +141,17 @@ def picker(codeName): self.ip += 1 op = self.code[self.ip] - #print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n ---") + print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory)+ "\n ---") picker(op) - #print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n ---------------") + print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory) + "\n -------------------------") aspenVM = VM([ - ["ICONST", "5", "ICONST", "4", "IL", "BRT", "0"], + ["ICONST", "5", "GSTORE", "4", "POP", "GLOAD", "4", "HALT"], - -1, -1, 4, 12, 2]) # code, IP, SP, FP, data, datasize + -1, -1, 4, 12, 12]) # code, IP, SP, FP, data, datasize aspenVM.cpu() From d7c7047040b885a18cad07762d3d4369c6a35176 Mon Sep 17 00:00:00 2001 From: Joshua Wright Date: Sat, 17 Feb 2018 18:57:04 -0800 Subject: [PATCH 4/7] If statements and variables! --- Aspen VM.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Aspen VM.py b/Aspen VM.py index a8b9bad..948b95c 100644 --- a/Aspen VM.py +++ b/Aspen VM.py @@ -19,7 +19,7 @@ def __init__(self, args): # args is an array of: code, ip, sp, fp, data, datasi self.data = args[4] self.datasize = args[5] - self.code = args[0] + self.code = args[0].split(" ") self.stack = [] self.memory = [None] * self.datasize @@ -141,15 +141,15 @@ def picker(codeName): self.ip += 1 op = self.code[self.ip] - print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory)+ "\n ---") + #print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory)+ "\n ---") picker(op) - print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory) + "\n -------------------------") + #print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory) + "\n -------------------------") aspenVM = VM([ - ["ICONST", "5", "GSTORE", "4", "POP", "GLOAD", "4", "HALT"], + 'ICONST 10 ICONST 25 IMULT ICONST 5 IADD PRINT', -1, -1, 4, 12, 12]) # code, IP, SP, FP, data, datasize From 78594682dd1d488f2488ceb1b594c4c91aa165e6 Mon Sep 17 00:00:00 2001 From: Joshua Wright Date: Tue, 27 Feb 2018 19:49:29 -0800 Subject: [PATCH 5/7] If statements and variables! --- Aspen VM.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Aspen VM.py b/Aspen VM.py index 948b95c..a56258f 100644 --- a/Aspen VM.py +++ b/Aspen VM.py @@ -10,6 +10,11 @@ #are those variables I see? #Memory? In the distance? #Why yes they are, young traveller. +#Its the 27th of feburary and I'm ready to do hash functions +#If the NSA is watching me implement this algorithm they invented... I hope y'all feel unappreciated + + +import hashlib class VM(): # Where the magic happens def __init__(self, args): # args is an array of: code, ip, sp, fp, data, datasize @@ -111,6 +116,13 @@ def gLoad(): addr = int(self.code[self.ip]) self.stack.append(self.memory[addr]) + def sha512(): + input = self.stack[-1] + newHash = hashlib.sha512(input.encode(encoding = 'UTF-8')).digest() + pop() + self.stack.append(newHash) + + decoder = { "HALT": halt, "POP": pop, @@ -129,6 +141,7 @@ def gLoad(): "BRF": branchIfFalse, "GSTORE": gStore, "GLOAD": gLoad, + "SHA": sha512 } # Ending the operations list ==================== @@ -141,15 +154,15 @@ def picker(codeName): self.ip += 1 op = self.code[self.ip] - #print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory)+ "\n ---") + print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory)+ "\n ---") picker(op) - #print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory) + "\n -------------------------") + print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory) + "\n -------------------------") aspenVM = VM([ - 'ICONST 10 ICONST 25 IMULT ICONST 5 IADD PRINT', + 'ICONST 5 SHA PRINT POP HALT', -1, -1, 4, 12, 12]) # code, IP, SP, FP, data, datasize From b6fb55951e19dad89016439fda97b8bffe3f9df1 Mon Sep 17 00:00:00 2001 From: Joshua Wright Date: Tue, 27 Feb 2018 19:50:23 -0800 Subject: [PATCH 6/7] SHA512 --- .idea/Aspen.iml | 11 +++++++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 4 files changed, 29 insertions(+) create mode 100644 .idea/Aspen.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/Aspen.iml b/.idea/Aspen.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/.idea/Aspen.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..53c3df0 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1a7fa1e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From 3d3dc81f924ff0acf13ca58a0e28c7bc13440549 Mon Sep 17 00:00:00 2001 From: Joshua Wright Date: Mon, 23 Apr 2018 10:41:41 -0700 Subject: [PATCH 7/7] Add files via upload --- Aspen VM.py | 407 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 251 insertions(+), 156 deletions(-) diff --git a/Aspen VM.py b/Aspen VM.py index 05754aa..9af1313 100644 --- a/Aspen VM.py +++ b/Aspen VM.py @@ -1,156 +1,251 @@ -import hashlib - -class VM(): #Where the magic happens - def __init__(self, args): #args is an array of: code, ip, sp, fp, data, datasize - self.ip = args[1] - self.sp = args[2] - self.fp = args[3] - - self.data = args[4] - self.datasize = args[5] - self.code = args[0].split(" ") - - self.stack = [] - self.memory = [None] * self.datasize - - def cpu(self): - # Starting the list of all the operations ============= - - def halt(): - return - - def pop(): - self.stack.pop() - self.sp -= 1 - - def iConst(): - self.ip += 1 - self.stack.append(self.code[self.ip]) - self.sp += 1 - - def iAdd(): - summation = int(self.stack[-1]) + int(self.stack[-2]) - pop() - pop() - self.stack.append(summation) - - def iMult(): - product = int(self.stack[-1]) * int(self.stack[-2]) - pop() - pop() - self.stack.append(product) - - def iDiv(): - quotient = int(self.stack[-1]) / int(self.stack[-2]) - pop() - pop() - self.stack.append(quotient) - - def iSub(): - difference = int(self.stack[-1]) - int(self.stack[-2]) # subtract the lower item in the stack from the higher item! - pop() - pop() - self.stack.append(difference) - - def cout(): - print(self.stack[-1]) - - def iMod(): - mod = int(self.stack[-1]) % int(self.stack[-2]) - pop() - pop() - self.stack.append(mod) - - def branch(): - self.ip += 1 - addr = int(self.code[self.ip]) - self.ip = addr - 1 - - def isLessThan(): - bul = self.stack[-1] < self.stack[-2] - self.stack.append(bul) - - def isEqualTo(): - bul = self.stack[-1]==self.stack[-2] - self.stack.append(bul) - - def isGreaterThan(): - bul = self.stack[-1] > self.stack[-2] - self.stack.append(bul) - - def branchIfTrue(): - if self.stack[-1]: - branch() - else: - self.ip += 1 - - def branchIfFalse(): - if not self.stack[-1]: - branch() - else: - self.ip += 1 - - def gStore(): - self.ip += 1 - addr = int(self.code[self.ip]) - self.memory[addr] = self.stack[-1] - - def gLoad(): - self.ip += 1 - addr = int(self.code[self.ip]) - self.stack.append(self.memory[addr]) - - def sha512(): - input = self.stack[-1] - newHash = hashlib.sha512(input.encode(encoding = 'UTF-8')).digest() - pop() - self.stack.append(newHash) - - - decoder = { - "HALT": halt, - "POP": pop, - "ICONST": iConst, - "IADD": iAdd, - "ISUB": iSub, - "IMULT": iMult, - "IDIV": iDiv, - "IMOD": iMod, - "PRINT": cout, - "BR": branch, - "IL": isLessThan, - "IQ": isEqualTo, - "IG": isGreaterThan, - "BRT": branchIfTrue, - "BRF": branchIfFalse, - "GSTORE": gStore, - "GLOAD": gLoad, - "SHA": sha512 - } - - # Ending the operations list ==================== - - def picker(codeName): - decoder[codeName]() - - while self.ip < len( - self.code) - 1: # Ok, all that other stuff was just buildup, this is where the REAL magic happens - self.ip += 1 - - op = self.code[self.ip] - print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory)+ "\n ---") - picker(op) - print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory) + "\n -------------------------") - - - -aspenVM = VM([ - - 'ICONST 5 SHA PRINT POP HALT', - - -1, -1, 4, 12, 12]) # code, IP, SP, FP, data, datasize - -aspenVM.cpu() - - - +import hashlib + +def chainDataFind(): + pass + + + + + + + + +class VM(): #Where the magic happens + def __init__(self, args, runData, blockChainData): #args is an array of: code, ip, sp, fp, data, datasize + #runData is [[this address, origin address, callerAddress], gas] + self.ip = args[1] + self.sp = args[2] + self.fp = args[3] + + self.data = args[4] + self.datasize = args[5] + + self.selfAddress = runData[0][0] + self.originAddress = runData[0][1] + self.callerAddress = runData[0][2] + + self.gas = runData[1] + + + + self.code = args[0].split(" ") + + self.stack = [] + self.memory = [None] * self.datasize + + def cpu(self): + # Starting the list of all the operations ============= + + def halt(): + + return + + def pop(): + self.gas -= 1 + + self.stack.pop() + self.sp -= 1 + + def iConst(): + self.gas -= 3 + + self.ip += 1 + self.stack.append(self.code[self.ip]) + self.sp += 1 + + def iAdd(): + self.gas -= 3 + + summation = int(self.stack[-1]) + int(self.stack[-2]) + pop() + pop() + self.stack.append(summation) + + def iMult(): + self.gas -= 5 + + product = int(self.stack[-1]) * int(self.stack[-2]) + pop() + pop() + self.stack.append(product) + + def iDiv(): + self.gas -= 5 + + quotient = int(self.stack[-1]) / int(self.stack[-2]) + pop() + pop() + self.stack.append(quotient) + + def iSub(): + self.gas -= 3 + + difference = int(self.stack[-1]) - int(self.stack[-2]) # subtract the lower item in the stack from the higher item! + pop() + pop() + self.stack.append(difference) + + def cout(): + print(self.stack[-1]) + + def iMod(): + self.gas -= 5 + + mod = int(self.stack[-1]) % int(self.stack[-2]) + pop() + pop() + self.stack.append(mod) + + def branch(): + self.gas -= 8 + + self.ip += 1 + addr = int(self.code[self.ip]) + self.ip = addr - 1 + + def isLessThan(): + self.gas -= 3 + + bul = self.stack[-1] < self.stack[-2] + self.stack.append(bul) + + def isEqualTo(): + self.gas -= 3 + + bul = self.stack[-1]==self.stack[-2] + self.stack.append(bul) + + def isGreaterThan(): + self.gas -= 3 + + bul = self.stack[-1] > self.stack[-2] + self.stack.append(bul) + + def branchIfTrue(): + self.gas -= 10 + + if self.stack[-1]: + branch() + else: + self.ip += 1 + + def branchIfFalse(): + self.gas -= 10 + + if not self.stack[-1]: + branch() + else: + self.ip += 1 + + def gStore(): + self.ip += 1 + addr = int(self.code[self.ip]) + self.memory[addr] = self.stack[-1] + + def gLoad(): + self.gas -= 200 + + self.ip += 1 + addr = int(self.code[self.ip]) + self.stack.append(self.memory[addr]) + + def sha512(): + input = self.stack[-1] + newHash = hashlib.sha512(input.encode(encoding = 'UTF-8')).digest() + pop() + self.stack.append(newHash) + + def Or(): + self.gas -= 3 + + firstCondition = self.stack[-1] + secondCondition = self.stack[-2] + self.stack.append(firstCondition or secondCondition) + + def And(): + self.gas -= 3 + + firstCondition = self.stack[-1] + secondCondition = self.stack[-2] + self.stack.append(firstCondition and secondCondition) + + def Not(): + self.gas -= 3 + + self.stack.append(self.stack[-1]==False) + + def Xor(): + self.gas -= 3 + + firstCondition = self.stack[-1] + secondCondition = self.stack[-2] + self.stack.append(firstCondition or secondCondition and not firstCondition and secondCondition) + + def selfAddress(): + self.stack.append(self.selfAddress) + + def originAddress(): + self.stack.append(self.originAddress) + + def callerAddress(): + self.stack.append(self.callerAddress) + + + + decoder = { + "HALT": halt, + + "POP": pop, + "ICONST": iConst, + + "IADD": iAdd, + "ISUB": iSub, + "IMULT": iMult, + "IDIV": iDiv, + "IMOD": iMod, + + "PRINT": cout, + + "IL": isLessThan, + "IQ": isEqualTo, + "IG": isGreaterThan, + "OR": Or, + "AND": And, + "NOT": Not, + "XOR": Xor, + + "BR": branch, + "BRT": branchIfTrue, + "BRF": branchIfFalse, + + "GSTORE": gStore, + "GLOAD": gLoad, + + "SHA": sha512, + + "SADDR": selfAddress, + "OADDR": originAddress, + "CADDR": callerAddress + } + + # Ending the operations list ==================== + + def picker(codeName): + decoder[codeName]() + + while self.ip < len( + self.code) - 1: # Ok, all that other stuff was just buildup, this is where the REAL magic happens + self.ip += 1 + + op = self.code[self.ip] + print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory)+ "\n GAS: "+str(self.gas)+ "\n ---") + picker(op) + print("OPCODE: " + str(op) + "\n IP: " + str(self.ip) + "\n STACK: " + str(self.stack) + "\n MEMORY: " + str(self.memory) + "\n GAS: "+str(self.gas)+ "\n -------------------------") + + + +aspenVM = VM(['ICONST 5 SHA PRINT POP HALT', -1, -1, 4, 12, 12, 10], # Args = [code, IP, SP, FP, data, datasize] + [["SANTA CLARA", "SANTA BARBARA", "SANTA CRUZ"], 20], # RunData = [[SADDR, OADDR, CADDR], gas] + blockChainData = "dummyData") + +aspenVM.cpu() \ No newline at end of file