GaijinEntertainment / daScript

daScript - high-performance statically strong typed scripting language

Home Page:https://daScript.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

try to AOT

jemoo opened this issue · comments

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)

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?

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.