summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2020-09-06 23:51:12 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2020-09-06 23:51:12 +0200
commit08f7a91e1ba41f7be3ae8633827b46580c0aec91 (patch)
tree5a1a2ac3e40bc277ed018e5e9b784aeebfddd76f /tonkadur.py
parent156de860e579eef1289ae9320a2a0d9cff41c4c3 (diff)
Adds support for 'Initialize'.
Diffstat (limited to 'tonkadur.py')
-rw-r--r--tonkadur.py29
1 files changed, 14 insertions, 15 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"):