|
@@ -14,11 +14,16 @@ sem::NativeScope qlow::sem::generateNativeScope(void)
|
|
|
NativeScope scope;
|
|
|
|
|
|
std::map<std::string, NativeType::Type> natives = {
|
|
|
- { "Integer", NativeType::INTEGER },
|
|
|
{ "Boolean", NativeType::BOOLEAN },
|
|
|
{ "Char", NativeType::CHAR },
|
|
|
{ "String", NativeType::STRING },
|
|
|
|
|
|
+ { "Float32", NativeType::FLOAT32 },
|
|
|
+ { "Float64", NativeType::FLOAT64 },
|
|
|
+ };
|
|
|
+
|
|
|
+ std::map<std::string, NativeType::Type> integers = {
|
|
|
+ { "Integer", NativeType::INTEGER },
|
|
|
{ "Int8", NativeType::INT8 },
|
|
|
{ "Int16", NativeType::INT16 },
|
|
|
{ "Int32", NativeType::INT32 },
|
|
@@ -30,9 +35,6 @@ sem::NativeScope qlow::sem::generateNativeScope(void)
|
|
|
{ "UInt32", NativeType::UINT32 },
|
|
|
{ "UInt64", NativeType::UINT64 },
|
|
|
{ "UInt128", NativeType::UINT128 },
|
|
|
-
|
|
|
- { "Float32", NativeType::FLOAT32 },
|
|
|
- { "Float64", NativeType::FLOAT64 },
|
|
|
};
|
|
|
|
|
|
for (auto [name, type] : natives) {
|
|
@@ -40,10 +42,46 @@ sem::NativeScope qlow::sem::generateNativeScope(void)
|
|
|
<std::shared_ptr<NativeType>>(std::make_shared<NativeType>(type)) });
|
|
|
}
|
|
|
|
|
|
+ for (auto [name, type] : integers) {
|
|
|
+ auto native = std::make_shared<NativeType>(type);
|
|
|
+
|
|
|
+ native->nativeMethods.insert(
|
|
|
+ { "+",
|
|
|
+ std::make_unique<BinaryNativeMethod>( native, native,
|
|
|
+ [] (llvm::IRBuilder<>& builder, llvm::Value* a, llvm::Value* b) {
|
|
|
+ return builder.CreateAdd(a, b);
|
|
|
+ })
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ scope.types.insert({ name, std::make_unique
|
|
|
+ <std::shared_ptr<NativeType>>(std::move(native)) });
|
|
|
+ }
|
|
|
+
|
|
|
return scope;
|
|
|
}
|
|
|
|
|
|
|
|
|
+llvm::Value* qlow::sem::UnaryNativeMethod::generateCode(llvm::IRBuilder<>& builder,
|
|
|
+ std::vector<llvm::Value*> arguments)
|
|
|
+{
|
|
|
+ if (arguments.size() != 1)
|
|
|
+ throw "invalid unary operation";
|
|
|
+ return generator(builder, arguments[0]);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+llvm::Value* qlow::sem::BinaryNativeMethod::generateCode(llvm::IRBuilder<>& builder,
|
|
|
+ std::vector<llvm::Value*> arguments)
|
|
|
+{
|
|
|
+ if (arguments.size() != 2)
|
|
|
+ throw "invalid binary operation";
|
|
|
+ return generator(builder, arguments[0], arguments[1]);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|