diff --git a/be-cpp/src/commonMain/kotlin/lang/temper/be/cpp/CppSupportNetwork.kt b/be-cpp/src/commonMain/kotlin/lang/temper/be/cpp/CppSupportNetwork.kt index 05a66310..cbc8c61b 100644 --- a/be-cpp/src/commonMain/kotlin/lang/temper/be/cpp/CppSupportNetwork.kt +++ b/be-cpp/src/commonMain/kotlin/lang/temper/be/cpp/CppSupportNetwork.kt @@ -190,9 +190,9 @@ internal object CppSupportNetwork : SupportNetwork { put("core.empty()", Like.core("empty")) put("core.ignore()", Like.ignoring(theLastArg)) put("core.type Boolean.toString()", Like.core("Boolean::toString")) - put("std/temporal.type Date.day", Like.core("Date::getDay")) - put("std/temporal.type Date.month", Like.core("Date::getMonth")) - put("std/temporal.type Date.year", Like.core("Date::getYear")) + put("std/temporal.type Date.get day()", Like.core("Date::getDay")) + put("std/temporal.type Date.get month()", Like.core("Date::getMonth")) + put("std/temporal.type Date.get year()", Like.core("Date::getYear")) put("std/temporal.type Date.get dayOfWeek()", Like.core("Date::getDayOfWeek")) put("std/temporal.type Date.toString()", Like.core("Date::toString")) put("std/temporal.type Date.yearsBetween()", Like.core("Date::yearsBetween")) diff --git a/be-cpp/src/commonMain/resources/lang/temper/be/cpp/core/date.hpp b/be-cpp/src/commonMain/resources/lang/temper/be/cpp/core/date.hpp index 85919929..1317d1ae 100644 --- a/be-cpp/src/commonMain/resources/lang/temper/be/cpp/core/date.hpp +++ b/be-cpp/src/commonMain/resources/lang/temper/be/cpp/core/date.hpp @@ -15,31 +15,31 @@ namespace temper { template int32_t getYear(const std::shared_ptr& d) { - return d->year; + return d->_year; } template int32_t getMonth(const std::shared_ptr& d) { - return d->month; + return d->_month; } template int32_t getDay(const std::shared_ptr& d) { - return d->day; + return d->_day; } template int32_t getDayOfWeek(const std::shared_ptr& d) { static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; - int64_t y = d->year; - int64_t m = d->month; + int64_t y = d->_year; + int64_t m = d->_month; if (m < 1 || m > 12) { bubble("month out of range"); } if (m < 3) { y = y - 1; } - int64_t dow = (y + y/4 - y/100 + y/400 + t[m-1] + d->day) % 7; + int64_t dow = (y + y/4 - y/100 + y/400 + t[m-1] + d->_day) % 7; if (dow < 0) { dow = dow + 7; } @@ -50,13 +50,13 @@ namespace temper { std::string toString( const std::shared_ptr& d, typename std::enable_if< - std::is_same().year), int32_t>::value - && std::is_same().month), int32_t>::value - && std::is_same().day), int32_t>::value + std::is_same()._year), int32_t>::value + && std::is_same()._month), int32_t>::value + && std::is_same()._day), int32_t>::value >::type* = nullptr ) { std::ostringstream oss; - int32_t y = d->year; + int32_t y = d->_year; if (y < 0) { oss << '-'; y = -y; } @@ -68,22 +68,22 @@ namespace temper { oss << "0"; } oss << y << '-'; - if (d->month < 10) { + if (d->_month < 10) { oss << '0'; } - oss << d->month << '-'; - if (d->day < 10) { + oss << d->_month << '-'; + if (d->_day < 10) { oss << '0'; } - oss << d->day; + oss << d->_day; return oss.str(); } template int32_t yearsBetween(const std::shared_ptr& from, const std::shared_ptr& to) { - int32_t years = to->year - from->year; - if (to->month < from->month - || (to->month == from->month && to->day < from->day)) { + int32_t years = to->_year - from->_year; + if (to->_month < from->_month + || (to->_month == from->_month && to->_day < from->_day)) { years = years - 1; } return years; @@ -92,9 +92,9 @@ namespace temper { template std::shared_ptr makeDate(int32_t year, int32_t month, int32_t day) { std::shared_ptr d = std::make_shared(); - d->year = year; - d->month = month; - d->day = day; + d->_year = year; + d->_month = month; + d->_day = day; return d; } diff --git a/be-csharp/src/commonMain/kotlin/lang/temper/be/csharp/CSharpSupportNetwork.kt b/be-csharp/src/commonMain/kotlin/lang/temper/be/csharp/CSharpSupportNetwork.kt index fcfc96ef..51d60bd3 100644 --- a/be-csharp/src/commonMain/kotlin/lang/temper/be/csharp/CSharpSupportNetwork.kt +++ b/be-csharp/src/commonMain/kotlin/lang/temper/be/csharp/CSharpSupportNetwork.kt @@ -1364,13 +1364,13 @@ private val regexFormatterPushCodeTo = StaticCall( ) private val dateConstructor = ObjectCreation("std/temporal.type Date.constructor()", StandardNames.systemDateTime) -private val dateGetDay = PropertyAccess("std/temporal.type Date.day", "Day") +private val dateGetDay = PropertyAccess("std/temporal.type Date.get day()", "Day") private val dateGetDayOfWeek = StaticCall( "std/temporal.type Date.get dayOfWeek()", StandardNames.temperStdTemporalTemporalSupportIsoWeekdayNum, ) -private val dateGetMonth = PropertyAccess("std/temporal.type Date.month", "Month") -private val dateGetYear = PropertyAccess("std/temporal.type Date.year", "Year") +private val dateGetMonth = PropertyAccess("std/temporal.type Date.get month()", "Month") +private val dateGetYear = PropertyAccess("std/temporal.type Date.get year()", "Year") private val dateToString = MethodCall( baseName = "std/temporal.type Date.toString()", memberNameId = "ToString", diff --git a/be-java/src/commonMain/kotlin/lang/temper/be/java/JavaSupportNetwork.kt b/be-java/src/commonMain/kotlin/lang/temper/be/java/JavaSupportNetwork.kt index 3262e7c0..86edb4ec 100644 --- a/be-java/src/commonMain/kotlin/lang/temper/be/java/JavaSupportNetwork.kt +++ b/be-java/src/commonMain/kotlin/lang/temper/be/java/JavaSupportNetwork.kt @@ -975,20 +975,20 @@ val JavaLang.dateToString by receiver { } } val JavaLang.dateGetYear by receiver { - inlineSupport("std/temporal.type Date.year", arity = 1, needsSelf = true) { pos, args -> + inlineSupport("std/temporal.type Date.get year()", arity = 1, needsSelf = true) { pos, args -> // LocalDate.getYear returns a proleptic year. 2 BC and before are negative. args[0].method("getYear", pos = pos) } } val JavaLang.dateGetMonth by receiver { - inlineSupport("std/temporal.type Date.month", arity = 1, needsSelf = true) { pos, args -> + inlineSupport("std/temporal.type Date.get month()", arity = 1, needsSelf = true) { pos, args -> // LocalDate.getMonth returns an instance of the Month enumeration // .getMonthValue returns an int. args[0].method("getMonthValue", pos = pos) } } val JavaLang.dateGetDay by receiver { - inlineSupport("std/temporal.type Date.day", arity = 1, needsSelf = true) { pos, args -> + inlineSupport("std/temporal.type Date.get day()", arity = 1, needsSelf = true) { pos, args -> args[0].method("getDayOfMonth", pos = pos) } } @@ -1439,10 +1439,10 @@ private val connections: Map SupportCode)> = mapOf( // "core.type Console.log()" to null, "std/temporal.type Date.constructor()" to { it.dateConstructor }, "std/temporal.type Date.fromIsoString()" to { it.dateFromIsoString }, - "std/temporal.type Date.day" to { it.dateGetDay }, + "std/temporal.type Date.get day()" to { it.dateGetDay }, "std/temporal.type Date.get dayOfWeek()" to { it.dateGetDayOfWeek }, - "std/temporal.type Date.month" to { it.dateGetMonth }, - "std/temporal.type Date.year" to { it.dateGetYear }, + "std/temporal.type Date.get month()" to { it.dateGetMonth }, + "std/temporal.type Date.get year()" to { it.dateGetYear }, "std/temporal.type Date.toString()" to { it.dateToString }, "std/temporal.type Date.today()" to { it.dateToday }, "std/temporal.type Date.yearsBetween()" to { it.dateYearsBetween }, diff --git a/be-js/src/commonMain/kotlin/lang/temper/be/js/JsSupportNetwork.kt b/be-js/src/commonMain/kotlin/lang/temper/be/js/JsSupportNetwork.kt index eabd3143..e8466c0b 100644 --- a/be-js/src/commonMain/kotlin/lang/temper/be/js/JsSupportNetwork.kt +++ b/be-js/src/commonMain/kotlin/lang/temper/be/js/JsSupportNetwork.kt @@ -249,9 +249,9 @@ internal object JsSupportNetwork : SupportNetwork { "std/temporal.type Date.constructor()" -> { p, args, strict, translator -> newDateIdiomExpander(p, args, strict = strict, genre = genre, translator = translator) } - "std/temporal.type Date.year" -> propertyReadToMethodCall("getUTCFullYear") - "std/temporal.type Date.month" -> dateGetMonthExpander // Need to add one to index - "std/temporal.type Date.day" -> propertyReadToMethodCall("getUTCDate") // getUTCDay is weekday + "std/temporal.type Date.get year()" -> propertyReadToMethodCall("getUTCFullYear") + "std/temporal.type Date.get month()" -> dateGetMonthExpander // Need to add one to index + "std/temporal.type Date.get day()" -> propertyReadToMethodCall("getUTCDate") // getUTCDay is weekday "std/temporal.type Date.get dayOfWeek()" -> dateGetDayOfWeekExpander // JS has Sunday as 0, not 7 "std/temporal.type Date.toString()" -> dateToIsoStringExpander "std/temporal.type Date.fromIsoString()" -> { p, args, strict, _ -> diff --git a/be-py/src/commonMain/kotlin/lang/temper/be/py/PySupportNetwork.kt b/be-py/src/commonMain/kotlin/lang/temper/be/py/PySupportNetwork.kt index 845e3cca..c6bbbbd3 100644 --- a/be-py/src/commonMain/kotlin/lang/temper/be/py/PySupportNetwork.kt +++ b/be-py/src/commonMain/kotlin/lang/temper/be/py/PySupportNetwork.kt @@ -379,9 +379,9 @@ val DictType = PySeparateCode("dict", SYS_BUILTINS) val MappingProxyType = PySeparateCode("MappingProxyType", SYS_TYPES) val DateConstructor = PySeparateCode("date", DATE_TIME) val DateType = PyConnectedType("date", DATE_TIME) -val DateGetDay = inlineAttribute("std/temporal.type Date.day", PyIdentifierName("day")) -val DateGetMonth = inlineAttribute("std/temporal.type Date.month", PyIdentifierName("month")) -val DateGetYear = inlineAttribute("std/temporal.type Date.year", PyIdentifierName("year")) +val DateGetDay = inlineAttribute("std/temporal.type Date.get day()", PyIdentifierName("day")) +val DateGetMonth = inlineAttribute("std/temporal.type Date.get month()", PyIdentifierName("month")) +val DateGetYear = inlineAttribute("std/temporal.type Date.get year()", PyIdentifierName("year")) val DateGetDayOfWeek = PyInlineSupportCode( "std/temporal.type Date.get dayOfWeek()", arity = 1, @@ -1068,10 +1068,10 @@ private val pyConnections = mapOf( "core.type Boolean.toString()" to BooleanToString, "std/temporal.type Date.constructor()" to DateConstructor, "std/temporal.type Date.fromIsoString()" to DateFromIsoString, - "std/temporal.type Date.day" to DateGetDay, + "std/temporal.type Date.get day()" to DateGetDay, "std/temporal.type Date.get dayOfWeek()" to DateGetDayOfWeek, - "std/temporal.type Date.month" to DateGetMonth, - "std/temporal.type Date.year" to DateGetYear, + "std/temporal.type Date.get month()" to DateGetMonth, + "std/temporal.type Date.get year()" to DateGetYear, "std/temporal.type Date.toString()" to DateToString, "std/temporal.type Date.today()" to DateToday, "std/temporal.type Date.yearsBetween()" to DateYearsBetween, diff --git a/be/src/commonMain/kotlin/lang/temper/be/README.md b/be/src/commonMain/kotlin/lang/temper/be/README.md index aa7cc186..6d45c1f2 100644 --- a/be/src/commonMain/kotlin/lang/temper/be/README.md +++ b/be/src/commonMain/kotlin/lang/temper/be/README.md @@ -77,7 +77,7 @@ The set of *\@connected* methods from Temper's *ImplicitsModule* are: - `core.type Float64.toString()` - `core.type Generator` - `core.type Generator.close()` -- `core.type Generator.done` +- `core.type Generator.get done()` - `core.type Generator.next()` - `core.type GeneratorResult` - `core.type GlobalConsole.globalLog()` @@ -211,13 +211,13 @@ to implement: - `std/regex.type RegexFormatter.regexFormat()` - `std/temporal.type Date` - `std/temporal.type Date.constructor()` -- `std/temporal.type Date.day` - `std/temporal.type Date.fromIsoString()` +- `std/temporal.type Date.get day()` - `std/temporal.type Date.get dayOfWeek()` -- `std/temporal.type Date.month` +- `std/temporal.type Date.get month()` +- `std/temporal.type Date.get year()` - `std/temporal.type Date.toString()` - `std/temporal.type Date.today()` -- `std/temporal.type Date.year` - `std/temporal.type Date.yearsBetween()` - `std/testing.processTestCases()` - `std/testing.reportTestResults()` diff --git a/be/src/commonMain/kotlin/lang/temper/be/tmpl/TranslateDotHelper.kt b/be/src/commonMain/kotlin/lang/temper/be/tmpl/TranslateDotHelper.kt index 99fe9917..7b819822 100644 --- a/be/src/commonMain/kotlin/lang/temper/be/tmpl/TranslateDotHelper.kt +++ b/be/src/commonMain/kotlin/lang/temper/be/tmpl/TranslateDotHelper.kt @@ -470,7 +470,7 @@ internal object TranslateDotHelper { internal fun connectedKeyForMember(member: MemberShape): String? = when (member) { is MethodShape -> connectedKeyForMethod(member) - is PropertyShape -> member.connectedKey + is PropertyShape -> null // connect only through accessors methods for now is VisibleMemberShape -> member.connectedKey else -> null } diff --git a/frontend/src/commonMain/kotlin/lang/temper/frontend/implicits/DateTodayFn.kt b/frontend/src/commonMain/kotlin/lang/temper/frontend/implicits/DateTodayFn.kt index 26d5733d..7f479583 100644 --- a/frontend/src/commonMain/kotlin/lang/temper/frontend/implicits/DateTodayFn.kt +++ b/frontend/src/commonMain/kotlin/lang/temper/frontend/implicits/DateTodayFn.kt @@ -39,9 +39,9 @@ class DateTodayFn(val sig: Signature2) : CallableValue, Stayless { val propertyName = propertyShape.name as ModularName val propertyParsedName = (propertyName as ResolvedParsedName).baseName val value = when (propertyParsedName.nameText) { - "year" -> Value(today.year, TInt) - "month" -> Value(today.monthNumber, TInt) - "day" -> Value(today.dayOfMonth, TInt) + "_year" -> Value(today.year, TInt) + "_month" -> Value(today.monthNumber, TInt) + "_day" -> Value(today.dayOfMonth, TInt) else -> error(propertyName) } properties[propertyName] = value diff --git a/frontend/src/commonMain/resources/implicits/Implicits.temper b/frontend/src/commonMain/resources/implicits/Implicits.temper index a89dcc0b..b32a6f24 100644 --- a/frontend/src/commonMain/resources/implicits/Implicits.temper +++ b/frontend/src/commonMain/resources/implicits/Implicits.temper @@ -178,7 +178,7 @@ export interface Generator<@out YIELD extends AnyValue> { * would get [snippet/builtin/true]. */ @connected - public done: Boolean; + public get done(): Boolean; /** * Should be called once it is realized that * [snippet/type/Generator/method/next] is not going to be called diff --git a/frontend/src/commonMain/resources/std/temporal/temporal.temper.md b/frontend/src/commonMain/resources/std/temporal/temporal.temper.md index b6a0b121..c971be44 100644 --- a/frontend/src/commonMain/resources/std/temporal/temporal.temper.md +++ b/frontend/src/commonMain/resources/std/temporal/temporal.temper.md @@ -90,22 +90,25 @@ Here's just enough of a Date type to get us started. * A Date identifies a day in the proleptic Gregorian calendar. * It is unconnected to a time of day or a timezone. */ - @imu - @json - @connected @imu @json + @imu @json @connected export class Date { /** The year. 1900 means 1900. */ @connected - public year: Int; + public get year(): Int { _year } + private _year: Int; + /** The month of the year in [1, 12]. */ @connected - public month: Int; + public get month(): Int { _month } + private _month: Int; + /** * The day of the month in [1, 31] * additionally constrained by the length of [month]. */ @connected - public day: Int; + public get day(): Int { _day } + private _day: Int; @connected public constructor(year: Int, month: Int, day: Int): Void throws Bubble { @@ -116,9 +119,9 @@ Here's just enough of a Date type to get us started. } else { isLeapYear(year) })) { - this.year = year; - this.month = month; - this.day = day; + this._year = year; + this._month = month; + this._day = day; } else { bubble(); }