diff --git a/.gitignore b/.gitignore index 9081efc..5eb14db 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ target/ scripts/.coursier scripts/.scalafmt-* /scala-native-bindgen-* + +.vscode/ +metals.sbt diff --git a/.scalafmt.conf b/.scalafmt.conf index 47157f6..fe597ce 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,3 +1,4 @@ +version = 1.5.1 style = defaultWithAlign docstrings = JavaDoc assumeStandardLibraryStripMargin = true @@ -8,4 +9,4 @@ project.excludeFilters = [ "tests/samples/[^/]*[.]scala" ] project.git = true -runner.dialect = Scala211 +runner.dialect = scala211 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 128ff49..5df5691 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,6 +11,12 @@ Important to note is that all contributors must have signed the [Scala CLA]. ## Developer Workflow +Install the following for macOS: +```sh +brew tap nlohmann/json +brew install nlohmann-json +``` + Build the `scalaBindgen` tool: ```sh diff --git a/bindgen/CMakeLists.txt b/bindgen/CMakeLists.txt index b72510d..9c7e802 100644 --- a/bindgen/CMakeLists.txt +++ b/bindgen/CMakeLists.txt @@ -3,6 +3,8 @@ project(scala-native-bindgen) option(STATIC_LINKING "Statically link the executable" OFF) +find_package(nlohmann_json REQUIRED) + # Locate LLVMConfig.cmake find_package(LLVM REQUIRED CONFIG) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") @@ -106,6 +108,7 @@ set_target_properties(bindgen target_link_libraries(bindgen PRIVATE + nlohmann_json clangFrontend clangTooling clangSerialization diff --git a/bindgen/TypeTranslator.cpp b/bindgen/TypeTranslator.cpp index 553e39a..3a03709 100644 --- a/bindgen/TypeTranslator.cpp +++ b/bindgen/TypeTranslator.cpp @@ -8,29 +8,29 @@ TypeTranslator::TypeTranslator(clang::ASTContext *ctx_, IR &ir) // Native Types typeMap["void"] = "Unit"; - typeMap["bool"] = "native.CBool"; - typeMap["_Bool"] = "native.CBool"; - typeMap["char"] = "native.CChar"; - typeMap["signed char"] = "native.CSignedChar"; - typeMap["unsigned char"] = "native.CUnsignedChar"; - typeMap["short"] = "native.CShort"; - typeMap["unsigned short"] = "native.CUnsignedShort"; - typeMap["int"] = "native.CInt"; - typeMap["long int"] = "native.CLongInt"; - typeMap["unsigned int"] = "native.CUnsignedInt"; - typeMap["unsigned long int"] = "native.CUnsignedLongInt"; - typeMap["long"] = "native.CLong"; - typeMap["unsigned long"] = "native.CUnsignedLong"; - typeMap["long long"] = "native.CLongLong"; - typeMap["unsigned long long"] = "native.CUnsignedLongLong"; - typeMap["size_t"] = "native.CSize"; - typeMap["ptrdiff_t"] = "native.CPtrDiff"; - typeMap["wchar_t"] = "native.CWideChar"; - typeMap["char16_t"] = "native.CChar16"; - typeMap["char32_t"] = "native.CChar32"; - typeMap["float"] = "native.CFloat"; - typeMap["double"] = "native.CDouble"; - typeMap["long double"] = "native.CDouble"; + typeMap["bool"] = "CBool"; + typeMap["_Bool"] = "CBool"; + typeMap["char"] = "CChar"; + typeMap["signed char"] = "CSignedChar"; + typeMap["unsigned char"] = "CUnsignedChar"; + typeMap["short"] = "CShort"; + typeMap["unsigned short"] = "CUnsignedShort"; + typeMap["int"] = "CInt"; + typeMap["long int"] = "CLongInt"; + typeMap["unsigned int"] = "CUnsignedInt"; + typeMap["unsigned long int"] = "CUnsignedLongInt"; + typeMap["long"] = "CLong"; + typeMap["unsigned long"] = "CUnsignedLong"; + typeMap["long long"] = "CLongLong"; + typeMap["unsigned long long"] = "CUnsignedLongLong"; + typeMap["size_t"] = "CSize"; + typeMap["ptrdiff_t"] = "CPtrDiff"; + typeMap["wchar_t"] = "CWideChar"; + typeMap["char16_t"] = "CChar16"; + typeMap["char32_t"] = "CChar32"; + typeMap["float"] = "CFloat"; + typeMap["double"] = "CDouble"; + typeMap["long double"] = "CDouble"; } std::shared_ptr @@ -73,8 +73,8 @@ TypeTranslator::translatePointer(const clang::QualType &pte) { // Take care of char* if (as->getKind() == clang::BuiltinType::Char_S || as->getKind() == clang::BuiltinType::SChar) { - // TODO: new PointerType(new PrimitiveType("native.CChar")) - return std::make_shared("native.CString"); + // TODO: new PointerType(new PrimitiveType("CChar")) + return std::make_shared("CString"); } } diff --git a/bindgen/Utils.h b/bindgen/Utils.h index 7ba919c..d4bf259 100644 --- a/bindgen/Utils.h +++ b/bindgen/Utils.h @@ -1,25 +1,31 @@ #ifndef UTILS_H #define UTILS_H +#include #include "ir/TypeDef.h" #include "ir/types/Type.h" #include -inline std::string uint64ToScalaNat(uint64_t v, std::string accumulator = "") { +inline std::string uint64ToScalaNat(uint64_t v, std::string acc = "") { if (v == 0) - return accumulator; + return acc; - auto last_digit = v % 10; - auto rest = v / 10; + auto v_str = std::to_string(v); + auto len = v_str.length(); - if (accumulator.empty()) { - return uint64ToScalaNat(rest, - "native.Nat._" + std::to_string(last_digit)); + if (len == 1) { + acc = acc + "Nat._" + v_str; } else { - return uint64ToScalaNat(rest, "native.Nat.Digit[native.Nat._" + - std::to_string(last_digit) + ", " + - accumulator + "]"); + for (char const &c: v_str) { + if (acc.empty()) { + acc = acc + "Nat.Digit" + std::to_string(len) + "[Nat._" + c; + } else { + acc = acc + ", Nat._" + c; + } + } + acc = acc + "]"; } + return acc; } static std::array reserved_words = { diff --git a/bindgen/defines/DefineFinder.cpp b/bindgen/defines/DefineFinder.cpp index 51db8cb..d104d9d 100644 --- a/bindgen/defines/DefineFinder.cpp +++ b/bindgen/defines/DefineFinder.cpp @@ -48,7 +48,7 @@ void DefineFinder::MacroDefined(const clang::Token ¯oNameTok, stringToken.getLength()); ir.addLiteralDefine( macroName, "c" + literal, - std::make_shared("native.CString")); + std::make_shared("CString")); } else if (tokens->size() == 1 && (*tokens)[0].getKind() == clang::tok::identifier) { // token might be a variable @@ -126,7 +126,7 @@ void DefineFinder::addNumericConstantDefine(const std::string ¯oName, if (parser.isLongLong) { /* literal has `LL` ending. `long long` is represented as `Long` * in Scala Native */ - type = "native.CLongLong"; + type = "CLongLong"; /* must fit into Scala integer type */ if (!integerFitsIntoType(parser, positive)) { @@ -134,7 +134,7 @@ void DefineFinder::addNumericConstantDefine(const std::string ¯oName, } } else if (parser.isLong) { /* literal has `L` ending */ - type = "native.CLong"; + type = "CLong"; /* must fit into Scala integer type */ if (!integerFitsIntoType(parser, positive)) { @@ -146,13 +146,13 @@ void DefineFinder::addNumericConstantDefine(const std::string ¯oName, if (!type.empty()) { scalaLiteral = getDecimalLiteral(parser); - if (type == "native.CLong" || type == "native.CLongLong") { + if (type == "CLong" || type == "CLongLong") { scalaLiteral = scalaLiteral + "L"; } } } else if (parser.isFloatingLiteral()) { if (fitsIntoDouble(parser)) { - type = "native.CDouble"; + type = "CDouble"; scalaLiteral = getDoubleLiteral(parser); } } @@ -172,9 +172,9 @@ DefineFinder::getTypeOfIntegerLiteral(const clang::NumericLiteralParser &parser, bool positive) { if (integerFitsIntoType(parser, positive)) { - return "native.CInt"; + return "CInt"; } else if (integerFitsIntoType(parser, positive)) { - return "native.CLong"; + return "CLong"; } else { llvm::errs() << "Warning: integer value does not fit into 8 bytes: " << literal << "\n"; diff --git a/bindgen/ir/Enum.cpp b/bindgen/ir/Enum.cpp index 80116f2..6ba842d 100644 --- a/bindgen/ir/Enum.cpp +++ b/bindgen/ir/Enum.cpp @@ -1,4 +1,5 @@ #include "Enum.h" +#include Enumerator::Enumerator(std::string name, int64_t value) : name(std::move(name)), value(value) {} @@ -29,11 +30,11 @@ std::string Enum::getEnumerators() const { std::string Enum::getTypeCastSuffix() const { std::string primitiveType = PrimitiveType::getType(); - if (primitiveType == "native.CLong") { + if (primitiveType == "CLong") { return "L"; - } else if (primitiveType == "native.CUnsignedInt") { + } else if (primitiveType == "CUnsignedInt") { return ".toUInt"; - } else if (primitiveType == "native.CUnsignedLong") { + } else if (primitiveType == "CUnsignedLong") { return "L.toULong"; } return ""; diff --git a/bindgen/ir/Function.cpp b/bindgen/ir/Function.cpp index ace1235..a298d9b 100644 --- a/bindgen/ir/Function.cpp +++ b/bindgen/ir/Function.cpp @@ -17,7 +17,7 @@ std::string Function::getDefinition(const LocationManager &locationManager) const { std::stringstream s; if (scalaName != name) { - s << " @native.link(\"" << name << "\")\n"; + s << " @link(\"" << name << "\")\n"; } s << " def " << handleReservedWords(scalaName) << "("; std::string sep = ""; @@ -29,9 +29,9 @@ Function::getDefinition(const LocationManager &locationManager) const { if (isVariadic) { /* the C Iso require at least one argument in a variadic function, so * the comma is fine */ - s << ", " << getVarargsParameterName() << ": native.CVararg*"; + s << ", " << getVarargsParameterName() << ": CVarArg*"; } - s << "): " << retType->str(locationManager) << " = native.extern\n"; + s << "): " << retType->str(locationManager) << " = extern\n"; return s.str(); } diff --git a/bindgen/ir/IR.cpp b/bindgen/ir/IR.cpp index fd5dd2b..462d623 100644 --- a/bindgen/ir/IR.cpp +++ b/bindgen/ir/IR.cpp @@ -1,5 +1,6 @@ #include "IR.h" #include "../Utils.h" +#include IR::IR(std::string libName, std::string linkName, std::string objectName, std::string packageName, const LocationManager &locationManager) @@ -102,15 +103,15 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) { return s; } - s << "import scala.scalanative._\n" - << "import scala.scalanative.native._\n\n"; + s << "import scala.scalanative.unsigned._\n" + << "import scala.scalanative.unsafe._\n\n"; if (!ir.functions.empty() || !ir.varDefines.empty() || !ir.variables.empty()) { if (!ir.linkName.empty()) { - s << "@native.link(\"" << ir.linkName << "\")\n"; + s << "@link(\"" << ir.linkName << "\")\n"; } - s << "@native.extern\n"; + s << "@extern\n"; } s << "object " << handleReservedWords(ir.objectName) << " {\n"; diff --git a/bindgen/ir/IR.h b/bindgen/ir/IR.h index 29b8b4d..85be95f 100644 --- a/bindgen/ir/IR.h +++ b/bindgen/ir/IR.h @@ -89,14 +89,14 @@ class IR { * * Example: * @code - * type __int32_t = native.CInt + * type __int32_t = CInt * type __darwin_pid_t = __int32_t * type pid_t = __darwin_pid_t * @endcode * * Becomes: * @code - * type pid_t = native.CInt + * type pid_t = CInt * @endcode * */ diff --git a/bindgen/ir/LocationManager.cpp b/bindgen/ir/LocationManager.cpp index dcd5af3..2c6fc92 100644 --- a/bindgen/ir/LocationManager.cpp +++ b/bindgen/ir/LocationManager.cpp @@ -4,6 +4,7 @@ #include "Struct.h" #include #include +#include LocationManager::LocationManager(std::string mainHeaderPath) : mainHeaderPath(std::move(mainHeaderPath)) {} diff --git a/bindgen/ir/Struct.cpp b/bindgen/ir/Struct.cpp index 5d1bd46..aac7e64 100644 --- a/bindgen/ir/Struct.cpp +++ b/bindgen/ir/Struct.cpp @@ -34,7 +34,7 @@ Struct::generateHelperClass(const LocationManager &locationManager) const { assert(hasHelperMethods()); std::stringstream s; std::string type = replaceChar(getTypeName(), " ", "_"); - s << " implicit class " << type << "_ops(val p: native.Ptr[" << type + s << " implicit class " << type << "_ops(val p: Ptr[" << type << "])" << " extends AnyVal {\n"; if (isRepresentedAsStruct()) { @@ -89,7 +89,7 @@ std::string Struct::getTypeName() const { return "struct " + name; } std::string Struct::str(const LocationManager &locationManager) const { std::stringstream ss; - ss << "native.CStruct" << std::to_string(fields.size()) << "["; + ss << "CStruct" << std::to_string(fields.size()) << "["; std::string sep = ""; for (const auto &field : fields) { @@ -136,12 +136,12 @@ std::string Struct::generateSetterForStructRepresentation( /* field type is changed to avoid cyclic types in generated code */ std::shared_ptr typeReplacement = getTypeReplacement( field->getType(), structTypesThatShouldBeReplaced); - value = value + ".cast[" + typeReplacement->str(locationManager) + "]"; + value = value + ".asInstanceOf[" + typeReplacement->str(locationManager) + "]"; } else if (isArrayOrRecord(field->getType())) { - value = "!" + value; + //value = "!" + value; } std::stringstream s; - s << " def " << setter << "(value: " + parameterType + "): Unit = !p._" + s << " def " << setter << "(value: " + parameterType + "): Unit = p._" << std::to_string(fieldIndex + 1) << " = " << value << "\n"; return s.str(); } @@ -154,10 +154,10 @@ std::string Struct::generateGetterForStructRepresentation( wrapArrayOrRecordInPointer(field->getType())->str(locationManager); std::string methodBody = "p._" + std::to_string(fieldIndex + 1); if (!isArrayOrRecord(field->getType())) { - methodBody = "!" + methodBody; + // methodBody = "!" + methodBody; if (!shouldFieldBreakCycle(field).empty()) { /* field type is changed to avoid cyclic types in generated code */ - methodBody = "(" + methodBody + ").cast[" + + methodBody = methodBody + ".asInstanceOf[" + field->getType()->str(locationManager) + "]"; } } @@ -186,7 +186,7 @@ std::string Struct::generateSetterForArrayRepresentation( castedField = "(" + castedField + " + " + std::to_string(offsetInBytes) + ")"; } - castedField = "!" + castedField + ".cast[" + + castedField = "!" + castedField + ".asInstanceOf[" + pointerToFieldType.str(locationManager) + "]"; std::vector> structTypesThatShouldBeReplaced = shouldFieldBreakCycle(field); @@ -194,9 +194,9 @@ std::string Struct::generateSetterForArrayRepresentation( /* field type is changed to avoid cyclic types in generated code */ std::shared_ptr typeReplacement = getTypeReplacement( field->getType(), structTypesThatShouldBeReplaced); - value = value + ".cast[" + typeReplacement->str(locationManager) + "]"; + value = value + ".asInstanceOf[" + typeReplacement->str(locationManager) + "]"; } else if (isArrayOrRecord(field->getType())) { - value = "!" + value; + //value = "!" + value; } std::stringstream s; s << " def " << setter @@ -221,13 +221,13 @@ std::string Struct::generateGetterForArrayRepresentation( methodBody = "p._1"; } methodBody = - methodBody + ".cast[" + pointerToFieldType.str(locationManager) + "]"; + methodBody + ".asInstanceOf[" + pointerToFieldType.str(locationManager) + "]"; if (!isArrayOrRecord(field->getType())) { - methodBody = "!" + methodBody; + //methodBody = "!" + methodBody; if (!shouldFieldBreakCycle(field).empty()) { /* field type is changed to avoid cyclic types in generated code */ - methodBody = "(" + methodBody + ").cast[" + + methodBody = "(" + methodBody + ").asInstanceOf[" + field->getType()->str(locationManager) + "]"; } } @@ -262,7 +262,7 @@ Struct::getTypeReplacement(std::shared_ptr type, * value type */ replacementType = replacementType->replaceType( recordTypeDef, - std::make_shared("native.CStruct0")); + std::make_shared("CStruct0")); } } return replacementType; @@ -350,8 +350,8 @@ Struct::getConstructorHelper(const LocationManager &locationManager) const { << " import implicits._\n"; /* constructor with no parameters */ - s << " def apply()(implicit z: native.Zone): native.Ptr[" + type + "]" - << " = native.alloc[" + type + "]\n"; + s << " def apply()(implicit z: Zone): Ptr[" + type + "]" + << " = alloc[" + type + "]\n"; /* constructor that initializes all fields */ s << " def apply("; @@ -361,8 +361,8 @@ Struct::getConstructorHelper(const LocationManager &locationManager) const { << wrapArrayOrRecordInPointer(field->getType())->str(locationManager); sep = ", "; } - s << ")(implicit z: native.Zone): native.Ptr[" << type << "] = {\n" - << " val ptr = native.alloc[" << type << "]\n"; + s << ")(implicit z: Zone): Ptr[" << type << "] = {\n" + << " val ptr = alloc[" << type << "]\n"; for (const auto &field : fields) { std::string name = handleReservedWords(field->getName()); s << " ptr." << name << " = " << name << "\n"; diff --git a/bindgen/ir/TypeDef.cpp b/bindgen/ir/TypeDef.cpp index 5a40266..d27c0fd 100644 --- a/bindgen/ir/TypeDef.cpp +++ b/bindgen/ir/TypeDef.cpp @@ -17,7 +17,7 @@ TypeDef::getDefinition(const LocationManager &locationManager) const { if (type) { s << type->str(locationManager); } else { - s << "native.CStruct0 // incomplete type"; + s << "CStruct0 // incomplete type"; } s << "\n"; return s.str(); diff --git a/bindgen/ir/Union.cpp b/bindgen/ir/Union.cpp index 855dee9..11d1951 100644 --- a/bindgen/ir/Union.cpp +++ b/bindgen/ir/Union.cpp @@ -23,7 +23,7 @@ Union::generateHelperClass(const LocationManager &locationManager) const { std::stringstream s; std::string type = replaceChar(getTypeName(), " ", "_"); s << " implicit class " << type << "_pos" - << "(val p: native.Ptr[" << type << "]) extends AnyVal {\n"; + << "(val p: Ptr[" << type << "]) extends AnyVal {\n"; for (const auto &field : fields) { if (!field->getName().empty()) { s << generateGetter(field, locationManager); @@ -71,8 +71,8 @@ Union::generateGetter(const std::shared_ptr &field, const LocationManager &locationManager) const { std::string getter = handleReservedWords(field->getName()); std::string ftype = field->getType()->str(locationManager); - return " def " + getter + ": native.Ptr[" + ftype + - "] = p.cast[native.Ptr[" + ftype + "]]\n"; + return " def " + getter + ": Ptr[" + ftype + + "] = p.asInstanceOf[Ptr[" + ftype + "]]\n"; } std::string @@ -82,9 +82,9 @@ Union::generateSetter(const std::shared_ptr &field, std::string ftype = field->getType()->str(locationManager); if (isAliasForType(field->getType().get()) || isAliasForType(field->getType().get())) { - return " def " + setter + "(value: native.Ptr[" + ftype + - "]): Unit = !p.cast[native.Ptr[" + ftype + "]] = !value\n"; + return " def " + setter + "(value: Ptr[" + ftype + + "]): Unit = !p.asInstanceOf[Ptr[" + ftype + "]] = value\n"; } return " def " + setter + "(value: " + ftype + - "): Unit = !p.cast[native.Ptr[" + ftype + "]] = value\n"; + "): Unit = !p.asInstanceOf[Ptr[" + ftype + "]] = value\n"; } diff --git a/bindgen/ir/VarDefine.cpp b/bindgen/ir/VarDefine.cpp index 3c6a5a0..69fb86f 100644 --- a/bindgen/ir/VarDefine.cpp +++ b/bindgen/ir/VarDefine.cpp @@ -7,7 +7,7 @@ std::string VarDefine::getDefinition(const LocationManager &locationManager) const { return " @name(\"" + variable->getName() + "\")\n" + " val " + name + ": " + variable->getType()->str(locationManager) + - " = native.extern\n"; + " = extern\n"; } bool VarDefine::hasIllegalUsageOfOpaqueType() const { diff --git a/bindgen/ir/Variable.cpp b/bindgen/ir/Variable.cpp index 1dc2c95..14b4cb1 100644 --- a/bindgen/ir/Variable.cpp +++ b/bindgen/ir/Variable.cpp @@ -7,7 +7,7 @@ Variable::Variable(const std::string &name, std::shared_ptr type) std::string Variable::getDefinition(const LocationManager &locationManager) const { return " val " + name + ": " + type->str(locationManager) + - " = native.extern\n"; + " = extern\n"; } bool Variable::hasIllegalUsageOfOpaqueType() const { diff --git a/bindgen/ir/types/ArrayType.cpp b/bindgen/ir/types/ArrayType.cpp index 0fb27dd..83c7111 100644 --- a/bindgen/ir/types/ArrayType.cpp +++ b/bindgen/ir/types/ArrayType.cpp @@ -6,7 +6,7 @@ ArrayType::ArrayType(std::shared_ptr elementsType, uint64_t size) : size(size), elementsType(std::move(elementsType)) {} std::string ArrayType::str(const LocationManager &locationManager) const { - return "native.CArray[" + elementsType->str(locationManager) + ", " + + return "CArray[" + elementsType->str(locationManager) + ", " + uint64ToScalaNat(size) + "]"; } diff --git a/bindgen/ir/types/FunctionPointerType.cpp b/bindgen/ir/types/FunctionPointerType.cpp index c5c7d5e..519bfbb 100644 --- a/bindgen/ir/types/FunctionPointerType.cpp +++ b/bindgen/ir/types/FunctionPointerType.cpp @@ -11,14 +11,14 @@ FunctionPointerType::FunctionPointerType( std::string FunctionPointerType::str(const LocationManager &locationManager) const { std::stringstream ss; - ss << "native.CFunctionPtr" << parametersTypes.size() << "["; + ss << "CFuncPtr" << parametersTypes.size() << "["; for (const auto ¶meterType : parametersTypes) { ss << parameterType->str(locationManager) << ", "; } if (isVariadic) { - ss << "native.CVararg, "; + ss << "CVarArg, "; } ss << returnType->str(locationManager) << "]"; return ss.str(); diff --git a/bindgen/ir/types/PointerType.cpp b/bindgen/ir/types/PointerType.cpp index e93d7ca..ec07791 100644 --- a/bindgen/ir/types/PointerType.cpp +++ b/bindgen/ir/types/PointerType.cpp @@ -5,7 +5,7 @@ PointerType::PointerType(std::shared_ptr type) : type(std::move(type)) {} std::string PointerType::str(const LocationManager &locationManager) const { - return "native.Ptr[" + type->str(locationManager) + "]"; + return "Ptr[" + type->str(locationManager) + "]"; } bool PointerType::usesType( diff --git a/bindgen/ir/types/PrimitiveType.h b/bindgen/ir/types/PrimitiveType.h index 83c91b3..25480c1 100644 --- a/bindgen/ir/types/PrimitiveType.h +++ b/bindgen/ir/types/PrimitiveType.h @@ -5,7 +5,7 @@ #include /** - * For example native.CInt + * For example CInt */ class PrimitiveType : virtual public Type { public: diff --git a/bindings/iconv/src/main/scala/org/scalanative/bindings/iconv.scala b/bindings/iconv/src/main/scala/org/scalanative/bindings/iconv.scala index 605462f..a74acfd 100644 --- a/bindings/iconv/src/main/scala/org/scalanative/bindings/iconv.scala +++ b/bindings/iconv/src/main/scala/org/scalanative/bindings/iconv.scala @@ -1,16 +1,16 @@ package org.scalanative.bindings -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.extern +@extern object iconv { - type iconv_t = native.Ptr[Byte] - def iconv_open(__tocode: native.CString, __fromcode: native.CString): native.Ptr[Byte] = native.extern - def iconv(__cd: native.Ptr[Byte], __inbuf: native.Ptr[native.CString], __inbytesleft: native.Ptr[native.CSize], __outbuf: native.Ptr[native.CString], __outbytesleft: native.Ptr[native.CSize]): native.CSize = native.extern - def iconv_close(__cd: native.Ptr[Byte]): native.CInt = native.extern + type iconv_t = Ptr[Byte] + def iconv_open(__tocode: CString, __fromcode: CString): Ptr[Byte] = extern + def iconv(__cd: Ptr[Byte], __inbuf: Ptr[CString], __inbytesleft: Ptr[CSize], __outbuf: Ptr[CString], __outbytesleft: Ptr[CSize]): CSize = extern + def iconv_close(__cd: Ptr[Byte]): CInt = extern object defines { - val _ICONV_H: native.CInt = 1 + val _ICONV_H: CInt = 1 } } diff --git a/bindings/iconv/src/test/scala/org/scalanative/bindings/tests/IconvSpec.scala b/bindings/iconv/src/test/scala/org/scalanative/bindings/tests/IconvSpec.scala index d13a5f4..7d9d2f8 100644 --- a/bindings/iconv/src/test/scala/org/scalanative/bindings/tests/IconvSpec.scala +++ b/bindings/iconv/src/test/scala/org/scalanative/bindings/tests/IconvSpec.scala @@ -1,13 +1,15 @@ package org.scalanative.bindings.tests -import org.scalatest.FunSpec +import org.scalatest.funspec.AnyFunSpec -class IconvSpec extends FunSpec { +class IconvSpec extends AnyFunSpec { describe("iconv") { it("should convert back and forth between UTF-8 and ISO-8859-1") { //#usage-example import org.scalanative.bindings.iconv._ - import scala.scalanative.native._ + import scala.scalanative.unsafe._ + import scala.scalanative.unsigned._ + import scala.scalanative.libc._ import java.nio.charset.Charset val UTF8 = Charset.forName("UTF-8") @@ -28,7 +30,7 @@ class IconvSpec extends FunSpec { val translatedBufPtr = alloc[CString] !translatedBufPtr = translatedBuf val translatedBytesLeft = alloc[CSize] - !translatedBytesLeft = 32 + !translatedBytesLeft = 32.toULong val translatedCode = iconv( encode, @@ -48,7 +50,7 @@ class IconvSpec extends FunSpec { val roundtripBufPtr = alloc[CString] !roundtripBufPtr = roundtripBuf val roundtripBytesLeft = alloc[CSize] - !roundtripBytesLeft = 32 + !roundtripBytesLeft = 32.toULong val roundtripCode = iconv( decode, diff --git a/bindings/posix/src/main/scala/org/scalanative/bindings/posix/fnmatch.scala b/bindings/posix/src/main/scala/org/scalanative/bindings/posix/fnmatch.scala index 7311a57..b1485e6 100644 --- a/bindings/posix/src/main/scala/org/scalanative/bindings/posix/fnmatch.scala +++ b/bindings/posix/src/main/scala/org/scalanative/bindings/posix/fnmatch.scala @@ -1,14 +1,14 @@ package org.scalanative.bindings.posix -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.extern +@extern object fnmatch { - def fnmatch(__pattern: native.CString, __name: native.CString, __flags: native.CInt): native.CInt = native.extern + def fnmatch(__pattern: CString, __name: CString, __flags: CInt): CInt = extern object defines { - val _FNMATCH_H: native.CInt = 1 - val FNM_NOMATCH: native.CInt = 1 + val _FNMATCH_H: CInt = 1 + val FNM_NOMATCH: CInt = 1 } } diff --git a/bindings/posix/src/main/scala/org/scalanative/bindings/posix/regex.scala b/bindings/posix/src/main/scala/org/scalanative/bindings/posix/regex.scala index 90282e8..b4952c5 100644 --- a/bindings/posix/src/main/scala/org/scalanative/bindings/posix/regex.scala +++ b/bindings/posix/src/main/scala/org/scalanative/bindings/posix/regex.scala @@ -1,11 +1,11 @@ package org.scalanative.bindings.posix -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.extern +@extern object regex { - type enum_reg_errcode_t = native.CUnsignedInt + type enum_reg_errcode_t = CUnsignedInt object enum_reg_errcode_t { final val REG_NOERROR: enum_reg_errcode_t = 0.toUInt final val REG_NOMATCH: enum_reg_errcode_t = 1.toUInt @@ -26,41 +26,41 @@ object regex { final val REG_ERPAREN: enum_reg_errcode_t = 16.toUInt } - type s_reg_t = native.CLong - type active_reg_t = native.CUnsignedLong - type reg_syntax_t = native.CUnsignedLong + type s_reg_t = CLong + type active_reg_t = CUnsignedLong + type reg_syntax_t = CUnsignedLong type reg_errcode_t = enum_reg_errcode_t - type struct_re_pattern_buffer = native.CArray[Byte, native.Nat.Digit[native.Nat._6, native.Nat._4]] + type struct_re_pattern_buffer = CArray[Byte, Nat.Digit2[Nat._6, Nat._4]] type regex_t = struct_re_pattern_buffer - type regoff_t = native.CInt - type struct_regmatch_t = native.CStruct2[regoff_t, regoff_t] + type regoff_t = CInt + type struct_regmatch_t = CStruct2[regoff_t, regoff_t] type regmatch_t = struct_regmatch_t - val re_syntax_options: reg_syntax_t = native.extern - def regcomp(__preg: native.Ptr[regex_t], __pattern: native.CString, __cflags: native.CInt): native.CInt = native.extern - def regexec(__preg: native.Ptr[regex_t], __string: native.CString, __nmatch: native.CSize, __pmatch: native.Ptr[regmatch_t], __eflags: native.CInt): native.CInt = native.extern - def regerror(__errcode: native.CInt, __preg: native.Ptr[regex_t], __errbuf: native.CString, __errbuf_size: native.CSize): native.CSize = native.extern - def regfree(__preg: native.Ptr[regex_t]): Unit = native.extern + val re_syntax_options: reg_syntax_t = extern + def regcomp(__preg: Ptr[regex_t], __pattern: CString, __cflags: CInt): CInt = extern + def regexec(__preg: Ptr[regex_t], __string: CString, __nmatch: CSize, __pmatch: Ptr[regmatch_t], __eflags: CInt): CInt = extern + def regerror(__errcode: CInt, __preg: Ptr[regex_t], __errbuf: CString, __errbuf_size: CSize): CSize = extern + def regfree(__preg: Ptr[regex_t]): Unit = extern object defines { - val _REGEX_H: native.CInt = 1 - val REG_EXTENDED: native.CInt = 1 - val REG_NOTBOL: native.CInt = 1 + val _REGEX_H: CInt = 1 + val REG_EXTENDED: CInt = 1 + val REG_NOTBOL: CInt = 1 } object implicits { - implicit class struct_regmatch_t_ops(val p: native.Ptr[struct_regmatch_t]) extends AnyVal { - def rm_so: regoff_t = !p._1 - def rm_so_=(value: regoff_t): Unit = !p._1 = value - def rm_eo: regoff_t = !p._2 - def rm_eo_=(value: regoff_t): Unit = !p._2 = value + implicit class struct_regmatch_t_ops(val p: Ptr[struct_regmatch_t]) extends AnyVal { + def rm_so: regoff_t = p._1 + def rm_so_=(value: regoff_t): Unit = p._1 = value + def rm_eo: regoff_t = p._2 + def rm_eo_=(value: regoff_t): Unit = p._2 = value } } object struct_regmatch_t { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_regmatch_t] = native.alloc[struct_regmatch_t] - def apply(rm_so: regoff_t, rm_eo: regoff_t)(implicit z: native.Zone): native.Ptr[struct_regmatch_t] = { - val ptr = native.alloc[struct_regmatch_t] + def apply()(implicit z: Zone): Ptr[struct_regmatch_t] = alloc[struct_regmatch_t] + def apply(rm_so: regoff_t, rm_eo: regoff_t)(implicit z: Zone): Ptr[struct_regmatch_t] = { + val ptr = alloc[struct_regmatch_t] ptr.rm_so = rm_so ptr.rm_eo = rm_eo ptr diff --git a/bindings/posix/src/test/scala/org/scalanative/bindings/tests/FnmatchSpec.scala b/bindings/posix/src/test/scala/org/scalanative/bindings/tests/FnmatchSpec.scala index 7658bab..2ac19e8 100644 --- a/bindings/posix/src/test/scala/org/scalanative/bindings/tests/FnmatchSpec.scala +++ b/bindings/posix/src/test/scala/org/scalanative/bindings/tests/FnmatchSpec.scala @@ -1,12 +1,12 @@ package org.scalanative.bindings.tests -import org.scalatest.FunSpec +import org.scalatest.funspec.AnyFunSpec -class FnmatchSpec extends FunSpec { +class FnmatchSpec extends AnyFunSpec { describe("fnmatch") { it("should match patterns") { //#usage-example - import scala.scalanative.native._ + import scala.scalanative.unsafe._ import org.scalanative.bindings.posix.fnmatch._ assert(fnmatch(c"*.md", c"README.md", 0) == 0) diff --git a/bindings/posix/src/test/scala/org/scalanative/bindings/tests/RegexSpec.scala b/bindings/posix/src/test/scala/org/scalanative/bindings/tests/RegexSpec.scala index ea11e69..9341484 100644 --- a/bindings/posix/src/test/scala/org/scalanative/bindings/tests/RegexSpec.scala +++ b/bindings/posix/src/test/scala/org/scalanative/bindings/tests/RegexSpec.scala @@ -1,12 +1,13 @@ package org.scalanative.bindings.tests -import org.scalatest.FunSpec +import org.scalatest.funspec.AnyFunSpec -class RegexSpec extends FunSpec { +class RegexSpec extends AnyFunSpec { describe("regex") { it("should match regular expressions") { //#usage-example - import scala.scalanative.native._ + import scala.scalanative.unsafe._ + import scala.scalanative.unsigned._ import org.scalanative.bindings.posix.regex._ val reg = stackalloc[regex_t] @@ -15,10 +16,10 @@ class RegexSpec extends FunSpec { regcomp(reg, c"Scala \(J\(S\|VM\)\|Native\)", defines.REG_EXTENDED) assert(compResult == 0) - assert(regexec(reg, c"Scala JVM", 0, null, 0) == 0) - assert(regexec(reg, c"Scala JS", 0, null, 0) == 0) - assert(regexec(reg, c"Scala Native", 0, null, 0) == 0) - assert(regexec(reg, c"Scala .NET", 0, null, 0) != 0) + assert(regexec(reg, c"Scala JVM", 0.toULong, null, 0) == 0) + assert(regexec(reg, c"Scala JS", 0.toULong, null, 0) == 0) + assert(regexec(reg, c"Scala Native", 0.toULong, null, 0) == 0) + assert(regexec(reg, c"Scala .NET", 0.toULong, null, 0) != 0) regfree(reg) //#usage-example diff --git a/bindings/utf8proc/src/main/scala/org/scalanative/bindings/utf8proc.scala b/bindings/utf8proc/src/main/scala/org/scalanative/bindings/utf8proc.scala index 9f92d24..69ccedf 100644 --- a/bindings/utf8proc/src/main/scala/org/scalanative/bindings/utf8proc.scala +++ b/bindings/utf8proc/src/main/scala/org/scalanative/bindings/utf8proc.scala @@ -1,12 +1,12 @@ package org.scalanative.bindings -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._, Nat._ -@native.link("utf8proc") -@native.extern +@link("utf8proc") +@extern object utf8proc { - type enum_utf8proc_option_t = native.CUnsignedInt + type enum_utf8proc_option_t = CUnsignedInt object enum_utf8proc_option_t { final val UTF8PROC_NULLTERM: enum_utf8proc_option_t = 1.toUInt final val UTF8PROC_STABLE: enum_utf8proc_option_t = 2.toUInt @@ -25,7 +25,7 @@ object utf8proc { final val UTF8PROC_STRIPMARK: enum_utf8proc_option_t = 8192.toUInt } - type enum_utf8proc_category_t = native.CUnsignedInt + type enum_utf8proc_category_t = CUnsignedInt object enum_utf8proc_category_t { final val UTF8PROC_CATEGORY_CN: enum_utf8proc_category_t = 0.toUInt final val UTF8PROC_CATEGORY_LU: enum_utf8proc_category_t = 1.toUInt @@ -59,7 +59,7 @@ object utf8proc { final val UTF8PROC_CATEGORY_CO: enum_utf8proc_category_t = 29.toUInt } - type enum_utf8proc_bidi_class_t = native.CUnsignedInt + type enum_utf8proc_bidi_class_t = CUnsignedInt object enum_utf8proc_bidi_class_t { final val UTF8PROC_BIDI_CLASS_L: enum_utf8proc_bidi_class_t = 1.toUInt final val UTF8PROC_BIDI_CLASS_LRE: enum_utf8proc_bidi_class_t = 2.toUInt @@ -86,7 +86,7 @@ object utf8proc { final val UTF8PROC_BIDI_CLASS_PDI: enum_utf8proc_bidi_class_t = 23.toUInt } - type enum_utf8proc_decomp_type_t = native.CUnsignedInt + type enum_utf8proc_decomp_type_t = CUnsignedInt object enum_utf8proc_decomp_type_t { final val UTF8PROC_DECOMP_TYPE_FONT: enum_utf8proc_decomp_type_t = 1.toUInt final val UTF8PROC_DECOMP_TYPE_NOBREAK: enum_utf8proc_decomp_type_t = 2.toUInt @@ -106,7 +106,7 @@ object utf8proc { final val UTF8PROC_DECOMP_TYPE_COMPAT: enum_utf8proc_decomp_type_t = 16.toUInt } - type enum_utf8proc_boundclass_t = native.CUnsignedInt + type enum_utf8proc_boundclass_t = CUnsignedInt object enum_utf8proc_boundclass_t { final val UTF8PROC_BOUNDCLASS_START: enum_utf8proc_boundclass_t = 0.toUInt final val UTF8PROC_BOUNDCLASS_OTHER: enum_utf8proc_boundclass_t = 1.toUInt @@ -129,65 +129,65 @@ object utf8proc { final val UTF8PROC_BOUNDCLASS_E_BASE_GAZ: enum_utf8proc_boundclass_t = 18.toUInt } - type int8_t = native.CSignedChar - type int16_t = native.CShort - type int32_t = native.CInt - type uint8_t = native.CUnsignedChar - type uint16_t = native.CUnsignedShort - type uint32_t = native.CUnsignedInt + type int8_t = CSignedChar + type int16_t = CShort + type int32_t = CInt + type uint8_t = CUnsignedChar + type uint16_t = CUnsignedShort + type uint32_t = CUnsignedInt type utf8proc_int8_t = int8_t type utf8proc_uint8_t = uint8_t type utf8proc_int16_t = int16_t type utf8proc_uint16_t = uint16_t type utf8proc_int32_t = int32_t type utf8proc_uint32_t = uint32_t - type utf8proc_size_t = native.CSize - type utf8proc_ssize_t = native.CPtrDiff - type utf8proc_bool = native.CBool + type utf8proc_size_t = CSize + type utf8proc_ssize_t = CSSize + type utf8proc_bool = CBool type utf8proc_option_t = enum_utf8proc_option_t type utf8proc_propval_t = utf8proc_int16_t - type struct_utf8proc_property_struct = native.CArray[Byte, native.Nat.Digit[native.Nat._2, native.Nat._4]] + type struct_utf8proc_property_struct = CArray[Byte, Digit2[_2, _4]] type utf8proc_property_t = struct_utf8proc_property_struct type utf8proc_category_t = enum_utf8proc_category_t type utf8proc_bidi_class_t = enum_utf8proc_bidi_class_t type utf8proc_decomp_type_t = enum_utf8proc_decomp_type_t type utf8proc_boundclass_t = enum_utf8proc_boundclass_t - type utf8proc_custom_func = native.CFunctionPtr2[utf8proc_int32_t, native.Ptr[Byte], utf8proc_int32_t] - val utf8proc_utf8class: native.CArray[utf8proc_int8_t, native.Nat.Digit[native.Nat._2, native.Nat.Digit[native.Nat._5, native.Nat._6]]] = native.extern - def utf8proc_version(): native.CString = native.extern - def utf8proc_errmsg(errcode: utf8proc_ssize_t): native.CString = native.extern - def utf8proc_iterate(str: native.Ptr[utf8proc_uint8_t], strlen: utf8proc_ssize_t, codepoint_ref: native.Ptr[utf8proc_int32_t]): utf8proc_ssize_t = native.extern - def utf8proc_codepoint_valid(codepoint: utf8proc_int32_t): utf8proc_bool = native.extern - def utf8proc_encode_char(codepoint: utf8proc_int32_t, dst: native.Ptr[utf8proc_uint8_t]): utf8proc_ssize_t = native.extern - def utf8proc_get_property(codepoint: utf8proc_int32_t): native.Ptr[utf8proc_property_t] = native.extern - def utf8proc_decompose_char(codepoint: utf8proc_int32_t, dst: native.Ptr[utf8proc_int32_t], bufsize: utf8proc_ssize_t, options: utf8proc_option_t, last_boundclass: native.Ptr[native.CInt]): utf8proc_ssize_t = native.extern - def utf8proc_decompose(str: native.Ptr[utf8proc_uint8_t], strlen: utf8proc_ssize_t, buffer: native.Ptr[utf8proc_int32_t], bufsize: utf8proc_ssize_t, options: utf8proc_option_t): utf8proc_ssize_t = native.extern - def utf8proc_decompose_custom(str: native.Ptr[utf8proc_uint8_t], strlen: utf8proc_ssize_t, buffer: native.Ptr[utf8proc_int32_t], bufsize: utf8proc_ssize_t, options: utf8proc_option_t, custom_func: native.CFunctionPtr2[utf8proc_int32_t, native.Ptr[Byte], utf8proc_int32_t], custom_data: native.Ptr[Byte]): utf8proc_ssize_t = native.extern - def utf8proc_normalize_utf32(buffer: native.Ptr[utf8proc_int32_t], length: utf8proc_ssize_t, options: utf8proc_option_t): utf8proc_ssize_t = native.extern - def utf8proc_reencode(buffer: native.Ptr[utf8proc_int32_t], length: utf8proc_ssize_t, options: utf8proc_option_t): utf8proc_ssize_t = native.extern - def utf8proc_grapheme_break_stateful(codepoint1: utf8proc_int32_t, codepoint2: utf8proc_int32_t, state: native.Ptr[utf8proc_int32_t]): utf8proc_bool = native.extern - def utf8proc_grapheme_break(codepoint1: utf8proc_int32_t, codepoint2: utf8proc_int32_t): utf8proc_bool = native.extern - def utf8proc_tolower(c: utf8proc_int32_t): utf8proc_int32_t = native.extern - def utf8proc_toupper(c: utf8proc_int32_t): utf8proc_int32_t = native.extern - def utf8proc_totitle(c: utf8proc_int32_t): utf8proc_int32_t = native.extern - def utf8proc_charwidth(codepoint: utf8proc_int32_t): native.CInt = native.extern - def utf8proc_category(codepoint: utf8proc_int32_t): utf8proc_category_t = native.extern - def utf8proc_category_string(codepoint: utf8proc_int32_t): native.CString = native.extern - def utf8proc_map(str: native.Ptr[utf8proc_uint8_t], strlen: utf8proc_ssize_t, dstptr: native.Ptr[native.Ptr[utf8proc_uint8_t]], options: utf8proc_option_t): utf8proc_ssize_t = native.extern - def utf8proc_map_custom(str: native.Ptr[utf8proc_uint8_t], strlen: utf8proc_ssize_t, dstptr: native.Ptr[native.Ptr[utf8proc_uint8_t]], options: utf8proc_option_t, custom_func: native.CFunctionPtr2[utf8proc_int32_t, native.Ptr[Byte], utf8proc_int32_t], custom_data: native.Ptr[Byte]): utf8proc_ssize_t = native.extern - def utf8proc_NFD(str: native.Ptr[utf8proc_uint8_t]): native.Ptr[utf8proc_uint8_t] = native.extern - def utf8proc_NFC(str: native.Ptr[utf8proc_uint8_t]): native.Ptr[utf8proc_uint8_t] = native.extern - def utf8proc_NFKD(str: native.Ptr[utf8proc_uint8_t]): native.Ptr[utf8proc_uint8_t] = native.extern - def utf8proc_NFKC(str: native.Ptr[utf8proc_uint8_t]): native.Ptr[utf8proc_uint8_t] = native.extern + type utf8proc_custom_func = CFuncPtr2[utf8proc_int32_t, Ptr[Byte], utf8proc_int32_t] + val utf8proc_utf8class: CArray[utf8proc_int8_t, Digit3[_2, _5, _6]] = extern + def utf8proc_version(): CString = extern + def utf8proc_errmsg(errcode: utf8proc_ssize_t): CString = extern + def utf8proc_iterate(str: Ptr[utf8proc_uint8_t], strlen: utf8proc_ssize_t, codepoint_ref: Ptr[utf8proc_int32_t]): utf8proc_ssize_t = extern + def utf8proc_codepoint_valid(codepoint: utf8proc_int32_t): utf8proc_bool = extern + def utf8proc_encode_char(codepoint: utf8proc_int32_t, dst: Ptr[utf8proc_uint8_t]): utf8proc_ssize_t = extern + def utf8proc_get_property(codepoint: utf8proc_int32_t): Ptr[utf8proc_property_t] = extern + def utf8proc_decompose_char(codepoint: utf8proc_int32_t, dst: Ptr[utf8proc_int32_t], bufsize: utf8proc_ssize_t, options: utf8proc_option_t, last_boundclass: Ptr[CInt]): utf8proc_ssize_t = extern + def utf8proc_decompose(str: Ptr[utf8proc_uint8_t], strlen: utf8proc_ssize_t, buffer: Ptr[utf8proc_int32_t], bufsize: utf8proc_ssize_t, options: utf8proc_option_t): utf8proc_ssize_t = extern + def utf8proc_decompose_custom(str: Ptr[utf8proc_uint8_t], strlen: utf8proc_ssize_t, buffer: Ptr[utf8proc_int32_t], bufsize: utf8proc_ssize_t, options: utf8proc_option_t, custom_func: CFuncPtr2[utf8proc_int32_t, Ptr[Byte], utf8proc_int32_t], custom_data: Ptr[Byte]): utf8proc_ssize_t = extern + def utf8proc_normalize_utf32(buffer: Ptr[utf8proc_int32_t], length: utf8proc_ssize_t, options: utf8proc_option_t): utf8proc_ssize_t = extern + def utf8proc_reencode(buffer: Ptr[utf8proc_int32_t], length: utf8proc_ssize_t, options: utf8proc_option_t): utf8proc_ssize_t = extern + def utf8proc_grapheme_break_stateful(codepoint1: utf8proc_int32_t, codepoint2: utf8proc_int32_t, state: Ptr[utf8proc_int32_t]): utf8proc_bool = extern + def utf8proc_grapheme_break(codepoint1: utf8proc_int32_t, codepoint2: utf8proc_int32_t): utf8proc_bool = extern + def utf8proc_tolower(c: utf8proc_int32_t): utf8proc_int32_t = extern + def utf8proc_toupper(c: utf8proc_int32_t): utf8proc_int32_t = extern + def utf8proc_totitle(c: utf8proc_int32_t): utf8proc_int32_t = extern + def utf8proc_charwidth(codepoint: utf8proc_int32_t): CInt = extern + def utf8proc_category(codepoint: utf8proc_int32_t): utf8proc_category_t = extern + def utf8proc_category_string(codepoint: utf8proc_int32_t): CString = extern + def utf8proc_map(str: Ptr[utf8proc_uint8_t], strlen: utf8proc_ssize_t, dstptr: Ptr[Ptr[utf8proc_uint8_t]], options: utf8proc_option_t): utf8proc_ssize_t = extern + def utf8proc_map_custom(str: Ptr[utf8proc_uint8_t], strlen: utf8proc_ssize_t, dstptr: Ptr[Ptr[utf8proc_uint8_t]], options: utf8proc_option_t, custom_func: CFuncPtr2[utf8proc_int32_t, Ptr[Byte], utf8proc_int32_t], custom_data: Ptr[Byte]): utf8proc_ssize_t = extern + def utf8proc_NFD(str: Ptr[utf8proc_uint8_t]): Ptr[utf8proc_uint8_t] = extern + def utf8proc_NFC(str: Ptr[utf8proc_uint8_t]): Ptr[utf8proc_uint8_t] = extern + def utf8proc_NFKD(str: Ptr[utf8proc_uint8_t]): Ptr[utf8proc_uint8_t] = extern + def utf8proc_NFKC(str: Ptr[utf8proc_uint8_t]): Ptr[utf8proc_uint8_t] = extern object defines { - val UTF8PROC_VERSION_MAJOR: native.CInt = 2 - val UTF8PROC_VERSION_MINOR: native.CInt = 1 - val UTF8PROC_VERSION_PATCH: native.CInt = 0 - val UTF8PROC_ERROR_NOMEM: native.CInt = -1 - val UTF8PROC_ERROR_OVERFLOW: native.CInt = -2 - val UTF8PROC_ERROR_INVALIDUTF8: native.CInt = -3 - val UTF8PROC_ERROR_NOTASSIGNED: native.CInt = -4 - val UTF8PROC_ERROR_INVALIDOPTS: native.CInt = -5 + val UTF8PROC_VERSION_MAJOR: CInt = 2 + val UTF8PROC_VERSION_MINOR: CInt = 1 + val UTF8PROC_VERSION_PATCH: CInt = 0 + val UTF8PROC_ERROR_NOMEM: CInt = -1 + val UTF8PROC_ERROR_OVERFLOW: CInt = -2 + val UTF8PROC_ERROR_INVALIDUTF8: CInt = -3 + val UTF8PROC_ERROR_NOTASSIGNED: CInt = -4 + val UTF8PROC_ERROR_INVALIDOPTS: CInt = -5 } } diff --git a/bindings/utf8proc/src/test/scala/org/scalanative/bindings/tests/Utf8procSpec.scala b/bindings/utf8proc/src/test/scala/org/scalanative/bindings/tests/Utf8procSpec.scala index e299c6b..f407b39 100644 --- a/bindings/utf8proc/src/test/scala/org/scalanative/bindings/tests/Utf8procSpec.scala +++ b/bindings/utf8proc/src/test/scala/org/scalanative/bindings/tests/Utf8procSpec.scala @@ -1,29 +1,31 @@ package org.scalanative.bindings.tests -import org.scalatest.FunSpec +import org.scalatest.funspec.AnyFunSpec -class Utf8procSpec extends FunSpec { +class Utf8procSpec extends AnyFunSpec { describe("utf8proc") { it("should iterate UTF-8 and count character width") { //#usage-example import org.scalanative.bindings.utf8proc._ - import scala.scalanative.native._ + import scala.scalanative.unsafe._ + import scala.scalanative.unsigned._ + import scala.scalanative.libc._ val text = c"Spørge" - val textlen = string.strlen(text) + val textlen = string.strlen(text).toInt - val codepoint = stackalloc[utf8proc_int32_t] - var textpos: CSize = 0 - var textwidth: CSize = 0 + val codepoint = stackalloc[utf8proc_int32_t] + var textpos = 0 + var textwidth = 0 while (textpos < textlen) { val bytes = utf8proc_iterate( - text.cast[Ptr[UByte]] + textpos, + text.asInstanceOf[Ptr[UByte]] + textpos, textlen - textpos, codepoint ) textwidth += utf8proc_charwidth(!codepoint) - textpos += bytes + textpos += bytes.toInt } assert(textlen == 7) diff --git a/build.sbt b/build.sbt index bdc0ee5..86ba6a3 100644 --- a/build.sbt +++ b/build.sbt @@ -5,13 +5,11 @@ import BindingHelpers._ addCommandAlias("verify", "; test ; ^scripted ; docs/makeSite") -val Versions = new { - val scala210 = "2.10.6" - val scala211 = "2.11.12" - val scala212 = "2.12.6" - val sbt013 = "0.13.17" - val sbt1 = "1.1.6" -} +val scala211 = "2.11.12" +val scala212 = "2.12.15" +val scala213 = "2.13.7" +val sbt1 = "1.3.13" +val scalaTest = "3.2.10" inThisBuild( Def.settings( @@ -27,7 +25,7 @@ inThisBuild( "-encoding", "utf8" ), - parallelExecution in Global := false, + Global / parallelExecution := false, scmInfo := Some( ScmInfo(url("https://github.com/scala-native/scala-native-bindgen"), "scm:git:git@github.com:scala-native/scala-native-bindgen.git")), @@ -98,7 +96,7 @@ lazy val tests = project("tests") "*.h" || "*.scala", NothingFilter ), - libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test + libraryDependencies += "org.scalatest" %% "scalatest" % scalaTest % Test ) .aggregate(samples) @@ -106,15 +104,13 @@ lazy val samples = nativeProject("samples") .in(file("tests/samples")) .settings( publish / skip := true, - libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.0-SNAP10" % Test, + libraryDependencies += "org.scalatest" %%% "scalatest" % scalaTest % Test, compileTask("bindgentests", baseDirectory) ) lazy val tools = project("tools") .settings( - crossScalaVersions := List(Versions.scala210, - Versions.scala211, - Versions.scala212) + crossScalaVersions := List(scala211, scala212, scala213) ) lazy val sbtPlugin = project("sbt-scala-native-bindgen") @@ -186,7 +182,7 @@ lazy val docs = nativeProject("docs") compileTask("vector", docsUsingBindingsDirectory), compileTask("geometry", docs3rdPartyBindingsDirectory), compileTask("wordcount", docsScalaNativeBindingsDirectory), - libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.0-SNAP10" % Test, + libraryDependencies += "org.scalatest" %%% "scalatest" % scalaTest % Test, Paradox / paradoxProperties ++= Map( "github.base_url" -> scmInfo.value.get.browseUrl.toString ), @@ -204,7 +200,7 @@ lazy val docs = nativeProject("docs") lazy val bindings = project("bindings") .settings( publish / skip := true, - scalaVersion := Versions.scala211 + scalaVersion := scala211 ) .aggregate( libiconv, @@ -247,11 +243,10 @@ def project(name: String) = { versionWithGit, git.useGitDescribe := true, git.remoteRepo := scmInfo.value.get.connection.replace("scm:git:", ""), - crossSbtVersions := List(Versions.sbt013, Versions.sbt1), + crossSbtVersions := List(sbt1), scalaVersion := { (pluginCrossBuild / sbtBinaryVersion).value match { - case "0.13" => Versions.scala210 - case _ => Versions.scala212 + case _ => scala212 } }, bintrayOrganization := Some("scala-native-bindgen"), @@ -268,7 +263,7 @@ def nativeProject(name: String) = { project(name) .enablePlugins(ScalaNativePlugin) .settings( - scalaVersion := Versions.scala211, + scalaVersion := scala211, nativeLinkStubs := true ) } @@ -340,7 +335,7 @@ def bindingProject(name: String, link: Option[String] = None)( .in(file(s"bindings/$name")) .settings( Keys.name := name, - libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.0-SNAP10" % Test, + libraryDependencies += "org.scalatest" %%% "scalatest" % scalaTest % Test, Compile / nativeBindgen / target := { packagePath.foldLeft((Compile / scalaSource).value)(_ / _) } @@ -349,9 +344,20 @@ def bindingProject(name: String, link: Option[String] = None)( headers.flatMap(binding(name, packagePath.mkString("."), link)): _*) } +/* /usr/include is not standard on macOS anymore + * The command below returns the path to the usr/include dir + * Example: /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk + * Ref: https://apple.stackexchange.com/questions/337940/why-is-usr-include-missing-i-have-xcode-and-command-line-tools-installed-moja + */ +lazy val usrInclude = { + val isMac = scala.util.Properties.isMac + (if (isMac) "xcrun --show-sdk-path".!!.trim else "") + "/usr/include" +} + def binding(name: String, packageName: String, link: Option[String])( header: String): Seq[Setting[_]] = { - val includeDirs = Seq("/usr/include", "/usr/local/include") + + val includeDirs = Seq(usrInclude, "/usr/local/include") val headerFiles = includeDirs.map(dir => file(dir) / header).filter(_.exists) headerFiles.headOption match { diff --git a/docs/src/test/resources/scala-native-bindings/config.json b/docs/src/test/resources/scala-native-bindings/config.json index 58948a7..4bd087a 100644 --- a/docs/src/test/resources/scala-native-bindings/config.json +++ b/docs/src/test/resources/scala-native-bindings/config.json @@ -1,8 +1,8 @@ { "stdio.h": { - "object": "scala.scalanative.native.stdio" + "object": "scala.scalanative.libc.stdio" }, "_stdio.h": { - "object": "scala.scalanative.native.stdio" + "object": "scala.scalanative.libc.stdio" } -} \ No newline at end of file +} diff --git a/docs/src/test/scala/com/example/custom/binding/Vector.scala b/docs/src/test/scala/com/example/custom/binding/Vector.scala index e09a104..04277bb 100644 --- a/docs/src/test/scala/com/example/custom/binding/Vector.scala +++ b/docs/src/test/scala/com/example/custom/binding/Vector.scala @@ -1,43 +1,40 @@ //#example package com.example.custom.binding -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("vector") -@native.extern +@link("vector") +@extern object Vector { - type Point = native.CStruct2[native.CFloat, native.CFloat] - type LineSegment = native.CStruct2[Point, Point] + type Point = CStruct2[CFloat, CFloat] + type LineSegment = CStruct2[Point, Point] // ... //#example - def cosine(v1: native.Ptr[LineSegment], - v2: native.Ptr[LineSegment]): native.CFloat = native.extern + def cosine(v1: Ptr[LineSegment], v2: Ptr[LineSegment]): CFloat = extern object implicits { - implicit class PointOps(val p: native.Ptr[Point]) extends AnyVal { - def x: native.CFloat = !p._1 - def x_=(value: native.CFloat): Unit = !p._1 = value - def y: native.CFloat = !p._2 - def y_=(value: native.CFloat): Unit = !p._2 = value + implicit class PointOps(val p: Ptr[Point]) extends AnyVal { + def x: CFloat = p._1 + def x_=(value: CFloat): Unit = p._1 = value + def y: CFloat = p._2 + def y_=(value: CFloat): Unit = p._2 = value } - implicit class LineSegmentOps(val p: native.Ptr[LineSegment]) - extends AnyVal { - def a: native.Ptr[Point] = p._1 - def a_=(value: native.Ptr[Point]): Unit = !p._1 = !value - def b: native.Ptr[Point] = p._2 - def b_=(value: native.Ptr[Point]): Unit = !p._2 = !value + implicit class LineSegmentOps(val p: Ptr[LineSegment]) extends AnyVal { + def a: Ptr[Point] = p._1.asInstanceOf[Ptr[Point]] + def a_=(value: Ptr[Point]): Unit = p._1 = value + def b: Ptr[Point] = p._2.asInstanceOf[Ptr[Point]] + def b_=(value: Ptr[Point]): Unit = p._2 = value } } object Point { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[Point] = - native.alloc[Point] - def apply(x: native.CFloat, y: native.CFloat)( - implicit z: native.Zone): native.Ptr[Point] = { - val ptr = native.alloc[Point] + def apply()(implicit z: Zone): Ptr[Point] = + alloc[Point] + def apply(x: CFloat, y: CFloat)(implicit z: Zone): Ptr[Point] = { + val ptr = alloc[Point] ptr.x = x ptr.y = y ptr @@ -46,11 +43,11 @@ object Vector { object LineSegment { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[LineSegment] = - native.alloc[LineSegment] - def apply(a: native.Ptr[Point], b: native.Ptr[Point])( - implicit z: native.Zone): native.Ptr[LineSegment] = { - val ptr = native.alloc[LineSegment] + def apply()(implicit z: Zone): Ptr[LineSegment] = + alloc[LineSegment] + def apply(a: Ptr[Point], b: Ptr[Point])( + implicit z: Zone): Ptr[LineSegment] = { + val ptr = alloc[LineSegment] ptr.a = a ptr.b = b ptr diff --git a/docs/src/test/scala/org/example/Geometry.scala b/docs/src/test/scala/org/example/Geometry.scala index 4cbcc87..e915d53 100644 --- a/docs/src/test/scala/org/example/Geometry.scala +++ b/docs/src/test/scala/org/example/Geometry.scala @@ -1,30 +1,30 @@ package org.example.geometry -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("geometry") -@native.extern +@link("geometry") +@extern object Geometry { //#using-struct-point - type struct_circle = native.CStruct2[com.example.custom.binding.Vector.Point, native.CDouble] + type struct_circle = CStruct2[com.example.custom.binding.Vector.Point, CDouble] //#using-struct-point - def circle_area(circle: native.Ptr[struct_circle]): native.CFloat = native.extern + def circle_area(circle: Ptr[struct_circle]): CFloat = extern object implicits { - implicit class struct_circle_ops(val p: native.Ptr[struct_circle]) extends AnyVal { - def point: native.Ptr[com.example.custom.binding.Vector.Point] = p._1 - def point_=(value: native.Ptr[com.example.custom.binding.Vector.Point]): Unit = !p._1 = !value - def radius: native.CDouble = !p._2 - def radius_=(value: native.CDouble): Unit = !p._2 = value + implicit class struct_circle_ops(val p: Ptr[struct_circle]) extends AnyVal { + def point: Ptr[com.example.custom.binding.Vector.Point] = p.at1 + def point_=(value: Ptr[com.example.custom.binding.Vector.Point]): Unit = p._1 = value + def radius: CDouble = p._2 + def radius_=(value: CDouble): Unit = p._2 = value } } object struct_circle { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_circle] = native.alloc[struct_circle] - def apply(point: native.Ptr[com.example.custom.binding.Vector.Point], radius: native.CDouble)(implicit z: native.Zone): native.Ptr[struct_circle] = { - val ptr = native.alloc[struct_circle] + def apply()(implicit z: Zone): Ptr[struct_circle] = alloc[struct_circle] + def apply(point: Ptr[com.example.custom.binding.Vector.Point], radius: CDouble)(implicit z: Zone): Ptr[struct_circle] = { + val ptr = alloc[struct_circle] ptr.point = point ptr.radius = radius ptr diff --git a/docs/src/test/scala/org/example/WordCount.scala b/docs/src/test/scala/org/example/WordCount.scala index 35d4b62..439841f 100644 --- a/docs/src/test/scala/org/example/WordCount.scala +++ b/docs/src/test/scala/org/example/WordCount.scala @@ -1,32 +1,32 @@ package org.example.wordcount -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("wordcount") -@native.extern +@link("wordcount") +@extern object WordCount { - type struct_wordcount = native.CStruct3[native.CLong, native.CLong, native.CLong] + type struct_wordcount = CStruct3[CLong, CLong, CLong] //#using-stdio-file - def wordcount(wordcount: native.Ptr[struct_wordcount], file: native.Ptr[scala.scalanative.native.stdio.FILE]): native.CInt = native.extern + def wordcount(wordcount: Ptr[struct_wordcount], file: Ptr[scala.scalanative.libc.stdio.FILE]): CInt = extern //#using-stdio-file object implicits { - implicit class struct_wordcount_ops(val p: native.Ptr[struct_wordcount]) extends AnyVal { - def chars: native.CLong = !p._1 - def chars_=(value: native.CLong): Unit = !p._1 = value - def lines: native.CLong = !p._2 - def lines_=(value: native.CLong): Unit = !p._2 = value - def words: native.CLong = !p._3 - def words_=(value: native.CLong): Unit = !p._3 = value + implicit class struct_wordcount_ops(val p: Ptr[struct_wordcount]) extends AnyVal { + def chars: CLong = p._1 + def chars_=(value: CLong): Unit = p._1 = value + def lines: CLong = p._2 + def lines_=(value: CLong): Unit = p._2 = value + def words: CLong = p._3 + def words_=(value: CLong): Unit = p._3 = value } } object struct_wordcount { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_wordcount] = native.alloc[struct_wordcount] - def apply(chars: native.CLong, lines: native.CLong, words: native.CLong)(implicit z: native.Zone): native.Ptr[struct_wordcount] = { - val ptr = native.alloc[struct_wordcount] + def apply()(implicit z: Zone): Ptr[struct_wordcount] = alloc[struct_wordcount] + def apply(chars: CLong, lines: CLong, words: CLong)(implicit z: Zone): Ptr[struct_wordcount] = { + val ptr = alloc[struct_wordcount] ptr.chars = chars ptr.lines = lines ptr.words = words diff --git a/docs/src/test/scala/org/example/vector.scala b/docs/src/test/scala/org/example/vector.scala index 29a9c4c..70fd973 100644 --- a/docs/src/test/scala/org/example/vector.scala +++ b/docs/src/test/scala/org/example/vector.scala @@ -1,36 +1,36 @@ package org.example -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("vector") -@native.extern +@link("vector") +@extern object vector { - type struct_point = native.CStruct2[native.CFloat, native.CFloat] - type struct_lineSegment = native.CStruct2[struct_point, struct_point] - def cosine(v1: native.Ptr[struct_lineSegment], v2: native.Ptr[struct_lineSegment]): native.CFloat = native.extern + type struct_point = CStruct2[CFloat, CFloat] + type struct_lineSegment = CStruct2[struct_point, struct_point] + def cosine(v1: Ptr[struct_lineSegment], v2: Ptr[struct_lineSegment]): CFloat = extern object implicits { - implicit class struct_point_ops(val p: native.Ptr[struct_point]) extends AnyVal { - def x: native.CFloat = !p._1 - def x_=(value: native.CFloat): Unit = !p._1 = value - def y: native.CFloat = !p._2 - def y_=(value: native.CFloat): Unit = !p._2 = value + implicit class struct_point_ops(val p: Ptr[struct_point]) extends AnyVal { + def x: CFloat = p._1 + def x_=(value: CFloat): Unit = p._1 = value + def y: CFloat = p._2 + def y_=(value: CFloat): Unit = p._2 = value } - implicit class struct_lineSegment_ops(val p: native.Ptr[struct_lineSegment]) extends AnyVal { - def a: native.Ptr[struct_point] = p._1 - def a_=(value: native.Ptr[struct_point]): Unit = !p._1 = !value - def b: native.Ptr[struct_point] = p._2 - def b_=(value: native.Ptr[struct_point]): Unit = !p._2 = !value + implicit class struct_lineSegment_ops(val p: Ptr[struct_lineSegment]) extends AnyVal { + def a: Ptr[struct_point] = p.at1 + def a_=(value: Ptr[struct_point]): Unit = p._1 = value + def b: Ptr[struct_point] = p.at2 + def b_=(value: Ptr[struct_point]): Unit = p._2 = value } } object struct_point { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_point] = native.alloc[struct_point] - def apply(x: native.CFloat, y: native.CFloat)(implicit z: native.Zone): native.Ptr[struct_point] = { - val ptr = native.alloc[struct_point] + def apply()(implicit z: Zone): Ptr[struct_point] = alloc[struct_point] + def apply(x: CFloat, y: CFloat)(implicit z: Zone): Ptr[struct_point] = { + val ptr = alloc[struct_point] ptr.x = x ptr.y = y ptr @@ -39,9 +39,9 @@ object vector { object struct_lineSegment { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_lineSegment] = native.alloc[struct_lineSegment] - def apply(a: native.Ptr[struct_point], b: native.Ptr[struct_point])(implicit z: native.Zone): native.Ptr[struct_lineSegment] = { - val ptr = native.alloc[struct_lineSegment] + def apply()(implicit z: Zone): Ptr[struct_lineSegment] = alloc[struct_lineSegment] + def apply(a: Ptr[struct_point], b: Ptr[struct_point])(implicit z: Zone): Ptr[struct_lineSegment] = { + val ptr = alloc[struct_lineSegment] ptr.a = a ptr.b = b ptr diff --git a/docs/src/test/scala/org/scalanative/bindgen/docs/GeometrySpec.scala b/docs/src/test/scala/org/scalanative/bindgen/docs/GeometrySpec.scala index b1599e3..a35a20c 100644 --- a/docs/src/test/scala/org/scalanative/bindgen/docs/GeometrySpec.scala +++ b/docs/src/test/scala/org/scalanative/bindgen/docs/GeometrySpec.scala @@ -1,14 +1,14 @@ package org.scalanative.bindgen.docs -import org.scalatest.FunSpec +import org.scalatest.funspec.AnyFunSpec -class GeometrySpec extends FunSpec { +class GeometrySpec extends AnyFunSpec { describe("geometry") { it("using generated bindings") { //#example import com.example.custom.binding.Vector.Point import org.example.geometry.Geometry._ - import scala.scalanative.native.Zone + import scala.scalanative.unsafe.Zone Zone { implicit zone => val center = Point(1, 1) diff --git a/docs/src/test/scala/org/scalanative/bindgen/docs/VectorSpec.scala b/docs/src/test/scala/org/scalanative/bindgen/docs/VectorSpec.scala index 8851fbf..b447802 100644 --- a/docs/src/test/scala/org/scalanative/bindgen/docs/VectorSpec.scala +++ b/docs/src/test/scala/org/scalanative/bindgen/docs/VectorSpec.scala @@ -1,13 +1,13 @@ package org.scalanative.bindgen.docs -import org.scalatest.FunSpec +import org.scalatest.funspec.AnyFunSpec -class VectorSpec extends FunSpec { +class VectorSpec extends AnyFunSpec { describe("vector") { it("using generated bindings") { //#step-1 import org.example.vector._ - import scala.scalanative.native.Zone + import scala.scalanative.unsafe.Zone Zone { implicit zone => val p1 = struct_point(1, 1) diff --git a/docs/src/test/scala/org/scalanative/bindgen/docs/WordCountSpec.scala b/docs/src/test/scala/org/scalanative/bindgen/docs/WordCountSpec.scala index dddb2dc..72f2c4b 100644 --- a/docs/src/test/scala/org/scalanative/bindgen/docs/WordCountSpec.scala +++ b/docs/src/test/scala/org/scalanative/bindgen/docs/WordCountSpec.scala @@ -1,20 +1,20 @@ package org.scalanative.bindgen.docs -import org.scalatest.FunSpec +import org.scalatest.funspec.AnyFunSpec -class WordCountSpec extends FunSpec { +class WordCountSpec extends AnyFunSpec { describe("wordcount") { it("using generated bindings") { //#example import org.example.wordcount.WordCount._ - import scalanative.native._ + import scala.scalanative.unsafe._ + import scala.scalanative.libc._ //#example val pathToFile = c"docs/src/test/resources/scala-native-bindings/wordcount.h" - import scalanative.posix.unistd.access - import scalanative.posix.fcntl.R_OK + import scala.scalanative.posix._, unistd.access, unistd.R_OK assert(access(pathToFile, R_OK) == 0, "Header file does not exist") //#example diff --git a/project/build.properties b/project/build.properties index 0cd8b07..10fd9ee 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.2.3 +sbt.version=1.5.5 diff --git a/project/plugins.sbt b/project/plugins.sbt index 4553fe0..0822b1d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,4 @@ -addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.8") +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0") addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.3.2") addSbtPlugin("io.github.jonas" % "sbt-paradox-material-theme" % "0.5.0") addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.2") diff --git a/sbt-scala-native-bindgen/src/main/scala/org/scalanative/bindgen/sbt/ScalaNativeBindgenPlugin.scala b/sbt-scala-native-bindgen/src/main/scala/org/scalanative/bindgen/sbt/ScalaNativeBindgenPlugin.scala index b46a10a..c009f1c 100644 --- a/sbt-scala-native-bindgen/src/main/scala/org/scalanative/bindgen/sbt/ScalaNativeBindgenPlugin.scala +++ b/sbt-scala-native-bindgen/src/main/scala/org/scalanative/bindgen/sbt/ScalaNativeBindgenPlugin.scala @@ -30,8 +30,8 @@ import org.scalanative.bindgen.{Bindgen, BindingOptions} * * - `nativeBindgenPath`: Path to the `scala-native-bindgen` executable. * - `nativeBindings`: Settings for each binding to generate. - * - `target in nativeBindgen`: Output folder of the generated code. - * - `version in nativeBindgen`: Version of the `scala-native-bindgen` + * - `nativeBindgen / target`: Output folder of the generated code. + * - `nativeBindgen / version`: Version of the `scala-native-bindgen` * to use when automatically downloading the executable. * - `nativeBindgen`: Generate Scala Native bindings. * @@ -70,12 +70,12 @@ object ScalaNativeBindgenPlugin extends AutoPlugin { nativeBindgenScopedSettings(Test) ++ Def.settings( ivyConfigurations += ScalaNativeBindgen, - version in nativeBindgen := BuildInfo.version, + nativeBindgen / version := BuildInfo.version, nativeBindgenPath := None, libraryDependencies ++= { (nativeBindgenPath.value, artifactName) match { case (None, Some(name)) => - val bindgenVersion = (version in nativeBindgen).value + val bindgenVersion = (nativeBindgen / version).value val url = s"${BuildInfo.projectUrl}/releases/download/v$bindgenVersion/$name" @@ -91,7 +91,7 @@ object ScalaNativeBindgenPlugin extends AutoPlugin { case None => Def.task { val scalaNativeBindgenUpdate = - (update in ScalaNativeBindgen).value + (ScalaNativeBindgen / update).value val artifactFile = artifactName match { case None => @@ -129,9 +129,9 @@ object ScalaNativeBindgenPlugin extends AutoPlugin { inConfig(conf)( Def.settings( nativeBindings := Seq.empty, - target in nativeBindgen := sourceManaged.value / "sbt-scala-native-bindgen", + nativeBindgen / target := sourceManaged.value / "sbt-scala-native-bindgen", sourceGenerators += Def.taskDyn { - val nativeBindgenTarget = (target in nativeBindgen).value.toPath + val nativeBindgenTarget = (nativeBindgen / target).value.toPath val managedSource = sourceManaged.value.toPath if (nativeBindgenTarget.startsWith(managedSource)) { @@ -143,7 +143,7 @@ object ScalaNativeBindgenPlugin extends AutoPlugin { nativeBindgen := { val bindgen = Bindgen(nativeBindgenResolvedPath.value) val optionsList = nativeBindings.value - val outputDirectory = (target in nativeBindgen).value + val outputDirectory = (nativeBindgen / target).value val logger = streams.value.log // FIXME: Check uniqueness of names. diff --git a/sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/build.sbt b/sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/build.sbt index 6599621..35b060c 100644 --- a/sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/build.sbt +++ b/sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/build.sbt @@ -25,7 +25,7 @@ nativeBindgenCustomTarget := baseDirectory.value / "src/main/scala/org/example" val nativeBindgenCoreBinding = SettingKey[NativeBinding]("nativeBindgenCoreBinding") nativeBindgenCoreBinding := { - NativeBinding((resourceDirectory in Compile).value / "core.h") + NativeBinding((Compile / resourceDirectory).value / "core.h") .packageName("org.example.app.core") .link("core") -} \ No newline at end of file +} diff --git a/sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/expected/core.scala b/sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/expected/core.scala index 8756836..61874c0 100644 --- a/sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/expected/core.scala +++ b/sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/expected/core.scala @@ -1,11 +1,11 @@ package org.example.app.core -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("core") -@native.extern +@link("core") +@extern object core { - def count_words(text: native.CString): native.CInt = native.extern - def __not_excluded(): Unit = native.extern + def count_words(text: CString): CInt = extern + def __not_excluded(): Unit = extern } diff --git a/sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/expected/stdlib.scala b/sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/expected/stdlib.scala index b4ea761..5754801 100644 --- a/sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/expected/stdlib.scala +++ b/sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/expected/stdlib.scala @@ -1,11 +1,14 @@ package org.example.app.stdlib -import scala.scalanative._ +import scala.scalanative.unsigned._ import scala.scalanative.native._ -@native.extern +@extern object stdlib { - def access(path: native.CString, mode: native.CInt): native.CInt = native.extern - def read(fildes: native.CInt, buf: native.Ptr[Byte], nbyte: native.CInt): native.CInt = native.extern - def printf(format: native.CString, varArgs: native.CVararg*): native.CInt = native.extern + def access(path: CString, mode: CInt): CInt = extern + def read(fildes: CInt, buf: Ptr[Byte], nbyte: CInt): CInt = extern + //def printf(format: CString, varArgs: CVararg*): CInt = extern + def printf(format: CString, args: CVarArg*): CInt = Zone { + implicit z => stdio.vprintf(format, toCVarArgList(args.toSeq)) + } } diff --git a/scripts/scalafmt b/scripts/scalafmt index fec77ef..0f6c0b4 100755 --- a/scripts/scalafmt +++ b/scripts/scalafmt @@ -8,12 +8,12 @@ COURSIER="$HERE/.coursier" SCALAFMT="$HERE/.scalafmt-$VERSION" if [ ! -f $COURSIER ]; then - curl -L -o $COURSIER https://git.io/vgvpD + curl -L -o $COURSIER https://git.io/coursier-cli chmod +x $COURSIER fi if [ ! -f $SCALAFMT ]; then - $COURSIER bootstrap com.geirsson:scalafmt-cli_2.11:$VERSION --main org.scalafmt.cli.Cli -o $SCALAFMT + $COURSIER bootstrap com.geirsson:scalafmt-cli_2.11:$VERSION -r sonatype:snapshots --main org.scalafmt.cli.Cli -o $SCALAFMT chmod +x $SCALAFMT fi diff --git a/tests/samples/AnonymousTypes.scala b/tests/samples/AnonymousTypes.scala index 3e2bf34..5f91e33 100644 --- a/tests/samples/AnonymousTypes.scala +++ b/tests/samples/AnonymousTypes.scala @@ -1,53 +1,53 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object AnonymousTypes { - type struct_anonymous_0 = native.CStruct1[native.CChar] - type union_anonymous_0 = native.CArray[Byte, native.Nat._8] - type struct_anonymous_1 = native.CStruct1[native.Ptr[union_anonymous_0]] - type struct_StructWithAnonymousStruct = native.CStruct2[native.Ptr[struct_anonymous_1], native.CUnsignedInt] - type struct_anonymous_2 = native.CStruct1[native.CInt] - def foo(s: native.Ptr[struct_anonymous_0]): Unit = native.extern - def bar(): native.Ptr[struct_anonymous_2] = native.extern + type struct_anonymous_0 = CStruct1[CChar] + type union_anonymous_0 = CArray[Byte, Nat._8] + type struct_anonymous_1 = CStruct1[Ptr[union_anonymous_0]] + type struct_StructWithAnonymousStruct = CStruct2[Ptr[struct_anonymous_1], CUnsignedInt] + type struct_anonymous_2 = CStruct1[CInt] + def foo(s: Ptr[struct_anonymous_0]): Unit = extern + def bar(): Ptr[struct_anonymous_2] = extern object implicits { - implicit class struct_anonymous_0_ops(val p: native.Ptr[struct_anonymous_0]) extends AnyVal { - def a: native.CChar = !p._1 - def a_=(value: native.CChar): Unit = !p._1 = value + implicit class struct_anonymous_0_ops(val p: Ptr[struct_anonymous_0]) extends AnyVal { + def a: CChar = p._1 + def a_=(value: CChar): Unit = p._1 = value } - implicit class struct_anonymous_1_ops(val p: native.Ptr[struct_anonymous_1]) extends AnyVal { - def innerUnion: native.Ptr[union_anonymous_0] = !p._1 - def innerUnion_=(value: native.Ptr[union_anonymous_0]): Unit = !p._1 = value + implicit class struct_anonymous_1_ops(val p: Ptr[struct_anonymous_1]) extends AnyVal { + def innerUnion: Ptr[union_anonymous_0] = p._1 + def innerUnion_=(value: Ptr[union_anonymous_0]): Unit = p._1 = value } - implicit class struct_StructWithAnonymousStruct_ops(val p: native.Ptr[struct_StructWithAnonymousStruct]) extends AnyVal { - def innerStruct: native.Ptr[struct_anonymous_1] = !p._1 - def innerStruct_=(value: native.Ptr[struct_anonymous_1]): Unit = !p._1 = value - def innerEnum: native.CUnsignedInt = !p._2 - def innerEnum_=(value: native.CUnsignedInt): Unit = !p._2 = value + implicit class struct_StructWithAnonymousStruct_ops(val p: Ptr[struct_StructWithAnonymousStruct]) extends AnyVal { + def innerStruct: Ptr[struct_anonymous_1] = p._1 + def innerStruct_=(value: Ptr[struct_anonymous_1]): Unit = p._1 = value + def innerEnum: CUnsignedInt = p._2 + def innerEnum_=(value: CUnsignedInt): Unit = p._2 = value } - implicit class struct_anonymous_2_ops(val p: native.Ptr[struct_anonymous_2]) extends AnyVal { - def result: native.CInt = !p._1 - def result_=(value: native.CInt): Unit = !p._1 = value + implicit class struct_anonymous_2_ops(val p: Ptr[struct_anonymous_2]) extends AnyVal { + def result: CInt = p._1 + def result_=(value: CInt): Unit = p._1 = value } - implicit class union_anonymous_0_pos(val p: native.Ptr[union_anonymous_0]) extends AnyVal { - def a: native.Ptr[native.CLong] = p.cast[native.Ptr[native.CLong]] - def a_=(value: native.CLong): Unit = !p.cast[native.Ptr[native.CLong]] = value + implicit class union_anonymous_0_pos(val p: Ptr[union_anonymous_0]) extends AnyVal { + def a: Ptr[CLong] = p.asInstanceOf[Ptr[CLong]] + def a_=(value: CLong): Unit = !p.asInstanceOf[Ptr[CLong]] = value } } object struct_anonymous_0 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_anonymous_0] = native.alloc[struct_anonymous_0] - def apply(a: native.CChar)(implicit z: native.Zone): native.Ptr[struct_anonymous_0] = { - val ptr = native.alloc[struct_anonymous_0] + def apply()(implicit z: Zone): Ptr[struct_anonymous_0] = alloc[struct_anonymous_0] + def apply(a: CChar)(implicit z: Zone): Ptr[struct_anonymous_0] = { + val ptr = alloc[struct_anonymous_0] ptr.a = a ptr } @@ -55,9 +55,9 @@ object AnonymousTypes { object struct_anonymous_1 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_anonymous_1] = native.alloc[struct_anonymous_1] - def apply(innerUnion: native.Ptr[union_anonymous_0])(implicit z: native.Zone): native.Ptr[struct_anonymous_1] = { - val ptr = native.alloc[struct_anonymous_1] + def apply()(implicit z: Zone): Ptr[struct_anonymous_1] = alloc[struct_anonymous_1] + def apply(innerUnion: Ptr[union_anonymous_0])(implicit z: Zone): Ptr[struct_anonymous_1] = { + val ptr = alloc[struct_anonymous_1] ptr.innerUnion = innerUnion ptr } @@ -65,9 +65,9 @@ object AnonymousTypes { object struct_StructWithAnonymousStruct { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_StructWithAnonymousStruct] = native.alloc[struct_StructWithAnonymousStruct] - def apply(innerStruct: native.Ptr[struct_anonymous_1], innerEnum: native.CUnsignedInt)(implicit z: native.Zone): native.Ptr[struct_StructWithAnonymousStruct] = { - val ptr = native.alloc[struct_StructWithAnonymousStruct] + def apply()(implicit z: Zone): Ptr[struct_StructWithAnonymousStruct] = alloc[struct_StructWithAnonymousStruct] + def apply(innerStruct: Ptr[struct_anonymous_1], innerEnum: CUnsignedInt)(implicit z: Zone): Ptr[struct_StructWithAnonymousStruct] = { + val ptr = alloc[struct_StructWithAnonymousStruct] ptr.innerStruct = innerStruct ptr.innerEnum = innerEnum ptr @@ -76,9 +76,9 @@ object AnonymousTypes { object struct_anonymous_2 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_anonymous_2] = native.alloc[struct_anonymous_2] - def apply(result: native.CInt)(implicit z: native.Zone): native.Ptr[struct_anonymous_2] = { - val ptr = native.alloc[struct_anonymous_2] + def apply()(implicit z: Zone): Ptr[struct_anonymous_2] = alloc[struct_anonymous_2] + def apply(result: CInt)(implicit z: Zone): Ptr[struct_anonymous_2] = { + val ptr = alloc[struct_anonymous_2] ptr.result = result ptr } diff --git a/tests/samples/CustomNames.scala b/tests/samples/CustomNames.scala index b61c3f7..14e83aa 100644 --- a/tests/samples/CustomNames.scala +++ b/tests/samples/CustomNames.scala @@ -1,19 +1,19 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object CustomNames { - type enum_enumWithTypedef = native.CUnsignedInt + type enum_enumWithTypedef = CUnsignedInt object enum_enumWithTypedef { final val CONST: enum_enumWithTypedef = 0.toUInt } type EnumWithTypedef = enum_enumWithTypedef - type page = native.CStruct2[native.CString, native.Ptr[Byte]] - type book = native.CStruct1[native.Ptr[page]] - type weight = native.CArray[Byte, native.Nat._4] - type MY_INT = native.CInt + type page = CStruct2[CString, Ptr[Byte]] + type book = CStruct1[Ptr[page]] + type weight = CArray[Byte, Nat._4] + type MY_INT = CInt } diff --git a/tests/samples/Cycles.scala b/tests/samples/Cycles.scala index cc844d8..bc8ab0b 100644 --- a/tests/samples/Cycles.scala +++ b/tests/samples/Cycles.scala @@ -1,110 +1,110 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ object Cycles { - type struct_node = native.CStruct2[native.CInt, native.Ptr[Byte]] - type struct_b = native.CStruct1[native.Ptr[native.Ptr[Byte]]] - type struct_a = native.CStruct1[native.Ptr[struct_b]] - type struct_c = native.CStruct1[struct_a] - type struct_FuncPointerCycle2 = native.CStruct1[native.CFunctionPtr0[native.Ptr[Byte]]] - type struct_FuncPointerCycle1 = native.CStruct1[native.Ptr[struct_FuncPointerCycle2]] - type struct_TypeWithTypedef1 = native.CStruct1[native.Ptr[struct_TypeWithTypedef2]] + type struct_node = CStruct2[CInt, Ptr[Byte]] + type struct_b = CStruct1[Ptr[Ptr[Byte]]] + type struct_a = CStruct1[Ptr[struct_b]] + type struct_c = CStruct1[struct_a] + type struct_FuncPointerCycle2 = CStruct1[CFuncPtr0[Ptr[Byte]]] + type struct_FuncPointerCycle1 = CStruct1[Ptr[struct_FuncPointerCycle2]] + type struct_TypeWithTypedef1 = CStruct1[Ptr[struct_TypeWithTypedef2]] type TypeWithTypedef1 = struct_TypeWithTypedef1 - type struct_TypeWithTypedef2 = native.CStruct1[native.Ptr[Byte]] - type struct_TwoTypesReplaced1 = native.CStruct1[native.Ptr[struct_TwoTypesReplaced2]] - type struct_TwoTypesReplaced2 = native.CStruct1[native.Ptr[struct_TwoTypesReplaced3]] - type struct_TwoTypesReplaced3 = native.CStruct1[native.CFunctionPtr1[native.Ptr[Byte], native.Ptr[Byte]]] - type union_cycleWithUnionU = native.CArray[Byte, native.Nat._8] - type struct_cycleWithUnionS = native.CStruct1[native.Ptr[union_cycleWithUnionU]] - type struct_FuncPointerWithValueType2 = native.CStruct1[native.CFunctionPtr0[native.CStruct0]] - type struct_FuncPointerWithValueType1 = native.CStruct1[native.Ptr[struct_FuncPointerWithValueType2]] + type struct_TypeWithTypedef2 = CStruct1[Ptr[Byte]] + type struct_TwoTypesReplaced1 = CStruct1[Ptr[struct_TwoTypesReplaced2]] + type struct_TwoTypesReplaced2 = CStruct1[Ptr[struct_TwoTypesReplaced3]] + type struct_TwoTypesReplaced3 = CStruct1[CFuncPtr1[Ptr[Byte], Ptr[Byte]]] + type union_cycleWithUnionU = CArray[Byte, Nat._8] + type struct_cycleWithUnionS = CStruct1[Ptr[union_cycleWithUnionU]] + type struct_FuncPointerWithValueType2 = CStruct1[CFuncPtr0[CStruct0]] + type struct_FuncPointerWithValueType1 = CStruct1[Ptr[struct_FuncPointerWithValueType2]] object implicits { - implicit class struct_node_ops(val p: native.Ptr[struct_node]) extends AnyVal { - def value: native.CInt = !p._1 - def value_=(value: native.CInt): Unit = !p._1 = value - def next: native.Ptr[struct_node] = (!p._2).cast[native.Ptr[struct_node]] - def next_=(value: native.Ptr[struct_node]): Unit = !p._2 = value.cast[native.Ptr[Byte]] + implicit class struct_node_ops(val p: Ptr[struct_node]) extends AnyVal { + def value: CInt = p._1 + def value_=(value: CInt): Unit = p._1 = value + def next: Ptr[struct_node] = p._2.asInstanceOf[Ptr[struct_node]] + def next_=(value: Ptr[struct_node]): Unit = p._2 = value.asInstanceOf[Ptr[Byte]] } - implicit class struct_a_ops(val p: native.Ptr[struct_a]) extends AnyVal { - def bb: native.Ptr[struct_b] = !p._1 - def bb_=(value: native.Ptr[struct_b]): Unit = !p._1 = value + implicit class struct_a_ops(val p: Ptr[struct_a]) extends AnyVal { + def bb: Ptr[struct_b] = p._1 + def bb_=(value: Ptr[struct_b]): Unit = p._1 = value } - implicit class struct_b_ops(val p: native.Ptr[struct_b]) extends AnyVal { - def cc: native.Ptr[native.Ptr[struct_c]] = (!p._1).cast[native.Ptr[native.Ptr[struct_c]]] - def cc_=(value: native.Ptr[native.Ptr[struct_c]]): Unit = !p._1 = value.cast[native.Ptr[native.Ptr[Byte]]] + implicit class struct_b_ops(val p: Ptr[struct_b]) extends AnyVal { + def cc: Ptr[Ptr[struct_c]] = p._1.asInstanceOf[Ptr[Ptr[struct_c]]] + def cc_=(value: Ptr[Ptr[struct_c]]): Unit = p._1 = value.asInstanceOf[Ptr[Ptr[Byte]]] } - implicit class struct_c_ops(val p: native.Ptr[struct_c]) extends AnyVal { - def aa: native.Ptr[struct_a] = p._1 - def aa_=(value: native.Ptr[struct_a]): Unit = !p._1 = !value + implicit class struct_c_ops(val p: Ptr[struct_c]) extends AnyVal { + def aa: Ptr[struct_a] = p._1.asInstanceOf[Ptr[struct_a]] + def aa_=(value: Ptr[struct_a]): Unit = p._1 = value } - implicit class struct_FuncPointerCycle1_ops(val p: native.Ptr[struct_FuncPointerCycle1]) extends AnyVal { - def s: native.Ptr[struct_FuncPointerCycle2] = !p._1 - def s_=(value: native.Ptr[struct_FuncPointerCycle2]): Unit = !p._1 = value + implicit class struct_FuncPointerCycle1_ops(val p: Ptr[struct_FuncPointerCycle1]) extends AnyVal { + def s: Ptr[struct_FuncPointerCycle2] = p._1 + def s_=(value: Ptr[struct_FuncPointerCycle2]): Unit = p._1 = value } - implicit class struct_FuncPointerCycle2_ops(val p: native.Ptr[struct_FuncPointerCycle2]) extends AnyVal { - def memberFunction: native.CFunctionPtr0[native.Ptr[struct_FuncPointerCycle1]] = (!p._1).cast[native.CFunctionPtr0[native.Ptr[struct_FuncPointerCycle1]]] - def memberFunction_=(value: native.CFunctionPtr0[native.Ptr[struct_FuncPointerCycle1]]): Unit = !p._1 = value.cast[native.CFunctionPtr0[native.Ptr[Byte]]] + implicit class struct_FuncPointerCycle2_ops(val p: Ptr[struct_FuncPointerCycle2]) extends AnyVal { + def memberFunction: CFuncPtr0[Ptr[struct_FuncPointerCycle1]] = p._1.asInstanceOf[CFuncPtr0[Ptr[struct_FuncPointerCycle1]]] + def memberFunction_=(value: CFuncPtr0[Ptr[struct_FuncPointerCycle1]]): Unit = p._1 = value.asInstanceOf[CFuncPtr0[Ptr[Byte]]] } - implicit class struct_TypeWithTypedef2_ops(val p: native.Ptr[struct_TypeWithTypedef2]) extends AnyVal { - def s: native.Ptr[TypeWithTypedef1] = (!p._1).cast[native.Ptr[TypeWithTypedef1]] - def s_=(value: native.Ptr[TypeWithTypedef1]): Unit = !p._1 = value.cast[native.Ptr[Byte]] + implicit class struct_TypeWithTypedef2_ops(val p: Ptr[struct_TypeWithTypedef2]) extends AnyVal { + def s: Ptr[TypeWithTypedef1] = p._1.asInstanceOf[Ptr[TypeWithTypedef1]] + def s_=(value: Ptr[TypeWithTypedef1]): Unit = p._1 = value.asInstanceOf[Ptr[Byte]] } - implicit class struct_TypeWithTypedef1_ops(val p: native.Ptr[struct_TypeWithTypedef1]) extends AnyVal { - def s: native.Ptr[struct_TypeWithTypedef2] = !p._1 - def s_=(value: native.Ptr[struct_TypeWithTypedef2]): Unit = !p._1 = value + implicit class struct_TypeWithTypedef1_ops(val p: Ptr[struct_TypeWithTypedef1]) extends AnyVal { + def s: Ptr[struct_TypeWithTypedef2] = p._1 + def s_=(value: Ptr[struct_TypeWithTypedef2]): Unit = p._1 = value } - implicit class struct_TwoTypesReplaced3_ops(val p: native.Ptr[struct_TwoTypesReplaced3]) extends AnyVal { - def memberFunction: native.CFunctionPtr1[native.Ptr[struct_TwoTypesReplaced2], native.Ptr[struct_TwoTypesReplaced1]] = (!p._1).cast[native.CFunctionPtr1[native.Ptr[struct_TwoTypesReplaced2], native.Ptr[struct_TwoTypesReplaced1]]] - def memberFunction_=(value: native.CFunctionPtr1[native.Ptr[struct_TwoTypesReplaced2], native.Ptr[struct_TwoTypesReplaced1]]): Unit = !p._1 = value.cast[native.CFunctionPtr1[native.Ptr[Byte], native.Ptr[Byte]]] + implicit class struct_TwoTypesReplaced3_ops(val p: Ptr[struct_TwoTypesReplaced3]) extends AnyVal { + def memberFunction: CFuncPtr1[Ptr[struct_TwoTypesReplaced2], Ptr[struct_TwoTypesReplaced1]] = p._1.asInstanceOf[CFuncPtr1[Ptr[struct_TwoTypesReplaced2], Ptr[struct_TwoTypesReplaced1]]] + def memberFunction_=(value: CFuncPtr1[Ptr[struct_TwoTypesReplaced2], Ptr[struct_TwoTypesReplaced1]]): Unit = p._1 = value.asInstanceOf[CFuncPtr1[Ptr[Byte], Ptr[Byte]]] } - implicit class struct_TwoTypesReplaced1_ops(val p: native.Ptr[struct_TwoTypesReplaced1]) extends AnyVal { - def s: native.Ptr[struct_TwoTypesReplaced2] = !p._1 - def s_=(value: native.Ptr[struct_TwoTypesReplaced2]): Unit = !p._1 = value + implicit class struct_TwoTypesReplaced1_ops(val p: Ptr[struct_TwoTypesReplaced1]) extends AnyVal { + def s: Ptr[struct_TwoTypesReplaced2] = p._1 + def s_=(value: Ptr[struct_TwoTypesReplaced2]): Unit = p._1 = value } - implicit class struct_TwoTypesReplaced2_ops(val p: native.Ptr[struct_TwoTypesReplaced2]) extends AnyVal { - def s: native.Ptr[struct_TwoTypesReplaced3] = !p._1 - def s_=(value: native.Ptr[struct_TwoTypesReplaced3]): Unit = !p._1 = value + implicit class struct_TwoTypesReplaced2_ops(val p: Ptr[struct_TwoTypesReplaced2]) extends AnyVal { + def s: Ptr[struct_TwoTypesReplaced3] = p._1 + def s_=(value: Ptr[struct_TwoTypesReplaced3]): Unit = p._1 = value } - implicit class struct_cycleWithUnionS_ops(val p: native.Ptr[struct_cycleWithUnionS]) extends AnyVal { - def u: native.Ptr[union_cycleWithUnionU] = !p._1 - def u_=(value: native.Ptr[union_cycleWithUnionU]): Unit = !p._1 = value + implicit class struct_cycleWithUnionS_ops(val p: Ptr[struct_cycleWithUnionS]) extends AnyVal { + def u: Ptr[union_cycleWithUnionU] = p._1 + def u_=(value: Ptr[union_cycleWithUnionU]): Unit = p._1 = value } - implicit class struct_FuncPointerWithValueType1_ops(val p: native.Ptr[struct_FuncPointerWithValueType1]) extends AnyVal { - def s: native.Ptr[struct_FuncPointerWithValueType2] = !p._1 - def s_=(value: native.Ptr[struct_FuncPointerWithValueType2]): Unit = !p._1 = value + implicit class struct_FuncPointerWithValueType1_ops(val p: Ptr[struct_FuncPointerWithValueType1]) extends AnyVal { + def s: Ptr[struct_FuncPointerWithValueType2] = p._1 + def s_=(value: Ptr[struct_FuncPointerWithValueType2]): Unit = p._1 = value } - implicit class struct_FuncPointerWithValueType2_ops(val p: native.Ptr[struct_FuncPointerWithValueType2]) extends AnyVal { - def memberFunction: native.CFunctionPtr0[struct_FuncPointerWithValueType1] = (!p._1).cast[native.CFunctionPtr0[struct_FuncPointerWithValueType1]] - def memberFunction_=(value: native.CFunctionPtr0[struct_FuncPointerWithValueType1]): Unit = !p._1 = value.cast[native.CFunctionPtr0[native.CStruct0]] + implicit class struct_FuncPointerWithValueType2_ops(val p: Ptr[struct_FuncPointerWithValueType2]) extends AnyVal { + def memberFunction: CFuncPtr0[struct_FuncPointerWithValueType1] = p._1.asInstanceOf[CFuncPtr0[struct_FuncPointerWithValueType1]] + def memberFunction_=(value: CFuncPtr0[struct_FuncPointerWithValueType1]): Unit = p._1 = value.asInstanceOf[CFuncPtr0[CStruct0]] } - implicit class union_cycleWithUnionU_pos(val p: native.Ptr[union_cycleWithUnionU]) extends AnyVal { - def s: native.Ptr[native.Ptr[struct_cycleWithUnionS]] = p.cast[native.Ptr[native.Ptr[struct_cycleWithUnionS]]] - def s_=(value: native.Ptr[struct_cycleWithUnionS]): Unit = !p.cast[native.Ptr[native.Ptr[struct_cycleWithUnionS]]] = value + implicit class union_cycleWithUnionU_pos(val p: Ptr[union_cycleWithUnionU]) extends AnyVal { + def s: Ptr[Ptr[struct_cycleWithUnionS]] = p.asInstanceOf[Ptr[Ptr[struct_cycleWithUnionS]]] + def s_=(value: Ptr[struct_cycleWithUnionS]): Unit = !p.asInstanceOf[Ptr[Ptr[struct_cycleWithUnionS]]] = value } } object struct_node { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_node] = native.alloc[struct_node] - def apply(value: native.CInt, next: native.Ptr[struct_node])(implicit z: native.Zone): native.Ptr[struct_node] = { - val ptr = native.alloc[struct_node] + def apply()(implicit z: Zone): Ptr[struct_node] = alloc[struct_node] + def apply(value: CInt, next: Ptr[struct_node])(implicit z: Zone): Ptr[struct_node] = { + val ptr = alloc[struct_node] ptr.value = value ptr.next = next ptr @@ -113,9 +113,9 @@ object Cycles { object struct_a { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_a] = native.alloc[struct_a] - def apply(bb: native.Ptr[struct_b])(implicit z: native.Zone): native.Ptr[struct_a] = { - val ptr = native.alloc[struct_a] + def apply()(implicit z: Zone): Ptr[struct_a] = alloc[struct_a] + def apply(bb: Ptr[struct_b])(implicit z: Zone): Ptr[struct_a] = { + val ptr = alloc[struct_a] ptr.bb = bb ptr } @@ -123,9 +123,9 @@ object Cycles { object struct_b { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_b] = native.alloc[struct_b] - def apply(cc: native.Ptr[native.Ptr[struct_c]])(implicit z: native.Zone): native.Ptr[struct_b] = { - val ptr = native.alloc[struct_b] + def apply()(implicit z: Zone): Ptr[struct_b] = alloc[struct_b] + def apply(cc: Ptr[Ptr[struct_c]])(implicit z: Zone): Ptr[struct_b] = { + val ptr = alloc[struct_b] ptr.cc = cc ptr } @@ -133,9 +133,9 @@ object Cycles { object struct_c { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_c] = native.alloc[struct_c] - def apply(aa: native.Ptr[struct_a])(implicit z: native.Zone): native.Ptr[struct_c] = { - val ptr = native.alloc[struct_c] + def apply()(implicit z: Zone): Ptr[struct_c] = alloc[struct_c] + def apply(aa: Ptr[struct_a])(implicit z: Zone): Ptr[struct_c] = { + val ptr = alloc[struct_c] ptr.aa = aa ptr } @@ -143,9 +143,9 @@ object Cycles { object struct_FuncPointerCycle1 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_FuncPointerCycle1] = native.alloc[struct_FuncPointerCycle1] - def apply(s: native.Ptr[struct_FuncPointerCycle2])(implicit z: native.Zone): native.Ptr[struct_FuncPointerCycle1] = { - val ptr = native.alloc[struct_FuncPointerCycle1] + def apply()(implicit z: Zone): Ptr[struct_FuncPointerCycle1] = alloc[struct_FuncPointerCycle1] + def apply(s: Ptr[struct_FuncPointerCycle2])(implicit z: Zone): Ptr[struct_FuncPointerCycle1] = { + val ptr = alloc[struct_FuncPointerCycle1] ptr.s = s ptr } @@ -153,9 +153,9 @@ object Cycles { object struct_FuncPointerCycle2 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_FuncPointerCycle2] = native.alloc[struct_FuncPointerCycle2] - def apply(memberFunction: native.CFunctionPtr0[native.Ptr[struct_FuncPointerCycle1]])(implicit z: native.Zone): native.Ptr[struct_FuncPointerCycle2] = { - val ptr = native.alloc[struct_FuncPointerCycle2] + def apply()(implicit z: Zone): Ptr[struct_FuncPointerCycle2] = alloc[struct_FuncPointerCycle2] + def apply(memberFunction: CFuncPtr0[Ptr[struct_FuncPointerCycle1]])(implicit z: Zone): Ptr[struct_FuncPointerCycle2] = { + val ptr = alloc[struct_FuncPointerCycle2] ptr.memberFunction = memberFunction ptr } @@ -163,9 +163,9 @@ object Cycles { object struct_TypeWithTypedef2 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_TypeWithTypedef2] = native.alloc[struct_TypeWithTypedef2] - def apply(s: native.Ptr[TypeWithTypedef1])(implicit z: native.Zone): native.Ptr[struct_TypeWithTypedef2] = { - val ptr = native.alloc[struct_TypeWithTypedef2] + def apply()(implicit z: Zone): Ptr[struct_TypeWithTypedef2] = alloc[struct_TypeWithTypedef2] + def apply(s: Ptr[TypeWithTypedef1])(implicit z: Zone): Ptr[struct_TypeWithTypedef2] = { + val ptr = alloc[struct_TypeWithTypedef2] ptr.s = s ptr } @@ -173,9 +173,9 @@ object Cycles { object struct_TypeWithTypedef1 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_TypeWithTypedef1] = native.alloc[struct_TypeWithTypedef1] - def apply(s: native.Ptr[struct_TypeWithTypedef2])(implicit z: native.Zone): native.Ptr[struct_TypeWithTypedef1] = { - val ptr = native.alloc[struct_TypeWithTypedef1] + def apply()(implicit z: Zone): Ptr[struct_TypeWithTypedef1] = alloc[struct_TypeWithTypedef1] + def apply(s: Ptr[struct_TypeWithTypedef2])(implicit z: Zone): Ptr[struct_TypeWithTypedef1] = { + val ptr = alloc[struct_TypeWithTypedef1] ptr.s = s ptr } @@ -183,9 +183,9 @@ object Cycles { object struct_TwoTypesReplaced3 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_TwoTypesReplaced3] = native.alloc[struct_TwoTypesReplaced3] - def apply(memberFunction: native.CFunctionPtr1[native.Ptr[struct_TwoTypesReplaced2], native.Ptr[struct_TwoTypesReplaced1]])(implicit z: native.Zone): native.Ptr[struct_TwoTypesReplaced3] = { - val ptr = native.alloc[struct_TwoTypesReplaced3] + def apply()(implicit z: Zone): Ptr[struct_TwoTypesReplaced3] = alloc[struct_TwoTypesReplaced3] + def apply(memberFunction: CFuncPtr1[Ptr[struct_TwoTypesReplaced2], Ptr[struct_TwoTypesReplaced1]])(implicit z: Zone): Ptr[struct_TwoTypesReplaced3] = { + val ptr = alloc[struct_TwoTypesReplaced3] ptr.memberFunction = memberFunction ptr } @@ -193,9 +193,9 @@ object Cycles { object struct_TwoTypesReplaced1 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_TwoTypesReplaced1] = native.alloc[struct_TwoTypesReplaced1] - def apply(s: native.Ptr[struct_TwoTypesReplaced2])(implicit z: native.Zone): native.Ptr[struct_TwoTypesReplaced1] = { - val ptr = native.alloc[struct_TwoTypesReplaced1] + def apply()(implicit z: Zone): Ptr[struct_TwoTypesReplaced1] = alloc[struct_TwoTypesReplaced1] + def apply(s: Ptr[struct_TwoTypesReplaced2])(implicit z: Zone): Ptr[struct_TwoTypesReplaced1] = { + val ptr = alloc[struct_TwoTypesReplaced1] ptr.s = s ptr } @@ -203,9 +203,9 @@ object Cycles { object struct_TwoTypesReplaced2 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_TwoTypesReplaced2] = native.alloc[struct_TwoTypesReplaced2] - def apply(s: native.Ptr[struct_TwoTypesReplaced3])(implicit z: native.Zone): native.Ptr[struct_TwoTypesReplaced2] = { - val ptr = native.alloc[struct_TwoTypesReplaced2] + def apply()(implicit z: Zone): Ptr[struct_TwoTypesReplaced2] = alloc[struct_TwoTypesReplaced2] + def apply(s: Ptr[struct_TwoTypesReplaced3])(implicit z: Zone): Ptr[struct_TwoTypesReplaced2] = { + val ptr = alloc[struct_TwoTypesReplaced2] ptr.s = s ptr } @@ -213,9 +213,9 @@ object Cycles { object struct_cycleWithUnionS { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_cycleWithUnionS] = native.alloc[struct_cycleWithUnionS] - def apply(u: native.Ptr[union_cycleWithUnionU])(implicit z: native.Zone): native.Ptr[struct_cycleWithUnionS] = { - val ptr = native.alloc[struct_cycleWithUnionS] + def apply()(implicit z: Zone): Ptr[struct_cycleWithUnionS] = alloc[struct_cycleWithUnionS] + def apply(u: Ptr[union_cycleWithUnionU])(implicit z: Zone): Ptr[struct_cycleWithUnionS] = { + val ptr = alloc[struct_cycleWithUnionS] ptr.u = u ptr } @@ -223,9 +223,9 @@ object Cycles { object struct_FuncPointerWithValueType1 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_FuncPointerWithValueType1] = native.alloc[struct_FuncPointerWithValueType1] - def apply(s: native.Ptr[struct_FuncPointerWithValueType2])(implicit z: native.Zone): native.Ptr[struct_FuncPointerWithValueType1] = { - val ptr = native.alloc[struct_FuncPointerWithValueType1] + def apply()(implicit z: Zone): Ptr[struct_FuncPointerWithValueType1] = alloc[struct_FuncPointerWithValueType1] + def apply(s: Ptr[struct_FuncPointerWithValueType2])(implicit z: Zone): Ptr[struct_FuncPointerWithValueType1] = { + val ptr = alloc[struct_FuncPointerWithValueType1] ptr.s = s ptr } @@ -233,9 +233,9 @@ object Cycles { object struct_FuncPointerWithValueType2 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_FuncPointerWithValueType2] = native.alloc[struct_FuncPointerWithValueType2] - def apply(memberFunction: native.CFunctionPtr0[struct_FuncPointerWithValueType1])(implicit z: native.Zone): native.Ptr[struct_FuncPointerWithValueType2] = { - val ptr = native.alloc[struct_FuncPointerWithValueType2] + def apply()(implicit z: Zone): Ptr[struct_FuncPointerWithValueType2] = alloc[struct_FuncPointerWithValueType2] + def apply(memberFunction: CFuncPtr0[struct_FuncPointerWithValueType1])(implicit z: Zone): Ptr[struct_FuncPointerWithValueType2] = { + val ptr = alloc[struct_FuncPointerWithValueType2] ptr.memberFunction = memberFunction ptr } diff --git a/tests/samples/Enum.scala b/tests/samples/Enum.scala index d11d4a3..d15387c 100644 --- a/tests/samples/Enum.scala +++ b/tests/samples/Enum.scala @@ -1,12 +1,12 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object Enum { - type enum_days = native.CUnsignedInt + type enum_days = CUnsignedInt object enum_days { final val MONDAY: enum_days = 0.toUInt final val TUESDAY: enum_days = 200.toUInt @@ -17,30 +17,30 @@ object Enum { final val SUNDAY: enum_days = 4.toUInt } - type enum_bigValues = native.CUnsignedLong + type enum_bigValues = CUnsignedLong object enum_bigValues { final val BIG_A: enum_bigValues = 10000000000L.toULong final val BIG_B: enum_bigValues = 1L.toULong } - type enum_anonymous_0 = native.CUnsignedInt + type enum_anonymous_0 = CUnsignedInt object enum_anonymous_0 { final val ANON_A: enum_anonymous_0 = 0.toUInt final val ANON_B: enum_anonymous_0 = 1.toUInt } - type enum_negativeValues = native.CInt + type enum_negativeValues = CInt object enum_negativeValues { final val NEG_A: enum_negativeValues = -1 final val NEG_B: enum_negativeValues = -2 } - type enum_bigNegativeValues = native.CLong + type enum_bigNegativeValues = CLong object enum_bigNegativeValues { final val BIG_NEG_A: enum_bigNegativeValues = -10000000000L final val BIG_NEG_B: enum_bigNegativeValues = -1L } - def get_WEDNESDAY(): enum_days = native.extern - def check_BIG_NEG_A(big_neg_a: enum_bigNegativeValues): native.CString = native.extern + def get_WEDNESDAY(): enum_days = extern + def check_BIG_NEG_A(big_neg_a: enum_bigNegativeValues): CString = extern } diff --git a/tests/samples/Extern.scala b/tests/samples/Extern.scala index bf36cbd..154978b 100644 --- a/tests/samples/Extern.scala +++ b/tests/samples/Extern.scala @@ -1,39 +1,39 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object Extern { - type enum_mode = native.CUnsignedInt + type enum_mode = CUnsignedInt object enum_mode { final val SYSTEM: enum_mode = 0.toUInt final val USER: enum_mode = 1.toUInt } - type struct_version = native.CStruct3[native.CInt, native.CInt, native.CInt] - val forty_two: native.CInt = native.extern - val version: native.CString = native.extern - val mode: enum_mode = native.extern - val semver: native.Ptr[struct_version] = native.extern + type struct_version = CStruct3[CInt, CInt, CInt] + val forty_two: CInt = extern + val version: CString = extern + val mode: enum_mode = extern + val semver: Ptr[struct_version] = extern object implicits { - implicit class struct_version_ops(val p: native.Ptr[struct_version]) extends AnyVal { - def major: native.CInt = !p._1 - def major_=(value: native.CInt): Unit = !p._1 = value - def minor: native.CInt = !p._2 - def minor_=(value: native.CInt): Unit = !p._2 = value - def patch: native.CInt = !p._3 - def patch_=(value: native.CInt): Unit = !p._3 = value + implicit class struct_version_ops(val p: Ptr[struct_version]) extends AnyVal { + def major: CInt = p._1 + def major_=(value: CInt): Unit = p._1 = value + def minor: CInt = p._2 + def minor_=(value: CInt): Unit = p._2 = value + def patch: CInt = p._3 + def patch_=(value: CInt): Unit = p._3 = value } } object struct_version { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_version] = native.alloc[struct_version] - def apply(major: native.CInt, minor: native.CInt, patch: native.CInt)(implicit z: native.Zone): native.Ptr[struct_version] = { - val ptr = native.alloc[struct_version] + def apply()(implicit z: Zone): Ptr[struct_version] = alloc[struct_version] + def apply(major: CInt, minor: CInt, patch: CInt)(implicit z: Zone): Ptr[struct_version] = { + val ptr = alloc[struct_version] ptr.major = major ptr.minor = minor ptr.patch = patch diff --git a/tests/samples/Function.scala b/tests/samples/Function.scala index d4b44c7..ce0495f 100644 --- a/tests/samples/Function.scala +++ b/tests/samples/Function.scala @@ -1,39 +1,39 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object Function { - type struct_s = native.CStruct1[native.CInt] + type struct_s = CStruct1[CInt] type s = struct_s - type union_u = native.CArray[Byte, native.Nat._4] - def no_args(): native.CInt = native.extern - def void_arg(): native.CFloat = native.extern - def one_arg(a: native.CInt): native.CChar = native.extern - def two_args(a: native.CFloat, b: native.CInt): native.Ptr[Byte] = native.extern - def anonymous_args(p0: native.CFloat, p1: native.CInt): native.CDouble = native.extern - def variadic_args(a: native.CDouble, varArgs: native.CString, varArgs0: native.CVararg*): native.CDouble = native.extern - def acceptsArray(p0: native.Ptr[native.CInt]): Unit = native.extern + type union_u = CArray[Byte, Nat._4] + def no_args(): CInt = extern + def void_arg(): CFloat = extern + def one_arg(a: CInt): CChar = extern + def two_args(a: CFloat, b: CInt): Ptr[Byte] = extern + def anonymous_args(p0: CFloat, p1: CInt): CDouble = extern + def variadic_args(a: CDouble, varArgs: CString, varArgs0: CVarArg*): CDouble = extern + def acceptsArray(p0: Ptr[CInt]): Unit = extern object implicits { - implicit class struct_s_ops(val p: native.Ptr[struct_s]) extends AnyVal { - def `val`: native.CInt = !p._1 - def `val_=`(value: native.CInt): Unit = !p._1 = value + implicit class struct_s_ops(val p: Ptr[struct_s]) extends AnyVal { + def `val`: CInt = p._1 + def `val_=`(value: CInt): Unit = p._1 = value } - implicit class union_u_pos(val p: native.Ptr[union_u]) extends AnyVal { - def a: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]] - def a_=(value: native.CInt): Unit = !p.cast[native.Ptr[native.CInt]] = value + implicit class union_u_pos(val p: Ptr[union_u]) extends AnyVal { + def a: Ptr[CInt] = p.asInstanceOf[Ptr[CInt]] + def a_=(value: CInt): Unit = !p.asInstanceOf[Ptr[CInt]] = value } } object struct_s { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_s] = native.alloc[struct_s] - def apply(`val`: native.CInt)(implicit z: native.Zone): native.Ptr[struct_s] = { - val ptr = native.alloc[struct_s] + def apply()(implicit z: Zone): Ptr[struct_s] = alloc[struct_s] + def apply(`val`: CInt)(implicit z: Zone): Ptr[struct_s] = { + val ptr = alloc[struct_s] ptr.`val` = `val` ptr } diff --git a/tests/samples/IncludesHeader.scala b/tests/samples/IncludesHeader.scala index af08d3b..51336bd 100644 --- a/tests/samples/IncludesHeader.scala +++ b/tests/samples/IncludesHeader.scala @@ -1,50 +1,50 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object IncludesHeader { - type enum_semester = native.CUnsignedInt + type enum_semester = CUnsignedInt object enum_semester { final val AUTUMN: enum_semester = 0.toUInt final val SPRING: enum_semester = 1.toUInt } - type size = native.CInt - type struct_metadata = native.CStruct2[native.CUnsignedInt, native.CString] + type size = CInt + type struct_metadata = CStruct2[CUnsignedInt, CString] type metadata = struct_metadata - type struct_document = native.CStruct1[metadata] - type struct_courseInfo = native.CStruct2[native.CString, enum_semester] - def getSize(d: native.Ptr[struct_document]): size = native.extern + type struct_document = CStruct1[metadata] + type struct_courseInfo = CStruct2[CString, enum_semester] + def getSize(d: Ptr[struct_document]): size = extern object implicits { - implicit class struct_metadata_ops(val p: native.Ptr[struct_metadata]) extends AnyVal { - def year: native.CUnsignedInt = !p._1 - def year_=(value: native.CUnsignedInt): Unit = !p._1 = value - def publisher: native.CString = !p._2 - def publisher_=(value: native.CString): Unit = !p._2 = value + implicit class struct_metadata_ops(val p: Ptr[struct_metadata]) extends AnyVal { + def year: CUnsignedInt = p._1 + def year_=(value: CUnsignedInt): Unit = p._1 = value + def publisher: CString = p._2 + def publisher_=(value: CString): Unit = p._2 = value } - implicit class struct_document_ops(val p: native.Ptr[struct_document]) extends AnyVal { - def m: native.Ptr[metadata] = p._1 - def m_=(value: native.Ptr[metadata]): Unit = !p._1 = !value + implicit class struct_document_ops(val p: Ptr[struct_document]) extends AnyVal { + def m: Ptr[metadata] = p._1.asInstanceOf[Ptr[metadata]] + def m_=(value: Ptr[metadata]): Unit = p._1 = value } - implicit class struct_courseInfo_ops(val p: native.Ptr[struct_courseInfo]) extends AnyVal { - def name: native.CString = !p._1 - def name_=(value: native.CString): Unit = !p._1 = value - def s: enum_semester = !p._2 - def s_=(value: enum_semester): Unit = !p._2 = value + implicit class struct_courseInfo_ops(val p: Ptr[struct_courseInfo]) extends AnyVal { + def name: CString = p._1 + def name_=(value: CString): Unit = p._1 = value + def s: enum_semester = p._2 + def s_=(value: enum_semester): Unit = p._2 = value } } object struct_metadata { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_metadata] = native.alloc[struct_metadata] - def apply(year: native.CUnsignedInt, publisher: native.CString)(implicit z: native.Zone): native.Ptr[struct_metadata] = { - val ptr = native.alloc[struct_metadata] + def apply()(implicit z: Zone): Ptr[struct_metadata] = alloc[struct_metadata] + def apply(year: CUnsignedInt, publisher: CString)(implicit z: Zone): Ptr[struct_metadata] = { + val ptr = alloc[struct_metadata] ptr.year = year ptr.publisher = publisher ptr @@ -53,9 +53,9 @@ object IncludesHeader { object struct_document { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_document] = native.alloc[struct_document] - def apply(m: native.Ptr[metadata])(implicit z: native.Zone): native.Ptr[struct_document] = { - val ptr = native.alloc[struct_document] + def apply()(implicit z: Zone): Ptr[struct_document] = alloc[struct_document] + def apply(m: Ptr[metadata])(implicit z: Zone): Ptr[struct_document] = { + val ptr = alloc[struct_document] ptr.m = m ptr } @@ -63,9 +63,9 @@ object IncludesHeader { object struct_courseInfo { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_courseInfo] = native.alloc[struct_courseInfo] - def apply(name: native.CString, s: enum_semester)(implicit z: native.Zone): native.Ptr[struct_courseInfo] = { - val ptr = native.alloc[struct_courseInfo] + def apply()(implicit z: Zone): Ptr[struct_courseInfo] = alloc[struct_courseInfo] + def apply(name: CString, s: enum_semester)(implicit z: Zone): Ptr[struct_courseInfo] = { + val ptr = alloc[struct_courseInfo] ptr.name = name ptr.s = s ptr diff --git a/tests/samples/LiteralDefine.scala b/tests/samples/LiteralDefine.scala index 5191cc9..dd31c2f 100644 --- a/tests/samples/LiteralDefine.scala +++ b/tests/samples/LiteralDefine.scala @@ -1,29 +1,29 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ object LiteralDefine { object defines { - val STRING: native.CString = c"Hello, World!" - val LONG: native.CLong = 1000000000000L - val LONG_WITHOUT_ENDING: native.CLong = 1000000000000L - val LONG_LONG: native.CLongLong = 1000000000000L - val MAXIMUM_SIGNED_LONG: native.CLong = 9223372036854775807L - val MINIMUM_SIGNED_LONG: native.CLong = -9223372036854775808L - val FLOAT: native.CDouble = 5.6 - val INT: native.CInt = 42 - val MAXIMUM_INT: native.CInt = 2147483647 - val NEW_INT: native.CInt = 42 - val NEG_INT: native.CInt = -42 - val SHOULD_BE_DEFINED: native.CString = c"Because INT is not equal to 0" - val OCTAL: native.CInt = 139 - val HEXADECIMAL: native.CInt = 75 - val EXPONENT: native.CDouble = 1e-10 - val DOT_EXPONENT: native.CDouble = 0.01 - val HEXADECIMAL_WITHOUT_RADIX: native.CDouble = 523264 - val HEXADECIMAL_WITH_RADIX: native.CDouble = 7.5 - val HEXADECIMAL_FRACTIONAL_WITH_RADIX: native.CDouble = 0.0355225 + val STRING: CString = c"Hello, World!" + val LONG: CLong = 1000000000000L + val LONG_WITHOUT_ENDING: CLong = 1000000000000L + val LONG_LONG: CLongLong = 1000000000000L + val MAXIMUM_SIGNED_LONG: CLong = 9223372036854775807L + val MINIMUM_SIGNED_LONG: CLong = -9223372036854775808L + val FLOAT: CDouble = 5.6 + val INT: CInt = 42 + val MAXIMUM_INT: CInt = 2147483647 + val NEW_INT: CInt = 42 + val NEG_INT: CInt = -42 + val SHOULD_BE_DEFINED: CString = c"Because INT is not equal to 0" + val OCTAL: CInt = 139 + val HEXADECIMAL: CInt = 75 + val EXPONENT: CDouble = 1e-10 + val DOT_EXPONENT: CDouble = 0.01 + val HEXADECIMAL_WITHOUT_RADIX: CDouble = 523264 + val HEXADECIMAL_WITH_RADIX: CDouble = 7.5 + val HEXADECIMAL_FRACTIONAL_WITH_RADIX: CDouble = 0.0355225 } } diff --git a/tests/samples/NativeTypes.scala b/tests/samples/NativeTypes.scala index 2778eeb..596b960 100644 --- a/tests/samples/NativeTypes.scala +++ b/tests/samples/NativeTypes.scala @@ -1,34 +1,34 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ object NativeTypes { - type size_t = native.CUnsignedInt - type ptrdiff_t = native.CUnsignedInt - type char16_t = native.CUnsignedShort - type char32_t = native.CUnsignedInt + type size_t = CUnsignedInt + type ptrdiff_t = CUnsignedInt + type char16_t = CUnsignedShort + type char32_t = CUnsignedInt type void_type = Unit - type char_type = native.CChar - type signed_char_type = native.CSignedChar - type unsigned_char_type = native.CUnsignedChar - type short_type = native.CShort - type unsigned_short_type = native.CUnsignedShort - type int_type = native.CInt - type unsigned_int_type = native.CUnsignedInt - type long_type = native.CLong - type long_int_type = native.CLong - type unsigned_long_type = native.CUnsignedLong - type unsigned_long_int_type = native.CUnsignedLong - type long_long_type = native.CLongLong - type unsigned_long_long_type = native.CUnsignedLongLong - type float_type = native.CFloat - type double_type = native.CDouble - type ptr_byte_type = native.Ptr[Byte] - type ptr_int_type = native.Ptr[native.CInt] - type cstring_type = native.CString - type size_t_type = native.CSize - type ptrdiff_t_type = native.CPtrDiff - type char16_t_type = native.CChar16 - type char32_t_type = native.CChar32 + type char_type = CChar + type signed_char_type = CSignedChar + type unsigned_char_type = CUnsignedChar + type short_type = CShort + type unsigned_short_type = CUnsignedShort + type int_type = CInt + type unsigned_int_type = CUnsignedInt + type long_type = CLong + type long_int_type = CLong + type unsigned_long_type = CUnsignedLong + type unsigned_long_int_type = CUnsignedLong + type long_long_type = CLongLong + type unsigned_long_long_type = CUnsignedLongLong + type float_type = CFloat + type double_type = CDouble + type ptr_byte_type = Ptr[Byte] + type ptr_int_type = Ptr[CInt] + type cstring_type = CString + type size_t_type = CSize + type ptrdiff_t_type = CPtrDiff + type char16_t_type = CChar16 + type char32_t_type = CChar32 } diff --git a/tests/samples/OpaqueTypes.scala b/tests/samples/OpaqueTypes.scala index a41de71..367ebdb 100644 --- a/tests/samples/OpaqueTypes.scala +++ b/tests/samples/OpaqueTypes.scala @@ -1,71 +1,71 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object OpaqueTypes { - type struct_undefinedIncludedStruct = native.CStruct0 // incomplete type + type struct_undefinedIncludedStruct = CStruct0 // incomplete type type undefinedIncludedStruct = struct_undefinedIncludedStruct - type struct_points = native.CStruct2[native.Ptr[struct_point], native.Ptr[struct_point]] + type struct_points = CStruct2[Ptr[struct_point], Ptr[struct_point]] type points = struct_points - type struct_point = native.CStruct2[native.CInt, native.CInt] - type union_u = native.CArray[Byte, native.Nat._4] + type struct_point = CStruct2[CInt, CInt] + type union_u = CArray[Byte, Nat._4] type u = union_u - type struct_undefinedStruct = native.CStruct0 // incomplete type - type struct_structWithPointerToUndefinedStruct = native.CStruct1[native.Ptr[struct_undefinedStruct]] - type union_unionWithPointerToUndefinedStruct = native.CArray[Byte, native.Nat._8] - type union_undefinedUnion = native.CStruct0 // incomplete type + type struct_undefinedStruct = CStruct0 // incomplete type + type struct_structWithPointerToUndefinedStruct = CStruct1[Ptr[struct_undefinedStruct]] + type union_unionWithPointerToUndefinedStruct = CArray[Byte, Nat._8] + type union_undefinedUnion = CStruct0 // incomplete type type undefinedUnion = union_undefinedUnion - type aliasToPointerOfUndefinedUnion = native.Ptr[undefinedUnion] + type aliasToPointerOfUndefinedUnion = Ptr[undefinedUnion] type aliasForUndefinedStruct = struct_undefinedStruct - type functionPointerWithPointerToOpaqueType = native.CFunctionPtr1[native.Ptr[native.Ptr[struct_undefinedStruct]], native.Ptr[undefinedUnion]] - def move(point: native.Ptr[struct_point], x: native.CInt, y: native.CInt): native.Ptr[struct_point] = native.extern - def processPoints(p: native.Ptr[points]): native.Ptr[union_u] = native.extern - def usePointerToUndefinedStruct(p0: native.Ptr[struct_undefinedStruct]): Unit = native.extern - def fun(): native.Ptr[native.Ptr[undefinedUnion]] = native.extern - def returnPointerToAliasOfUndefinedStruct(): native.Ptr[aliasForUndefinedStruct] = native.extern - def usePointerToUndefinedIncludedStruct(p0: native.Ptr[undefinedIncludedStruct]): Unit = native.extern + type functionPointerWithPointerToOpaqueType = CFuncPtr1[Ptr[Ptr[struct_undefinedStruct]], Ptr[undefinedUnion]] + def move(point: Ptr[struct_point], x: CInt, y: CInt): Ptr[struct_point] = extern + def processPoints(p: Ptr[points]): Ptr[union_u] = extern + def usePointerToUndefinedStruct(p0: Ptr[struct_undefinedStruct]): Unit = extern + def fun(): Ptr[Ptr[undefinedUnion]] = extern + def returnPointerToAliasOfUndefinedStruct(): Ptr[aliasForUndefinedStruct] = extern + def usePointerToUndefinedIncludedStruct(p0: Ptr[undefinedIncludedStruct]): Unit = extern object implicits { - implicit class struct_points_ops(val p: native.Ptr[struct_points]) extends AnyVal { - def point1: native.Ptr[struct_point] = !p._1 - def point1_=(value: native.Ptr[struct_point]): Unit = !p._1 = value - def point2: native.Ptr[struct_point] = !p._2 - def point2_=(value: native.Ptr[struct_point]): Unit = !p._2 = value + implicit class struct_points_ops(val p: Ptr[struct_points]) extends AnyVal { + def point1: Ptr[struct_point] = p._1 + def point1_=(value: Ptr[struct_point]): Unit = p._1 = value + def point2: Ptr[struct_point] = p._2 + def point2_=(value: Ptr[struct_point]): Unit = p._2 = value } - implicit class struct_point_ops(val p: native.Ptr[struct_point]) extends AnyVal { - def x: native.CInt = !p._1 - def x_=(value: native.CInt): Unit = !p._1 = value - def y: native.CInt = !p._2 - def y_=(value: native.CInt): Unit = !p._2 = value + implicit class struct_point_ops(val p: Ptr[struct_point]) extends AnyVal { + def x: CInt = p._1 + def x_=(value: CInt): Unit = p._1 = value + def y: CInt = p._2 + def y_=(value: CInt): Unit = p._2 = value } - implicit class struct_structWithPointerToUndefinedStruct_ops(val p: native.Ptr[struct_structWithPointerToUndefinedStruct]) extends AnyVal { - def field: native.Ptr[struct_undefinedStruct] = !p._1 - def field_=(value: native.Ptr[struct_undefinedStruct]): Unit = !p._1 = value + implicit class struct_structWithPointerToUndefinedStruct_ops(val p: Ptr[struct_structWithPointerToUndefinedStruct]) extends AnyVal { + def field: Ptr[struct_undefinedStruct] = p._1 + def field_=(value: Ptr[struct_undefinedStruct]): Unit = p._1 = value } - implicit class union_u_pos(val p: native.Ptr[union_u]) extends AnyVal { - def i: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]] - def i_=(value: native.CInt): Unit = !p.cast[native.Ptr[native.CInt]] = value - def f: native.Ptr[native.CFloat] = p.cast[native.Ptr[native.CFloat]] - def f_=(value: native.CFloat): Unit = !p.cast[native.Ptr[native.CFloat]] = value + implicit class union_u_pos(val p: Ptr[union_u]) extends AnyVal { + def i: Ptr[CInt] = p.asInstanceOf[Ptr[CInt]] + def i_=(value: CInt): Unit = !p.asInstanceOf[Ptr[CInt]] = value + def f: Ptr[CFloat] = p.asInstanceOf[Ptr[CFloat]] + def f_=(value: CFloat): Unit = !p.asInstanceOf[Ptr[CFloat]] = value } - implicit class union_unionWithPointerToUndefinedStruct_pos(val p: native.Ptr[union_unionWithPointerToUndefinedStruct]) extends AnyVal { - def field: native.Ptr[native.Ptr[struct_undefinedStruct]] = p.cast[native.Ptr[native.Ptr[struct_undefinedStruct]]] - def field_=(value: native.Ptr[struct_undefinedStruct]): Unit = !p.cast[native.Ptr[native.Ptr[struct_undefinedStruct]]] = value + implicit class union_unionWithPointerToUndefinedStruct_pos(val p: Ptr[union_unionWithPointerToUndefinedStruct]) extends AnyVal { + def field: Ptr[Ptr[struct_undefinedStruct]] = p.asInstanceOf[Ptr[Ptr[struct_undefinedStruct]]] + def field_=(value: Ptr[struct_undefinedStruct]): Unit = !p.asInstanceOf[Ptr[Ptr[struct_undefinedStruct]]] = value } } object struct_points { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_points] = native.alloc[struct_points] - def apply(point1: native.Ptr[struct_point], point2: native.Ptr[struct_point])(implicit z: native.Zone): native.Ptr[struct_points] = { - val ptr = native.alloc[struct_points] + def apply()(implicit z: Zone): Ptr[struct_points] = alloc[struct_points] + def apply(point1: Ptr[struct_point], point2: Ptr[struct_point])(implicit z: Zone): Ptr[struct_points] = { + val ptr = alloc[struct_points] ptr.point1 = point1 ptr.point2 = point2 ptr @@ -74,9 +74,9 @@ object OpaqueTypes { object struct_point { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_point] = native.alloc[struct_point] - def apply(x: native.CInt, y: native.CInt)(implicit z: native.Zone): native.Ptr[struct_point] = { - val ptr = native.alloc[struct_point] + def apply()(implicit z: Zone): Ptr[struct_point] = alloc[struct_point] + def apply(x: CInt, y: CInt)(implicit z: Zone): Ptr[struct_point] = { + val ptr = alloc[struct_point] ptr.x = x ptr.y = y ptr @@ -85,9 +85,9 @@ object OpaqueTypes { object struct_structWithPointerToUndefinedStruct { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_structWithPointerToUndefinedStruct] = native.alloc[struct_structWithPointerToUndefinedStruct] - def apply(field: native.Ptr[struct_undefinedStruct])(implicit z: native.Zone): native.Ptr[struct_structWithPointerToUndefinedStruct] = { - val ptr = native.alloc[struct_structWithPointerToUndefinedStruct] + def apply()(implicit z: Zone): Ptr[struct_structWithPointerToUndefinedStruct] = alloc[struct_structWithPointerToUndefinedStruct] + def apply(field: Ptr[struct_undefinedStruct])(implicit z: Zone): Ptr[struct_structWithPointerToUndefinedStruct] = { + val ptr = alloc[struct_structWithPointerToUndefinedStruct] ptr.field = field ptr } diff --git a/tests/samples/PrivateMembers.scala b/tests/samples/PrivateMembers.scala index 9cdb9e5..a853700 100644 --- a/tests/samples/PrivateMembers.scala +++ b/tests/samples/PrivateMembers.scala @@ -1,78 +1,78 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object PrivateMembers { - type enum___privateEnum = native.CUnsignedInt + type enum___privateEnum = CUnsignedInt object enum___privateEnum { final val A: enum___privateEnum = 0.toUInt final val B: enum___privateEnum = 1.toUInt } - type enum_enumWithPrivateMembers = native.CUnsignedInt + type enum_enumWithPrivateMembers = CUnsignedInt object enum_enumWithPrivateMembers { final val __C: enum_enumWithPrivateMembers = 0.toUInt final val D: enum_enumWithPrivateMembers = 1.toUInt } - type enum_anonymous_0 = native.CUnsignedInt + type enum_anonymous_0 = CUnsignedInt object enum_anonymous_0 { final val __E: enum_anonymous_0 = 0.toUInt final val F: enum_anonymous_0 = 1.toUInt } - type pid_t = native.CInt - type __private_type = native.CInt - type struct_structWithPrivateType = native.CStruct2[native.CInt, __private_type] - type union___unionWithPrivateName = native.CArray[Byte, native.Nat._4] - type struct_structWithPrivateStruct = native.CStruct1[native.Ptr[struct_structWithPrivateType]] - type struct_normalStruct = native.CStruct1[native.CInt] - type struct_privateStructWithTypedef = native.CStruct1[native.Ptr[__private_type]] + type pid_t = CInt + type __private_type = CInt + type struct_structWithPrivateType = CStruct2[CInt, __private_type] + type union___unionWithPrivateName = CArray[Byte, Nat._4] + type struct_structWithPrivateStruct = CStruct1[Ptr[struct_structWithPrivateType]] + type struct_normalStruct = CStruct1[CInt] + type struct_privateStructWithTypedef = CStruct1[Ptr[__private_type]] type privateStructWithTypedef = struct_privateStructWithTypedef - type privateStructWithTypedefPtr = native.Ptr[struct_privateStructWithTypedef] - def getTypeThatUsesPrivateTypes(): pid_t = native.extern - def getPrivateType(): native.Ptr[__private_type] = native.extern - def usesPrivateUnion(p0: native.Ptr[union___unionWithPrivateName]): Unit = native.extern - def usesPrivateStruct(p0: native.Ptr[struct_structWithPrivateType], p1: native.Ptr[struct_normalStruct]): Unit = native.extern - def usesPrivateEnum(p0: native.Ptr[enum___privateEnum]): Unit = native.extern + type privateStructWithTypedefPtr = Ptr[struct_privateStructWithTypedef] + def getTypeThatUsesPrivateTypes(): pid_t = extern + def getPrivateType(): Ptr[__private_type] = extern + def usesPrivateUnion(p0: Ptr[union___unionWithPrivateName]): Unit = extern + def usesPrivateStruct(p0: Ptr[struct_structWithPrivateType], p1: Ptr[struct_normalStruct]): Unit = extern + def usesPrivateEnum(p0: Ptr[enum___privateEnum]): Unit = extern object implicits { - implicit class struct_structWithPrivateType_ops(val p: native.Ptr[struct_structWithPrivateType]) extends AnyVal { - def field1: native.CInt = !p._1 - def field1_=(value: native.CInt): Unit = !p._1 = value - def field2: __private_type = !p._2 - def field2_=(value: __private_type): Unit = !p._2 = value + implicit class struct_structWithPrivateType_ops(val p: Ptr[struct_structWithPrivateType]) extends AnyVal { + def field1: CInt = p._1 + def field1_=(value: CInt): Unit = p._1 = value + def field2: __private_type = p._2 + def field2_=(value: __private_type): Unit = p._2 = value } - implicit class struct_structWithPrivateStruct_ops(val p: native.Ptr[struct_structWithPrivateStruct]) extends AnyVal { - def s: native.Ptr[struct_structWithPrivateType] = !p._1 - def s_=(value: native.Ptr[struct_structWithPrivateType]): Unit = !p._1 = value + implicit class struct_structWithPrivateStruct_ops(val p: Ptr[struct_structWithPrivateStruct]) extends AnyVal { + def s: Ptr[struct_structWithPrivateType] = p._1 + def s_=(value: Ptr[struct_structWithPrivateType]): Unit = p._1 = value } - implicit class struct_normalStruct_ops(val p: native.Ptr[struct_normalStruct]) extends AnyVal { - def a: native.CInt = !p._1 - def a_=(value: native.CInt): Unit = !p._1 = value + implicit class struct_normalStruct_ops(val p: Ptr[struct_normalStruct]) extends AnyVal { + def a: CInt = p._1 + def a_=(value: CInt): Unit = p._1 = value } - implicit class struct_privateStructWithTypedef_ops(val p: native.Ptr[struct_privateStructWithTypedef]) extends AnyVal { - def a: native.Ptr[__private_type] = !p._1 - def a_=(value: native.Ptr[__private_type]): Unit = !p._1 = value + implicit class struct_privateStructWithTypedef_ops(val p: Ptr[struct_privateStructWithTypedef]) extends AnyVal { + def a: Ptr[__private_type] = p._1 + def a_=(value: Ptr[__private_type]): Unit = p._1 = value } - implicit class union___unionWithPrivateName_pos(val p: native.Ptr[union___unionWithPrivateName]) extends AnyVal { - def a: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]] - def a_=(value: native.CInt): Unit = !p.cast[native.Ptr[native.CInt]] = value + implicit class union___unionWithPrivateName_pos(val p: Ptr[union___unionWithPrivateName]) extends AnyVal { + def a: Ptr[CInt] = p.asInstanceOf[Ptr[CInt]] + def a_=(value: CInt): Unit = !p.asInstanceOf[Ptr[CInt]] = value } } object struct_structWithPrivateType { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_structWithPrivateType] = native.alloc[struct_structWithPrivateType] - def apply(field1: native.CInt, field2: __private_type)(implicit z: native.Zone): native.Ptr[struct_structWithPrivateType] = { - val ptr = native.alloc[struct_structWithPrivateType] + def apply()(implicit z: Zone): Ptr[struct_structWithPrivateType] = alloc[struct_structWithPrivateType] + def apply(field1: CInt, field2: __private_type)(implicit z: Zone): Ptr[struct_structWithPrivateType] = { + val ptr = alloc[struct_structWithPrivateType] ptr.field1 = field1 ptr.field2 = field2 ptr @@ -81,9 +81,9 @@ object PrivateMembers { object struct_structWithPrivateStruct { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_structWithPrivateStruct] = native.alloc[struct_structWithPrivateStruct] - def apply(s: native.Ptr[struct_structWithPrivateType])(implicit z: native.Zone): native.Ptr[struct_structWithPrivateStruct] = { - val ptr = native.alloc[struct_structWithPrivateStruct] + def apply()(implicit z: Zone): Ptr[struct_structWithPrivateStruct] = alloc[struct_structWithPrivateStruct] + def apply(s: Ptr[struct_structWithPrivateType])(implicit z: Zone): Ptr[struct_structWithPrivateStruct] = { + val ptr = alloc[struct_structWithPrivateStruct] ptr.s = s ptr } @@ -91,9 +91,9 @@ object PrivateMembers { object struct_normalStruct { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_normalStruct] = native.alloc[struct_normalStruct] - def apply(a: native.CInt)(implicit z: native.Zone): native.Ptr[struct_normalStruct] = { - val ptr = native.alloc[struct_normalStruct] + def apply()(implicit z: Zone): Ptr[struct_normalStruct] = alloc[struct_normalStruct] + def apply(a: CInt)(implicit z: Zone): Ptr[struct_normalStruct] = { + val ptr = alloc[struct_normalStruct] ptr.a = a ptr } @@ -101,9 +101,9 @@ object PrivateMembers { object struct_privateStructWithTypedef { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_privateStructWithTypedef] = native.alloc[struct_privateStructWithTypedef] - def apply(a: native.Ptr[__private_type])(implicit z: native.Zone): native.Ptr[struct_privateStructWithTypedef] = { - val ptr = native.alloc[struct_privateStructWithTypedef] + def apply()(implicit z: Zone): Ptr[struct_privateStructWithTypedef] = alloc[struct_privateStructWithTypedef] + def apply(a: Ptr[__private_type])(implicit z: Zone): Ptr[struct_privateStructWithTypedef] = { + val ptr = alloc[struct_privateStructWithTypedef] ptr.a = a ptr } diff --git a/tests/samples/ReservedWords.scala b/tests/samples/ReservedWords.scala index 4ed1c03..0a7e456 100644 --- a/tests/samples/ReservedWords.scala +++ b/tests/samples/ReservedWords.scala @@ -1,63 +1,63 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object ReservedWords { - type `match` = native.CInt - type `var` = native.CArray[`match`, native.Nat._5] - type struct_object = native.CStruct2[`match`, native.CInt] + type `match` = CInt + type `var` = CArray[`match`, Nat._5] + type struct_object = CStruct2[`match`, CInt] type `object` = struct_object type `type` = struct_object - type struct_anonymous_0 = native.CStruct2[native.CChar, native.Ptr[`type`]] - type union_lazy = native.CArray[Byte, native.Nat._8] + type struct_anonymous_0 = CStruct2[CChar, Ptr[`type`]] + type union_lazy = CArray[Byte, Nat._8] type `lazy` = union_lazy type `def` = `match` - type struct_finally = native.CStruct2[`def`, `lazy`] + type struct_finally = CStruct2[`def`, `lazy`] type `finally` = struct_finally - def `with`(`sealed`: `match`, `implicit`: native.Ptr[`match`], `forSome`: native.Ptr[`lazy`]): native.Ptr[`type`] = native.extern - def `implicit`(`type`: native.Ptr[`finally`]): `match` = native.extern - def _1(): Unit = native.extern + def `with`(`sealed`: `match`, `implicit`: Ptr[`match`], `forSome`: Ptr[`lazy`]): Ptr[`type`] = extern + def `implicit`(`type`: Ptr[`finally`]): `match` = extern + def _1(): Unit = extern object implicits { - implicit class struct_object_ops(val p: native.Ptr[struct_object]) extends AnyVal { - def `yield`: `match` = !p._1 - def `yield_=`(value: `match`): Unit = !p._1 = value - def `val`: native.CInt = !p._2 - def `val_=`(value: native.CInt): Unit = !p._2 = value + implicit class struct_object_ops(val p: Ptr[struct_object]) extends AnyVal { + def `yield`: `match` = p._1 + def `yield_=`(value: `match`): Unit = p._1 = value + def `val`: CInt = p._2 + def `val_=`(value: CInt): Unit = p._2 = value } - implicit class struct_anonymous_0_ops(val p: native.Ptr[struct_anonymous_0]) extends AnyVal { - def `def`: native.CChar = !p._1 - def `def_=`(value: native.CChar): Unit = !p._1 = value - def `super`: native.Ptr[`type`] = !p._2 - def `super_=`(value: native.Ptr[`type`]): Unit = !p._2 = value + implicit class struct_anonymous_0_ops(val p: Ptr[struct_anonymous_0]) extends AnyVal { + def `def`: CChar = p._1 + def `def_=`(value: CChar): Unit = p._1 = value + def `super`: Ptr[`type`] = p._2 + def `super_=`(value: Ptr[`type`]): Unit = p._2 = value } - implicit class struct_finally_ops(val p: native.Ptr[struct_finally]) extends AnyVal { - def `val`: `def` = !p._1 - def `val_=`(value: `def`): Unit = !p._1 = value - def `finally`: native.Ptr[`lazy`] = p._2 - def `finally_=`(value: native.Ptr[`lazy`]): Unit = !p._2 = !value + implicit class struct_finally_ops(val p: Ptr[struct_finally]) extends AnyVal { + def `val`: `def` = p._1 + def `val_=`(value: `def`): Unit = p._1 = value + def `finally`: Ptr[`lazy`] = p._2.asInstanceOf[Ptr[`lazy`]] + def `finally_=`(value: Ptr[`lazy`]): Unit = p._2 = !value } - implicit class union_lazy_pos(val p: native.Ptr[union_lazy]) extends AnyVal { - def instance: native.Ptr[native.Ptr[`object`]] = p.cast[native.Ptr[native.Ptr[`object`]]] - def instance_=(value: native.Ptr[`object`]): Unit = !p.cast[native.Ptr[native.Ptr[`object`]]] = value - def `forSome`: native.Ptr[`match`] = p.cast[native.Ptr[`match`]] - def `forSome_=`(value: `match`): Unit = !p.cast[native.Ptr[`match`]] = value - def `implicit`: native.Ptr[native.Ptr[struct_anonymous_0]] = p.cast[native.Ptr[native.Ptr[struct_anonymous_0]]] - def `implicit_=`(value: native.Ptr[struct_anonymous_0]): Unit = !p.cast[native.Ptr[native.Ptr[struct_anonymous_0]]] = value + implicit class union_lazy_ops(val p: Ptr[union_lazy]) extends AnyVal { + def instance: Ptr[Ptr[`object`]] = p.asInstanceOf[Ptr[Ptr[`object`]]] + def instance_=(value: Ptr[`object`]): Unit = !p.asInstanceOf[Ptr[Ptr[`object`]]] = value + def `forSome`: Ptr[`match`] = p.asInstanceOf[Ptr[`match`]] + def `forSome_=`(value: `match`): Unit = !p.asInstanceOf[Ptr[`match`]] = value + def `implicit`: Ptr[Ptr[struct_anonymous_0]] = p.asInstanceOf[Ptr[Ptr[struct_anonymous_0]]] + def `implicit_=`(value: Ptr[struct_anonymous_0]): Unit = !p.asInstanceOf[Ptr[Ptr[struct_anonymous_0]]] = value } } object struct_object { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_object] = native.alloc[struct_object] - def apply(`yield`: `match`, `val`: native.CInt)(implicit z: native.Zone): native.Ptr[struct_object] = { - val ptr = native.alloc[struct_object] + def apply()(implicit z: Zone): Ptr[struct_object] = alloc[struct_object] + def apply(`yield`: `match`, `val`: CInt)(implicit z: Zone): Ptr[struct_object] = { + val ptr = alloc[struct_object] ptr.`yield` = `yield` ptr.`val` = `val` ptr @@ -66,9 +66,9 @@ object ReservedWords { object struct_anonymous_0 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_anonymous_0] = native.alloc[struct_anonymous_0] - def apply(`def`: native.CChar, `super`: native.Ptr[`type`])(implicit z: native.Zone): native.Ptr[struct_anonymous_0] = { - val ptr = native.alloc[struct_anonymous_0] + def apply()(implicit z: Zone): Ptr[struct_anonymous_0] = alloc[struct_anonymous_0] + def apply(`def`: CChar, `super`: Ptr[`type`])(implicit z: Zone): Ptr[struct_anonymous_0] = { + val ptr = alloc[struct_anonymous_0] ptr.`def` = `def` ptr.`super` = `super` ptr @@ -77,9 +77,9 @@ object ReservedWords { object struct_finally { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_finally] = native.alloc[struct_finally] - def apply(`val`: `def`, `finally`: native.Ptr[`lazy`])(implicit z: native.Zone): native.Ptr[struct_finally] = { - val ptr = native.alloc[struct_finally] + def apply()(implicit z: Zone): Ptr[struct_finally] = alloc[struct_finally] + def apply(`val`: `def`, `finally`: Ptr[`lazy`])(implicit z: Zone): Ptr[struct_finally] = { + val ptr = alloc[struct_finally] ptr.`val` = `val` ptr.`finally` = `finally` ptr diff --git a/tests/samples/ReuseBindings.scala b/tests/samples/ReuseBindings.scala index 91553cd..251687c 100644 --- a/tests/samples/ReuseBindings.scala +++ b/tests/samples/ReuseBindings.scala @@ -1,35 +1,35 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object ReuseBindings { type aliasForBigStruct = org.scalanative.bindgen.samples.Struct.struct_bigStruct - type struct_usesImportedEnum = native.CStruct2[org.scalanative.bindgen.samples.Struct.enum_pointIndex, org.scalanative.bindgen.samples.CustomNames.weight] - def useStruct(p0: native.Ptr[org.scalanative.bindgen.samples.Struct.struct_point]): Unit = native.extern - def returnTypedef_point_s(): native.Ptr[org.scalanative.bindgen.samples.Struct.struct_point] = native.extern - def returnTypedef_point(): native.Ptr[org.scalanative.bindgen.samples.Struct.point] = native.extern - def readBook(book: native.Ptr[org.scalanative.bindgen.samples.CustomNames.book]): Unit = native.extern - def getWeight(weight: native.Ptr[org.scalanative.bindgen.samples.CustomNames.weight]): Unit = native.extern - def getMyInt(): org.scalanative.bindgen.samples.CustomNames.MY_INT = native.extern - def getEnum(): org.scalanative.bindgen.samples.CustomNames.EnumWithTypedef = native.extern + type struct_usesImportedEnum = CStruct2[org.scalanative.bindgen.samples.Struct.enum_pointIndex, org.scalanative.bindgen.samples.CustomNames.weight] + def useStruct(p0: Ptr[org.scalanative.bindgen.samples.Struct.struct_point]): Unit = extern + def returnTypedef_point_s(): Ptr[org.scalanative.bindgen.samples.Struct.struct_point] = extern + def returnTypedef_point(): Ptr[org.scalanative.bindgen.samples.Struct.point] = extern + def readBook(book: Ptr[org.scalanative.bindgen.samples.CustomNames.book]): Unit = extern + def getWeight(weight: Ptr[org.scalanative.bindgen.samples.CustomNames.weight]): Unit = extern + def getMyInt(): org.scalanative.bindgen.samples.CustomNames.MY_INT = extern + def getEnum(): org.scalanative.bindgen.samples.CustomNames.EnumWithTypedef = extern object implicits { - implicit class struct_usesImportedEnum_ops(val p: native.Ptr[struct_usesImportedEnum]) extends AnyVal { - def index: org.scalanative.bindgen.samples.Struct.enum_pointIndex = !p._1 - def index_=(value: org.scalanative.bindgen.samples.Struct.enum_pointIndex): Unit = !p._1 = value - def weight: native.Ptr[org.scalanative.bindgen.samples.CustomNames.weight] = p._2 - def weight_=(value: native.Ptr[org.scalanative.bindgen.samples.CustomNames.weight]): Unit = !p._2 = !value + implicit class struct_usesImportedEnum_ops(val p: Ptr[struct_usesImportedEnum]) extends AnyVal { + def index: org.scalanative.bindgen.samples.Struct.enum_pointIndex = p._1 + def index_=(value: org.scalanative.bindgen.samples.Struct.enum_pointIndex): Unit = p._1 = value + def weight: Ptr[org.scalanative.bindgen.samples.CustomNames.weight] = p._2.asInstanceOf[Ptr[org.scalanative.bindgen.samples.CustomNames.weight]] + def weight_=(value: Ptr[org.scalanative.bindgen.samples.CustomNames.weight]): Unit = p._2 = value } } object struct_usesImportedEnum { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_usesImportedEnum] = native.alloc[struct_usesImportedEnum] - def apply(index: org.scalanative.bindgen.samples.Struct.enum_pointIndex, weight: native.Ptr[org.scalanative.bindgen.samples.CustomNames.weight])(implicit z: native.Zone): native.Ptr[struct_usesImportedEnum] = { - val ptr = native.alloc[struct_usesImportedEnum] + def apply()(implicit z: Zone): Ptr[struct_usesImportedEnum] = alloc[struct_usesImportedEnum] + def apply(index: org.scalanative.bindgen.samples.Struct.enum_pointIndex, weight: Ptr[org.scalanative.bindgen.samples.CustomNames.weight])(implicit z: Zone): Ptr[struct_usesImportedEnum] = { + val ptr = alloc[struct_usesImportedEnum] ptr.index = index ptr.weight = weight ptr diff --git a/tests/samples/Struct.c b/tests/samples/Struct.c index cce03f8..b01b5c8 100644 --- a/tests/samples/Struct.c +++ b/tests/samples/Struct.c @@ -1,5 +1,6 @@ #include "Struct.h" #include +#include void setPoints(struct points *points, int x1, int y1, int x2, int y2) { points->p1.x = x1; @@ -48,6 +49,26 @@ int struct_test_long(struct bigStruct *s, enum struct_op op, long value) { } } +int struct_test_char(struct bigStruct *s, enum struct_op op, char value) { + switch (op) { + case STRUCT_SET: + s->two = value; + return 1; + case STRUCT_TEST: + return s->two == value; + } +} + +int struct_test_int(struct bigStruct *s, enum struct_op op, int value) { + switch (op) { + case STRUCT_SET: + s->three = value; + return 1; + case STRUCT_TEST: + return s->three == value; + } +} + int struct_test_double(struct bigStruct *s, enum struct_op op, double value) { switch (op) { case STRUCT_SET: @@ -65,6 +86,7 @@ int struct_test_point(struct bigStruct *s, enum struct_op op, s->six = *value; return 1; case STRUCT_TEST: + printf("s->six.x %d, value->x %d, s->six.y %d , value->y %d\n", s->six.x, value->x, s->six.y, value->y); return (s->six.x == value->x) && (s->six.y == value->y); } } diff --git a/tests/samples/Struct.h b/tests/samples/Struct.h index 823d935..9da2d7b 100644 --- a/tests/samples/Struct.h +++ b/tests/samples/Struct.h @@ -79,6 +79,8 @@ char getIntFromAnonymousStruct(struct structWithAnonymousStruct *s); enum struct_op { STRUCT_SET, STRUCT_TEST }; +int struct_test_char(struct bigStruct *s, enum struct_op op, char value); +int struct_test_int(struct bigStruct *s, enum struct_op op, int value); int struct_test_long(struct bigStruct *s, enum struct_op op, long value); int struct_test_double(struct bigStruct *s, enum struct_op op, double value); int struct_test_point(struct bigStruct *s, enum struct_op op, diff --git a/tests/samples/Struct.scala b/tests/samples/Struct.scala index 75e4683..3f297b8 100644 --- a/tests/samples/Struct.scala +++ b/tests/samples/Struct.scala @@ -1,12 +1,12 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object Struct { - type enum_pointIndex = native.CUnsignedInt + type enum_pointIndex = CUnsignedInt object enum_pointIndex { final val X1: enum_pointIndex = 0.toUInt final val Y1: enum_pointIndex = 1.toUInt @@ -14,116 +14,118 @@ object Struct { final val Y2: enum_pointIndex = 3.toUInt } - type enum_struct_op = native.CUnsignedInt + type enum_struct_op = CUnsignedInt object enum_struct_op { final val STRUCT_SET: enum_struct_op = 0.toUInt final val STRUCT_TEST: enum_struct_op = 1.toUInt } - type struct_point = native.CStruct2[native.CInt, native.CInt] + type struct_point = CStruct2[CInt, CInt] type point = struct_point - type struct_points = native.CStruct2[struct_point, point] - type point_s = native.Ptr[struct_point] - type struct_bigStruct = native.CArray[Byte, native.Nat.Digit[native.Nat._1, native.Nat.Digit[native.Nat._1, native.Nat._2]]] - type struct_anonymous_0 = native.CStruct2[native.CChar, native.CInt] - type struct_structWithAnonymousStruct = native.CStruct2[native.CInt, struct_anonymous_0] - type struct_packedStruct = native.CStruct1[native.CChar] - type struct_bitFieldStruct = native.CArray[Byte, native.Nat._2] - type struct_bitFieldOffsetDivByEight = native.CArray[Byte, native.Nat._4] - def setPoints(points: native.Ptr[struct_points], x1: native.CInt, y1: native.CInt, x2: native.CInt, y2: native.CInt): Unit = native.extern - def getPoint(points: native.Ptr[struct_points], pointIndex: enum_pointIndex): native.CInt = native.extern - def createPoint(): native.Ptr[struct_point] = native.extern - def getBigStructSize(): native.CInt = native.extern - def getCharFromAnonymousStruct(s: native.Ptr[struct_structWithAnonymousStruct]): native.CChar = native.extern - def getIntFromAnonymousStruct(s: native.Ptr[struct_structWithAnonymousStruct]): native.CChar = native.extern - def struct_test_long(s: native.Ptr[struct_bigStruct], op: enum_struct_op, value: native.CLong): native.CInt = native.extern - def struct_test_double(s: native.Ptr[struct_bigStruct], op: enum_struct_op, value: native.CDouble): native.CInt = native.extern - def struct_test_point(s: native.Ptr[struct_bigStruct], op: enum_struct_op, value: native.Ptr[struct_point]): native.CInt = native.extern + type struct_points = CStruct2[struct_point, point] + type point_s = Ptr[struct_point] + type struct_bigStruct = CArray[Byte, Nat.Digit3[Nat._1, Nat._1, Nat._2]] + type struct_anonymous_0 = CStruct2[CChar, CInt] + type struct_structWithAnonymousStruct = CStruct2[CInt, struct_anonymous_0] + type struct_packedStruct = CStruct1[CChar] + type struct_bitFieldStruct = CArray[Byte, Nat._2] + type struct_bitFieldOffsetDivByEight = CArray[Byte, Nat._4] + def setPoints(points: Ptr[struct_points], x1: CInt, y1: CInt, x2: CInt, y2: CInt): Unit = extern + def getPoint(points: Ptr[struct_points], pointIndex: enum_pointIndex): CInt = extern + def createPoint(): Ptr[struct_point] = extern + def getBigStructSize(): CInt = extern + def getCharFromAnonymousStruct(s: Ptr[struct_structWithAnonymousStruct]): CChar = extern + def getIntFromAnonymousStruct(s: Ptr[struct_structWithAnonymousStruct]): CChar = extern + def struct_test_char(s: Ptr[struct_bigStruct], op: enum_struct_op, value: CChar): CInt = extern + def struct_test_int(s: Ptr[struct_bigStruct], op: enum_struct_op, value: CInt): CInt = extern + def struct_test_long(s: Ptr[struct_bigStruct], op: enum_struct_op, value: CLong): CInt = extern + def struct_test_double(s: Ptr[struct_bigStruct], op: enum_struct_op, value: CDouble): CInt = extern + def struct_test_point(s: Ptr[struct_bigStruct], op: enum_struct_op, value: Ptr[struct_point]): CInt = extern object implicits { - implicit class struct_point_ops(val p: native.Ptr[struct_point]) extends AnyVal { - def x: native.CInt = !p._1 - def x_=(value: native.CInt): Unit = !p._1 = value - def y: native.CInt = !p._2 - def y_=(value: native.CInt): Unit = !p._2 = value + implicit class struct_point_ops(val p: Ptr[struct_point]) extends AnyVal { + def x: CInt = p._1 + def x_=(value: CInt): Unit = p._1 = value + def y: CInt = p._2 + def y_=(value: CInt): Unit = p._2 = value } - implicit class struct_points_ops(val p: native.Ptr[struct_points]) extends AnyVal { - def p1: native.Ptr[struct_point] = p._1 - def p1_=(value: native.Ptr[struct_point]): Unit = !p._1 = !value - def p2: native.Ptr[point] = p._2 - def p2_=(value: native.Ptr[point]): Unit = !p._2 = !value + implicit class struct_points_ops(val p: Ptr[struct_points]) extends AnyVal { + def p1: Ptr[struct_point] = p.at1 + def p1_=(value: Ptr[struct_point]): Unit = !p.at1 = value + def p2: Ptr[point] = p.at2 + def p2_=(value: Ptr[point]): Unit = !p.at2 = value } - implicit class struct_bigStruct_ops(val p: native.Ptr[struct_bigStruct]) extends AnyVal { - def one: native.CLong = !p._1.cast[native.Ptr[native.CLong]] - def one_=(value: native.CLong): Unit = !p._1.cast[native.Ptr[native.CLong]] = value - def two: native.CChar = !(p._1 + 8).cast[native.Ptr[native.CChar]] - def two_=(value: native.CChar): Unit = !(p._1 + 8).cast[native.Ptr[native.CChar]] = value - def three: native.CInt = !(p._1 + 12).cast[native.Ptr[native.CInt]] - def three_=(value: native.CInt): Unit = !(p._1 + 12).cast[native.Ptr[native.CInt]] = value - def four: native.CFloat = !(p._1 + 16).cast[native.Ptr[native.CFloat]] - def four_=(value: native.CFloat): Unit = !(p._1 + 16).cast[native.Ptr[native.CFloat]] = value - def five: native.CDouble = !(p._1 + 24).cast[native.Ptr[native.CDouble]] - def five_=(value: native.CDouble): Unit = !(p._1 + 24).cast[native.Ptr[native.CDouble]] = value - def six: native.Ptr[struct_point] = (p._1 + 32).cast[native.Ptr[struct_point]] - def six_=(value: native.Ptr[struct_point]): Unit = !(p._1 + 32).cast[native.Ptr[struct_point]] = !value - def seven: native.Ptr[struct_point] = !(p._1 + 40).cast[native.Ptr[native.Ptr[struct_point]]] - def seven_=(value: native.Ptr[struct_point]): Unit = !(p._1 + 40).cast[native.Ptr[native.Ptr[struct_point]]] = value - def eight: native.CInt = !(p._1 + 48).cast[native.Ptr[native.CInt]] - def eight_=(value: native.CInt): Unit = !(p._1 + 48).cast[native.Ptr[native.CInt]] = value - def nine: native.CInt = !(p._1 + 52).cast[native.Ptr[native.CInt]] - def nine_=(value: native.CInt): Unit = !(p._1 + 52).cast[native.Ptr[native.CInt]] = value - def ten: native.CInt = !(p._1 + 56).cast[native.Ptr[native.CInt]] - def ten_=(value: native.CInt): Unit = !(p._1 + 56).cast[native.Ptr[native.CInt]] = value - def eleven: native.CInt = !(p._1 + 60).cast[native.Ptr[native.CInt]] - def eleven_=(value: native.CInt): Unit = !(p._1 + 60).cast[native.Ptr[native.CInt]] = value - def twelve: native.CInt = !(p._1 + 64).cast[native.Ptr[native.CInt]] - def twelve_=(value: native.CInt): Unit = !(p._1 + 64).cast[native.Ptr[native.CInt]] = value - def thirteen: native.CInt = !(p._1 + 68).cast[native.Ptr[native.CInt]] - def thirteen_=(value: native.CInt): Unit = !(p._1 + 68).cast[native.Ptr[native.CInt]] = value - def fourteen: native.CInt = !(p._1 + 72).cast[native.Ptr[native.CInt]] - def fourteen_=(value: native.CInt): Unit = !(p._1 + 72).cast[native.Ptr[native.CInt]] = value - def fifteen: native.CInt = !(p._1 + 76).cast[native.Ptr[native.CInt]] - def fifteen_=(value: native.CInt): Unit = !(p._1 + 76).cast[native.Ptr[native.CInt]] = value - def sixteen: native.CInt = !(p._1 + 80).cast[native.Ptr[native.CInt]] - def sixteen_=(value: native.CInt): Unit = !(p._1 + 80).cast[native.Ptr[native.CInt]] = value - def seventeen: native.CInt = !(p._1 + 84).cast[native.Ptr[native.CInt]] - def seventeen_=(value: native.CInt): Unit = !(p._1 + 84).cast[native.Ptr[native.CInt]] = value - def eighteen: native.CInt = !(p._1 + 88).cast[native.Ptr[native.CInt]] - def eighteen_=(value: native.CInt): Unit = !(p._1 + 88).cast[native.Ptr[native.CInt]] = value - def nineteen: native.CInt = !(p._1 + 92).cast[native.Ptr[native.CInt]] - def nineteen_=(value: native.CInt): Unit = !(p._1 + 92).cast[native.Ptr[native.CInt]] = value - def twenty: native.CInt = !(p._1 + 96).cast[native.Ptr[native.CInt]] - def twenty_=(value: native.CInt): Unit = !(p._1 + 96).cast[native.Ptr[native.CInt]] = value - def twentyOne: native.CInt = !(p._1 + 100).cast[native.Ptr[native.CInt]] - def twentyOne_=(value: native.CInt): Unit = !(p._1 + 100).cast[native.Ptr[native.CInt]] = value - def twentyTwo: native.CInt = !(p._1 + 104).cast[native.Ptr[native.CInt]] - def twentyTwo_=(value: native.CInt): Unit = !(p._1 + 104).cast[native.Ptr[native.CInt]] = value - def twentyThree: native.CInt = !(p._1 + 108).cast[native.Ptr[native.CInt]] - def twentyThree_=(value: native.CInt): Unit = !(p._1 + 108).cast[native.Ptr[native.CInt]] = value + implicit class struct_bigStruct_ops(val p: Ptr[struct_bigStruct]) extends AnyVal { + def one: CLong = !p.asInstanceOf[Ptr[CLong]] + def one_=(value: CLong): Unit = !p.asInstanceOf[Ptr[CLong]] = value + def two: CChar = !p.at(8).asInstanceOf[Ptr[CChar]] + def two_=(value: CChar): Unit = !p.at(8).asInstanceOf[Ptr[CChar]] = value + def three: CInt = !p.at(12).asInstanceOf[Ptr[CInt]] + def three_=(value: CInt): Unit = !p.at(12).asInstanceOf[Ptr[CInt]] = value + def four: CFloat = !p.at(16).asInstanceOf[Ptr[CFloat]] + def four_=(value: CFloat): Unit = !p.at(16).asInstanceOf[Ptr[CFloat]] = value + def five: CDouble = !p.at(24).asInstanceOf[Ptr[CDouble]] + def five_=(value: CDouble): Unit = !p.at(24).asInstanceOf[Ptr[CDouble]] = value + def six: Ptr[struct_point] = p.at(32).asInstanceOf[Ptr[struct_point]] + def six_=(value: Ptr[struct_point]): Unit = !p.at(32).asInstanceOf[Ptr[Ptr[struct_point]]] = value + def seven: Ptr[struct_point] = p.at(40).asInstanceOf[Ptr[struct_point]] + def seven_=(value: Ptr[struct_point]): Unit = !p.at(40).asInstanceOf[Ptr[Ptr[struct_point]]] = value + def eight: CInt = !p.at(48).asInstanceOf[Ptr[CInt]] + def eight_=(value: CInt): Unit = !p.at(48).asInstanceOf[Ptr[CInt]] = value + def nine: CInt = !p.at(52).asInstanceOf[Ptr[CInt]] + def nine_=(value: CInt): Unit = !p.at(52).asInstanceOf[Ptr[CInt]] = value + def ten: CInt = !p.at(56).asInstanceOf[Ptr[CInt]] + def ten_=(value: CInt): Unit = !p.at(56).asInstanceOf[Ptr[CInt]] = value + def eleven: CInt = !p.at(60).asInstanceOf[Ptr[CInt]] + def eleven_=(value: CInt): Unit = !p.at(60).asInstanceOf[Ptr[CInt]] = value + def twelve: CInt = !p.at(64).asInstanceOf[Ptr[CInt]] + def twelve_=(value: CInt): Unit = !p.at(64).asInstanceOf[Ptr[CInt]] = value + def thirteen: CInt = !p.at(68).asInstanceOf[Ptr[CInt]] + def thirteen_=(value: CInt): Unit = !p.at(68).asInstanceOf[Ptr[CInt]] = value + def fourteen: CInt = !p.at(72).asInstanceOf[Ptr[CInt]] + def fourteen_=(value: CInt): Unit = !p.at(72).asInstanceOf[Ptr[CInt]] = value + def fifteen: CInt = !p.at(76).asInstanceOf[Ptr[CInt]] + def fifteen_=(value: CInt): Unit = !p.at(76).asInstanceOf[Ptr[CInt]] = value + def sixteen: CInt = !p.at(80).asInstanceOf[Ptr[CInt]] + def sixteen_=(value: CInt): Unit = !p.at(80).asInstanceOf[Ptr[CInt]] = value + def seventeen: CInt = !p.at(84).asInstanceOf[Ptr[CInt]] + def seventeen_=(value: CInt): Unit = !p.at(84).asInstanceOf[Ptr[CInt]] = value + def eighteen: CInt = !p.at(88).asInstanceOf[Ptr[CInt]] + def eighteen_=(value: CInt): Unit = !p.at(88).asInstanceOf[Ptr[CInt]] = value + def nineteen: CInt = !p.at(92).asInstanceOf[Ptr[CInt]] + def nineteen_=(value: CInt): Unit = !p.at(92).asInstanceOf[Ptr[CInt]] = value + def twenty: CInt = !p.at(96).asInstanceOf[Ptr[CInt]] + def twenty_=(value: CInt): Unit = !p.at(96).asInstanceOf[Ptr[CInt]] = value + def twentyOne: CInt = !p.at(100).asInstanceOf[Ptr[CInt]] + def twentyOne_=(value: CInt): Unit = !p.at(100).asInstanceOf[Ptr[CInt]] = value + def twentyTwo: CInt = !p.at(104).asInstanceOf[Ptr[CInt]] + def twentyTwo_=(value: CInt): Unit = !p.at(104).asInstanceOf[Ptr[CInt]] = value + def twentyThree: CInt = !p.at(108).asInstanceOf[Ptr[CInt]] + def twentyThree_=(value: CInt): Unit = !p.at(108).asInstanceOf[Ptr[CInt]] = value } - implicit class struct_anonymous_0_ops(val p: native.Ptr[struct_anonymous_0]) extends AnyVal { - def c: native.CChar = !p._1 - def c_=(value: native.CChar): Unit = !p._1 = value - def i: native.CInt = !p._2 - def i_=(value: native.CInt): Unit = !p._2 = value + implicit class struct_anonymous_0_ops(val p: Ptr[struct_anonymous_0]) extends AnyVal { + def c: CChar = p._1 + def c_=(value: CChar): Unit = p._1 = value + def i: CInt = p._2 + def i_=(value: CInt): Unit = p._2 = value } - implicit class struct_structWithAnonymousStruct_ops(val p: native.Ptr[struct_structWithAnonymousStruct]) extends AnyVal { - def a: native.CInt = !p._1 - def a_=(value: native.CInt): Unit = !p._1 = value - def anonymousStruct: native.Ptr[struct_anonymous_0] = p._2 - def anonymousStruct_=(value: native.Ptr[struct_anonymous_0]): Unit = !p._2 = !value + implicit class struct_structWithAnonymousStruct_ops(val p: Ptr[struct_structWithAnonymousStruct]) extends AnyVal { + def a: CInt = p._1 + def a_=(value: CInt): Unit = p._1 = value + def anonymousStruct: Ptr[struct_anonymous_0] = p.at2 + def anonymousStruct_=(value: Ptr[struct_anonymous_0]): Unit = p._2 = value } } object struct_point { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_point] = native.alloc[struct_point] - def apply(x: native.CInt, y: native.CInt)(implicit z: native.Zone): native.Ptr[struct_point] = { - val ptr = native.alloc[struct_point] + def apply()(implicit z: Zone): Ptr[struct_point] = alloc[struct_point] + def apply(x: CInt, y: CInt)(implicit z: Zone): Ptr[struct_point] = { + val ptr = alloc[struct_point] ptr.x = x ptr.y = y ptr @@ -132,9 +134,9 @@ object Struct { object struct_points { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_points] = native.alloc[struct_points] - def apply(p1: native.Ptr[struct_point], p2: native.Ptr[point])(implicit z: native.Zone): native.Ptr[struct_points] = { - val ptr = native.alloc[struct_points] + def apply()(implicit z: Zone): Ptr[struct_points] = alloc[struct_points] + def apply(p1: Ptr[struct_point], p2: Ptr[point])(implicit z: Zone): Ptr[struct_points] = { + val ptr = alloc[struct_points] ptr.p1 = p1 ptr.p2 = p2 ptr @@ -143,9 +145,9 @@ object Struct { object struct_bigStruct { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_bigStruct] = native.alloc[struct_bigStruct] - def apply(one: native.CLong, two: native.CChar, three: native.CInt, four: native.CFloat, five: native.CDouble, six: native.Ptr[struct_point], seven: native.Ptr[struct_point], eight: native.CInt, nine: native.CInt, ten: native.CInt, eleven: native.CInt, twelve: native.CInt, thirteen: native.CInt, fourteen: native.CInt, fifteen: native.CInt, sixteen: native.CInt, seventeen: native.CInt, eighteen: native.CInt, nineteen: native.CInt, twenty: native.CInt, twentyOne: native.CInt, twentyTwo: native.CInt, twentyThree: native.CInt)(implicit z: native.Zone): native.Ptr[struct_bigStruct] = { - val ptr = native.alloc[struct_bigStruct] + def apply()(implicit z: Zone): Ptr[struct_bigStruct] = alloc[struct_bigStruct] + def apply(one: CLong, two: CChar, three: CInt, four: CFloat, five: CDouble, six: Ptr[struct_point], seven: Ptr[struct_point], eight: CInt, nine: CInt, ten: CInt, eleven: CInt, twelve: CInt, thirteen: CInt, fourteen: CInt, fifteen: CInt, sixteen: CInt, seventeen: CInt, eighteen: CInt, nineteen: CInt, twenty: CInt, twentyOne: CInt, twentyTwo: CInt, twentyThree: CInt)(implicit z: Zone): Ptr[struct_bigStruct] = { + val ptr = alloc[struct_bigStruct] ptr.one = one ptr.two = two ptr.three = three @@ -175,9 +177,9 @@ object Struct { object struct_anonymous_0 { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_anonymous_0] = native.alloc[struct_anonymous_0] - def apply(c: native.CChar, i: native.CInt)(implicit z: native.Zone): native.Ptr[struct_anonymous_0] = { - val ptr = native.alloc[struct_anonymous_0] + def apply()(implicit z: Zone): Ptr[struct_anonymous_0] = alloc[struct_anonymous_0] + def apply(c: CChar, i: CInt)(implicit z: Zone): Ptr[struct_anonymous_0] = { + val ptr = alloc[struct_anonymous_0] ptr.c = c ptr.i = i ptr @@ -186,9 +188,9 @@ object Struct { object struct_structWithAnonymousStruct { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_structWithAnonymousStruct] = native.alloc[struct_structWithAnonymousStruct] - def apply(a: native.CInt, anonymousStruct: native.Ptr[struct_anonymous_0])(implicit z: native.Zone): native.Ptr[struct_structWithAnonymousStruct] = { - val ptr = native.alloc[struct_structWithAnonymousStruct] + def apply()(implicit z: Zone): Ptr[struct_structWithAnonymousStruct] = alloc[struct_structWithAnonymousStruct] + def apply(a: CInt, anonymousStruct: Ptr[struct_anonymous_0])(implicit z: Zone): Ptr[struct_structWithAnonymousStruct] = { + val ptr = alloc[struct_structWithAnonymousStruct] ptr.a = a ptr.anonymousStruct = anonymousStruct ptr diff --git a/tests/samples/Typedef.scala b/tests/samples/Typedef.scala index 7bead84..216fcad 100644 --- a/tests/samples/Typedef.scala +++ b/tests/samples/Typedef.scala @@ -1,10 +1,10 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ object Typedef { - type enum_days = native.CUnsignedInt + type enum_days = CUnsignedInt object enum_days { final val MONDAY: enum_days = 0.toUInt final val TUESDAY: enum_days = 1.toUInt @@ -15,14 +15,14 @@ object Typedef { final val SUNDAY: enum_days = 6.toUInt } - type enum_toggle_e = native.CUnsignedInt + type enum_toggle_e = CUnsignedInt object enum_toggle_e { final val OFF: enum_toggle_e = 0.toUInt final val ON: enum_toggle_e = 1.toUInt } type toggle_e = enum_toggle_e - type int2int = native.CFunctionPtr1[native.CInt, native.CInt] - type day2string = native.CFunctionPtr1[enum_days, native.CString] - type toggle = native.CFunctionPtr1[toggle_e, Unit] + type int2int = CFuncPtr1[CInt, CInt] + type day2string = CFuncPtr1[enum_days, CString] + type toggle = CFuncPtr1[toggle_e, Unit] } diff --git a/tests/samples/Union.scala b/tests/samples/Union.scala index 374adb5..7c059db 100644 --- a/tests/samples/Union.scala +++ b/tests/samples/Union.scala @@ -1,54 +1,54 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object Union { - type enum_union_op = native.CUnsignedInt + type enum_union_op = CUnsignedInt object enum_union_op { final val UNION_SET: enum_union_op = 0.toUInt final val UNION_TEST: enum_union_op = 1.toUInt } - type struct_s = native.CStruct1[native.CInt] - type union_values = native.CArray[Byte, native.Nat._8] - def union_get_sizeof(): native.CInt = native.extern - def union_test_int(v: native.Ptr[union_values], op: enum_union_op, value: native.CInt): native.CInt = native.extern - def union_test_long(v: native.Ptr[union_values], op: enum_union_op, value: native.CLong): native.CInt = native.extern - def union_test_long_long(v: native.Ptr[union_values], op: enum_union_op, value: native.CLongLong): native.CInt = native.extern - def union_test_double(v: native.Ptr[union_values], op: enum_union_op, value: native.CDouble): native.CInt = native.extern - def union_test_string(v: native.Ptr[union_values], op: enum_union_op, value: native.CString): native.CInt = native.extern - def union_test_struct(v: native.Ptr[union_values], op: enum_union_op, value: native.Ptr[struct_s]): native.CInt = native.extern + type struct_s = CStruct1[CInt] + type union_values = CArray[Byte, Nat._8] + def union_get_sizeof(): CInt = extern + def union_test_int(v: Ptr[union_values], op: enum_union_op, value: CInt): CInt = extern + def union_test_long(v: Ptr[union_values], op: enum_union_op, value: CLong): CInt = extern + def union_test_long_long(v: Ptr[union_values], op: enum_union_op, value: CLongLong): CInt = extern + def union_test_double(v: Ptr[union_values], op: enum_union_op, value: CDouble): CInt = extern + def union_test_string(v: Ptr[union_values], op: enum_union_op, value: CString): CInt = extern + def union_test_struct(v: Ptr[union_values], op: enum_union_op, value: Ptr[struct_s]): CInt = extern object implicits { - implicit class struct_s_ops(val p: native.Ptr[struct_s]) extends AnyVal { - def a: native.CInt = !p._1 - def a_=(value: native.CInt): Unit = !p._1 = value + implicit class struct_s_ops(val p: Ptr[struct_s]) extends AnyVal { + def a: CInt = p._1 + def a_=(value: CInt): Unit = p._1 = value } - implicit class union_values_pos(val p: native.Ptr[union_values]) extends AnyVal { - def l: native.Ptr[native.CLong] = p.cast[native.Ptr[native.CLong]] - def l_=(value: native.CLong): Unit = !p.cast[native.Ptr[native.CLong]] = value - def i: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]] - def i_=(value: native.CInt): Unit = !p.cast[native.Ptr[native.CInt]] = value - def ll: native.Ptr[native.CLongLong] = p.cast[native.Ptr[native.CLongLong]] - def ll_=(value: native.CLongLong): Unit = !p.cast[native.Ptr[native.CLongLong]] = value - def d: native.Ptr[native.CDouble] = p.cast[native.Ptr[native.CDouble]] - def d_=(value: native.CDouble): Unit = !p.cast[native.Ptr[native.CDouble]] = value - def s: native.Ptr[native.CString] = p.cast[native.Ptr[native.CString]] - def s_=(value: native.CString): Unit = !p.cast[native.Ptr[native.CString]] = value - def structInUnion: native.Ptr[struct_s] = p.cast[native.Ptr[struct_s]] - def structInUnion_=(value: native.Ptr[struct_s]): Unit = !p.cast[native.Ptr[struct_s]] = !value + implicit class union_values_pos(val p: Ptr[union_values]) extends AnyVal { + def l: Ptr[CLong] = p.asInstanceOf[Ptr[CLong]] + def l_=(value: CLong): Unit = !p.asInstanceOf[Ptr[CLong]] = value + def i: Ptr[CInt] = p.asInstanceOf[Ptr[CInt]] + def i_=(value: CInt): Unit = !p.asInstanceOf[Ptr[CInt]] = value + def ll: Ptr[CLongLong] = p.asInstanceOf[Ptr[CLongLong]] + def ll_=(value: CLongLong): Unit = !p.asInstanceOf[Ptr[CLongLong]] = value + def d: Ptr[CDouble] = p.asInstanceOf[Ptr[CDouble]] + def d_=(value: CDouble): Unit = !p.asInstanceOf[Ptr[CDouble]] = value + def s: Ptr[CString] = p.asInstanceOf[Ptr[CString]] + def s_=(value: CString): Unit = !p.asInstanceOf[Ptr[CString]] = value + def structInUnion: Ptr[struct_s] = p.asInstanceOf[Ptr[struct_s]] + def structInUnion_=(value: Ptr[struct_s]): Unit = !p.asInstanceOf[Ptr[struct_s]] = value } } object struct_s { import implicits._ - def apply()(implicit z: native.Zone): native.Ptr[struct_s] = native.alloc[struct_s] - def apply(a: native.CInt)(implicit z: native.Zone): native.Ptr[struct_s] = { - val ptr = native.alloc[struct_s] + def apply()(implicit z: Zone): Ptr[struct_s] = alloc[struct_s] + def apply(a: CInt)(implicit z: Zone): Ptr[struct_s] = { + val ptr = alloc[struct_s] ptr.a = a ptr } diff --git a/tests/samples/VarDefine.scala b/tests/samples/VarDefine.scala index 535fb1e..33ed58d 100644 --- a/tests/samples/VarDefine.scala +++ b/tests/samples/VarDefine.scala @@ -1,20 +1,20 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object VarDefine { - val a: native.CInt = native.extern - val constInt: native.CInt = native.extern - val constIntPointer: native.Ptr[native.CInt] = native.extern - val c: native.CInt = native.extern - val f: native.CFloat = native.extern + val a: CInt = extern + val constInt: CInt = extern + val constIntPointer: Ptr[CInt] = extern + val c: CInt = extern + val f: CFloat = extern @name("a") - val A: native.CInt = native.extern + val A: CInt = extern @name("constInt") - val CONST_INT: native.CInt = native.extern + val CONST_INT: CInt = extern @name("constIntPointer") - val CONST_INT_POINTER: native.Ptr[native.CInt] = native.extern + val CONST_INT_POINTER: Ptr[CInt] = extern } diff --git a/tests/samples/native.scala b/tests/samples/native.scala index cc3cfe8..ab1b6f2 100644 --- a/tests/samples/native.scala +++ b/tests/samples/native.scala @@ -1,13 +1,13 @@ package org.scalanative.bindgen.samples -import scala.scalanative._ -import scala.scalanative.native._ +import scala.scalanative.unsigned._ +import scala.scalanative.unsafe._ -@native.link("bindgentests") -@native.extern +@link("bindgentests") +@extern object nativeLib { - type nativeFunc0 = native.CInt - @native.link("native") - def nativeFunc0(p0: native.CInt): Unit = native.extern - def nativeFunc(p0: native.CFloat): Unit = native.extern + type nativeFunc0 = CInt + @link("native") + def nativeFunc0(p0: CInt): Unit = extern + def nativeFunc(p0: CFloat): Unit = extern } diff --git a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/EnumSpec.scala b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/EnumSpec.scala index fbbacc0..71a109d 100644 --- a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/EnumSpec.scala +++ b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/EnumSpec.scala @@ -1,9 +1,9 @@ package org.scalanative.bindgen.samples -import org.scalatest.FunSpec -import scalanative.native._ +import org.scalatest.funspec.AnyFunSpec +import scala.scalanative.unsafe._ -class EnumSpec extends FunSpec { +class EnumSpec extends AnyFunSpec { describe("enum bindings") { it("should bind to C enum values") { assert(Enum.get_WEDNESDAY() == Enum.enum_days.WEDNESDAY) diff --git a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/ExternSpec.scala b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/ExternSpec.scala index e986593..eb31dd4 100644 --- a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/ExternSpec.scala +++ b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/ExternSpec.scala @@ -1,9 +1,9 @@ package org.scalanative.bindgen.samples -import org.scalatest.FunSpec -import scalanative.native._ +import org.scalatest.funspec.AnyFunSpec +import scala.scalanative.unsafe._ -class ExternSpec extends FunSpec { +class ExternSpec extends AnyFunSpec { describe("extern variable bindings") { it("should bind to C variable") { assert(Extern.forty_two == 42) diff --git a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/FunctionSpec.scala b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/FunctionSpec.scala index 56caf03..af685d2 100644 --- a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/FunctionSpec.scala +++ b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/FunctionSpec.scala @@ -1,9 +1,9 @@ package org.scalanative.bindgen.samples -import org.scalatest.FunSpec -import scalanative.native._ +import org.scalatest.funspec.AnyFunSpec +import scala.scalanative.unsafe._ -class FunctionSpec extends FunSpec { +class FunctionSpec extends AnyFunSpec { describe("function bindings") { it("should bind to function with no args") { assert(Function.no_args() == 42) @@ -19,7 +19,7 @@ class FunctionSpec extends FunSpec { it("should bind to function with two arg") { val result = Function.two_args(3.14.toFloat, 1024) - val string = fromCString(result.cast[CString]) + val string = fromCString(result) assert(string == "3.14 1024") } diff --git a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/StructSpec.scala b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/StructSpec.scala index e5d2a4d..110cfbd 100644 --- a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/StructSpec.scala +++ b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/StructSpec.scala @@ -1,11 +1,12 @@ package org.scalanative.bindgen.samples -import org.scalatest.FunSpec -import scalanative.native._ +import org.scalatest.funspec.AnyFunSpec +import scala.scalanative.unsafe._ +import scala.scalanative.unsigned._ import org.scalanative.bindgen.samples.Struct.implicits._ -class StructSpec extends FunSpec { +class StructSpec extends AnyFunSpec { describe("struct bindings") { it("should provide field getters and setters") { val point = Struct.createPoint() @@ -58,8 +59,8 @@ class StructSpec extends FunSpec { Zone { implicit zone => val anonymousStruct: Ptr[struct_anonymousStruct] = alloc[struct_anonymousStruct] - !anonymousStruct._1 = 'a' - !anonymousStruct._2 = 42 + anonymousStruct._1 = 'a' + anonymousStruct._2 = 42 val structWithAnonymousStruct = Struct.struct_structWithAnonymousStruct() @@ -73,7 +74,8 @@ class StructSpec extends FunSpec { } it("should match size of C memory layout for big structs") { - assert(Struct.getBigStructSize() == sizeof[Struct.struct_bigStruct]) + assert( + Struct.getBigStructSize().toULong == sizeof[Struct.struct_bigStruct]) } it("should provide field getters for big structs") { @@ -86,6 +88,20 @@ class StructSpec extends FunSpec { assert(structPtr.one == value) } + for (value <- Seq[Byte](Byte.MinValue, -1, 0, 1, Byte.MaxValue)) { + Struct.struct_test_char(structPtr, + Struct.enum_struct_op.STRUCT_SET, + value) + assert(structPtr.two == value) + } + + for (value <- Seq(Int.MinValue, -1, 0, 1, Int.MaxValue)) { + Struct.struct_test_int(structPtr, + Struct.enum_struct_op.STRUCT_SET, + value) + assert(structPtr.three == value) + } + for (value <- Seq(Double.MinValue, -1, 0, 1, Double.MaxValue)) { Struct.struct_test_double(structPtr, Struct.enum_struct_op.STRUCT_SET, @@ -116,6 +132,22 @@ class StructSpec extends FunSpec { value) == 1) } + for (value <- Seq[Byte](Byte.MinValue, -1, 0, 1, Byte.MaxValue)) { + structPtr.two = value + assert( + Struct.struct_test_char(structPtr, + Struct.enum_struct_op.STRUCT_TEST, + value) == 1) + } + + for (value <- Seq(Int.MinValue, -1, 0, 1, Int.MaxValue)) { + structPtr.three = value + assert( + Struct.struct_test_int(structPtr, + Struct.enum_struct_op.STRUCT_TEST, + value) == 1) + } + for (value <- Seq(Double.MinValue, -1, 0, 1, Double.MaxValue)) { structPtr.five = value assert( diff --git a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/UnionSpec.scala b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/UnionSpec.scala index 2da96a3..09d4c04 100644 --- a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/UnionSpec.scala +++ b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/UnionSpec.scala @@ -1,14 +1,15 @@ package org.scalanative.bindgen.samples -import org.scalatest.FunSpec -import scala.scalanative.native._ +import org.scalatest.funspec.AnyFunSpec +import scala.scalanative.unsafe._ +import scala.scalanative.unsigned._ import org.scalanative.bindgen.samples.Union.implicits._ -class UnionSpec extends FunSpec { +class UnionSpec extends AnyFunSpec { describe("union bindings") { it("should match size of C memory layout") { - assert(Union.union_get_sizeof() == sizeof[Union.union_values]) + assert(Union.union_get_sizeof().toULong == sizeof[Union.union_values]) } it("should provide field getters") { diff --git a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/VarDefineSpec.scala b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/VarDefineSpec.scala index e75956e..e4205d9 100644 --- a/tests/samples/src/test/scala/org/scalanative/bindgen/samples/VarDefineSpec.scala +++ b/tests/samples/src/test/scala/org/scalanative/bindgen/samples/VarDefineSpec.scala @@ -1,9 +1,9 @@ package org.scalanative.bindgen.samples -import org.scalatest.FunSpec -import scala.scalanative.native._ +import org.scalatest.funspec.AnyFunSpec +import scala.scalanative.unsafe._ -class VarDefineSpec extends FunSpec { +class VarDefineSpec extends AnyFunSpec { describe("variable #define bindings") { it("should have the value of the referenced variable") { assert(VarDefine.A == 23) diff --git a/tests/src/test/scala/org/scalanative/bindgen/BindgenReportingSpec.scala b/tests/src/test/scala/org/scalanative/bindgen/BindgenReportingSpec.scala index afe7b82..9f43052 100644 --- a/tests/src/test/scala/org/scalanative/bindgen/BindgenReportingSpec.scala +++ b/tests/src/test/scala/org/scalanative/bindgen/BindgenReportingSpec.scala @@ -2,9 +2,9 @@ package org.scalanative.bindgen import java.io.{File, PrintWriter} -import org.scalatest.FunSpec +import org.scalatest.funspec.AnyFunSpec -class BindgenReportingSpec extends FunSpec { +class BindgenReportingSpec extends AnyFunSpec { describe("Bindgen") { val bindgen = Bindgen(new File(System.getProperty("bindgen.path"))) diff --git a/tests/src/test/scala/org/scalanative/bindgen/BindgenSpec.scala b/tests/src/test/scala/org/scalanative/bindgen/BindgenSpec.scala index 3ed5163..0c6ae84 100644 --- a/tests/src/test/scala/org/scalanative/bindgen/BindgenSpec.scala +++ b/tests/src/test/scala/org/scalanative/bindgen/BindgenSpec.scala @@ -1,10 +1,10 @@ package org.scalanative.bindgen import java.io.File -import org.scalatest.FunSpec +import org.scalatest.funspec.AnyFunSpec import scala.io.Source -class BindgenSpec extends FunSpec { +class BindgenSpec extends AnyFunSpec { describe("Bindgen") { val bindgen = Bindgen(new File(System.getProperty("bindgen.path"))) val inputDirectory = new File("samples")