Skip to content

Commit

Permalink
[compiler/parse] Accept programs that combine entrypoint and export
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulBone committed Jan 26, 2025
1 parent 9cebb84 commit abb7771
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/parse.m
Original file line number Diff line number Diff line change
Expand Up @@ -1598,13 +1598,20 @@
tokens::in, tokens::out) is det.

maybe_parse_func_export(Sharing, IsEntrypoint, !Tokens) :-
parse_export(Sharing0, !Tokens),
optional(match_token(entrypoint), ok(MaybeEntrypoint), !Tokens),
( MaybeEntrypoint = yes(_),
Sharing = s_private,
( Sharing0 = s_private,
% the export keyword might have come after entrypoint, so check
% again.
parse_export(Sharing, !Tokens)
; Sharing0 = s_public,
Sharing = s_public
),
IsEntrypoint = is_entrypoint
; MaybeEntrypoint = no,
parse_export(Sharing, !Tokens),
IsEntrypoint = not_entrypoint
IsEntrypoint = not_entrypoint,
Sharing = Sharing0
).

:- pred parse_export_opaque(sharing_opaque::out,
Expand Down
11 changes: 11 additions & 0 deletions tests/modules/BUILD.plz
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This is free and unencumbered software released into the public domain.
# See ../LICENSE.unlicense

[entrypoint_2]
type = program
modules = [Entrypoint2a, Entrypoint2b]

[entrypoint_3]
type = program
modules = [Entrypoint3a, Entrypoint3b]

1 change: 1 addition & 0 deletions tests/modules/entrypoint_2.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test 2
15 changes: 15 additions & 0 deletions tests/modules/entrypoint_2a.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* vim: ft=plasma
* This is free and unencumbered software released into the public domain.
* See ../LICENSE.unlicense
*/

module Entrypoint2a

export entrypoint
func test2a() uses IO -> Int {
print!("Test 2\n")

return 0
}

14 changes: 14 additions & 0 deletions tests/modules/entrypoint_2b.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* vim: ft=plasma
* This is free and unencumbered software released into the public domain.
* See ../LICENSE.unlicense
*/

module Entrypoint2b

import Entrypoint2a as T2a

func test2b() uses IO -> Int {
return T2a.test2a!()
}

1 change: 1 addition & 0 deletions tests/modules/entrypoint_3.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test 3
16 changes: 16 additions & 0 deletions tests/modules/entrypoint_3a.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* vim: ft=plasma
* This is free and unencumbered software released into the public domain.
* See ../LICENSE.unlicense
*/

module Entrypoint3a

// entrypoint2 has the keywords in the opposite order.
entrypoint export
func test3a() uses IO -> Int {
print!("Test 3\n")

return 0
}

14 changes: 14 additions & 0 deletions tests/modules/entrypoint_3b.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* vim: ft=plasma
* This is free and unencumbered software released into the public domain.
* See ../LICENSE.unlicense
*/

module Entrypoint3b

import Entrypoint3a as T3a

func test3b() uses IO -> Int {
return T3a.test3a!()
}

0 comments on commit abb7771

Please sign in to comment.