diff --git a/build/supertiny.flx b/build/supertiny.flx index 5a5b84e5..3a15b0ec 100644 --- a/build/supertiny.flx +++ b/build/supertiny.flx @@ -30,16 +30,19 @@ struct foo { do { var addr: ipv4 - addr.raw = 123445; + // addr.raw = -16668480; + addr.raw = 0xff01a8c0; - addr.bytes[0] = 192 - addr.bytes[1] = 168 - addr.bytes[2] = 1 - addr.bytes[3] = 1 + printf("%d.%d.%d.%d\n", addr._.bytes[0], addr._.bytes[1], addr._.bytes[2], addr._.bytes[3]); + + // addr._.bytes[0] = 192 + // addr._.bytes[1] = 168 + // addr._.bytes[2] = 1 + // addr._.bytes[3] = 1 } - do { + /* do { var x: @raw union { bar: f64 foo: i64 @@ -49,7 +52,7 @@ struct foo printf("x = %.2lf\n", x.bar) printf("x = %d\n", x.foo) - } + } */ } diff --git a/source/codegen/autocasting.cpp b/source/codegen/autocasting.cpp index 8a54791d..e0a05707 100644 --- a/source/codegen/autocasting.cpp +++ b/source/codegen/autocasting.cpp @@ -29,14 +29,14 @@ namespace cgn } else { - if(ty->getMinBits() <= fir::Type::getInt64()->getBitWidth() - 1) - return fir::ConstantInt::getInt64(cn->getInt64()); + if(ty->getMinBits() <= fir::Type::getInt64()->getBitWidth() - 1) + return fir::ConstantInt::getInt64(cn->getInt64()); - else if(ty->isSigned() && ty->getMinBits() <= fir::Type::getUint64()->getBitWidth()) - return fir::ConstantInt::getUint64(cn->getUint64()); + else if(ty->isSigned() && ty->getMinBits() <= fir::Type::getUint64()->getBitWidth()) + return fir::ConstantInt::getUint64(cn->getUint64()); - else - error("int overflow"); + else + error("int overflow"); } } @@ -65,7 +65,7 @@ namespace cgn if(target->toPrimitiveType()->getBitWidth() < ty->getMinBits()) { // TODO: actually do what we say. - warn(cs->loc(), "Casting literal to type '%s' will cause an overflow; resulting value will be the limit of the casted type", + warn(cs->loc(), "Casting literal to type '%s' will cause an overflow; value will be truncated bitwise to fit", target); } diff --git a/source/fir/Types/Type.cpp b/source/fir/Types/Type.cpp index edba1285..f8c1cdf4 100644 --- a/source/fir/Types/Type.cpp +++ b/source/fir/Types/Type.cpp @@ -608,6 +608,11 @@ namespace fir return this->isIntegerType() && this->toPrimitiveType()->isSigned(); } + bool Type::isUnsignedIntType() + { + return this->isIntegerType() && !this->toPrimitiveType()->isSigned(); + } + bool Type::isFunctionType() { return this->kind == TypeKind::Function; diff --git a/source/frontend/parser/expr.cpp b/source/frontend/parser/expr.cpp index d937d18b..ad753729 100644 --- a/source/frontend/parser/expr.cpp +++ b/source/frontend/parser/expr.cpp @@ -238,16 +238,19 @@ namespace parser { switch(t) { - // () and [] have the same precedence. - // not sure if this should stay -- works for now. + case TT::DoubleColon: + return 5000; + case TT::LParen: - case TT::LSquare: return 2000; case TT::Period: - case TT::DoubleColon: + return 1500; + + case TT::LSquare: return 1000; + // unary ! // unary +/- // bitwise ~ diff --git a/source/include/ir/type.h b/source/include/ir/type.h index 39e2e330..a6185a95 100644 --- a/source/include/ir/type.h +++ b/source/include/ir/type.h @@ -148,6 +148,7 @@ namespace fir bool isIntegerType(); bool isFunctionType(); bool isSignedIntType(); + bool isUnsignedIntType(); bool isFloatingPointType(); bool isArraySliceType(); diff --git a/source/typecheck/literals.cpp b/source/typecheck/literals.cpp index 802d9559..4d6a0d71 100644 --- a/source/typecheck/literals.cpp +++ b/source/typecheck/literals.cpp @@ -15,8 +15,12 @@ TCResult ast::LitNumber::typecheck(sst::TypecheckState* fs, fir::Type* infer) fs->pushLoc(this); defer(fs->popLoc()); - // set base = 0 to autodetect. - auto number = mpfr::mpreal(this->num, mpfr_get_default_prec(), /* base: */ 0); + // i don't think mpfr auto-detects base, LMAO + int base = 10; + if(this->num.find("0x") == 0 || this->num.find("0X") == 0) + base = 16; + + auto number = mpfr::mpreal(this->num, mpfr_get_default_prec(), base); bool sgn = mpfr::signbit(number); bool flt = !mpfr::isint(number); @@ -35,6 +39,7 @@ TCResult ast::LitNumber::typecheck(sst::TypecheckState* fs, fir::Type* infer) size_t bits = mpfr_min_prec(mpfr::mpreal(this->num.substr(0, this->num.size() - 1) + "9").mpfr_ptr()); + printf("number %s: %d / %d\n", number.toString().c_str(), sgn, bits); auto ret = util::pool(this->loc, (infer && infer->isPrimitiveType()) ? infer : fir::ConstantNumberType::get(sgn, flt, bits)); ret->num = mpfr::mpreal(this->num);