| summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/Tonkadur')
| -rw-r--r-- | src/Tonkadur/Compute.elm | 5 | ||||
| -rw-r--r-- | src/Tonkadur/Execute.elm | 96 | ||||
| -rw-r--r-- | src/Tonkadur/Types.elm | 9 |
3 files changed, 80 insertions, 30 deletions
diff --git a/src/Tonkadur/Compute.elm b/src/Tonkadur/Compute.elm index 489ab3b..2a3410f 100644 --- a/src/Tonkadur/Compute.elm +++ b/src/Tonkadur/Compute.elm @@ -160,7 +160,10 @@ newline : Tonkadur.Types.State -> Tonkadur.Types.Value newline state = (TextValue Newline) next_allocable_address : Tonkadur.Types.State -> Tonkadur.Types.Value -next_allocable_address state = (IntValue state.next_allocable_address) +next_allocable_address state = + if (List.isEmpty state.freed_addresses) + then (PointerValue [(".alloc." ++ (String.fromInt state.allocated_data))]) + else (PointerValue [state.freed_addresses[0]]) operation : ( Tonkadur.Types.State -> diff --git a/src/Tonkadur/Execute.elm b/src/Tonkadur/Execute.elm index cf582dd..cf88968 100644 --- a/src/Tonkadur/Execute.elm +++ b/src/Tonkadur/Execute.elm @@ -89,23 +89,51 @@ initialize : ( Tonkadur.Types.State ) initialize type_name address state = - {state | - memory = - (Tonkadur.Types.apply_at_address - (Tonkadur.Types.value_to_list - (Tonkadur.Compute.compute state address) - ) - (\last_addr dict -> - (Dict.insert - last_addr - (Tonkadur.Types.get_default state type_name) - dict + let + new_state = + {state | + memory = + (Tonkadur.Types.apply_at_address + (Tonkadur.Types.value_to_list + (Tonkadur.Compute.compute state address) + ) + (\last_addr dict -> + (Dict.insert + last_addr + (Tonkadur.Types.get_default state type_name) + dict + ) + ) + state.memory ) - ) - state.memory - ) - -- TODO: detect allocated memory for special handling. - } + -- TODO: detect allocated memory for special handling. + } + in + case address of + [single_element] -> + if (String.startsWith ".alloc." single_element) + then + if + ( + single_element + == (".alloc." ++ (String.fromInt new_state.allocated_data)) + ) + then + {new_state | + allocated_data = new_state.allocated_data + 1 + } + else + {new_state | + freed_addresses = + (List.filter + (\addr -> (addr /= single_element)) + new_state.freed_addresses + ) + } + + else new_state + + _ -> new_state prompt_command : ( Tonkadur.Types.PromptInstructionData -> @@ -161,17 +189,31 @@ remove : ( Tonkadur.Types.State ) remove address state = - {state | - memory = - (Tonkadur.Types.apply_at_address - (Tonkadur.Types.value_to_list - (Tonkadur.Compute.compute state address) - ) - (\last_addr dict -> (Dict.remove last_addr dict)) - state.memory - ) - -- TODO: detect allocated memory for special handling. - } + let + new_state = + {state | + memory = + (Tonkadur.Types.apply_at_address + (Tonkadur.Types.value_to_list + (Tonkadur.Compute.compute state address) + ) + (\last_addr dict -> (Dict.remove last_addr dict)) + state.memory + ) + } + in + case address of + [single_element] -> + if (String.startsWith ".alloc." single_element) + then + {new_state | + freed_addresses = + (single_element :: new_state.freed_addresses) + } + else new_state + + _ -> new_state + resolve_choice : Tonkadur.Types.State -> Tonkadur.Types.State resolve_choice state = diff --git a/src/Tonkadur/Types.elm b/src/Tonkadur/Types.elm index 504695b..ec6c3c2 100644 --- a/src/Tonkadur/Types.elm +++ b/src/Tonkadur/Types.elm @@ -97,7 +97,8 @@ type alias State = available_options : (List Option), memorized_target : Value, - last_instruction_effect : InstructionEffect + last_instruction_effect : InstructionEffect, + freed_addresses : (List String) } -------------------------------------------------------------------------------- @@ -120,7 +121,8 @@ new_state = available_options = [], memorized_target = (PointerValue [""]), - last_instruction_effect = MustContinue + last_instruction_effect = MustContinue, + freed_addresses = [] } value_to_bool : Value -> Bool @@ -302,3 +304,6 @@ apply_at_address address fun memory = ) memory ) + +allow_continuing : State -> State +allow_continuing state = {state | last_instruction_effect = MustContinue} |


