Skip to content

Commit 218c967

Browse files
committed
refactor(stdlib): move stdlib into defaultImports
1 parent 5cc6727 commit 218c967

18 files changed

+458
-483
lines changed

lib/Sema/GlobalScopeVisitor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ class GlobalScopeVisitor
233233
void visitImportDecl(ast::ImportDecl *node)
234234
{
235235
assert(_importManager && "ImportManager must be provided for imports");
236-
if (_skipPrivateImports && node->isPrivate()) {
237-
_importManager->addSkippedImport(
238-
node->getLocation(), node->getImportPath()
239-
);
240-
return;
241-
}
236+
// if (_skipPrivateImports && node->isPrivate()) {
237+
// _importManager->addSkippedImport(
238+
// node->getLocation(), node->getImportPath()
239+
// );
240+
// return;
241+
// }
242242
if (!_importManager->handleImport(
243243
node->getLocation(), node->getImportPath(), _scopeTable,
244244
node->getVisibility()

stdlib/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ function(glu_compile_module module_name)
2020
endfunction()
2121

2222
# List of stdlib modules (without extension)
23-
set(stdlib_modules defaultImports/stringType defaultImports/operators defaultImports/defaultImports glucinfo allocation string io file)
23+
set(stdlib_modules
24+
glucinfo
25+
allocation
26+
defaultImports/stringType
27+
defaultImports/operators
28+
defaultImports/std
29+
defaultImports/defaultImports
30+
defaultImports/string
31+
defaultImports/io
32+
defaultImports/file)
2433

2534
# Copy explicit .glu files from stdlib to build/tools/lib/glu
2635
set(stdlib_src_files)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
public import operators::*;
22
public import stringType::*;
3+
public import std;
File renamed without changes.

stdlib/defaultImports/io.glu

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import stringType::*;
2+
3+
@no_mangling
4+
public func getchar() -> Char;
5+
6+
@no_mangling @c_variadic
7+
public func printf(s: *Char) -> Int;
8+
9+
public func printout(c: Char) -> Void {
10+
printf("%c", c);
11+
}
12+
13+
public func printout(s: String) -> Void {
14+
printf("%s", s.data);
15+
}
16+
17+
public func printout(i: Int) -> Void {
18+
printf("%d", i);
19+
}
20+
21+
public func printout(b: Bool) -> Void {
22+
printf(b ? "true" : "false");
23+
}
24+
25+
#define PRINT(Type) public func print(variable: Type) -> Void { \
26+
printout(variable); \
27+
printf("\n"); \
28+
}
29+
30+
PRINT(String)
31+
PRINT(Char)
32+
PRINT(Int)
33+
PRINT(Bool)
34+
35+
#undef PRINT

stdlib/defaultImports/std.glu

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

stdlib/string.glu renamed to stdlib/defaultImports/string.glu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import allocation::allocate;
2+
import stringType::*;
3+
import operators::*;
24

35
@no_mangling func strlen(s: *Char) -> Int;
46
@no_mangling func strcat(destination: *Char, source: *Char) -> *Char;

stdlib/io.glu

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/functional/ASTPrinter/unicode_test.glu

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

5-
import io;
6-
75
func main() -> Int {
86
// CHECK: Name: capital_a
97
// CHECK: Type: Char

test/functional/Sema/invalid_char_lit.glu

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
// RUN: not gluc -c %s -o %t.o 2>&1 | FileCheck -v %s
33
//
44

5-
import io::printCharacter;
5+
func printCharacter(c: Char) {
6+
std::print(c);
7+
}
68

79
func main() -> Int {
8-
// CHECK: invalid_char_lit.glu:9:20: error: Character literal must be a single character
9-
printCharacter("abc");
1010
// CHECK: invalid_char_lit.glu:11:20: error: Character literal must be a single character
11+
printCharacter("abc");
12+
// CHECK: invalid_char_lit.glu:13:20: error: Character literal must be a single character
1113
printCharacter("");
1214
return 0;
1315
}

0 commit comments

Comments
 (0)