Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions pytrace-generator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)

type_name_regex = re.compile("<class '(?:__main__\\.)?(.*)'>")
function_str_regex = re.compile(r"^(<function .+) at .+>")
import_regex = re.compile(r"^(?:[^'\"]+\s)?import[\s*]")

# Frame objects:
Expand All @@ -26,10 +27,11 @@ def eprint(*args, **kwargs):
float: "float",
bool: "bool",
str: "str",
type(None): "none"
type(None): "none",
type: "type",
types.FunctionType: "function"
}
HEAP_TYPES = {
type: "type",
list: "list",
tuple: "tuple",
dict: "dict",
Expand Down Expand Up @@ -112,6 +114,18 @@ def format(self):
"type": self.type_str,
"value": self.value
}
if type(d["value"]) == type:
type_name = str(d["value"])
search_result = type_name_regex.search(type_name)
if search_result is not None:
type_name = f"<class '{search_result.group(1)}'>"
d["value"] = type_name
elif inspect.isfunction(d["value"]):
function_desc = str(d["value"])
search_result = function_str_regex.search(function_desc)
if search_result is not None:
function_desc = f"{search_result.group(1)}>"
d["value"] = function_desc
if self.variable_name is not None:
d["name"] = self.variable_name
return d
Expand Down Expand Up @@ -200,11 +214,6 @@ def store(self, address, value):
stored_value[key_id] = prim_value
if prim_value.is_ref():
inner_values.append(v)
elif value_type == type:
stored_value = str(value)
search_result = type_name_regex.search(stored_value)
if search_result is not None:
stored_value = f"<class '{search_result.group(1)}'>"
elif inspect.isgenerator(value):
stored_value = {}
else:
Expand Down
132 changes: 33 additions & 99 deletions pytrace-generator/test/test-cases/divideByZero.py.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@
"frameName": "<module>",
"locals": [
{
"type": "ref",
"value": 0,
"type": "function",
"value": "<function bar>",
"name": "bar"
}
]
}
],
"heap": {
"0": {
"type": "instance",
"value": {},
"name": "function"
}
},
"heap": {},
"stdout": ""
},
{
Expand All @@ -43,20 +37,14 @@
"frameName": "<module>",
"locals": [
{
"type": "ref",
"value": 0,
"type": "function",
"value": "<function bar>",
"name": "bar"
}
]
}
],
"heap": {
"0": {
"type": "instance",
"value": {},
"name": "function"
}
},
"heap": {},
"stdout": ""
},
{
Expand All @@ -67,8 +55,8 @@
"frameName": "<module>",
"locals": [
{
"type": "ref",
"value": 0,
"type": "function",
"value": "<function bar>",
"name": "bar"
}
]
Expand All @@ -84,13 +72,7 @@
]
}
],
"heap": {
"0": {
"type": "instance",
"value": {},
"name": "function"
}
},
"heap": {},
"stdout": ""
},
{
Expand All @@ -101,8 +83,8 @@
"frameName": "<module>",
"locals": [
{
"type": "ref",
"value": 0,
"type": "function",
"value": "<function bar>",
"name": "bar"
}
]
Expand All @@ -118,13 +100,7 @@
]
}
],
"heap": {
"0": {
"type": "instance",
"value": {},
"name": "function"
}
},
"heap": {},
"stdout": ""
},
{
Expand All @@ -135,8 +111,8 @@
"frameName": "<module>",
"locals": [
{
"type": "ref",
"value": 0,
"type": "function",
"value": "<function bar>",
"name": "bar"
}
]
Expand All @@ -162,13 +138,7 @@
]
}
],
"heap": {
"0": {
"type": "instance",
"value": {},
"name": "function"
}
},
"heap": {},
"stdout": ""
},
{
Expand All @@ -179,8 +149,8 @@
"frameName": "<module>",
"locals": [
{
"type": "ref",
"value": 0,
"type": "function",
"value": "<function bar>",
"name": "bar"
}
]
Expand All @@ -206,13 +176,7 @@
]
}
],
"heap": {
"0": {
"type": "instance",
"value": {},
"name": "function"
}
},
"heap": {},
"stdout": ""
},
{
Expand All @@ -223,8 +187,8 @@
"frameName": "<module>",
"locals": [
{
"type": "ref",
"value": 0,
"type": "function",
"value": "<function bar>",
"name": "bar"
}
]
Expand Down Expand Up @@ -260,13 +224,7 @@
]
}
],
"heap": {
"0": {
"type": "instance",
"value": {},
"name": "function"
}
},
"heap": {},
"stdout": ""
},
{
Expand All @@ -277,8 +235,8 @@
"frameName": "<module>",
"locals": [
{
"type": "ref",
"value": 0,
"type": "function",
"value": "<function bar>",
"name": "bar"
}
]
Expand Down Expand Up @@ -314,13 +272,7 @@
]
}
],
"heap": {
"0": {
"type": "instance",
"value": {},
"name": "function"
}
},
"heap": {},
"stdout": ""
},
{
Expand All @@ -331,20 +283,14 @@
"frameName": "<module>",
"locals": [
{
"type": "ref",
"value": 0,
"type": "function",
"value": "<function bar>",
"name": "bar"
}
]
}
],
"heap": {
"0": {
"type": "instance",
"value": {},
"name": "function"
}
},
"heap": {},
"stdout": ""
},
{
Expand All @@ -355,20 +301,14 @@
"frameName": "<module>",
"locals": [
{
"type": "ref",
"value": 0,
"type": "function",
"value": "<function bar>",
"name": "bar"
}
]
}
],
"heap": {
"0": {
"type": "instance",
"value": {},
"name": "function"
}
},
"heap": {},
"stdout": ""
},
{
Expand All @@ -379,20 +319,14 @@
"frameName": "<module>",
"locals": [
{
"type": "ref",
"value": 0,
"type": "function",
"value": "<function bar>",
"name": "bar"
}
]
}
],
"heap": {
"0": {
"type": "instance",
"value": {},
"name": "function"
}
},
"heap": {},
"stdout": ""
}
]
Loading