@forthic/interp 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/forthic/global_module.d.ts +4 -3
- package/dist/cjs/forthic/global_module.js +66 -51
- package/dist/cjs/forthic/global_module.js.map +1 -1
- package/dist/cjs/forthic/interpreter.d.ts +7 -2
- package/dist/cjs/forthic/interpreter.js +21 -3
- package/dist/cjs/forthic/interpreter.js.map +1 -1
- package/dist/cjs/forthic/utils.d.ts +4 -4
- package/dist/cjs/forthic/utils.js +13 -19
- package/dist/cjs/forthic/utils.js.map +1 -1
- package/dist/esm/forthic/global_module.d.ts +4 -3
- package/dist/esm/forthic/global_module.js +66 -51
- package/dist/esm/forthic/global_module.js.map +1 -1
- package/dist/esm/forthic/interpreter.d.ts +7 -2
- package/dist/esm/forthic/interpreter.js +21 -3
- package/dist/esm/forthic/interpreter.js.map +1 -1
- package/dist/esm/forthic/utils.d.ts +4 -4
- package/dist/esm/forthic/utils.js +13 -19
- package/dist/esm/forthic/utils.js.map +1 -1
- package/package.json +4 -1
|
@@ -7,10 +7,10 @@ exports.is_array = is_array;
|
|
|
7
7
|
exports.is_empty_object = is_empty_object;
|
|
8
8
|
exports.pretty_print = pretty_print;
|
|
9
9
|
exports.to_string = to_string;
|
|
10
|
-
exports.is_valid_date = is_valid_date;
|
|
11
10
|
exports.to_date = to_date;
|
|
12
11
|
exports.date_to_string = date_to_string;
|
|
13
12
|
exports.date_to_int = date_to_int;
|
|
13
|
+
const temporal_polyfill_1 = require("temporal-polyfill");
|
|
14
14
|
function is_string(value) {
|
|
15
15
|
return typeof value === "string" || value instanceof String;
|
|
16
16
|
}
|
|
@@ -37,36 +37,30 @@ function pretty_print(value) {
|
|
|
37
37
|
function to_string(obj) {
|
|
38
38
|
return pretty_print(obj);
|
|
39
39
|
}
|
|
40
|
-
function is_valid_date(date) {
|
|
41
|
-
if (date instanceof Date) {
|
|
42
|
-
return !isNaN(date.getTime());
|
|
43
|
-
}
|
|
44
|
-
else if (typeof date === "string" || typeof date === "number") {
|
|
45
|
-
const parsedDate = new Date(date);
|
|
46
|
-
return !isNaN(parsedDate.getTime());
|
|
47
|
-
}
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
40
|
function to_date(obj) {
|
|
51
41
|
let result;
|
|
52
|
-
if (obj instanceof
|
|
42
|
+
if (obj instanceof temporal_polyfill_1.Temporal.PlainDate) {
|
|
53
43
|
result = obj;
|
|
54
44
|
}
|
|
55
|
-
else if (
|
|
56
|
-
result =
|
|
45
|
+
else if (obj instanceof temporal_polyfill_1.Temporal.PlainDateTime) {
|
|
46
|
+
result = temporal_polyfill_1.Temporal.PlainDate.from(obj);
|
|
47
|
+
}
|
|
48
|
+
else if (typeof obj === "number" || typeof obj === "string") {
|
|
49
|
+
// Assume number is seconds since epoch
|
|
50
|
+
const date = new Date(obj);
|
|
51
|
+
result = temporal_polyfill_1.Temporal.PlainDate.from({ year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() });
|
|
57
52
|
}
|
|
58
53
|
else {
|
|
59
54
|
return null;
|
|
60
55
|
}
|
|
61
|
-
result.setHours(0, 0, 0, 0);
|
|
62
56
|
return result;
|
|
63
57
|
}
|
|
64
58
|
function date_to_string(date) {
|
|
65
59
|
let result = "";
|
|
66
|
-
if (date instanceof
|
|
67
|
-
const m = date.
|
|
68
|
-
const d = date.
|
|
69
|
-
const y = date.
|
|
60
|
+
if (date instanceof temporal_polyfill_1.Temporal.PlainDate) {
|
|
61
|
+
const m = date.month;
|
|
62
|
+
const d = date.day;
|
|
63
|
+
const y = date.year;
|
|
70
64
|
let m_str = `${m}`;
|
|
71
65
|
let d_str = `${d}`;
|
|
72
66
|
if (m < 10)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/forthic/utils.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","s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OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAgB,WAAW,CAAC,IAAwB;IAClD,MAAM,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Module, Word } from "./module";
|
|
2
|
+
import { Temporal } from "temporal-polyfill";
|
|
2
3
|
import { type Interpreter } from "./interpreter";
|
|
3
4
|
export declare class GlobalModule extends Module {
|
|
4
5
|
literal_handlers: Array<(value: any) => any>;
|
|
@@ -9,8 +10,8 @@ export declare class GlobalModule extends Module {
|
|
|
9
10
|
to_bool(str_val: string): boolean | null;
|
|
10
11
|
to_int(str_val: string): number | null;
|
|
11
12
|
to_float(str_val: string): number | null;
|
|
12
|
-
to_literal_date(str_val: string):
|
|
13
|
-
to_time(str_val: string):
|
|
13
|
+
to_literal_date(str_val: string): Temporal.PlainDate | null;
|
|
14
|
+
to_time(str_val: string): Temporal.PlainTime | null;
|
|
14
15
|
make_element_word(element_name: string): (interp: Interpreter) => Promise<void>;
|
|
15
16
|
add_element_word(element_name: string): void;
|
|
16
17
|
word_VARIABLES(interp: Interpreter): void;
|
|
@@ -94,7 +95,7 @@ export declare class GlobalModule extends Module {
|
|
|
94
95
|
word_FRIDAY(interp: Interpreter): void;
|
|
95
96
|
word_SATURDAY(interp: Interpreter): void;
|
|
96
97
|
word_SUNDAY(interp: Interpreter): void;
|
|
97
|
-
static get_day_this_week(day_of_week:
|
|
98
|
+
static get_day_this_week(day_of_week: number, timezone: Temporal.TimeZoneLike): Temporal.PlainDate;
|
|
98
99
|
word_ADD_DAYS(interp: Interpreter): void;
|
|
99
100
|
word_SUBTRACT_DATES(interp: Interpreter): void;
|
|
100
101
|
word_DATE_to_STR(interp: Interpreter): void;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GlobalModule = void 0;
|
|
4
4
|
const module_1 = require("./module");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
|
+
const temporal_polyfill_1 = require("temporal-polyfill");
|
|
6
7
|
const map_word_1 = require("./global_module/map_word");
|
|
7
8
|
const tokenizer_1 = require("./tokenizer");
|
|
8
9
|
const errors_1 = require("./errors");
|
|
@@ -261,9 +262,11 @@ class GlobalModule extends module_1.Module {
|
|
|
261
262
|
const year = Number(match[1]);
|
|
262
263
|
const month = Number(match[2]);
|
|
263
264
|
const day = Number(match[3]);
|
|
264
|
-
const result =
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
const result = temporal_polyfill_1.Temporal.PlainDate.from({
|
|
266
|
+
year,
|
|
267
|
+
month,
|
|
268
|
+
day,
|
|
269
|
+
});
|
|
267
270
|
return result;
|
|
268
271
|
}
|
|
269
272
|
to_time(str_val) {
|
|
@@ -276,8 +279,10 @@ class GlobalModule extends module_1.Module {
|
|
|
276
279
|
return null;
|
|
277
280
|
if (minutes >= 60)
|
|
278
281
|
return null;
|
|
279
|
-
const result =
|
|
280
|
-
|
|
282
|
+
const result = temporal_polyfill_1.Temporal.PlainTime.from({
|
|
283
|
+
hour: hours,
|
|
284
|
+
minute: minutes,
|
|
285
|
+
});
|
|
281
286
|
return result;
|
|
282
287
|
}
|
|
283
288
|
// Convenience function to create element word handlers
|
|
@@ -1581,45 +1586,54 @@ class GlobalModule extends module_1.Module {
|
|
|
1581
1586
|
// ( time -- time )
|
|
1582
1587
|
word_AM(interp) {
|
|
1583
1588
|
const time = interp.stack_pop();
|
|
1584
|
-
if (!(time instanceof
|
|
1589
|
+
if (!(time instanceof temporal_polyfill_1.Temporal.PlainTime))
|
|
1585
1590
|
throw "AM expecting a time";
|
|
1586
1591
|
let result = time;
|
|
1587
|
-
if (time.
|
|
1588
|
-
result =
|
|
1589
|
-
|
|
1590
|
-
|
|
1592
|
+
if (time.hour >= 12) {
|
|
1593
|
+
result = temporal_polyfill_1.Temporal.PlainTime.from({
|
|
1594
|
+
hour: time.hour - 12,
|
|
1595
|
+
minute: time.minute,
|
|
1596
|
+
});
|
|
1591
1597
|
}
|
|
1592
1598
|
interp.stack_push(result);
|
|
1593
1599
|
}
|
|
1594
1600
|
// ( time -- time )
|
|
1595
1601
|
word_PM(interp) {
|
|
1596
1602
|
const time = interp.stack_pop();
|
|
1597
|
-
if (!(time instanceof
|
|
1603
|
+
if (!(time instanceof temporal_polyfill_1.Temporal.PlainTime))
|
|
1598
1604
|
throw "PM expecting a time";
|
|
1599
1605
|
let result = time;
|
|
1600
|
-
if (time.
|
|
1601
|
-
result =
|
|
1602
|
-
|
|
1603
|
-
|
|
1606
|
+
if (time.hour < 12) {
|
|
1607
|
+
result = temporal_polyfill_1.Temporal.PlainTime.from({
|
|
1608
|
+
hour: time.hour + 12,
|
|
1609
|
+
minute: time.minute,
|
|
1610
|
+
});
|
|
1604
1611
|
}
|
|
1605
1612
|
interp.stack_push(result);
|
|
1606
1613
|
}
|
|
1607
1614
|
// ( -- time )
|
|
1608
1615
|
word_NOW(interp) {
|
|
1609
|
-
const result =
|
|
1616
|
+
const result = temporal_polyfill_1.Temporal.Now.plainDateTimeISO(interp.get_timezone());
|
|
1610
1617
|
interp.stack_push(result);
|
|
1611
1618
|
}
|
|
1612
1619
|
// ( item -- time )
|
|
1613
1620
|
word_to_TIME(interp) {
|
|
1614
1621
|
const item = interp.stack_pop();
|
|
1615
1622
|
let result;
|
|
1616
|
-
if (item instanceof
|
|
1623
|
+
if (item instanceof temporal_polyfill_1.Temporal.PlainTime) {
|
|
1617
1624
|
result = item;
|
|
1618
1625
|
}
|
|
1626
|
+
else if (item instanceof temporal_polyfill_1.Temporal.PlainDateTime) {
|
|
1627
|
+
result = temporal_polyfill_1.Temporal.PlainTime.from(item);
|
|
1628
|
+
}
|
|
1619
1629
|
else {
|
|
1620
1630
|
// NB: We need a date in order for Date.parse to succeed. Also assuming str is a time
|
|
1621
1631
|
const date_string = "Jan 1, 2000 " + item;
|
|
1622
|
-
|
|
1632
|
+
const date = new Date(Date.parse(date_string));
|
|
1633
|
+
result = temporal_polyfill_1.Temporal.PlainTime.from({
|
|
1634
|
+
hour: date.getHours(),
|
|
1635
|
+
minute: date.getMinutes(),
|
|
1636
|
+
});
|
|
1623
1637
|
}
|
|
1624
1638
|
interp.stack_push(result);
|
|
1625
1639
|
}
|
|
@@ -1637,64 +1651,57 @@ class GlobalModule extends module_1.Module {
|
|
|
1637
1651
|
}
|
|
1638
1652
|
// ( -- date )
|
|
1639
1653
|
word_TODAY(interp) {
|
|
1640
|
-
const result =
|
|
1641
|
-
result.setHours(0, 0, 0, 0);
|
|
1654
|
+
const result = temporal_polyfill_1.Temporal.Now.plainDateISO(interp.get_timezone());
|
|
1642
1655
|
interp.stack_push(result);
|
|
1643
1656
|
}
|
|
1644
1657
|
// ( -- date )
|
|
1645
1658
|
word_MONDAY(interp) {
|
|
1646
|
-
interp.stack_push(GlobalModule.get_day_this_week(0));
|
|
1659
|
+
interp.stack_push(GlobalModule.get_day_this_week(0, interp.get_timezone()));
|
|
1647
1660
|
}
|
|
1648
1661
|
// ( -- date )
|
|
1649
1662
|
word_TUESDAY(interp) {
|
|
1650
|
-
interp.stack_push(GlobalModule.get_day_this_week(1));
|
|
1663
|
+
interp.stack_push(GlobalModule.get_day_this_week(1, interp.get_timezone()));
|
|
1651
1664
|
}
|
|
1652
1665
|
// ( -- date )
|
|
1653
1666
|
word_WEDNESDAY(interp) {
|
|
1654
|
-
interp.stack_push(GlobalModule.get_day_this_week(2));
|
|
1667
|
+
interp.stack_push(GlobalModule.get_day_this_week(2, interp.get_timezone()));
|
|
1655
1668
|
}
|
|
1656
1669
|
// ( -- date )
|
|
1657
1670
|
word_THURSDAY(interp) {
|
|
1658
|
-
interp.stack_push(GlobalModule.get_day_this_week(3));
|
|
1671
|
+
interp.stack_push(GlobalModule.get_day_this_week(3, interp.get_timezone()));
|
|
1659
1672
|
}
|
|
1660
1673
|
// ( -- date )
|
|
1661
1674
|
word_FRIDAY(interp) {
|
|
1662
|
-
interp.stack_push(GlobalModule.get_day_this_week(4));
|
|
1675
|
+
interp.stack_push(GlobalModule.get_day_this_week(4, interp.get_timezone()));
|
|
1663
1676
|
}
|
|
1664
1677
|
// ( -- date )
|
|
1665
1678
|
word_SATURDAY(interp) {
|
|
1666
|
-
interp.stack_push(GlobalModule.get_day_this_week(5));
|
|
1679
|
+
interp.stack_push(GlobalModule.get_day_this_week(5, interp.get_timezone()));
|
|
1667
1680
|
}
|
|
1668
1681
|
// ( -- date )
|
|
1669
1682
|
word_SUNDAY(interp) {
|
|
1670
|
-
interp.stack_push(GlobalModule.get_day_this_week(6));
|
|
1671
|
-
}
|
|
1672
|
-
static get_day_this_week(day_of_week) {
|
|
1673
|
-
//
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
}
|
|
1677
|
-
const today = new Date();
|
|
1678
|
-
today.setHours(0, 0, 0, 0);
|
|
1679
|
-
const delta_days = (day_of_week - normalize_day(today.getDay())) % 7;
|
|
1680
|
-
const result = today;
|
|
1681
|
-
result.setDate(result.getDate() + delta_days + 1);
|
|
1683
|
+
interp.stack_push(GlobalModule.get_day_this_week(6, interp.get_timezone()));
|
|
1684
|
+
}
|
|
1685
|
+
static get_day_this_week(day_of_week, timezone) {
|
|
1686
|
+
// Get plain date for day of week
|
|
1687
|
+
const today = temporal_polyfill_1.Temporal.Now.plainDateISO(timezone);
|
|
1688
|
+
const delta_days = (day_of_week - today.dayOfWeek) % 7;
|
|
1689
|
+
const result = today.add({ days: delta_days });
|
|
1682
1690
|
return result;
|
|
1683
1691
|
}
|
|
1684
1692
|
// ( date num-days -- date )
|
|
1685
1693
|
word_ADD_DAYS(interp) {
|
|
1686
1694
|
const num_days = interp.stack_pop();
|
|
1687
1695
|
const date = interp.stack_pop();
|
|
1688
|
-
const result =
|
|
1689
|
-
result.setDate(result.getDate() + num_days);
|
|
1696
|
+
const result = temporal_polyfill_1.Temporal.PlainDate.from(date).add({ days: num_days });
|
|
1690
1697
|
interp.stack_push(result);
|
|
1691
1698
|
}
|
|
1692
1699
|
// ( l_date r_date -- num_days )
|
|
1693
1700
|
word_SUBTRACT_DATES(interp) {
|
|
1694
|
-
const r_date = interp.stack_pop();
|
|
1695
|
-
const l_date = interp.stack_pop();
|
|
1696
|
-
|
|
1697
|
-
const result =
|
|
1701
|
+
const r_date = temporal_polyfill_1.Temporal.PlainDate.from(interp.stack_pop());
|
|
1702
|
+
const l_date = temporal_polyfill_1.Temporal.PlainDate.from(interp.stack_pop());
|
|
1703
|
+
// Subtract the dates and get the difference in days
|
|
1704
|
+
const result = r_date.until(l_date).total({ unit: "days" });
|
|
1698
1705
|
interp.stack_push(result);
|
|
1699
1706
|
}
|
|
1700
1707
|
// ( date -- str )
|
|
@@ -1712,28 +1719,36 @@ class GlobalModule extends module_1.Module {
|
|
|
1712
1719
|
}
|
|
1713
1720
|
// ( date time -- datetime )
|
|
1714
1721
|
word_DATE_TIME_to_DATETIME(interp) {
|
|
1715
|
-
const time = interp.stack_pop();
|
|
1716
|
-
const date = interp.stack_pop();
|
|
1717
|
-
const
|
|
1718
|
-
|
|
1722
|
+
const time = temporal_polyfill_1.Temporal.PlainTime.from(interp.stack_pop());
|
|
1723
|
+
const date = temporal_polyfill_1.Temporal.PlainDate.from(interp.stack_pop());
|
|
1724
|
+
const result = temporal_polyfill_1.Temporal.PlainDateTime.from({
|
|
1725
|
+
year: date.year,
|
|
1726
|
+
month: date.month,
|
|
1727
|
+
day: date.day,
|
|
1728
|
+
hour: time.hour,
|
|
1729
|
+
minute: time.minute,
|
|
1730
|
+
});
|
|
1719
1731
|
interp.stack_push(result);
|
|
1720
1732
|
}
|
|
1721
1733
|
// ( datetime -- timestamp )
|
|
1722
1734
|
word_DATETIME_to_TIMESTAMP(interp) {
|
|
1723
1735
|
const datetime = interp.stack_pop();
|
|
1724
|
-
|
|
1736
|
+
// Convert to ZonedDateTime
|
|
1737
|
+
const zonedDateTime = datetime.toZonedDateTime(interp.get_timezone());
|
|
1738
|
+
const result = zonedDateTime.toInstant().epochSeconds;
|
|
1725
1739
|
interp.stack_push(result);
|
|
1726
1740
|
}
|
|
1727
1741
|
// ( timestamp -- datetime )
|
|
1728
1742
|
word_TIMESTAMP_to_DATETIME(interp) {
|
|
1729
1743
|
const timestamp = interp.stack_pop();
|
|
1730
|
-
const result =
|
|
1744
|
+
const result = temporal_polyfill_1.Temporal.Instant.fromEpochSeconds(timestamp).toZonedDateTime({ timeZone: interp.get_timezone(), calendar: "iso8601" });
|
|
1731
1745
|
interp.stack_push(result);
|
|
1732
1746
|
}
|
|
1733
1747
|
// ( str -- datetime )
|
|
1734
1748
|
word_STR_to_DATETIME(interp) {
|
|
1735
1749
|
const s = interp.stack_pop();
|
|
1736
|
-
const
|
|
1750
|
+
const date = new Date(s);
|
|
1751
|
+
const result = temporal_polyfill_1.Temporal.Instant.fromEpochMilliseconds(date.getTime()).toZonedDateTime({ timeZone: interp.get_timezone(), calendar: "iso8601" });
|
|
1737
1752
|
interp.stack_push(result);
|
|
1738
1753
|
}
|
|
1739
1754
|
// ( str -- timestamp )
|