Skip to content

Commit

Permalink
changed name from compiler_flags to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-snezhko committed Apr 28, 2023
1 parent 430df72 commit 3667416
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 63 deletions.
4 changes: 2 additions & 2 deletions compiler/src/compile.re
Expand Up @@ -128,8 +128,8 @@ let next_state = (~is_root_file=false, {cstate_desc, cstate_filename} as cs) =>
Parsed(parsed);
| Parsed(p) =>
Grain_utils.Config.apply_attribute_flags(
~no_pervasives=p.compile_flags.no_pervasives,
~runtime_mode=p.compile_flags.runtime_mode,
~no_pervasives=p.attributes.no_pervasives,
~runtime_mode=p.attributes.runtime_mode,
);
if (is_root_file) {
Grain_utils.Config.set_root_config();
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/formatting/format.re
Expand Up @@ -5235,14 +5235,14 @@ let format_ast =
);
let attrs =
(
if (parsed_program.compile_flags.no_pervasives) {
if (parsed_program.attributes.no_pervasives) {
[(Location.mknoloc("noPervasives"), [])];
} else {
[];
}
)
@ (
if (parsed_program.compile_flags.runtime_mode) {
if (parsed_program.attributes.runtime_mode) {
[(Location.mknoloc("runtimeMode"), [])];
} else {
[];
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/parsing/driver.re
Expand Up @@ -160,8 +160,8 @@ let read_imports = (program: Parsetree.parsed_program) => {
},
Grain_utils.Config.with_attribute_flags(
~on_error=_ => (),
~no_pervasives=program.compile_flags.no_pervasives,
~runtime_mode=program.compile_flags.runtime_mode,
~no_pervasives=program.attributes.no_pervasives,
~runtime_mode=program.attributes.runtime_mode,
Grain_utils.Config.get_implicit_opens,
),
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/parsing/parser_header.re
Expand Up @@ -132,7 +132,7 @@ let make_program = (module_attrs, module_name, statements) => {
module_attrs,
);
fix_blocks({
compile_flags: {
attributes: {
no_pervasives,
runtime_mode,
},
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/parsing/parsetree.re
Expand Up @@ -659,14 +659,14 @@ type comment =
/** The type for parsed programs */

[@deriving (sexp, yojson)]
type compile_flags = {
type module_attributes = {
no_pervasives: bool,
runtime_mode: bool,
};

[@deriving (sexp, yojson)]
type parsed_program = {
compile_flags,
attributes: module_attributes,
module_name: loc(string),
statements: list(toplevel_stmt),
comments: list(comment),
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/typed/typemod.re
Expand Up @@ -1020,8 +1020,7 @@ let type_implementation = prog => {
let signature =
Env.build_signature(normalized_sig, module_name, filename, type_metadata);
{
has_flags:
prog.compile_flags.no_pervasives || prog.compile_flags.runtime_mode,
has_flags: prog.attributes.no_pervasives || prog.attributes.runtime_mode,
module_name: prog.module_name,
statements,
env: finalenv,
Expand Down
14 changes: 7 additions & 7 deletions compiler/test/runner.re
Expand Up @@ -210,17 +210,17 @@ let doc = (file, arguments) => {

let module_header = "module Test; ";

let create_compile_flags = compile_flags =>
let create_module_attributes = attributes =>
Grain_parsing.Parsetree.(
(
if (compile_flags.no_pervasives) {
if (attributes.no_pervasives) {
"@noPervasives\n";
} else {
"";
}
)
++ (
if (compile_flags.runtime_mode) {
if (attributes.runtime_mode) {
"@runtimeMode\n";
} else {
"";
Expand Down Expand Up @@ -316,7 +316,7 @@ let makeRunner =
test,
~num_pages=?,
~config_fn=?,
~compile_flags=Test_utils.default_compile_flags,
~attributes=Test_utils.default_module_attributes,
name,
prog,
expected,
Expand All @@ -328,7 +328,7 @@ let makeRunner =
~num_pages?,
~config_fn?,
name,
create_compile_flags(compile_flags) ++ module_header ++ prog,
create_module_attributes(attributes) ++ module_header ++ prog,
);
let (result, _) = run(~num_pages?, wasmfile(name));
expect.string(result).toEqual(expected);
Expand Down Expand Up @@ -459,10 +459,10 @@ let makeParseRunner =
};
let strip_locs =
(
{compile_flags, module_name, statements, comments}: Parsetree.parsed_program,
{attributes, module_name, statements, comments}: Parsetree.parsed_program,
) =>
Parsetree.{
compile_flags,
attributes,
module_name: {
...module_name,
loc: Location.dummy_loc,
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/suites/arrays.re
Expand Up @@ -123,7 +123,7 @@ describe("arrays", ({test, testSkip}) => {
state[0] =
5",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [
Toplevel.expr(
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/suites/basic_functionality.re
Expand Up @@ -255,7 +255,7 @@ describe("basic functionality", ({test, testSkip}) => {
type 脺ber = Number
|},
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [
Toplevel.data([
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/suites/blocks.re
Expand Up @@ -12,7 +12,7 @@ describe("blocks", ({test}) => {
"block_parse_lone_no_args_enum",
"module Test; { Foo }",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [
Toplevel.expr(
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/suites/chars.re
Expand Up @@ -102,7 +102,7 @@ Did you mean to create the string "\{\\"test\\": 1\}" instead?|},
"char_loc_simple",
"module Test\n'a'",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name:
Location.mkloc(
"Test",
Expand All @@ -122,7 +122,7 @@ Did you mean to create the string "\{\\"test\\": 1\}" instead?|},
"char_loc_code",
"module Test\n'\\u{1F3F4}'",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name:
Location.mkloc(
"Test",
Expand All @@ -142,7 +142,7 @@ Did you mean to create the string "\{\\"test\\": 1\}" instead?|},
"char_loc_emoji",
"module Test\n'馃挴'",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name:
Location.mkloc(
"Test",
Expand Down
24 changes: 12 additions & 12 deletions compiler/test/suites/comments.re
Expand Up @@ -12,7 +12,7 @@ describe("comments", ({test}) => {
"comment_parse_1",
"// Test\nmodule Test",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [],
comments: [
Expand All @@ -29,7 +29,7 @@ describe("comments", ({test}) => {
"comment_parse_2",
"/* Test */module Test",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [],
comments: [
Expand All @@ -46,7 +46,7 @@ describe("comments", ({test}) => {
"comment_parse_block_multiline_trim",
"/* Test\n Weird indent\n Normal indent */module Test",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [],
comments: [
Expand All @@ -63,7 +63,7 @@ describe("comments", ({test}) => {
"comment_parse_block_multiline_trim2",
"/* Test\r\n Weird indent\r\n Normal indent */module Test",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [],
comments: [
Expand All @@ -80,7 +80,7 @@ describe("comments", ({test}) => {
"comment_parse_3",
"/** Test */module Test",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [],
comments: [
Expand All @@ -97,7 +97,7 @@ describe("comments", ({test}) => {
"comment_parse_doc_multiline_trim_all_same_indent",
"/**\n Test\n Weird indent\n Normal indent */module Test",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [],
comments: [
Expand All @@ -114,7 +114,7 @@ describe("comments", ({test}) => {
"comment_parse_doc_multiline_trim_keeps_differnt_indent",
"/** Test\n Weird indent\n Normal indent */module Test",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [],
comments: [
Expand All @@ -132,7 +132,7 @@ describe("comments", ({test}) => {
// Note: There are explicit tab characters in this string to test them
"/**\n Test\r\n Weird indent\r\n Normal indent */module Test",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [],
comments: [
Expand All @@ -149,7 +149,7 @@ describe("comments", ({test}) => {
"comment_parse_4",
"#!/bin/grain\nmodule Test",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [],
comments: [
Expand All @@ -166,7 +166,7 @@ describe("comments", ({test}) => {
"comment_parse_block_deasterisk",
"/* Test\n* no space before\n * space before\n * tab before\n *no space after */module Test",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [],
comments: [
Expand All @@ -183,7 +183,7 @@ describe("comments", ({test}) => {
"comment_parse_doc_deasterisk",
"/** Test\n* no space before\n * space before\n * tab before\n *no space after */module Test",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [],
comments: [
Expand All @@ -200,7 +200,7 @@ describe("comments", ({test}) => {
"comment_parse_doc_deasterisk2",
"/** Test\n* no space before\n * space before\n * tab before\n * trailing space after */module Test",
{
compile_flags: Grain_tests.Test_utils.default_compile_flags,
attributes: Grain_tests.Test_utils.default_module_attributes,
module_name: Location.mknoloc("Test"),
statements: [],
comments: [
Expand Down

0 comments on commit 3667416

Please sign in to comment.