Update list example

This commit is contained in:
Abdelrahman Said 2025-03-01 22:43:43 +00:00
parent f3fc2d5c41
commit 7b16c7511f

View File

@ -154,6 +154,13 @@ def test_typed_array():
def test_doubly_linked_list(): def test_doubly_linked_list():
def __format_func_body(filename: Path, type_string: str):
return load_func_body_from_file(filename).format(
T=type_string,
Tupper=type_string.upper(),
Tlower=type_string.lower(),
)
datatypes: dict[CDataType, list[CInclude]] = {"Str8": [CInclude(header="str8.h", local=True)]} datatypes: dict[CDataType, list[CInclude]] = {"Str8": [CInclude(header="str8.h", local=True)]}
snippets_dir = Path("snippets") snippets_dir = Path("snippets")
@ -186,11 +193,7 @@ def test_doubly_linked_list():
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST), CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST),
CArg(name="index", _type=CType.U64), CArg(name="index", _type=CType.U64),
], ],
body=load_func_body_from_file(Path(__file__).parent / snippets_dir / "list_get").format( body=__format_func_body(Path(__file__).parent / snippets_dir / "list_get", type_string),
T=type_string,
Tupper=type_string.upper(),
Tlower=type_string.lower()
),
pointer=CPointer(CPointerType.SINGLE), pointer=CPointer(CPointerType.SINGLE),
) )
@ -201,11 +204,7 @@ def test_doubly_linked_list():
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)), CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="node", _type=node, pointer=CPointer(CPointerType.SINGLE)), CArg(name="node", _type=node, pointer=CPointer(CPointerType.SINGLE)),
], ],
body=load_func_body_from_file(Path(__file__).parent / snippets_dir / "list_push_front").format( body=__format_func_body(Path(__file__).parent / snippets_dir / "list_push_front", type_string),
T=type_string,
Tupper=type_string.upper(),
Tlower=type_string.lower()
),
) )
push_back_func = CFunc( push_back_func = CFunc(
@ -215,11 +214,7 @@ def test_doubly_linked_list():
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)), CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="node", _type=node, pointer=CPointer(CPointerType.SINGLE)), CArg(name="node", _type=node, pointer=CPointer(CPointerType.SINGLE)),
], ],
body=load_func_body_from_file(Path(__file__).parent / snippets_dir / "list_push_back").format( body=__format_func_body(Path(__file__).parent / snippets_dir / "list_push_back", type_string),
T=type_string,
Tupper=type_string.upper(),
Tlower=type_string.lower()
),
) )
insert_func = CFunc( insert_func = CFunc(
@ -230,11 +225,7 @@ def test_doubly_linked_list():
CArg(name="node", _type=node, pointer=CPointer(CPointerType.SINGLE)), CArg(name="node", _type=node, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="index", _type=CType.U64), CArg(name="index", _type=CType.U64),
], ],
body=load_func_body_from_file(Path(__file__).parent / snippets_dir / "list_insert").format( body=__format_func_body(Path(__file__).parent / snippets_dir / "list_insert", type_string),
T=type_string,
Tupper=type_string.upper(),
Tlower=type_string.lower()
),
) )
pop_front_func = CFunc( pop_front_func = CFunc(
@ -243,11 +234,7 @@ def test_doubly_linked_list():
args=[ args=[
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)), CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
], ],
body=load_func_body_from_file(Path(__file__).parent / snippets_dir / "list_pop_front").format( body=__format_func_body(Path(__file__).parent / snippets_dir / "list_pop_front", type_string),
T=type_string,
Tupper=type_string.upper(),
Tlower=type_string.lower()
),
pointer=CPointer(CPointerType.SINGLE), pointer=CPointer(CPointerType.SINGLE),
) )
@ -257,11 +244,7 @@ def test_doubly_linked_list():
args=[ args=[
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)), CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
], ],
body=load_func_body_from_file(Path(__file__).parent / snippets_dir / "list_pop_back").format( body=__format_func_body(Path(__file__).parent / snippets_dir / "list_pop_back", type_string),
T=type_string,
Tupper=type_string.upper(),
Tlower=type_string.lower()
),
pointer=CPointer(CPointerType.SINGLE), pointer=CPointer(CPointerType.SINGLE),
) )
@ -272,11 +255,7 @@ def test_doubly_linked_list():
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)), CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="index", _type=CType.U64), CArg(name="index", _type=CType.U64),
], ],
body=load_func_body_from_file(Path(__file__).parent / snippets_dir / "list_remove").format( body=__format_func_body(Path(__file__).parent / snippets_dir / "list_remove", type_string),
T=type_string,
Tupper=type_string.upper(),
Tlower=type_string.lower()
),
pointer=CPointer(CPointerType.SINGLE), pointer=CPointer(CPointerType.SINGLE),
) )
@ -286,11 +265,7 @@ def test_doubly_linked_list():
args=[ args=[
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)), CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
], ],
body=load_func_body_from_file(Path(__file__).parent / snippets_dir / "list_empty").format( body=__format_func_body(Path(__file__).parent / snippets_dir / "list_empty", type_string),
T=type_string,
Tupper=type_string.upper(),
Tlower=type_string.lower()
),
) )
node_to_list_func = CFunc( node_to_list_func = CFunc(
@ -299,11 +274,7 @@ def test_doubly_linked_list():
args=[ args=[
CArg(name="node", _type=node, pointer=CPointer(CPointerType.SINGLE)), CArg(name="node", _type=node, pointer=CPointer(CPointerType.SINGLE)),
], ],
body=load_func_body_from_file(Path(__file__).parent / snippets_dir / "node_to_list").format( body=__format_func_body(Path(__file__).parent / snippets_dir / "node_to_list", type_string),
T=type_string,
Tupper=type_string.upper(),
Tlower=type_string.lower(),
),
qualifiers=[CQualifier.INTERNAL], qualifiers=[CQualifier.INTERNAL],
) )
@ -334,9 +305,6 @@ def test_doubly_linked_list():
header.includes.extend(includes) header.includes.extend(includes)
source.includes.extend(includes) source.includes.extend(includes)
header.includes = sorted(header.includes, key=lambda inc: inc.local, reverse=True)
source.includes = sorted(source.includes, key=lambda inc: inc.local, reverse=True)
header.save(Path(".")) header.save(Path("."))
source.save(Path(".")) source.save(Path("."))