Skip to content

Commit

Permalink
webassembly
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Delaunay committed Aug 19, 2024
1 parent 8cbfe75 commit 55a3d0b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
30 changes: 25 additions & 5 deletions lython/header/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def parse_files(self, folder_or_file):
"-nostdinc",
# "-I", str(folder_or_file),
"-I", "K:/lython/src",
"-I", "/home/newton/work/lython/src",
"-DKMETA_PROCESSING=1",
]
tu = self.index.parse(
Expand Down Expand Up @@ -174,10 +175,23 @@ def generate_method(self, struct, attr, fp):

ann = attr.get("ann", {}) or {}
overriden_type = ann.get("type", None)



if overriden_type:
if attrname.startswith("operator"):
ops = {
"==": "operator_equal",
"!=": "operator_notequal"
}
op = attrname.replace("operator", "")
name = ops.get(op, "Unhandled")
else:
name = attrname

print(
f' using {attrname}T = {overriden_type};\n'
f' lython::meta::register_member<static_cast<{attrname}T>(&{typename}::{attrname})>("{attrname}");',
f' using {name}T = {overriden_type};\n'
f' lython::meta::register_member<static_cast<{name}T>(&{typename}::{attrname})>("{attrname}");',
file=fp,
)

Expand All @@ -194,13 +208,18 @@ def generate_method(self, struct, attr, fp):
def parse_annotation(self, ann):
return ann

def add_field(self, members, node, gather_members, field_ann):
def add_field(self, members, node: clang.cindex.Cursor, gather_members, field_ann):
ann = None
for attr in node.get_children():
if attr.kind == clang.cindex.CursorKind.ANNOTATE_ATTR:
ann = self.parse_annotation(attr.spelling)
break

if node.access_specifier != clang.cindex.AccessSpecifier.PUBLIC:
return

# print(node.availability)
# print(node.access_specifier)
data = {
"id": len(members),
"name": node.spelling,
Expand All @@ -225,8 +244,9 @@ def has_meta_info(self, node):

def accept_path(self, p):
try:
os.path.commonpath([str(p), *self.files])
return True
return str(p).startswith(str(self.folder))
print(os.path.commonpath([str(p), self.folder]))
return True
except:
return False

Expand Down
3 changes: 3 additions & 0 deletions src/ast/values/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ struct Value {
return !((*this) == val);
}


KFUNCTION(type=bool(lython::Value::*)(Value const&) const)
bool operator==(Value const& val) const;

KFUNCTION(type=bool(lython::Value::*)(Value const&) const)
bool operator!=(Value const& val) const { return !((*this) == val); }

template <typename T>
Expand Down

0 comments on commit 55a3d0b

Please sign in to comment.