Skip to content

Commit

Permalink
Merge pull request #90
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy authored Sep 7, 2023
2 parents b014c83 + dbd4506 commit 29fd847
Show file tree
Hide file tree
Showing 541 changed files with 5,299 additions and 5,554 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/cross-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ concurrency:

jobs:
cross-compile:
runs-on: ubuntu-20.04
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- platform: macos
- platform: linux
- platform: windows
- os: ubuntu-20.04
platform: macos
- os: ubuntu-22.04
platform: macos
- os: ubuntu-20.04
platform: linux
- os: ubuntu-22.04
platform: linux
- os: ubuntu-20.04
platform: windows
- os: ubuntu-22.04
platform: windows
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: thelang-io/setup-the@v1
- run: sudo apt-get update
- run: sudo apt-get install mingw-w64 ninja-build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
release:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: thelang-io/setup-the@v1
- run: the run scripts/pre-process-codegen
- run: cmake -B ./build -D CMAKE_BUILD_TYPE=Release
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
platform: windows
generator: Visual Studio 17 2022
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: thelang-io/setup-the@v1
- if: runner.os == 'Linux'
run: |
Expand All @@ -49,10 +49,8 @@ jobs:
run: brew install ninja
- if: runner.os != 'Windows'
run: uname -a
- if: runner.os == 'macOS'
run: the run scripts/pre-process-codegen --arch=x86_64 # todo remove after 0.14
- if: runner.os != 'macOS'
run: the run scripts/pre-process-codegen
- run: the -v
- run: the run scripts/pre-process-codegen
- run: curl -fsSL https://cdn.thelang.io/deps.tar.gz -o deps.tar.gz
- run: tar -xzf deps.tar.gz the/native/${{ matrix.config.platform }}
- if: runner.os == 'Linux'
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ endif ()

if (EXISTS "${PROJECT_SOURCE_DIR}/lab")
add_executable(lab lab/lab.c)
target_compile_options(lab PRIVATE -Wno-incompatible-pointer-types-discards-qualifiers)
target_include_directories(lab PRIVATE "$ENV{DEPS_DIR}/include")
target_link_directories(lab PRIVATE "$ENV{DEPS_DIR}/lib")
target_link_libraries(lab PRIVATE crypto ssl)
Expand Down
2 changes: 1 addition & 1 deletion packages/zip/package.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: the/zip
version: 0.1.5
version: 0.1.10
description: Zip Utilities
license: MIT
main: src/main
26 changes: 16 additions & 10 deletions packages/zip/src/main
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@ export fn zip (name: str, path: str, cwd: str? = nil) {
throw error_NewError("Can't perform zip operation, path doesn't exists")
}

mut cmd := os_NAME == "Windows"
? "tar -a -c -f '" + name + "' " + (path == "*" ? "*" : "'" + path + "'")
: "zip -qr '" + name + "' " + (path == "*" ? "*" : "'" + path + "'")
mut cmd: str

if cwd != nil {
cmd = "(cd '" + cwd + "' && " + cmd + ")"
if os_NAME == "Windows" {
cmd = "powershell Compress-Archive -Path " + (path == "*" ? "*" : "\"" + path + "\"") + " -DestinationPath \"" + name + "\""
cmd = cwd == nil ? "" : ("(cd \"" + cwd + "\" && " + cmd + ")")
} else {
cmd = "zip -qr '" + name + "' " + (path == "*" ? "*" : "'" + path + "'")
cmd = cwd == nil ? "" : ("(cd '" + cwd + "' && " + cmd + ")")
}

process_runSync(cmd)
}

