aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2021-12-24 15:09:43 +0100
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2021-12-24 15:09:43 +0100
commitc45d1b542f064f4d0da312642e3364c9f1e2dbeb (patch)
treed443102e4a659e78ee578f5b79cd1f930e92e526
parent54cccfd693939f0f01b0b36767690097cc1c5f90 (diff)
downloadtonkadur-python-interpreter-c45d1b542f064f4d0da312642e3364c9f1e2dbeb.zip
tonkadur-python-interpreter-c45d1b542f064f4d0da312642e3364c9f1e2dbeb.tar.bz2
prompt_command + get_allocable_addressHEADmaster
-rw-r--r--tonkadur.py38
-rw-r--r--tonkadur_ui.py20
2 files changed, 50 insertions, 8 deletions
diff --git a/tonkadur.py b/tonkadur.py
index 970a362..9178cd6 100644
--- a/tonkadur.py
+++ b/tonkadur.py
@@ -123,13 +123,8 @@ class Tonkadur:
return self.compute(computation['if_true'])
else:
return self.compute(computation['if_false'])
- elif (computation_category == "new"):
- address = ".alloc." + str(self.allocated_data)
- self.allocated_data += 1
- self.memory[address] = self.generate_instance_of(computation['target'])
- #print("Allocated " + str(address) + " = " + str(self.memory[address]))
-
- return [address]
+ elif (computation_category == "get_allocable_address"):
+ return [(".alloc." + str(self.allocated_data))]
elif (computation_category == "operation"):
operator = computation['operator']
x = self.compute(computation['x'])
@@ -252,6 +247,17 @@ class Tonkadur:
pre_val[last_access] = value
+ def store_command (self, value):
+ current_val = self.memory
+
+ for access in self.memorized_target:
+ pre_val = current_val
+ last_access = access
+ if (access in current_val):
+ current_val = current_val[access]
+
+ pre_val[last_access] = value
+
def run (self):
while True:
#print("\nmemory: " + str(self.memory))
@@ -328,7 +334,7 @@ class Tonkadur:
last_access = access
current_val = current_val[access]
- #print("Removing " + str(last_access) + " of " + str(pre_val))
+ print("Removing " + str(last_access) + " of " + str(pre_val))
del pre_val[last_access]
self.program_counter += 1
@@ -362,6 +368,9 @@ class Tonkadur:
current_val = self.memory
access_full = self.compute(instruction["reference"])
+ if (access_full == [(".alloc." + str(self.allocated_data))]):
+ self.allocated_data += 1
+
for access in access_full[:-1]:
current_val = current_val[access]
@@ -381,6 +390,19 @@ class Tonkadur:
return result
+ elif (instruction_category == "prompt_command"):
+ result = dict()
+ result["category"] = "prompt_command"
+ result["min"] = self.compute(instruction['min'])
+ result["max"] = self.compute(instruction['max'])
+ result["label"] = self.compute(instruction['label'])
+
+ self.memorized_target = self.compute(instruction['target'])
+
+ self.program_counter += 1
+
+ return result
+
elif (instruction_category == "prompt_string"):
result = dict()
result["category"] = "prompt_string"
diff --git a/tonkadur_ui.py b/tonkadur_ui.py
index 6fb5b5b..5962b6d 100644
--- a/tonkadur_ui.py
+++ b/tonkadur_ui.py
@@ -87,6 +87,26 @@ try:
print("Input size not within range.")
state.store_string(user_input)
+ elif (result_category == "prompt_command"):
+ while True:
+ user_input = input(
+ display_text(result['label'])
+ + " "
+ + "["
+ + str(result['min'])
+ + ", "
+ + str(result['max'])
+ + "] "
+ )
+ if (
+ (len(user_input) >= result['min'])
+ and (len(user_input) <= result['max'])
+ ):
+ break
+ else:
+ print("Input size not within range.")
+ state.store_command(user_input.split(' '))
+
elif (result_category == "assert"):
print(
"Assert failed at line "