Skip to content

Commit eb28d9d

Browse files
committed
fix(stdlib): fix all imports in stdlib to be imported by default
1 parent 1a5e990 commit eb28d9d

File tree

12 files changed

+26
-20
lines changed

12 files changed

+26
-20
lines changed

stdlib/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ endfunction()
2222
# List of stdlib modules (without extension)
2323
set(stdlib_modules
2424
glucinfo
25-
allocation
25+
std
26+
defaultImports/allocation
2627
defaultImports/stringType
2728
defaultImports/operators
2829
defaultImports/std
File renamed without changes.

stdlib/defaultImports/file.glu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@no_mangling func write(fildes: Int, buf: *Char, nbyte: Int) -> Int;
66
// func close(fildes: Int) -> Int;
77

8-
struct File {
8+
public struct File {
99
fd: Int
1010
}
1111

stdlib/defaultImports/io.glu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import stringType::*;
1+
public import stringType::*;
22

33
@no_mangling
44
public func getchar() -> Char;

stdlib/defaultImports/std.glu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
public import io::*;
2+
public import file::*;
3+
public import string::*;
4+
public import allocation::*;

stdlib/defaultImports/string.glu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import allocation::allocate;
2-
import stringType::*;
2+
public import stringType::*;
33
import operators::*;
44

55
@no_mangling func strlen(s: *Char) -> Int;
66
@no_mangling func strcat(destination: *Char, source: *Char) -> *Char;
77
@no_mangling func memcpy(dst: *Char, src: *Char, n: Int) -> *Char;
88
@no_mangling func abort();
99

10-
func createStringFromPointer(s: *Char) -> String {
10+
public func createStringFromPointer(s: *Char) -> String {
1111
var str: String;
1212

1313
str.data = s;

stdlib/std.glu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public import defaultImports::std::*;

test/functional/Sema/bad_drop_overload.glu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: not gluc %s 2>&1 | FileCheck %s
33
//
44

5-
import file;
5+
66

77
struct FileDescriptor {
88
value: Int
@@ -20,7 +20,7 @@ func drop(b: Bool) {
2020
}
2121

2222
// CHECK: bad_drop_overload.glu:23:1: error: Invalid 'drop' overload: cannot overload 'drop' for types from other modules
23-
func drop(b: file::File) {
23+
func drop(b: std::File) {
2424

2525
}
2626

test/functional/Sema/defaultable_overload.glu

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// RUN: gluc %s -o %t && %t | FileCheck -v %s
33
//
44

5-
import io::printLine;
6-
75
// Defaultable
86
func process(x: Int) -> String {
97
return "processed int";
@@ -21,18 +19,18 @@ func main() -> Int {
2119
// Defaultable overload resolution:
2220

2321
// CHECK: processed int
24-
printLine(process(42));
22+
std::print(process(42));
2523

2624
// CHECK: processed float
27-
printLine(process(42.0));
25+
std::print(process(42.0));
2826

2927
// CHECK: processed string
30-
printLine(process("hello"));
28+
std::print(process("hello"));
3129

3230
// Explicit type annotations:
3331

3432
// CHECK: processed float
35-
printLine(process(42 as Float));
33+
std::print(process(42 as Float));
3634

3735
return 0;
3836
}

test/functional/run/function_overloads.glu

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44

55
@no_mangling func puts(s: *Char);
66

7-
func +(a: *Char, b: *Char) -> *Char {
7+
struct Custom {
8+
9+
}
10+
11+
func +(a: *Char, b: Custom) -> *Char {
812
puts("overload is working");
913
return "troll";
1014
}
1115

1216
// CHECK: overload is working
1317
// CHECK: troll
1418
func main() -> Int {
15-
let result = "wesh" + "alors";
19+
let custom: Custom = {};
20+
let result = "wesh" + custom;
1621
puts(result);
1722
return 0;
1823
}

0 commit comments

Comments
 (0)