#include "share/atspre_define.hats"
#include "{$LIBATSCC2JS}/staloadall.hats"
staload NS = "test-2.dats"
dynload "test-2.dats"
#define ATS_MAINATSFLAG 1
#define ATS_DYNLOADNAME "js_main_dynload"
%{$
js_main_dynload();
%}
// Empty.
patsopt -d "test-1.dats" >"test-1.c"
atscc2js -o "test-1.js" <"test-1.c"
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)
extern atsvoid_t0ype
>>val () = test_2_dynload ()
should be
val () = $extfcall(void, "test_2_dynload")
'x' is not exported. So using $NS.x leads to an error.
extern val x: string
implement x = "aaaaa"
In this case, the error reporting is rather mysterious. If you read the output from
patsopt, you can see the error: PMVerr(...)
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.
extern val x: string
implement x = "aaaaa"
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
--
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/57080c81-2021-42fb-99a9-033b385febfa%40googlegroups.com.
By the way, I have fixed the issue with dynload functions. You
should be able to use
dynload "test_2.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();
%}
#define ATS_DYNLOADNAME "test_2_dynload"
#include "share/atspre_define.hats"
#include "{$LIBATSCC2JS}/staloadall.hats"
extern val x: string
implement x = "a"
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`.
| D0Cdyncst_valdec _ => ()
| D0Cdyncst_valimp _ => ()
| 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, ";")
}
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, ";")
}
| 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, ";")
}
Still looking at how to fix the dynload-flag issue.
--
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/208e5a1c-9762-47c7-a9a7-b4ce7c664294%40googlegroups.com.
--
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.
You need to put the following line in test-2.dats to resolve the issue:After combining C code, we link the generated object code. But JS does
#define ATS_MAINATSFLAG 1
not have a link-time. I do not have a good solution to this problem...
dyncst_valdec means a global variable is used in the current filebut it is declared in another file. In C, dyncst_valdec translates toan extern declaration. What should it be translated into in JS?
You need to put the following line in test-2.dats to resolve the issue:
#define ATS_MAINATSFLAG 1
--
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.
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
--
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.
>>Do you mean you want the following:>>macdef foo = foo_get()I think that this is a personal preference issue. I personally like '()' very much :)