export fn unzip (path: str) {
if !fs_existsSync(path) {
export fn unzip (source: str, destination: str) {
if !fs_existsSync(source) {
throw error_NewError("Can't perform unzip operation, path doesn't exists")
}

cmd := os_NAME == "Windows"
? "tar.exe -x -f '" + path + "'"
: "unzip '" + path + "'"
mut cmd: str

if os_NAME == "Windows" {
cmd = "powershell Expand-Archive -Path \"" + source + "\" -DestinationPath \"" + destination + "\""
} else {
cmd = "unzip -q '" + source + "' -d '" + destination + "'"
}

process_runSync(cmd)
}
25 changes: 14 additions & 11 deletions src/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,15 +639,10 @@ void AST::_forwardNode (const ParserBlock &block, ASTPhase phase) {

auto importNodes = importItem->nodes;
auto importNodesExports = ASTChecker(importItem->nodes).getNodeOfType<ASTNodeExportDecl>(false);
auto importNodesObjects = ASTChecker(importItem->nodes).getNodeOfType<ASTNodeObjDecl>(false);

for (const auto &importNodesObject : importNodesObjects) {
auto nodeObjDecl = std::get<ASTNodeObjDecl>(*importNodesObject.body);

for (const auto &method : nodeObjDecl.methods) {
this->typeMap.insert(method.var->type);
this->varMap.insert(method.var);
}
for (const auto &item : importItem->ast->varMap.methods()) {
this->typeMap.insert(item->type);
this->varMap.insert(item);
}

if (!stmtImportDecl.specifiers.empty()) {
Expand All @@ -661,8 +656,15 @@ void AST::_forwardNode (const ParserBlock &block, ASTPhase phase) {
auto exportName = AST::getExportName(node);
auto exportCodeName = AST::getExportCodeName(node);
auto exportType = AST::getExportType(node);
auto exportVar = AST::getExportVar(node);

namespaceFields.push_back(TypeField{exportName, exportType, false, false, TypeCallInfo{exportCodeName}});
namespaceFields.push_back(TypeField{
exportName,
exportType,
exportVar != nullptr && exportVar->mut,
false,
TypeCallInfo{exportCodeName}
});

if (!exportType->isEnum()) {
this->varMap.add(specifierLocal + "." + exportName, exportCodeName, exportType);
Expand All @@ -686,7 +688,7 @@ void AST::_forwardNode (const ParserBlock &block, ASTPhase phase) {
auto exportType = AST::getExportType(*specifierExport);

if (exportVar != nullptr) {
this->varMap.add(specifierLocal, exportVar->codeName, exportVar->type);
this->varMap.add(specifierLocal, exportVar->codeName, exportVar->type, exportVar->mut);
} else if (specifierImported != specifierLocal) {
this->typeMap.createAlias(specifierLocal, exportType);
} else {
Expand Down Expand Up @@ -782,7 +784,8 @@ void AST::_forwardNode (const ParserBlock &block, ASTPhase phase) {
auto methodDeclAliasType = this->typeMap.createAlias(methodDeclName, methodDeclType);

this->varMap.restore();
this->varMap.add(type->name + "." + methodDeclName, methodDeclAliasType->codeName, methodDeclType);
auto methodVar = this->varMap.add(type->name + "." + methodDeclName, methodDeclAliasType->codeName, methodDeclType);
methodVar->frame = 0;
type->fields.push_back(TypeField{methodDeclName, methodDeclType, false});
} else if (std::holds_alternative<ParserStmtVarDecl>(*member.body)) {
auto stmtVarDecl = std::get<ParserStmtVarDecl>(*member.body);
Expand Down
16 changes: 10 additions & 6 deletions src/TypeMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <utility>
#include "codegen-api.hpp"

std::string actualName (const Type *type) {
return type->codeName[0] == '@' ? type->name : type->codeName;
}

std::string genFnTypeBodyParamId (const TypeFnParam &param) {
if (param.mut && param.required) return "FP5";
else if (param.mut && param.variadic) return "FP6";
Expand Down Expand Up @@ -124,7 +128,7 @@ Type *TypeMap::createArr (Type *elementType) {
return this->createArr(std::get<TypeAlias>(elementType->body).type);
}

auto newType = Type{"array_" + elementType->name, "@array_" + elementType->name, TypeArray{elementType}};
auto newType = Type{"array_" + actualName(elementType), "@array_" + actualName(elementType), TypeArray{elementType}};

for (const auto &it : this->_items) {
if (
Expand Down Expand Up @@ -188,7 +192,7 @@ Type *TypeMap::createMap (Type *keyType, Type *valueType) {
auto actualKeyType = Type::actual(keyType);
auto actualValueType = Type::actual(valueType);

auto n = "map_" + actualKeyType->name + "MS" + actualValueType->name + "ME";
auto n = "map_" + actualName(actualKeyType) + "MS" + actualName(actualValueType) + "ME";
auto codeName = "@map_" + actualKeyType->codeName + "MS" + actualValueType->codeName + "ME";
auto newType = Type{n, codeName, TypeBodyMap{actualKeyType, actualValueType}};

Expand Down Expand Up @@ -244,7 +248,7 @@ Type *TypeMap::createNamespace (const std::string &n, const std::vector<TypeFiel
}

Type *TypeMap::createObj (const std::string &n, const std::vector<TypeField> &fields, bool builtin) {
auto newType = Type{n, this->name(n), TypeObj{}, fields, builtin};
auto newType = Type{n, builtin ? n : this->name(n), TypeObj{}, fields, builtin};
this->_items.push_back(std::make_unique<Type>(newType));
auto selfType = this->_items.back().get();
auto refSelfType = this->createRef(selfType);
Expand All @@ -257,7 +261,7 @@ Type *TypeMap::createOpt (Type *type) {
return this->createOpt(std::get<TypeAlias>(type->body).type);
}

auto newType = Type{"opt_" + type->name, "@opt_" + type->name, TypeOptional{type}};
auto newType = Type{"opt_" + actualName(type), "@opt_" + actualName(type), TypeOptional{type}};

for (const auto &it : this->_items) {
if (
Expand All @@ -282,7 +286,7 @@ Type *TypeMap::createRef (Type *refType) {
return this->createRef(std::get<TypeAlias>(refType->body).type);
}

auto newType = Type{"ref_" + refType->name, "@ref_" + refType->name, TypeRef{refType}};
auto newType = Type{"ref_" + actualName(refType), "@ref_" + actualName(refType), TypeRef{refType}};

for (const auto &it : this->_items) {
if (
Expand All @@ -305,7 +309,7 @@ Type *TypeMap::createUnion (const std::vector<Type *> &subTypes) {

for (const auto &subType : subTypes) {
actualSubTypes.push_back(Type::actual(subType));
n += actualSubTypes.back()->name + "US";
n += actualName(actualSubTypes.back()) + "US";
codeName += actualSubTypes.back()->codeName + "US";
}

Expand Down
12 changes: 12 additions & 0 deletions src/VarMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ std::shared_ptr<Var> VarMap::insert (const std::shared_ptr<Var> &var) {
return this->_items.back();
}

std::vector<std::shared_ptr<Var>> VarMap::methods () const {
auto result = std::vector<std::shared_ptr<Var>>{};

for (const auto &it : this->_items) {
if (it->type->isMethod()) {
result.push_back(it);
}
}

return result;
}

std::string VarMap::name (const std::string &name) const {
auto fullName = name + "_";

Expand Down
1 change: 1 addition & 0 deletions src/VarMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class VarMap {
bool has (const std::string &) const;
void init (TypeMap &);
std::shared_ptr<Var> insert (const std::shared_ptr<Var> &);
std::vector<std::shared_ptr<Var>> methods () const;
std::string name (const std::string &) const;
void restore ();
void save ();
Expand Down
2 changes: 0 additions & 2 deletions src/codegen-api/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ const std::vector<std::string> codegenError = {
R"~( stack->l = message.l;)~" EOL
R"~( stack->d = _{re_alloc}(stack->d, stack->l);)~" EOL
R"~( _{memcpy}(stack->d, message.d, stack->l);)~" EOL
R"~( int i = 0;)~" EOL
R"~( for (_{err_stack_t} *it = fn_err_state->stack_last; it != _{NULL}; it = it->prev) {)~" EOL
R"~( _{size_t} z;)~" EOL
R"~( char *fmt;)~" EOL
Expand All @@ -108,7 +107,6 @@ const std::vector<std::string> codegenError = {
R"~( _{sprintf}(&stack->d[stack->l], fmt, it->name, it->file, it->line, it->col);)~" EOL
R"~( })~" EOL
R"~( stack->l += z;)~" EOL
R"~( i++;)~" EOL
R"~( })~" EOL
R"~(})~" EOL,

Expand Down
24 changes: 10 additions & 14 deletions src/codegen-api/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,18 @@ const std::vector<std::string> codegenFs = {
R"(})" EOL,

R"(void fs_chownSync (_{err_state_t} *fn_err_state, int line, int col, _{struct str} s, _{int32_t} u, _{int32_t} g) {)" EOL
R"( #ifdef _{THE_OS_WINDOWS})" EOL
R"( _{str_free}(s);)" EOL
R"( return;)" EOL
R"( #ifndef _{THE_OS_WINDOWS})" EOL
R"( char *c = _{str_cstr}(s);)" EOL
R"( if (_{chown}(c, u, g) != 0) {)" EOL
R"( const char *fmt = "failed to change owner to %" _{PRId32} " and group to %" _{PRId32} " for file `%s`";)" EOL
R"( _{size_t} z = _{snprintf}(_{NULL}, 0, fmt, u, g, c);)" EOL
R"( char *d = _{alloc}(z + 1);)" EOL
R"( _{sprintf}(d, fmt, u, g, c);)" EOL
R"( _{error_assign}(fn_err_state, _{TYPE_error_Error}, (void *) _{error_Error_alloc}((_{struct str}) {d, z}, (_{struct str}) {_{NULL}, 0}), (void (*) (void *)) &_{error_Error_free}, line, col);)" EOL
R"( })" EOL
R"( _{free}(c);)" EOL
R"( #endif)" EOL
R"( char *c = _{str_cstr}(s);)" EOL
R"( if (_{chown}(c, u, g) != 0) {)" EOL
R"( const char *fmt = "failed to change owner to %" _{PRId32} " and group to %" _{PRId32} " for file `%s`";)" EOL
R"( _{size_t} z = _{snprintf}(_{NULL}, 0, fmt, u, g, c);)" EOL
R"( char *d = _{alloc}(z + 1);)" EOL
R"( _{sprintf}(d, fmt, u, g, c);)" EOL
R"( _{error_assign}(fn_err_state, _{TYPE_error_Error}, (void *) _{error_Error_alloc}((_{struct str}) {d, z}, (_{struct str}) {_{NULL}, 0}), (void (*) (void *)) &_{error_Error_free}, line, col);)" EOL
R"( goto fs_chownSync_cleanup;)" EOL
R"( })" EOL
R"(fs_chownSync_cleanup:)" EOL
R"( _{str_free}(s);)" EOL
R"( _{free}(c);)" EOL
R"( if (fn_err_state->id != -1) _{longjmp}(fn_err_state->buf_last->buf, fn_err_state->id);)" EOL
R"(})" EOL,

Expand Down
5 changes: 4 additions & 1 deletion test/CodegenTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,10 @@ INSTANTIATE_TEST_SUITE_P(NodeImport, CodegenPassTest, testing::Values(
"node-import-empty-specifiers",
"node-import-package",
"node-import-package-of-package",
"node-import-priority"
"node-import-priority",
"node-import-with-mutable-usage",
"node-import-with-mutable-namespace-usage",
"node-import-deep-methods"
));

INSTANTIATE_TEST_SUITE_P(NodeLoop, CodegenPassTest, testing::Values(
Expand Down
4 changes: 2 additions & 2 deletions test/TypeMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ TEST_F(TypeMapTest, MethodInserts) {

EXPECT_NE(this->tm_.get("fn_sFRvoidFE"), nullptr);
EXPECT_NE(this->tm_.get("fn_sFSTestFP3intFRvoidFE"), nullptr);
EXPECT_NE(this->tm_.get("fn_sFSref_TestFP1intFP4strFRstrFE"), nullptr);
EXPECT_NE(this->tm_.get("fn_sFSref_TestFRanyFE"), nullptr);
EXPECT_NE(this->tm_.get("fn_sFSref_test_Test_0FP1intFP4strFRstrFE"), nullptr);
EXPECT_NE(this->tm_.get("fn_sFSref_test_Test_0FRanyFE"), nullptr);
EXPECT_NE(this->tm_.get("fn_aFRvoidFE"), nullptr);
EXPECT_FALSE(type1->builtin);
EXPECT_TRUE(std::holds_alternative<TypeFn>(type1->body));
Expand Down
9 changes: 9 additions & 0 deletions test/VarMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ TEST_F(VarMapTest, InsertsVar) {
EXPECT_EQ(this->vm_.get("test1")->frame, 1);
}

TEST_F(VarMapTest, FiltersMethods) {
this->vm_.add("test1", "test1_0", this->tm_.get("int"), false);
EXPECT_EQ(this->vm_.methods().size(), 0);
this->vm_.add("test2", "test2_0", this->tm_.createMethod({}, this->tm_.get("int"), false, TypeCallInfo{}));
EXPECT_EQ(this->vm_.methods().size(), 1);
this->vm_.add("test3", "test3_0", this->tm_.createMethod({}, this->tm_.get("str"), false, TypeCallInfo{}));
EXPECT_EQ(this->vm_.methods().size(), 2);
}

TEST_F(VarMapTest, NameGeneratesValid) {
EXPECT_EQ(this->vm_.name("test"), "test_0");
this->vm_.add("test", this->vm_.name("test"), this->tm_.get("int"), false);
Expand Down
2 changes: 1 addition & 1 deletion test/ast-test/expr-array-root.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ main {
</NodeExpr>
<NodeExpr>
<NodeExprType>
<TypeArray name="array_TestObj">
<TypeArray name="array_test_TestObj_0">
<TypeObj codeName="test_TestObj_0" name="TestObj">
<TypeField name="a">
<BuiltinType name="int" />
Expand Down
Loading

0 comments on commit 29fd847

Please sign in to comment.