meta_language/translation/
primitive_value_rules.rs1#[must_use]
5pub fn accept_object_property_definition(name: &str, computed: bool, colon: bool) -> bool {
6 name != "__proto__" || computed || !colon
7}
8
9#[must_use]
11pub fn read_absent_number_value(operation: &str, absence: &str) -> String {
12 if absence != "null" && absence != "undefined" {
13 String::new()
14 } else if operation == "arithmetic" {
15 if absence == "null" {
16 String::from("zero")
17 } else {
18 String::from("not-a-number")
19 }
20 } else if operation == "array-index" {
21 String::from("not-a-number")
22 } else {
23 String::new()
24 }
25}
26
27#[must_use]
29pub fn render_absent_number_expression(target: &str, operation: &str, absence: &str) -> String {
30 {
31 let value =
32 crate::translation::primitive_value_rules::read_absent_number_value(operation, absence);
33 if value.is_empty() {
34 String::new()
35 } else if target == "JavaScript" {
36 if value == "zero" {
37 String::from("0")
38 } else {
39 String::from("NaN")
40 }
41 } else if target == "Rust" {
42 if value == "zero" {
43 String::from("0f64")
44 } else {
45 String::from("f64::NAN")
46 }
47 } else if target == "Lean" {
48 if value == "zero" {
49 String::from("(0 : Float)")
50 } else {
51 String::from("(0 / 0 : Float)")
52 }
53 } else if target == "Rocq" {
54 if value == "zero" {
55 String::from("0%float")
56 } else {
57 String::from("PrimFloat.nan")
58 }
59 } else {
60 String::new()
61 }
62 }
63}
64
65#[must_use]
67pub fn read_number_display_refusal(language: &str, kind: &str) -> String {
68 if language == "Rust" && kind == "float" {
69 String::from(
70 "Rust formatting retains negative zero, spells infinities inf and expands exponents; it needs its own operational formatter",
71 )
72 } else {
73 String::new()
74 }
75}
76
77#[must_use]
79pub fn read_number_display_function(kind: &str, console_style: bool) -> String {
80 if kind == "float" {
81 if console_style {
82 String::from("js_console")
83 } else {
84 String::from("js_number")
85 }
86 } else {
87 String::new()
88 }
89}
90
91#[must_use]
93pub fn accept_linked_text_conversion_kind(kind: &str) -> bool {
94 kind == "bool"
95 || kind == "float"
96 || kind == "int"
97 || kind == "nat"
98 || kind == "fixed"
99 || kind == "string"
100 || kind == "record"
101}
102
103#[must_use]
105pub fn read_scalar_cell_operation(expression: &str) -> String {
106 if expression == "cellAllocate" {
107 String::from("allocate-reference-cell")
108 } else if expression == "cellRead" {
109 String::from("read-reference-cell")
110 } else if expression == "cellWrite" {
111 String::from("write-reference-cell")
112 } else {
113 String::new()
114 }
115}
116
117#[must_use]
119pub fn require_data_object_freeze(language: &str, explicit_frozen: bool) -> bool {
120 explicit_frozen || language != "JavaScript"
121}
122
123#[must_use]
125pub fn accept_object_freeze_operand(expression: &str, readonly_literal: bool) -> bool {
126 expression == "ctorObject" || expression == "array" && readonly_literal
127}
128
129#[must_use]
131pub fn accept_immutable_product_kind(kind: &str) -> bool {
132 kind == "bool" || kind == "float" || kind == "fixed" || kind == "unit" || kind == "tuple"
133}
134
135#[must_use]
137pub fn accept_tuple_index(index: f64, length: f64) -> bool {
138 (0.0_f64..=9_007_199_254_740_991_f64).contains(&index)
139 && (index % 1f64) == 0f64
140 && index < length
141}
142
143#[must_use]
145pub fn read_tuple_position(index: f64) -> f64 {
146 if index == 0f64 { 0f64 } else { index }
147}