`dynload` and `atscc2js`: is there anything special?

You need to put the following line in test-2.dats to resolve the issue:

#define ATS_MAINATSFLAG 1

After combining C code, we link the generated object code. But JS does
not have a link-time. I do not have a good solution to this problem…On Tue, May 12, 2015 at 8:27 AM, ‘Yannick Duchêne’ via ats-lang-users < ats-lan...@googlegroups.com> wrote:

Le mardi 12 mai 2015 13:55:05 UTC+2, Yannick Duchêne a écrit :

Still looking at how to fix the dynload-flag issue.

I have a feeling a ATSdynloadflag_init is missing in test-2.c, so may
be for this one it’s an error in ATSCC2JS, or may be something I don’t
understand. There is one in test-1.c, and there is no in test-1.c.


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/d74a2d69-586a-4c2b-bca4-1b2457617325%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/d74a2d69-586a-4c2b-bca4-1b2457617325%40googlegroups.com?utm_medium=email&utm_source=footer
.

‘x’ is not exported. So using $NS.x leads to an error.

Using something like this, professor?

extern val x: string
implement x = “aaaaa”

I tried this after
http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/HTMLTOC/c1696.html
, but I get an error too. It’s OK with extern val x: string = "mac#", but
I prefer a proper ATS value.

In this case, the error reporting is rather mysterious. If you read the

output from
patsopt, you can see the error: PMVerr(…)

Yes, I noticed it, but though this was another related error. What’s
miss-leading, is that it says it’s a parsing error.

into this:
| D0Cdyncst_valdec (name, _) =>
{
val () = emit_text (out, "var ")
val () = emit_text (out, symbol_get_name(name.i0de_sym))
val () = emit_text (out, “;”)
}
| D0Cdyncst_valimp (name, _) =>
{
val () = emit_text (out, "var ")
val () = emit_text (out, symbol_get_name(name.i0de_sym))
val () = emit_text (out, “;”)
}

While for D0Cdyncst_valdec, it should be something like this (I forget the
initialization):

| D0Cdyncst_valdec (name, s0e) =>
{
val () = emit_text (out, "var ")
val () = emit_text (out, symbol_get_name(name.i0de_sym))
val () = emit_text (out, " = ")
val () = emit_s0exp (out, s0e)
val () = emit_text (out, “;”)
}

but no emit_s0exp is defined (it is for some other target, but not for JS)

By the way, I have fixed the issue with dynload functions. You
should be able to use

dynload “test_2.dats”

My bad, I did not check this one yesterday, and 2JS still complains on this.

If still using val () = $extfcall(void, "test_2_dynload") , there are
errors in the generated JS.

Using this:

test-1.dats
#define ATS_MAINATSFLAG 1
#define ATS_DYNLOADNAME “js_main_dynload”

#include “share/atspre_define.hats”
#include “{$LIBATSCC2JS}/staloadall.hats”

staload NS = “test-2.dats”
//dynload “test-2.dats”
val () = $extfcall(void, “test_2_dynload”)
val y = $NS.x + “b”

%{$
js_main_dynload();
%}

test-2.dats
#define ATS_DYNLOADNAME “test_2_dynload”

#include “share/atspre_define.hats”
#include “{$LIBATSCC2JS}/staloadall.hats”

extern val x: string
implement x = “a”

There are errors in the generated test-1.js and test-2.js.

At line 24 of test-1.js, there is an access to an undefined variable,
“[…]_test_055_2_056_dats__x”. It’s erroneously defined in test-2.js. It’s
defined at line 19 of test-2.js, but inside a function named
“[…]_test_055_2_056_dats__dynload”, so only in its internal scope and not
in the outer scope, that’s why it appears as undefined from test-1.js

Then at line 17 of test-2.js, there is an access to an undefined
“[…]_test_055_2_056_dats__dynloadflag”, which I guess should be defined at
the top of test-2.js, as test-1.js do. The corresponding dynload-flag is
defined at line 10 of test-1.js, but test-2.js has none.

I will look at the C files to see if it’s from the C files or from ATSCC2JS.

I have incorporated a fix like yours for ATSdyncst_valimp.
Changes have been uploaded into Github.On Tuesday, May 12, 2015 at 7:55:05 AM UTC-4, Yannick Duchêne wrote:

Le mardi 12 mai 2015 13:23:50 UTC+2, Yannick Duchêne a écrit :

I don’t really understand it, by my raw guess is that it come from
catsparse_emit2_js.dats at line 943, which says D0Cdyncst_valimp _ => (), which seems to output nothing, while I guess it should output
something like var name.

May be my first ATS fix, I’m very happy.

In catspars_emit2_js.dats , at line 942…

I changed this:
| D0Cdyncst_valdec _ => ()
| D0Cdyncst_valimp _ => ()

