Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to AOT #1001

Closed
jemoo opened this issue Mar 3, 2024 · 3 comments
Closed

try to AOT #1001

jemoo opened this issue Mar 3, 2024 · 3 comments

Comments

@jemoo
Copy link

jemoo commented Mar 3, 2024

I'm trying to AOT the following code:

print("{new String("hello!")->to_upper()->utf8()}\n");

got:

builtin_print(das_string_builder(__context__,SimNode_AotInterop<2>(__tinfo_0, cast<char *>::from(das_invoke_function<char *>::invoke<test::String &>(__context__,nullptr,das_invoke_function<test::String & *>::invoke<test::String &>(__context__,nullptr,das_new<test::String>::make_and_init(__context__,[&]() { return das_invoke_function<test::String>::invoke_cmres<char * const >(__context__,nullptr,Func(__context__->fnByMangledName(/*@test::String Cs*/ 12949979443183231949u)),((char *) "hello!")); })->to_upper,das_arg<test::String>::pass(das_cast<test::String const >::cast(das_deref(__context__,das_new<test::String>::make_and_init(__context__,[&]() { return das_invoke_function<test::String>::invoke_cmres<char * const >(__context__,nullptr,Func(__context__->fnByMangledName(/*@test::String Cs*/ 12949979443183231949u)),((char *) "hello!")); })))))->utf8,das_arg<test::String>::pass(das_cast<test::String const >::cast(das_deref(__context__,das_invoke_function<test::String *>::invoke<test::String &>(__context__,nullptr,das_new<test::String>::make_and_init(__context__,[&]() { return das_invoke_function<test::String>::invoke_cmres<char * const >(__context__,nullptr,Func(__context__->fnByMangledName(/*@test::String Cs*/ 12949979443183231949u)),((char *) "hello!")); })->to_upper,das_arg<test::String>::pass(das_cast<test::String const >::cast(das_deref(__context__,das_new<test::String>::make_and_init(__context__,[&]() { return das_invoke_function<test::String>::invoke_cmres<char * const >(__context__,nullptr,Func(__context__->fnByMangledName(/*@test::String Cs*/ 12949979443183231949u)),((char *) "hello!")); })))))))))), cast<char * const >::from(((char *) "\n")))),__context__,((LineInfoArg *)(&LineInfo::g_LineInfoNULL)));

with some compile errors. I noticed a few issues in it,

  1. create a pointer to a reference das_invoke_function<test::String & *>
  2. new String("hello!") appears multiple times? (I'm not quite sure)
@jemoo
Copy link
Author

jemoo commented Jun 8, 2024

I found that this issue not only occurs in AOT mode, but also exists in the interpretation mode.

When I try to run the following code...

class MyString
	def MyString
		print("MyString\n")
	def to_upper(): MyString?
		print("to_upper\n")
		return addr(self)
	def utf8(): MyString?
		print("utf8\n")
		return addr(self)

[export]
def main
	print("${new MyString()->to_upper()->utf8()}\n")

I get the following output:

D:\daScript\bin\Debug>daScript.exe test.das
MyString
MyString
to_upper
MyString
MyString
to_upper
utf8
$[[ 0x12f13335970; MyString'__finalize/*MyString'__finalize S<MyString>*/; MyString`to_upper/*MyString`to_upper S<MyString>*/; MyString`utf8/*MyString`utf8 S<MyString>*/]]

It doesn't perform as expected. Is there a mistake in my code?

@borisbat
Copy link
Collaborator

It is indeed a bug. Currently /* a->b(args) is short for invoke(a.b, cast deref(a), args) */. This clearly does not work for chaining class methods. Will fix shortly.

@borisbat
Copy link
Collaborator

#1151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants