As I’m not yet really used to ATS, I may miss something, but the sample is
simple enough, so may be the question is worth to be asked.
If some module defines some values of some implementations, it has to be
dynloaded additionally to being staloaded. Trying to dynload anything, with
ATSCC2JS I always get an error. I came to this reduced sample, made of test-1.dats and test-2.dats.
Hello from atscc2js!
ParsingErrors:
: 5408(line=198, offs=1) – 5414(line=198, offs=7): error(parsing): the
keyword [EOF] is needed.
exit(ATS): uncaught exception at run-time: […]/JavaScript/catsparse.sats:
FatalErrorExn(1024)
At line 198 of test-1.c, is this:
extern atsvoid_t0ype
As this a very simple sample, I wonder if dynloading is to be used with the
JavaScript target too or if this is something special with this target and
dynloading.
‘x’ is not exported. So using $NS.x leads to an error.
In this case, the error reporting is rather mysterious. If you read the
output from
patsopt, you can see the error: PMVerr(…)
I will try to improve the error reporting when I have time.On Monday, May 11, 2015 at 12:29:33 PM UTC-4, Yannick Duchêne wrote:
Le lundi 11 mai 2015 17:33:52 UTC+2, gmhwxi a écrit :
val () = test_2_dynload ()
should be
val () = $extfcall(void, “test_2_dynload”)
This one works. Still remains at least another issue (may be more, I don’t
know), although I’m not sure it’s not my own fault: if in test-2.dats I add val x = "y" then in test-1.dats I add val z = $NS.x + "something" I
get errors too, and the first one seems to be a variant, as on the
incriminated line there is a ATSextern().
Should I try to restrict to using #include for now instead? Or is this a
different error from me?
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
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.
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.
This is not yet supported by atscc2js. For now, you need to explicitly
name the dynload function for test_2.dats. For insta ce, add the following
line in test_2.dats:
#defined ATS_DYNLOADNAME “test_2_dynload”
Then you can add the following line in test_1.dats:
val () = test_2_dynload ()On Monday, May 11, 2015 at 11:09:00 AM UTC-4, Yannick Duchêne wrote:
As I’m not yet really used to ATS, I may miss something, but the sample is
simple enough, so may be the question is worth to be asked.
If some module defines some values of some implementations, it has to be
dynloaded additionally to being staloaded. Trying to dynload anything, with
ATSCC2JS I always get an error. I came to this reduced sample, made of test-1.dats and test-2.dats.
Hello from atscc2js!
ParsingErrors:
: 5408(line=198, offs=1) – 5414(line=198, offs=7): error(parsing): the
keyword [EOF] is needed.
exit(ATS): uncaught exception at run-time: […]/JavaScript/catsparse.sats:
FatalErrorExn(1024)
At line 198 of test-1.c, is this:
extern atsvoid_t0ype
As this a very simple sample, I wonder if dynloading is to be used with
the JavaScript target too or if this is something special with this target
and dynloading.
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.
With the newest version of atscc2js, you should be able to
use the above code in test_2.datsOn 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.
val () = $extfcall(void, “test_2_dynload”)On Monday, May 11, 2015 at 11:32:34 AM UTC-4, gmhwxi wrote:
dynload “test_2.dats”
This is not yet supported by atscc2js. For now, you need to explicitly
name the dynload function for test_2.dats. For insta ce, add the following
line in test_2.dats:
#defined ATS_DYNLOADNAME “test_2_dynload”
Then you can add the following line in test_1.dats:
val () = test_2_dynload ()
On Monday, May 11, 2015 at 11:09:00 AM UTC-4, Yannick Duchêne wrote:
As I’m not yet really used to ATS, I may miss something, but the sample
is simple enough, so may be the question is worth to be asked.
If some module defines some values of some implementations, it has to be
dynloaded additionally to being staloaded. Trying to dynload anything, with
ATSCC2JS I always get an error. I came to this reduced sample, made of test-1.dats and test-2.dats.
Hello from atscc2js!
ParsingErrors:
: 5408(line=198, offs=1) – 5414(line=198, offs=7): error(parsing): the
keyword [EOF] is needed.
exit(ATS): uncaught exception at run-time: […]/JavaScript/catsparse.sats:
FatalErrorExn(1024)
At line 198 of test-1.c, is this:
extern atsvoid_t0ype
As this a very simple sample, I wonder if dynloading is to be used with
the JavaScript target too or if this is something special with this target
and dynloading.
dyncst_valdec means a global variable is used in the current file
but it is declared in another file. In C, dyncst_valdec translates to
an extern declaration. What should it be translated into in JS?
dyncst_valimp means a global variable is implemented in the current
file. So it should translate into something like:
var _the_implemented_variable_On Tue, May 12, 2015 at 8:14 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 :
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)
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
If efficiency is of the concern, then Closure should be able to inline
calls to foo_get.On Tuesday, May 12, 2015 at 10:43:55 AM UTC-4, gmhwxi wrote:
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…
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.
With the newest version of atscc2js, you should be able to
use the above code in test_2.dats
Checked! I will test more in the days to come, as I’m to port a tiny web
application to ATS.
I also just wanted to know if this is the proper way to define a constant.
When I tried this, I wasn’t sure (while I guess, probably, as that’s the
way functions are defined).
This one works. Still remains at least another issue (may be more, I don’t
know), although I’m not sure it’s not my own fault: if in test-2.dats I add val x = "y" then in test-1.dats I add val z = $NS.x + "something" I
get errors too, and the first one seems to be a variant, as on the
incriminated line there is a ATSextern().
Should I try to restrict to using #include for now instead? Or is this a
different error from me?
dyncst_valdec means a global variable is used in the current file
but it is declared in another file. In C, dyncst_valdec translates to
an extern declaration. What should it be translated into in JS?
OK. So it should be translated into nothing, as it was.
I also just wanted to know if this is the proper way to define a
constant. When I tried this, I wasn’t sure (while I guess, probably, as
that’s the way functions are defined).
Yes, it is. I would often prefer to use a template:
extern
fun{} my_x(): int
This means that you can re-implement my_x if needed.On Mon, May 11, 2015 at 8:38 PM, ‘Yannick Duchêne’ via ats-lang-users < ats-lan...@googlegroups.com> wrote:
Le mardi 12 mai 2015 02:10:47 UTC+2, gmhwxi a écrit :
extern val x: string
implement x = “aaaaa”
With the newest version of atscc2js, you should be able to
use the above code in test_2.dats
Checked! I will test more in the days to come, as I’m to port a tiny web
application to ATS.
I also just wanted to know if this is the proper way to define a constant.
When I tried this, I wasn’t sure (while I guess, probably, as that’s the
way functions are defined).
I think that this is a personal preference issue. I personally like ‘()’
very much :)On Tue, May 12, 2015 at 12:12 PM, Hongwei Xi gmh...@gmail.com wrote:
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.
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.