into this:
| D0Cdyncst_valdec (name, _) =>
{
val () = emit_text (out, "var ")
val () = emit_text (out, symbol_get_name(name.i0de_sym))
val () = emit_text (out, “;”)
}
| D0Cdyncst_valimp (name, _) =>
{
val () = emit_text (out, "var ")
val () = emit_text (out, symbol_get_name(name.i0de_sym))
val () = emit_text (out, “;”)
}

and it solved the missing declaration issue.

Still looking at how to fix the dynload-flag issue.

Do you mean you want the following:

macdef foo = foo_get()On Tue, May 12, 2015 at 11:51 AM, ‘Yannick Duchêne’ via ats-lang-users < ats-lan...@googlegroups.com> wrote:

Le mardi 12 mai 2015 16:58:20 UTC+2, gmhwxi a écrit :

Because there is no link-time for JS, using global value
declaration is a risky business when you want to compile into JS.
My attitude is that this practice should be avoided unless there
is a very good reason to justify it. It can be readily avoided: You
just turn a global value into a global function:

val foo = 0

changes into

fun foo_get(): int = 0

The issue I would see, is rather with writing. I agree a constant is many
times a parameterless (and side-effectless) function, the difference is in
the required (). I already had this same though with SML, and wished the
name of a function could stand its evaluation with no () if it has no
parameter, and use a syntactical operator to say we want to refer to the
function as a function and not its evaluation. The rational is that
references to a function’s evaluation occurs more often than references to
function’s proper expression.


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/1e482954-a2cf-4b0b-b3ac-38301279f8a8%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/1e482954-a2cf-4b0b-b3ac-38301279f8a8%40googlegroups.com?utm_medium=email&utm_source=footer
.

You need to put the following line in test-2.dats to resolve the issue:

#define ATS_MAINATSFLAG 1

I did, but though it was a hack. So ATS_MAINATSFLAG is not just for the
main module? I though it was to say a module defines the main()
equivalent.

s0e means type (static expression). It is not needed or used for compiling
into JS.On Tuesday, May 12, 2015 at 8:14:38 AM UTC-4, Yannick Duchêne wrote:

Le mardi 12 mai 2015 13:55:05 UTC+2, Yannick Duchêne a écrit :

into this:
| D0Cdyncst_valdec (name, _) =>
{
val () = emit_text (out, "var ")
val () = emit_text (out, symbol_get_name(name.i0de_sym))
val () = emit_text (out, “;”)
}
| D0Cdyncst_valimp (name, _) =>
{
val () = emit_text (out, "var ")
val () = emit_text (out, symbol_get_name(name.i0de_sym))
val () = emit_text (out, “;”)
}

While for D0Cdyncst_valdec, it should be something like this (I forget
the initialization):

| D0Cdyncst_valdec (name, s0e) =>
{
val () = emit_text (out, "var ")
val () = emit_text (out, symbol_get_name(name.i0de_sym))
val () = emit_text (out, " = ")
val () = emit_s0exp (out, s0e)
val () = emit_text (out, “;”)
}

but no emit_s0exp is defined (it is for some other target, but not for JS)

I though it was to say a module defines the main() equivalent.

Yes, this is true for C.

The side-effect of defining ATS_MAINATSFLAG is that the compiler (patsopt)
also generates a variable to indicate whether the compiled file is
initialized. This
is precisely what is needed here.On Tue, May 12, 2015 at 11:02 AM, ‘Yannick Duchêne’ via ats-lang-users < ats-lan...@googlegroups.com> wrote:

Le mardi 12 mai 2015 16:43:55 UTC+2, gmhwxi a écrit :

You need to put the following line in test-2.dats to resolve the issue:

#define ATS_MAINATSFLAG 1

I did, but though it was a hack. So ATS_MAINATSFLAG is not just for the
main module? I though it was to say a module defines the main()
equivalent.


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/54cb238d-7d05-485c-bbd3-560761d9767d%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/54cb238d-7d05-485c-bbd3-560761d9767d%40googlegroups.com?utm_medium=email&utm_source=footer
.

Okay, I will try to fix this one tonight.

The truth is that atscc2js has not been extensively used. Your trying
it is very helpful.On Monday, May 11, 2015 at 2:17:43 PM UTC-4, Yannick Duchêne wrote:

Le lundi 11 mai 2015 18:41:49 UTC+2, gmhwxi a écrit :

‘x’ is not exported. So using $NS.x leads to an error.

Using something like this, professor?

extern val x: string
implement x = “aaaaa”

I tried this after
http://ats-lang.sourceforge.net/DOCUMENT/INT2PROGINATS/HTML/HTMLTOC/c1696.html
, but I get an error too. It’s OK with extern val x: string = "mac#", but
I prefer a proper ATS value.

In this case, the error reporting is rather mysterious. If you read the

output from
patsopt, you can see the error: PMVerr(…)

Yes, I noticed it, but though this was another related error. What’s
miss-leading, is that it says it’s a parsing error.