Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Delaunay committed May 16, 2024
1 parent b03a507 commit 193cd9c
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/ast/values/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ Value _new_object(int _typeid, Args... args) {
template <typename T, typename... Args>
Value _new_object(GarbageCollector& gc, int _typeid, Args... args) {
// up to the user to free it correctly
void* memory = gc->malloc(sizeof(T));
void* memory = gc.malloc(sizeof(T));
new (memory) T(args...);
// now the deleter needs to know the gc
// unless the GC takes care of everything then no deleter needed
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/llvm/llvm_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#if WITH_LLVM && WITH_LLVM_CODEGEN
// Kiwi
#include "utilities/guard.h"
#include "utilities/printing.h" ators.h "
#include "utilities/printing.h"
#include "utilities/printing.h"
#include "utilities/strings.h"

Expand Down
8 changes: 6 additions & 2 deletions src/plugin/example.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ struct ExampleVisitor: public lython::VisitorPlugin {
#define STMT(name, fun) TYPE_GEN(name)
#define MOD(name, fun) TYPE_GEN(name)
#define MATCH(name, fun) TYPE_GEN(name)
#define VM(name, fun)

NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH)
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH, VM)

#undef X
#undef SSECTION
#undef EXPR
#undef STMT
#undef MOD
#undef MATCH
#undef VM
#undef TYPE_GEN

#define FUNCTION_GEN(name, fun, ret) ret fun(name##_t* n, int depth) override;
Expand All @@ -44,15 +46,17 @@ struct ExampleVisitor: public lython::VisitorPlugin {
#define EXPR(name, fun) FUNCTION_GEN(name, fun, ExprRet)
#define STMT(name, fun) FUNCTION_GEN(name, fun, StmtRet)
#define MATCH(name, fun) FUNCTION_GEN(name, fun, PatRet)
#define VM(name, fun)

NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH)
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH, VM)

#undef X
#undef SSECTION
#undef EXPR
#undef STMT
#undef MOD
#undef MATCH
#undef VM

#undef FUNCTION_GEN
};
Expand Down
8 changes: 6 additions & 2 deletions src/plugin/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ struct VisitorPlugin: BaseVisitor<VisitorPlugin, false, VisitorPluginTrait> {
#define STMT(name, fun) TYPE_GEN(name)
#define MOD(name, fun) TYPE_GEN(name)
#define MATCH(name, fun) TYPE_GEN(name)
#define VM(name, fun)

NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH)
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH, VM)

#undef X
#undef SSECTION
#undef EXPR
#undef STMT
#undef MOD
#undef MATCH
#undef VM
#undef TYPE_GEN

virtual ~VisitorPlugin() {}
Expand All @@ -57,15 +59,17 @@ struct VisitorPlugin: BaseVisitor<VisitorPlugin, false, VisitorPluginTrait> {
#define EXPR(name, fun) FUNCTION_GEN(name, fun, ExprRet)
#define STMT(name, fun) FUNCTION_GEN(name, fun, StmtRet)
#define MATCH(name, fun) FUNCTION_GEN(name, fun, PatRet)
#define VM(name, fun)

NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH)
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH, VM)

#undef X
#undef SSECTION
#undef EXPR
#undef STMT
#undef MOD
#undef MATCH
#undef VM

#undef FUNCTION_GEN
};
Expand Down
2 changes: 1 addition & 1 deletion src/sema/native_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void register_native_object(GCObject* root, Bindings& binding, String const& nam
int varid = binding.add(self->name, nullptr, Type_t(), meta::type_id<T*>());

Name* class_t = root->new_object<Name>();
class_t->varid = varid;
//class_t->varid = varid;
class_t->id = identifier;

create_constructor<T, Args...>(root, binding, StringRef("name"));
Expand Down
4 changes: 3 additions & 1 deletion src/tide/ast_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,17 @@ struct ASTRender: public BaseVisitor<ASTRender, false, ASTRenderTrait> {
#define STMT(name, fun) FUNCTION_GEN(name, fun, LY_ReturnType)
#define MOD(name, fun) FUNCTION_GEN(name, fun, LY_ReturnType)
#define MATCH(name, fun) FUNCTION_GEN(name, fun, LY_ReturnType)
#define VM(name, fun)

NODEKIND_ENUM(X, SECTION, EXPR, STMT, MOD, MATCH)
NODEKIND_ENUM(X, SECTION, EXPR, STMT, MOD, MATCH, VM)

#undef X
#undef SECTION
#undef EXPR
#undef STMT
#undef MOD
#undef MATCH
#undef VM

#undef FUNCTION_GEN
};
Expand Down
2 changes: 1 addition & 1 deletion src/tide/ast_render_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,6 @@ void ASTRender::arguments(Arguments& self, int depth) {
}
}

LY_ReturnType ASTRender::condjump(CondJump_t* n, int depth) { return false; }
// LY_ReturnType ASTRender::condjump(CondJump_t* n, int depth) { return false; }

} // namespace lython
8 changes: 6 additions & 2 deletions src/tide/convert/to_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,17 @@ struct ToGraph: public BaseVisitor<ToGraph, false, ToGraphVisitorTrait> {
#define STMT(name, fun) TYPE_GEN(name)
#define MOD(name, fun) TYPE_GEN(name)
#define MATCH(name, fun) TYPE_GEN(name)
#define VM(name, fun)

NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH)
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH, VM)

