aboutsummaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-09-06 23:51:12 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-09-06 23:51:12 +0200 |
commit | 08f7a91e1ba41f7be3ae8633827b46580c0aec91 (patch) | |
tree | 5a1a2ac3e40bc277ed018e5e9b784aeebfddd76f | |
parent | 156de860e579eef1289ae9320a2a0d9cff41c4c3 (diff) | |
download | tonkadur-python-interpreter-08f7a91e1ba41f7be3ae8633827b46580c0aec91.zip tonkadur-python-interpreter-08f7a91e1ba41f7be3ae8633827b46580c0aec91.tar.bz2 |
Adds support for 'Initialize'.
-rw-r--r-- | tonkadur.py | 29 | ||||
-rw-r--r-- | tonkadur_ui.py | 2 |
2 files changed, 15 insertions, 16 deletions
diff --git a/tonkadur.py b/tonkadur.py index cf89976..e8504b8 100644 --- a/tonkadur.py +++ b/tonkadur.py @@ -48,10 +48,6 @@ class Tonkadur: self.types[typedef['name']] = new_type - #### INITIALIZE VARIABLES ########################################## - for vardef in json_content['variables']: - self.memory[vardef['name']] = self.generate_instance_of(vardef['type']) - #### INITIALIZE SEQUENCES ########################################## for seqdef in json_content['sequences']: self.sequences[seqdef['name']] = seqdef['line'] @@ -310,27 +306,30 @@ class Tonkadur: elif (instruction_category == "set_pc"): self.program_counter = self.compute(instruction["value"]) elif (instruction_category == "set_value"): - pre_val = self.memory - current_val = pre_val - last_access = "" + current_val = self.memory #print("Reference:" + str(instruction["reference"])) access_full = self.compute(instruction["reference"]) #print("Writing: " + str(access_full)) - for access in access_full: - pre_val = current_val - last_access = access - #print("Writing " + str(access) + " of " + str(current_val)) - if (access in current_val): - current_val = current_val[access] - + for access in access_full[:-1]: + current_val = current_val[access] result = self.compute(instruction["value"]) if (isinstance(result, list) or isinstance(result, dict)): result = copy.deepcopy(result) - pre_val[last_access] = result + current_val[access_full[-1]] = result + + self.program_counter += 1 + elif (instruction_category == "initialize"): + current_val = self.memory + access_full = self.compute(instruction["reference"]) + + for access in access_full[:-1]: + current_val = current_val[access] + + current_val[access_full[-1]] = self.generate_instance_of(instruction["type"]) self.program_counter += 1 elif (instruction_category == "prompt_integer"): diff --git a/tonkadur_ui.py b/tonkadur_ui.py index b7a8f8e..b4b7efc 100644 --- a/tonkadur_ui.py +++ b/tonkadur_ui.py @@ -103,7 +103,7 @@ try: print("Unhandled event:" + str(result)) except: - print("failed.\n") + print("failed at line " + str(state.program_counter) + ".\n") print(str(state.memory)) raise print(str(state.memory)) |