-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added type promotion for nodes, tasks
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from amitools.vamos.libstructs import NodeType, LibraryStruct | ||
from .node import Node | ||
from .task import Task | ||
from .process import Process | ||
|
||
node_map = { | ||
NodeType.NT_TASK: Task, | ||
NodeType.NT_PROCESS: Process, | ||
NodeType.NT_DEVICE: LibraryStruct, | ||
NodeType.NT_LIBRARY: LibraryStruct, | ||
} | ||
|
||
|
||
def promote_type(obj): | ||
"""convert objects according to Amiga rules | ||
* if its a node then use the node type to derive the actual class | ||
* if its a task but of type process | ||
""" | ||
if type(obj) is Node: | ||
node_type = obj.type.get() | ||
if node_type in node_map: | ||
node_cls = node_map[node_type] | ||
return obj.clone(node_cls) | ||
|
||
# promote a task to a process | ||
elif type(obj) is Task: | ||
node_type = obj.node.type.get() | ||
if node_type == NodeType.NT_PROCESS: | ||
return obj.clone(Process) | ||
|
||
# no promotion applied | ||
return obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from amitools.vamos.machine.mock import MockMemory | ||
from amitools.vamos.libstructs import NodeType | ||
from amitools.vamos.libtypes import promote_type, Node, Task, Process | ||
from amitools.vamos.libtypes.promote import node_map | ||
|
||
|
||
def libtypes_promote_node_test(): | ||
mem = MockMemory() | ||
for node_type, node_cls in node_map.items(): | ||
node = Node(mem, 0x40) | ||
node.type.set(node_type) | ||
new_node = promote_type(node) | ||
assert type(new_node) is node_cls | ||
|
||
|
||
def libtypes_promote_task_test(): | ||
mem = MockMemory() | ||
task = Task(mem, 0x40) | ||
task.node.type.set(NodeType.NT_PROCESS) | ||
proc = promote_type(task) | ||
assert type(proc) is Process |