#๐Ÿ”’ Error while creating a programming language and compiler LLVM

36 messages ยท Page 1 of 1 (latest)

hollow oriole
#

I'm a beginner working on a programming language called HolyS that Idolizes HolyC that was created by Legend Terry Davis, the language is built on python and uses LLVM Lite, it also follows CodeDuckers playlist on YouTube.

The Error:
Traceback (most recent call last):
File "c:\Users\essam\Desktop\HolyS-main\Lang\main.py", line 39, in <module>
c.compile(node=program)
File "c:\Users\essam\Desktop\HolyS-main\Lang\compiler.py", line 24, in compile
self.__visit_program(node)
File "c:\Users\essam\Desktop\HolyS-main\Lang\compiler.py", line 46, in __visit_program
self.compile(stmt)
File "c:\Users\essam\Desktop\HolyS-main\Lang\compiler.py", line 30, in compile
self.__visit_function_statement(node)
File "c:\Users\essam\Desktop\HolyS-main\Lang\compiler.py", line 94, in __visit_function_statement
self.compile(body)
UnboundLocalError: local variable 'body' referenced before assignment

The code:
https://github.com/scriptties/HolyS/tree/main/Lang

GitHub

Contribute to scriptties/HolyS development by creating an account on GitHub.

sturdy burrowBOT
#

@hollow oriole

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

midnight delta
#
body: BlockStatement

You didnt give body a value.

#

That's just a type annotation. That doesn't define the name body.

#

What value do you want it to hold? An empty BlockStatement object?

hollow oriole
#

how do I define it ?

midnight delta
#

=, like you're doing with the other variables.

#

You need to assign a value to the name.

hollow oriole
#

so body = BlockStatement ?

#

or body: BlockStatement = something

midnight delta
#

Either. The : part is just a hint to Python about what type you intend for it to be. It doesn't actually "do" anything though. The = is the important part.

hollow oriole
#

alr I'll try to check

#

@midnight delta I tried gives me the same error

midnight delta
#

Show what you tried.

#

Sorry, I got distracted with something.

hollow oriole
midnight delta
#

You wouldn't get the same error with that.

hollow oriole
#

I did tho

midnight delta
#

You may have gotten a different error, but not the same error.

hollow oriole
midnight delta
#

You'll likely get a type error at some point since you need () to instantiate the class.

#

What's the full error message that you're getting?

hollow oriole
#

ohh yeah I got a different error now

#

Traceback (most recent call last):
File "c:\Users\essam\Desktop\HolyS-main\Lang\main.py", line 39, in <module>
c.compile(node=program)
File "c:\Users\essam\Desktop\HolyS-main\Lang\compiler.py", line 24, in compile
self.__visit_program(node)
File "c:\Users\essam\Desktop\HolyS-main\Lang\compiler.py", line 46, in __visit_program
self.compile(stmt)
File "c:\Users\essam\Desktop\HolyS-main\Lang\compiler.py", line 30, in compile
self.__visit_function_statement(node)
File "c:\Users\essam\Desktop\HolyS-main\Lang\compiler.py", line 94, in __visit_function_statement
self.compile(body)
File "c:\Users\essam\Desktop\HolyS-main\Lang\compiler.py", line 22, in compile
match node.type():
TypeError: BlockStatement.type() missing 1 required positional argument: 'self'

midnight delta
#

You need to instantiate the class.

#

BlockStatement(). And you'll need to pass in any statements that you want to be a part of the block, if there are any.

hollow oriole
#

I don't understand

midnight delta
#

Replace = BlockStatement with = BlockStatement().

hollow oriole
#

PS C:\Users\essam\Desktop\HolyS-main\Lang> & C:/Users/essam/AppData/Local/Programs/Python/Python310/python.exe c:/Users/essam/Desktop/HolyS-main/Lang/main.py
Traceback (most recent call last):
File "c:\Users\essam\Desktop\HolyS-main\Lang\main.py", line 39, in <module>
c.compile(node=program)
File "c:\Users\essam\Desktop\HolyS-main\Lang\compiler.py", line 24, in compile
self.__visit_program(node)
File "c:\Users\essam\Desktop\HolyS-main\Lang\compiler.py", line 49, in __visit_program
self.builder.ret(return_value)
File "C:\Users\essam\AppData\Local\Programs\Python\Python310\lib\site-packages\llvmlite\ir\builder.py", line 863, in ret
instructions.Ret(self.block, "ret", value))
File "C:\Users\essam\AppData\Local\Programs\Python\Python310\lib\site-packages\llvmlite\ir\instructions.py", line 228, in init
super(Ret, self).init(parent, opname, operands)
File "C:\Users\essam\AppData\Local\Programs\Python\Python310\lib\site-packages\llvmlite\ir\instructions.py", line 202, in init
super(Terminator, self).init(parent, types.VoidType(), opname,
File "C:\Users\essam\AppData\Local\Programs\Python\Python310\lib\site-packages\llvmlite\ir\instructions.py", line 14, in init
super(Instruction, self).init(parent, typ, name=name)
File "C:\Users\essam\AppData\Local\Programs\Python\Python310\lib\site-packages\llvmlite\ir\values.py", line 538, in init
assert parent is not None
AssertionError

#

I feel like we're in a rabbit hole here

midnight delta
#

That's another, new error. I've never used that library, so I don't knownwhat causes that.

hollow oriole
#

nvm it

sleek vine
sturdy burrowBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.