#undef X
#undef SSECTION
#undef EXPR
#undef STMT
#undef MOD
#undef MATCH
#undef VM
#undef TYPE_GEN

Bindings bindings;
Expand All @@ -122,15 +124,17 @@ struct ToGraph: public BaseVisitor<ToGraph, false, ToGraphVisitorTrait> {
#define EXPR(name, fun) FUNCTION_GEN(name, fun, ExprRet)
#define STMT(name, fun) FUNCTION_GEN(name, fun, StmtRet)
#define MATCH(name, fun) FUNCTION_GEN(name, fun, PatRet)
#define VM(name, fun)

NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH)
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH, VM)

#undef X
#undef SSECTION
#undef EXPR
#undef STMT
#undef MOD
#undef MATCH
#undef VM

#undef FUNCTION_GEN
};
Expand Down
1 change: 1 addition & 0 deletions src/utilities/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct ToPointer {
using type = T*;
};

inline
auto counter() {
int count = 0;
return [count] () mutable {
Expand Down
8 changes: 4 additions & 4 deletions src/utilities/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace lython {
struct has_ ## name <T, decltype(EXPR, void())> : std::true_type {};

#define KW_DEFINE_HAS_METHOD(name, method) \
KW_IS_EXPR_VALID(name, std::declval<T>(). ## method())
KW_IS_EXPR_VALID(name, std::declval<T>().method())


KW_DEFINE_HAS_METHOD(len, __len__)
Expand All @@ -36,7 +36,7 @@ void print(T const& obj, std::ostream& out = std::cout) {
out << obj;
return;
} else {
static_assert(false, "Could not find a convert function");
//static_assert(false, "Could not find a convert function");
obj.print(out);
}
}
Expand All @@ -58,7 +58,7 @@ String str(T const& obj) {
ss << obj;
return ss.str();
} else {
static_assert(false, "Could not find a convert function");
//static_assert(false, "Could not find a convert function");
}
}

Expand Down Expand Up @@ -98,7 +98,7 @@ int len(T const& val) {
} else if constexpr (has_size<T const&>::value) {
return IndexType(val.size());
} else {
static_assert(false, "Object does not provide len method");
//static_assert(false, "Object does not provide len method");
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/cases.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH, VM)
#undef STMT
#undef MOD
#undef MATCH
#undef VM

#undef GENTEST

Expand Down
4 changes: 3 additions & 1 deletion tests/cases_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ namespace lython {
#define STMT(name, _) GENCASES(name)
#define MOD(name, _)
#define MATCH(name, _)
#define VM(n, m)

NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH)
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH, VM)

#undef X
#undef SSECTION
#undef EXPR
#undef STMT
#undef MOD
#undef MATCH
#undef VM

#undef GENTEST
}
4 changes: 3 additions & 1 deletion tests/equality_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ void run_testcase(String const& name, Array<TestCase> cases) {
#define STMT(name, _) GENTEST(name)
#define MOD(name, _)
#define MATCH(name, _)
#define VM(n, m)

NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH)
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH, VM)

#undef X
#undef SSECTION
#undef EXPR
#undef STMT
#undef MOD
#undef MATCH
#undef VM

#undef GENTEST
4 changes: 3 additions & 1 deletion tests/llvm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,17 @@ void run_testcases(String const& name, Array<VMTestCase> const& cases) {
#define STMT(name, _) GENTEST(name)
#define MOD(name, _)
#define MATCH(name, _)
#define VM(n, m)

NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH)
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH, VM)

#undef X
#undef SSECTION
#undef EXPR
#undef STMT
#undef MOD
#undef MATCH
#undef VM

#undef GENTEST
#endif
9 changes: 5 additions & 4 deletions tests/meta_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <catch2/catch_all.hpp>

using namespace lython;

struct NewPoint {
float x = 3;
int y = 3;
Expand Down Expand Up @@ -113,10 +115,10 @@ TEST_CASE("ArrowBuilder") {

TEST_CASE("Debug Print") {

print(std::cout, std::tuple<std::string, int>{"k1", 1});
print(std::tuple<std::string, int>{"k1", 1});
std::cout << "\n";

print(std::cout,
print(
std::vector<std::string>{
"k1",
"k2",
Expand All @@ -126,8 +128,7 @@ TEST_CASE("Debug Print") {
});
std::cout << "\n";

print(std::cout,
std::unordered_map<std::string, int>{
print(std::unordered_map<std::string, int>{
{"k1", 1},
{"k2", 2},
{"k3", 3},
Expand Down
4 changes: 3 additions & 1 deletion tests/parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,16 @@ void run_testcase(String const& name,
#define STMT(name, _) GENTEST(name)
#define MOD(name, _)
#define MATCH(name, _)
#define VM(n, m)

NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH)
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH, VM)

#undef X
#undef SSECTION
#undef EXPR
#undef STMT
#undef MOD
#undef MATCH
#undef VM

#undef GENTEST
4 changes: 3 additions & 1 deletion tests/sema_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,16 @@ TEST_CASE("Class_Attribute_Lookup") {
#define STMT(name, _) GENTEST(name)
#define MOD(name, _)
#define MATCH(name, _)
#define VM(n, m)

NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH)
NODEKIND_ENUM(X, SSECTION, EXPR, STMT, MOD, MATCH, VM)

#undef X
#undef SSECTION
#undef EXPR
#undef STMT
#undef MOD
#undef MATCH
#undef VM

#undef GENTEST

0 comments on commit 193cd9c

Please sign in to comment.