Skip to content

Commit

Permalink
codegen: always export function main, since it is the entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Jun 28, 2024
1 parent c02d7ba commit d5d8fd6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions bsc/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def gen_file(self, file):

module_fields = []
for sym in file.mod_sym.scope.syms:
if sym.access_modifier.is_public():
if (file.mod_sym.is_pkg
and sym.name == "main") or sym.access_modifier.is_public():
module_fields.append(
LuaTableField(LuaIdent(sym.name), LuaIdent(sym.name))
)
Expand Down Expand Up @@ -104,8 +105,7 @@ def gen_fn_decl(self, decl):
for arg in decl.args:
args.append(LuaIdent(arg.name))
luafn = LuaFunction(
decl.sym.codegen_qualname(), args,
is_associated = decl.sym.is_associated()
decl.sym.codegen_qualname(), args, is_static = decl.sym.is_static()
)
for arg in decl.args:
if arg.default_value != None:
Expand Down
4 changes: 2 additions & 2 deletions bsc/lua_ast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def __init__(self, fields):
self.fields = fields

class LuaFunction:
def __init__(self, name, args, is_associated = False):
def __init__(self, name, args, is_static = False):
self.name = name
self.args = args
self.is_associated = is_associated
self.is_static = is_static
self.block = LuaBlock()

# Statements
Expand Down
2 changes: 1 addition & 1 deletion bsc/lua_ast/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def render_mod(self, stmt):
)

def render_fn_stmt(self, stmt):
if not stmt.is_associated:
if not stmt.is_static:
self.write("local ")
self.write(f"function {stmt.name}(")
for i, arg in enumerate(stmt.args):
Expand Down
2 changes: 1 addition & 1 deletion bsc/sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def __init__(self, access_modifier, name, args, scope, pos = None):
scope.owner = self
self.scope = scope

def is_associated(self):
def is_static(self):
return isinstance(self.parent, TypeSym)

class Scope:
Expand Down

0 comments on commit d5d8fd6

Please sign in to comment.