@ugo-studio/jspp 0.1.3 → 0.1.5

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.
Files changed (83) hide show
  1. package/README.md +2 -2
  2. package/dist/analysis/scope.js +33 -4
  3. package/dist/analysis/typeAnalyzer.js +260 -21
  4. package/dist/ast/symbols.js +29 -0
  5. package/dist/cli-utils/args.js +57 -0
  6. package/dist/cli-utils/colors.js +9 -0
  7. package/dist/cli-utils/file-utils.js +20 -0
  8. package/dist/cli-utils/spinner.js +55 -0
  9. package/dist/cli.js +105 -31
  10. package/dist/core/codegen/class-handlers.js +131 -0
  11. package/dist/core/codegen/control-flow-handlers.js +474 -0
  12. package/dist/core/codegen/declaration-handlers.js +36 -15
  13. package/dist/core/codegen/expression-handlers.js +579 -125
  14. package/dist/core/codegen/function-handlers.js +222 -37
  15. package/dist/core/codegen/helpers.js +158 -4
  16. package/dist/core/codegen/index.js +20 -8
  17. package/dist/core/codegen/literal-handlers.js +18 -6
  18. package/dist/core/codegen/statement-handlers.js +171 -228
  19. package/dist/core/codegen/visitor.js +31 -3
  20. package/package.json +3 -3
  21. package/src/prelude/any_value.hpp +510 -633
  22. package/src/prelude/any_value_access.hpp +151 -0
  23. package/src/prelude/any_value_defines.hpp +190 -0
  24. package/src/prelude/any_value_helpers.hpp +139 -225
  25. package/src/prelude/exception.hpp +32 -0
  26. package/src/prelude/exception_helpers.hpp +49 -0
  27. package/src/prelude/index.hpp +25 -9
  28. package/src/prelude/library/array.hpp +190 -0
  29. package/src/prelude/library/console.hpp +14 -13
  30. package/src/prelude/library/error.hpp +113 -0
  31. package/src/prelude/library/function.hpp +10 -0
  32. package/src/prelude/library/global.hpp +35 -4
  33. package/src/prelude/library/math.hpp +308 -0
  34. package/src/prelude/library/object.hpp +288 -0
  35. package/src/prelude/library/performance.hpp +2 -2
  36. package/src/prelude/library/process.hpp +39 -0
  37. package/src/prelude/library/promise.hpp +131 -0
  38. package/src/prelude/library/symbol.hpp +46 -59
  39. package/src/prelude/library/timer.hpp +92 -0
  40. package/src/prelude/scheduler.hpp +145 -0
  41. package/src/prelude/types.hpp +58 -1
  42. package/src/prelude/utils/access.hpp +345 -0
  43. package/src/prelude/utils/assignment_operators.hpp +99 -0
  44. package/src/prelude/utils/log_any_value/array.hpp +245 -0
  45. package/src/prelude/utils/log_any_value/config.hpp +32 -0
  46. package/src/prelude/utils/log_any_value/function.hpp +39 -0
  47. package/src/prelude/utils/log_any_value/fwd.hpp +15 -0
  48. package/src/prelude/utils/log_any_value/helpers.hpp +62 -0
  49. package/src/prelude/utils/log_any_value/log_any_value.hpp +94 -0
  50. package/src/prelude/utils/log_any_value/object.hpp +136 -0
  51. package/src/prelude/utils/log_any_value/primitives.hpp +43 -0
  52. package/src/prelude/utils/operators.hpp +751 -0
  53. package/src/prelude/utils/well_known_symbols.hpp +25 -0
  54. package/src/prelude/values/array.hpp +10 -7
  55. package/src/prelude/{descriptors.hpp → values/descriptors.hpp} +2 -2
  56. package/src/prelude/values/function.hpp +85 -51
  57. package/src/prelude/values/helpers/array.hpp +80 -35
  58. package/src/prelude/values/helpers/function.hpp +110 -77
  59. package/src/prelude/values/helpers/iterator.hpp +16 -10
  60. package/src/prelude/values/helpers/object.hpp +85 -10
  61. package/src/prelude/values/helpers/promise.hpp +181 -0
  62. package/src/prelude/values/helpers/string.hpp +3 -3
  63. package/src/prelude/values/helpers/symbol.hpp +2 -2
  64. package/src/prelude/values/iterator.hpp +14 -6
  65. package/src/prelude/values/object.hpp +14 -3
  66. package/src/prelude/values/promise.hpp +73 -0
  67. package/src/prelude/values/prototypes/array.hpp +855 -16
  68. package/src/prelude/values/prototypes/function.hpp +4 -4
  69. package/src/prelude/values/prototypes/iterator.hpp +11 -10
  70. package/src/prelude/values/prototypes/number.hpp +153 -0
  71. package/src/prelude/values/prototypes/object.hpp +26 -0
  72. package/src/prelude/values/prototypes/promise.hpp +134 -0
  73. package/src/prelude/values/prototypes/string.hpp +29 -29
  74. package/src/prelude/values/prototypes/symbol.hpp +22 -3
  75. package/src/prelude/values/shape.hpp +52 -0
  76. package/src/prelude/values/string.hpp +1 -1
  77. package/src/prelude/values/symbol.hpp +1 -1
  78. package/src/prelude/access.hpp +0 -91
  79. package/src/prelude/error.hpp +0 -31
  80. package/src/prelude/error_helpers.hpp +0 -59
  81. package/src/prelude/log_string.hpp +0 -407
  82. package/src/prelude/operators.hpp +0 -256
  83. package/src/prelude/well_known_symbols.hpp +0 -14
@@ -1,634 +1,511 @@
1
- #pragma once
2
-
3
- #include <cassert>
4
- #include <cstdint>
5
- #include <cstring>
6
- #include <limits>
7
- #include <new>
8
- #include <sstream>
9
- #include <iomanip>
10
- #include <type_traits>
11
- #include <memory>
12
- #include <utility>
13
- #include <string>
14
- #include <map>
15
- #include <vector>
16
- #include <functional>
17
- #include <cmath>
18
- #include <optional>
19
-
20
- #include "types.hpp"
21
- #include "values/non_values.hpp"
22
- #include "values/object.hpp"
23
- #include "values/array.hpp"
24
- #include "values/function.hpp"
25
- #include "values/iterator.hpp"
26
- #include "values/symbol.hpp"
27
- #include "values/string.hpp"
28
- #include "error.hpp"
29
- #include "descriptors.hpp"
30
- #include "well_known_symbols.hpp"
31
-
32
- namespace jspp
33
- {
34
- enum class JsType : uint8_t
35
- {
36
- Undefined = 0,
37
- Null = 1,
38
- Uninitialized = 2,
39
- Boolean = 3,
40
- Number = 4,
41
- String = 5,
42
- Object = 6,
43
- Array = 7,
44
- Function = 8,
45
- Iterator = 9,
46
- Symbol = 10,
47
- DataDescriptor = 11,
48
- AccessorDescriptor = 12,
49
- };
50
-
51
- // Tagged storage with a union for payload
52
- struct TaggedValue
53
- {
54
- JsType type;
55
- union
56
- {
57
- JsUndefined undefined;
58
- JsNull null;
59
- JsUninitialized uninitialized;
60
- bool boolean;
61
- double number;
62
- std::shared_ptr<JsString> str;
63
- std::shared_ptr<JsObject> object;
64
- std::shared_ptr<JsArray> array;
65
- std::shared_ptr<JsFunction> function;
66
- std::shared_ptr<JsIterator<AnyValue>> iterator;
67
- std::shared_ptr<JsSymbol> symbol;
68
- std::shared_ptr<DataDescriptor> data_desc;
69
- std::shared_ptr<AccessorDescriptor> accessor_desc;
70
- };
71
-
72
- TaggedValue() noexcept : type(JsType::Undefined), undefined{} {}
73
- ~TaggedValue() {}
74
- };
75
-
76
- class AnyValue
77
- {
78
- private:
79
- TaggedValue storage;
80
-
81
- void destroy_value() noexcept
82
- {
83
- switch (storage.type)
84
- {
85
- case JsType::String:
86
- storage.str.~shared_ptr();
87
- break;
88
- case JsType::Object:
89
- storage.object.~shared_ptr();
90
- break;
91
- case JsType::Array:
92
- storage.array.~shared_ptr();
93
- break;
94
- case JsType::Function:
95
- storage.function.~shared_ptr();
96
- break;
97
- case JsType::Iterator:
98
- storage.iterator.~shared_ptr();
99
- break;
100
- case JsType::Symbol:
101
- storage.symbol.~shared_ptr();
102
- break;
103
- case JsType::DataDescriptor:
104
- storage.data_desc.~shared_ptr();
105
- break;
106
- case JsType::AccessorDescriptor:
107
- storage.accessor_desc.~shared_ptr();
108
- break;
109
- default:
110
- break;
111
- }
112
- }
113
-
114
- void reset_to_undefined() noexcept
115
- {
116
- destroy_value();
117
- storage.type = JsType::Undefined;
118
- storage.undefined = JsUndefined{};
119
- }
120
-
121
- void move_from(AnyValue &other) noexcept
122
- {
123
- storage.type = other.storage.type;
124
- switch (other.storage.type)
125
- {
126
- case JsType::Undefined:
127
- storage.undefined = JsUndefined{};
128
- break;
129
- case JsType::Null:
130
- storage.null = JsNull{};
131
- break;
132
- case JsType::Uninitialized:
133
- storage.uninitialized = JsUninitialized{};
134
- break;
135
- case JsType::Boolean:
136
- storage.boolean = other.storage.boolean;
137
- break;
138
- case JsType::Number:
139
- storage.number = other.storage.number;
140
- break;
141
- case JsType::String:
142
- new (&storage.str) std::shared_ptr<JsString>(std::move(other.storage.str));
143
- break;
144
- case JsType::Object:
145
- new (&storage.object) std::shared_ptr<JsObject>(std::move(other.storage.object));
146
- break;
147
- case JsType::Array:
148
- new (&storage.array) std::shared_ptr<JsArray>(std::move(other.storage.array));
149
- break;
150
- case JsType::Function:
151
- new (&storage.function) std::shared_ptr<JsFunction>(std::move(other.storage.function));
152
- break;
153
- case JsType::Iterator:
154
- new (&storage.iterator) std::shared_ptr<JsIterator<AnyValue>>(std::move(other.storage.iterator));
155
- break;
156
- case JsType::Symbol:
157
- new (&storage.symbol) std::shared_ptr<JsSymbol>(std::move(other.storage.symbol));
158
- break;
159
- case JsType::DataDescriptor:
160
- new (&storage.data_desc) std::shared_ptr<DataDescriptor>(std::move(other.storage.data_desc));
161
- break;
162
- case JsType::AccessorDescriptor:
163
- new (&storage.accessor_desc) std::shared_ptr<AccessorDescriptor>(std::move(other.storage.accessor_desc));
164
- break;
165
- }
166
- }
167
-
168
- void copy_from(const AnyValue &other)
169
- {
170
- storage.type = other.storage.type;
171
- switch (other.storage.type)
172
- {
173
- case JsType::Undefined:
174
- storage.undefined = JsUndefined{};
175
- break;
176
- case JsType::Null:
177
- storage.null = JsNull{};
178
- break;
179
- case JsType::Uninitialized:
180
- storage.uninitialized = JsUninitialized{};
181
- break;
182
- case JsType::Boolean:
183
- storage.boolean = other.storage.boolean;
184
- break;
185
- case JsType::Number:
186
- storage.number = other.storage.number;
187
- break;
188
- case JsType::String:
189
- new (&storage.str) std::shared_ptr<JsString>(std::make_shared<JsString>(*other.storage.str));
190
- break;
191
- case JsType::Object:
192
- new (&storage.object) std::shared_ptr<JsObject>(other.storage.object); // shallow copy
193
- break;
194
- case JsType::Array:
195
- new (&storage.array) std::shared_ptr<JsArray>(other.storage.array); // shallow copy
196
- break;
197
- case JsType::Function:
198
- new (&storage.function) std::shared_ptr<JsFunction>(other.storage.function); // shallow copy
199
- break;
200
- case JsType::Iterator:
201
- new (&storage.iterator) std::shared_ptr<JsIterator<AnyValue>>(other.storage.iterator); // shallow copy
202
- break;
203
- case JsType::Symbol:
204
- new (&storage.symbol) std::shared_ptr<JsSymbol>(other.storage.symbol); // shallow copy (shared)
205
- break;
206
- case JsType::DataDescriptor:
207
- new (&storage.data_desc) std::shared_ptr<DataDescriptor>(other.storage.data_desc); // shallow copy
208
- break;
209
- case JsType::AccessorDescriptor:
210
- new (&storage.accessor_desc) std::shared_ptr<AccessorDescriptor>(other.storage.accessor_desc); // shallow copy
211
- break;
212
- }
213
- }
214
-
215
- public:
216
- // default ctor (Undefined)
217
- AnyValue() noexcept
218
- {
219
- storage.type = JsType::Undefined;
220
- storage.undefined = JsUndefined{};
221
- }
222
-
223
- // 1. Destructor
224
- ~AnyValue() noexcept
225
- {
226
- destroy_value();
227
- }
228
-
229
- // 2. Copy Constructor (deep copy)
230
- AnyValue(const AnyValue &other)
231
- {
232
- copy_from(other);
233
- }
234
-
235
- // 3. Copy Assignment Operator
236
- AnyValue &operator=(const AnyValue &other)
237
- {
238
- if (this != &other)
239
- {
240
- destroy_value();
241
- copy_from(other);
242
- }
243
- return *this;
244
- }
245
-
246
- // 4. Move Constructor
247
- AnyValue(AnyValue &&other) noexcept
248
- {
249
- storage.type = JsType::Undefined;
250
- storage.undefined = JsUndefined{};
251
- move_from(other);
252
- other.reset_to_undefined();
253
- }
254
-
255
- // 5. Move Assignment Operator
256
- AnyValue &operator=(AnyValue &&other) noexcept
257
- {
258
- if (this != &other)
259
- {
260
- destroy_value();
261
- move_from(other);
262
- other.reset_to_undefined();
263
- }
264
- return *this;
265
- }
266
-
267
- friend void swap(AnyValue &a, AnyValue &b) noexcept
268
- {
269
- AnyValue tmp(std::move(a));
270
- a = std::move(b);
271
- b = std::move(tmp);
272
- }
273
-
274
- // factories -------------------------------------------------------
275
- static AnyValue make_number(double d) noexcept
276
- {
277
- AnyValue v;
278
- v.storage.type = JsType::Number;
279
- v.storage.number = d;
280
- return v;
281
- }
282
- static AnyValue make_nan() noexcept
283
- {
284
- AnyValue v;
285
- v.storage.type = JsType::Number;
286
- v.storage.number = std::numeric_limits<double>::quiet_NaN();
287
- return v;
288
- }
289
- static AnyValue make_uninitialized() noexcept
290
- {
291
- AnyValue v;
292
- v.storage.type = JsType::Uninitialized;
293
- v.storage.uninitialized = JsUninitialized{};
294
- return v;
295
- }
296
- static AnyValue make_undefined() noexcept
297
- {
298
- AnyValue v;
299
- v.storage.type = JsType::Undefined;
300
- v.storage.undefined = JsUndefined{};
301
- return v;
302
- }
303
- static AnyValue make_null() noexcept
304
- {
305
- AnyValue v;
306
- v.storage.type = JsType::Null;
307
- v.storage.null = JsNull{};
308
- return v;
309
- }
310
- static AnyValue make_boolean(bool b) noexcept
311
- {
312
- AnyValue v;
313
- v.storage.type = JsType::Boolean;
314
- v.storage.boolean = b;
315
- return v;
316
- }
317
- static AnyValue make_string(const std::string &raw_s) noexcept
318
- {
319
- AnyValue v;
320
- v.storage.type = JsType::String;
321
- new (&v.storage.str) std::shared_ptr<JsString>(std::make_shared<JsString>(raw_s));
322
- return v;
323
- }
324
- static AnyValue make_object(const std::map<std::string, AnyValue> &props) noexcept
325
- {
326
- AnyValue v;
327
- v.storage.type = JsType::Object;
328
- new (&v.storage.object) std::shared_ptr<JsObject>(std::make_shared<JsObject>(props));
329
- return v;
330
- }
331
- static AnyValue make_array(const std::vector<std::optional<AnyValue>> &dense) noexcept
332
- {
333
- AnyValue v;
334
- v.storage.type = JsType::Array;
335
- new (&v.storage.array) std::shared_ptr<JsArray>(std::make_shared<JsArray>(dense));
336
- return v;
337
- }
338
- static AnyValue make_function(const JsFunctionCallable &call, const std::string &name) noexcept
339
- {
340
- AnyValue v;
341
- v.storage.type = JsType::Function;
342
- new (&v.storage.function) std::shared_ptr<JsFunction>(std::make_shared<JsFunction>(call, name));
343
- return v;
344
- }
345
- static AnyValue make_generator(const JsFunctionCallable &call, const std::string &name) noexcept
346
- {
347
- AnyValue v;
348
- v.storage.type = JsType::Function;
349
- new (&v.storage.function) std::shared_ptr<JsFunction>(std::make_shared<JsFunction>(call, true, name));
350
- return v;
351
- }
352
- static AnyValue make_symbol(const std::string &description = "") noexcept
353
- {
354
- AnyValue v;
355
- v.storage.type = JsType::Symbol;
356
- new (&v.storage.symbol) std::shared_ptr<JsSymbol>(std::make_shared<JsSymbol>(description));
357
- return v;
358
- }
359
- static AnyValue make_data_descriptor(const AnyValue &value, bool writable, bool enumerable, bool configurable) noexcept
360
- {
361
- AnyValue v;
362
- v.storage.type = JsType::DataDescriptor;
363
- new (&v.storage.data_desc) std::shared_ptr<DataDescriptor>(std::make_shared<DataDescriptor>(std::make_shared<AnyValue>(value), writable, enumerable, configurable));
364
- return v;
365
- }
366
- static AnyValue make_accessor_descriptor(const std::optional<std::function<AnyValue(const std::vector<AnyValue> &)>> &get,
367
- const std::optional<std::function<AnyValue(const std::vector<AnyValue> &)>> &set,
368
- bool enumerable,
369
- bool configurable) noexcept
370
- {
371
- AnyValue v;
372
- v.storage.type = JsType::AccessorDescriptor;
373
- new (&v.storage.accessor_desc) std::shared_ptr<AccessorDescriptor>(std::make_shared<AccessorDescriptor>(get, set, enumerable, configurable));
374
- return v;
375
- }
376
-
377
- static AnyValue from_symbol(std::shared_ptr<JsSymbol> sym) noexcept
378
- {
379
- AnyValue v;
380
- v.storage.type = JsType::Symbol;
381
- new (&v.storage.symbol) std::shared_ptr<JsSymbol>(std::move(sym));
382
- return v;
383
- }
384
- static AnyValue from_string(std::shared_ptr<JsString> str) noexcept
385
- {
386
- AnyValue v;
387
- v.storage.type = JsType::String;
388
- new (&v.storage.str) std::shared_ptr<JsString>(std::move(str));
389
- return v;
390
- }
391
- static AnyValue from_iterator(JsIterator<AnyValue> &&iterator) noexcept
392
- {
393
- AnyValue v;
394
- v.storage.type = JsType::Iterator;
395
- new (&v.storage.iterator) std::shared_ptr<JsIterator<AnyValue>>(std::make_shared<JsIterator<AnyValue>>(std::move(iterator)));
396
- return v;
397
- }
398
- static AnyValue from_iterator_ref(JsIterator<AnyValue> *iterator) noexcept
399
- {
400
- AnyValue v;
401
- v.storage.type = JsType::Iterator;
402
- new (&v.storage.iterator) std::shared_ptr<JsIterator<AnyValue>>(iterator, [](JsIterator<AnyValue> *) {});
403
- return v;
404
- }
405
-
406
- // property resolution helpers ---------------------------------------
407
- static AnyValue resolve_property_for_read(const AnyValue &val) noexcept
408
- {
409
- switch (val.storage.type)
410
- {
411
- case JsType::DataDescriptor:
412
- {
413
- return *(val.storage.data_desc->value);
414
- }
415
- case JsType::AccessorDescriptor:
416
- {
417
- if (val.storage.accessor_desc->get.has_value())
418
- return val.storage.accessor_desc->get.value()({});
419
- else
420
- {
421
- static AnyValue undefined = AnyValue{};
422
- return undefined;
423
- }
424
- }
425
- default:
426
- {
427
- return val;
428
- }
429
- }
430
- }
431
- static AnyValue resolve_property_for_write(AnyValue &val, const AnyValue &new_val)
432
- {
433
- switch (val.storage.type)
434
- {
435
- case JsType::DataDescriptor:
436
- {
437
- *(val.storage.data_desc->value) = new_val;
438
- return new_val;
439
- }
440
- case JsType::AccessorDescriptor:
441
- {
442
- if (val.storage.accessor_desc->set.has_value())
443
- {
444
- val.storage.accessor_desc->set.value()({new_val});
445
- return new_val;
446
- }
447
- else
448
- {
449
- throw RuntimeError::make_error("Cannot set property of #<Object> which has only a getter", "TypeError");
450
- }
451
- }
452
- default:
453
- {
454
- val = new_val;
455
- return new_val;
456
- }
457
- }
458
- }
459
-
460
- // type checkers and accessors ---------------------------------------
461
- bool is_number() const noexcept { return storage.type == JsType::Number; }
462
- bool is_string() const noexcept { return storage.type == JsType::String; }
463
- bool is_object() const noexcept { return storage.type == JsType::Object; }
464
- bool is_array() const noexcept { return storage.type == JsType::Array; }
465
- bool is_function() const noexcept { return storage.type == JsType::Function; }
466
- bool is_iterator() const noexcept { return storage.type == JsType::Iterator; }
467
- bool is_boolean() const noexcept { return storage.type == JsType::Boolean; }
468
- bool is_symbol() const noexcept { return storage.type == JsType::Symbol; }
469
- bool is_null() const noexcept { return storage.type == JsType::Null; }
470
- bool is_undefined() const noexcept { return storage.type == JsType::Undefined; }
471
- bool is_uninitialized() const noexcept { return storage.type == JsType::Uninitialized; }
472
- bool is_data_descriptor() const noexcept { return storage.type == JsType::DataDescriptor; }
473
- bool is_accessor_descriptor() const noexcept { return storage.type == JsType::AccessorDescriptor; }
474
- bool is_generator() const noexcept { return storage.type == JsType::Function && storage.function->is_generator; }
475
-
476
- // --- TYPE CASTERS
477
- double as_double() const noexcept
478
- {
479
- assert(is_number());
480
- return storage.number;
481
- }
482
- bool as_boolean() const noexcept
483
- {
484
- assert(is_boolean());
485
- return storage.boolean;
486
- }
487
- JsString *as_string() const noexcept
488
- {
489
- assert(is_string());
490
- return storage.str.get();
491
- }
492
- JsObject *as_object() const noexcept
493
- {
494
- assert(is_object());
495
- return storage.object.get();
496
- }
497
- JsArray *as_array() const noexcept
498
- {
499
- assert(is_array());
500
- return storage.array.get();
501
- }
502
- JsFunction *as_function(const std::optional<std::string> &expression = std::nullopt) const
503
- {
504
- if (is_function())
505
- return storage.function.get();
506
- throw RuntimeError::make_error(expression.value_or(to_std_string()) + " is not a function", "TypeError");
507
- }
508
- JsSymbol *as_symbol() const noexcept
509
- {
510
- assert(is_symbol());
511
- return storage.symbol.get();
512
- }
513
- std::shared_ptr<JsIterator<AnyValue>> as_iterator() const
514
- {
515
- assert(is_iterator());
516
- return storage.iterator; // Returns the shared_ptr, incrementing ref count
517
- }
518
- DataDescriptor *as_data_descriptor() const noexcept
519
- {
520
- assert(is_data_descriptor());
521
- return storage.data_desc.get();
522
- }
523
- AccessorDescriptor *as_accessor_descriptor() const noexcept
524
- {
525
- assert(is_accessor_descriptor());
526
- return storage.accessor_desc.get();
527
- }
528
-
529
- // --- PROPERTY ACCESS OPERATORS
530
- AnyValue get_own_property(const std::string &key) const
531
- {
532
- switch (storage.type)
533
- {
534
- case JsType::Object:
535
- return storage.object->get_property(key);
536
- case JsType::Array:
537
- return storage.array->get_property(key);
538
- case JsType::Function:
539
- return storage.function->get_property(key);
540
- case JsType::Iterator:
541
- return storage.iterator->get_property(key);
542
- case JsType::Symbol:
543
- return storage.symbol->get_property(key);
544
- case JsType::String:
545
- return storage.str->get_property(key);
546
- case JsType::Undefined:
547
- throw RuntimeError::make_error("Cannot read properties of undefined (reading '" + key + "')", "TypeError");
548
- case JsType::Null:
549
- throw RuntimeError::make_error("Cannot read properties of null (reading '" + key + "')", "TypeError");
550
- default:
551
- return AnyValue::make_undefined();
552
- }
553
- }
554
- AnyValue get_own_property(uint32_t idx) const noexcept
555
- {
556
- switch (storage.type)
557
- {
558
- case JsType::Array:
559
- return storage.array->get_property(idx);
560
- case JsType::String:
561
- return storage.str->get_property(idx);
562
- default:
563
- return get_own_property(std::to_string(idx));
564
- }
565
- }
566
- AnyValue get_own_property(const AnyValue &key) const noexcept
567
- {
568
- if (key.storage.type == JsType::Number && storage.type == JsType::Array)
569
- return storage.array->get_property(key.storage.number);
570
- if (key.storage.type == JsType::Number && storage.type == JsType::String)
571
- return storage.str->get_property(key.storage.number);
572
-
573
- // If the key is a Symbol, use its internal key string
574
- if (key.storage.type == JsType::Symbol)
575
- return get_own_property(key.storage.symbol->key);
576
-
577
- return get_own_property(key.to_std_string());
578
- }
579
- // for setting values
580
- AnyValue set_own_property(const std::string &key, const AnyValue &value) const
581
- {
582
- switch (storage.type)
583
- {
584
- case JsType::Object:
585
- return storage.object->set_property(key, value);
586
- case JsType::Array:
587
- return storage.array->set_property(key, value);
588
- case JsType::Function:
589
- return storage.function->set_property(key, value);
590
- case JsType::Undefined:
591
- throw RuntimeError::make_error("Cannot set properties of undefined (setting '" + key + "')", "TypeError");
592
- case JsType::Null:
593
- throw RuntimeError::make_error("Cannot set properties of null (setting '" + key + "')", "TypeError");
594
- default:
595
- return value;
596
- }
597
- }
598
- AnyValue set_own_property(uint32_t idx, const AnyValue &value) const
599
- {
600
- if (storage.type == JsType::Array)
601
- {
602
- return storage.array->set_property(idx, value);
603
- }
604
- return set_own_property(std::to_string(idx), value);
605
- }
606
- AnyValue set_own_property(const AnyValue &key, const AnyValue &value) const
607
- {
608
- if (key.storage.type == JsType::Number && storage.type == JsType::Array)
609
- {
610
- return storage.array->set_property(key.storage.number, value);
611
- }
612
-
613
- // If the key is a Symbol, use its internal key string
614
- if (key.storage.type == JsType::Symbol)
615
- return set_own_property(key.storage.symbol->key, value);
616
-
617
- return set_own_property(key.to_std_string(), value);
618
- }
619
-
620
- // --- HELPERS
621
- const bool is_truthy() const noexcept;
622
-
623
- const bool is_strictly_equal_to(const AnyValue &other) const noexcept;
624
- const bool is_equal_to(const AnyValue &other) const noexcept;
625
-
626
- const AnyValue is_strictly_equal_to_primitive(const AnyValue &other) const noexcept;
627
- const AnyValue is_equal_to_primitive(const AnyValue &other) const noexcept;
628
-
629
- const AnyValue not_strictly_equal_to_primitive(const AnyValue &other) const noexcept;
630
- const AnyValue not_equal_to_primitive(const AnyValue &other) const noexcept;
631
-
632
- const std::string to_std_string() const noexcept;
633
- };
1
+ #pragma once
2
+
3
+ #include <cassert>
4
+ #include <cstdint>
5
+ #include <cstring>
6
+ #include <limits>
7
+ #include <new>
8
+ #include <sstream>
9
+ #include <iomanip>
10
+ #include <type_traits>
11
+ #include <memory>
12
+ #include <utility>
13
+ #include <string>
14
+ #include <map>
15
+ #include <vector>
16
+ #include <functional>
17
+ #include <cmath>
18
+ #include <optional>
19
+ #include <coroutine>
20
+ #include <variant>
21
+
22
+ #include "types.hpp"
23
+ #include "values/non_values.hpp"
24
+ #include "values/object.hpp"
25
+ #include "values/array.hpp"
26
+ #include "values/function.hpp"
27
+ #include "values/iterator.hpp"
28
+ #include "values/promise.hpp"
29
+ #include "values/symbol.hpp"
30
+ #include "values/string.hpp"
31
+ #include "values/descriptors.hpp"
32
+ #include "exception.hpp"
33
+ #include "utils/well_known_symbols.hpp"
34
+
35
+ namespace jspp
36
+ {
37
+ enum class JsType : uint8_t
38
+ {
39
+ Undefined = 0,
40
+ Null = 1,
41
+ Uninitialized = 2,
42
+ Boolean = 3,
43
+ Number = 4,
44
+ String = 5,
45
+ Object = 6,
46
+ Array = 7,
47
+ Function = 8,
48
+ Iterator = 9,
49
+ Symbol = 10,
50
+ Promise = 11,
51
+ DataDescriptor = 12,
52
+ AccessorDescriptor = 13,
53
+ };
54
+
55
+ // The variant order MUST match JsType
56
+ using AnyValueVariant = std::variant<
57
+ JsUndefined,
58
+ JsNull,
59
+ JsUninitialized,
60
+ bool,
61
+ double,
62
+ std::shared_ptr<JsString>,
63
+ std::shared_ptr<JsObject>,
64
+ std::shared_ptr<JsArray>,
65
+ std::shared_ptr<JsFunction>,
66
+ std::shared_ptr<JsIterator<AnyValue>>,
67
+ std::shared_ptr<JsSymbol>,
68
+ std::shared_ptr<JsPromise>,
69
+ std::shared_ptr<DataDescriptor>,
70
+ std::shared_ptr<AccessorDescriptor>>;
71
+
72
+ class AnyValue
73
+ {
74
+ private:
75
+ AnyValueVariant storage;
76
+
77
+ public:
78
+ // default ctor (Undefined)
79
+ AnyValue() noexcept = default;
80
+
81
+ // Copy/Move handled by std::variant
82
+ AnyValue(const AnyValue &) = default;
83
+ AnyValue(AnyValue &&) noexcept = default;
84
+ AnyValue &operator=(const AnyValue &) = default;
85
+ AnyValue &operator=(AnyValue &&) noexcept = default;
86
+
87
+ ~AnyValue() = default;
88
+
89
+ // Assignments
90
+ AnyValue &operator=(const double &val)
91
+ {
92
+ storage = val;
93
+ return *this;
94
+ };
95
+
96
+ friend void swap(AnyValue &a, AnyValue &b) noexcept
97
+ {
98
+ std::swap(a.storage, b.storage);
99
+ }
100
+
101
+ // --- FRIENDS for Optimized Operators
102
+ friend AnyValue &operator+=(AnyValue &lhs, const AnyValue &rhs);
103
+ friend AnyValue &operator-=(AnyValue &lhs, const AnyValue &rhs);
104
+ friend AnyValue &operator*=(AnyValue &lhs, const AnyValue &rhs);
105
+ friend AnyValue &operator/=(AnyValue &lhs, const AnyValue &rhs);
106
+ friend AnyValue &operator%=(AnyValue &lhs, const AnyValue &rhs);
107
+ friend AnyValue &operator++(AnyValue &val);
108
+ friend AnyValue operator++(AnyValue &val, int);
109
+ friend AnyValue &operator--(AnyValue &val);
110
+ friend AnyValue operator--(AnyValue &val, int);
111
+
112
+ // factories -------------------------------------------------------
113
+ static AnyValue make_number(double d) noexcept
114
+ {
115
+ AnyValue v;
116
+ v.storage = d;
117
+ return v;
118
+ }
119
+ static AnyValue make_nan() noexcept
120
+ {
121
+ AnyValue v;
122
+ v.storage = std::numeric_limits<double>::quiet_NaN();
123
+ return v;
124
+ }
125
+ static AnyValue make_uninitialized() noexcept
126
+ {
127
+ AnyValue v;
128
+ v.storage = JsUninitialized{};
129
+ return v;
130
+ }
131
+ static AnyValue make_undefined() noexcept
132
+ {
133
+ AnyValue v;
134
+ v.storage = JsUndefined{};
135
+ return v;
136
+ }
137
+ static AnyValue make_null() noexcept
138
+ {
139
+ AnyValue v;
140
+ v.storage = JsNull{};
141
+ return v;
142
+ }
143
+ static AnyValue make_boolean(bool b) noexcept
144
+ {
145
+ AnyValue v;
146
+ v.storage = b;
147
+ return v;
148
+ }
149
+ static AnyValue make_string(const std::string &raw_s) noexcept
150
+ {
151
+ AnyValue v;
152
+ v.storage = std::make_shared<JsString>(raw_s);
153
+ return v;
154
+ }
155
+ static AnyValue make_object(std::initializer_list<std::pair<std::string, AnyValue>> props) noexcept
156
+ {
157
+ AnyValue v;
158
+ v.storage = std::make_shared<JsObject>(props);
159
+ return v;
160
+ }
161
+ static AnyValue make_object(const std::map<std::string, AnyValue> &props) noexcept
162
+ {
163
+ AnyValue v;
164
+ v.storage = std::make_shared<JsObject>(props);
165
+ return v;
166
+ }
167
+ static AnyValue make_object_with_proto(std::initializer_list<std::pair<std::string, AnyValue>> props, const AnyValue &proto) noexcept
168
+ {
169
+ AnyValue v;
170
+ auto protoPtr = std::make_shared<AnyValue>(proto);
171
+ v.storage = std::make_shared<JsObject>(props, protoPtr);
172
+ return v;
173
+ }
174
+ static AnyValue make_object_with_proto(const std::map<std::string, AnyValue> &props, const AnyValue &proto) noexcept
175
+ {
176
+ AnyValue v;
177
+ auto protoPtr = std::make_shared<AnyValue>(proto);
178
+ v.storage = std::make_shared<JsObject>(props, protoPtr);
179
+ return v;
180
+ }
181
+ static AnyValue make_array(std::span<const AnyValue> dense) noexcept
182
+ {
183
+ AnyValue v;
184
+ std::vector<AnyValue> vec;
185
+ vec.reserve(dense.size());
186
+ for (const auto &item : dense)
187
+ vec.push_back(item);
188
+ v.storage = std::make_shared<JsArray>(std::move(vec));
189
+ return v;
190
+ }
191
+ static AnyValue make_array(const std::vector<AnyValue> &dense) noexcept
192
+ {
193
+ AnyValue v;
194
+ v.storage = std::make_shared<JsArray>(dense);
195
+ return v;
196
+ }
197
+ static AnyValue make_array(std::vector<AnyValue> &&dense) noexcept
198
+ {
199
+ AnyValue v;
200
+ v.storage = std::make_shared<JsArray>(std::move(dense));
201
+ return v;
202
+ }
203
+ static AnyValue make_array_with_proto(std::span<const AnyValue> dense, const AnyValue &proto) noexcept
204
+ {
205
+ AnyValue v;
206
+ std::vector<AnyValue> vec;
207
+ vec.reserve(dense.size());
208
+ for (const auto &item : dense)
209
+ vec.push_back(item);
210
+ v.storage = std::make_shared<JsArray>(std::move(vec));
211
+ std::get<std::shared_ptr<JsArray>>(v.storage)->proto = std::make_shared<AnyValue>(proto);
212
+ return v;
213
+ }
214
+ static AnyValue make_array_with_proto(const std::vector<AnyValue> &dense, const AnyValue &proto) noexcept
215
+ {
216
+ AnyValue v;
217
+ v.storage = std::make_shared<JsArray>(dense);
218
+ std::get<std::shared_ptr<JsArray>>(v.storage)->proto = std::make_shared<AnyValue>(proto);
219
+ return v;
220
+ }
221
+ static AnyValue make_function(const JsFunctionCallable &call, const std::optional<std::string> &name = std::nullopt, bool is_constructor = true) noexcept
222
+ {
223
+ AnyValue v;
224
+ v.storage = std::make_shared<JsFunction>(call, name, std::unordered_map<std::string, AnyValue>{}, false, is_constructor);
225
+
226
+ auto proto = make_object({});
227
+ proto.define_data_property("constructor", AnyValue::make_data_descriptor(v, true, false, false));
228
+ v.define_data_property("prototype", AnyValue::make_data_descriptor(proto, false, false, false));
229
+
230
+ return v;
231
+ }
232
+ static AnyValue make_class(const JsFunctionCallable &call, const std::optional<std::string> &name = std::nullopt) noexcept
233
+ {
234
+ AnyValue v;
235
+ // use Constructor A with is_cls = true
236
+ v.storage = std::make_shared<JsFunction>(call, name, std::unordered_map<std::string, AnyValue>{}, true);
237
+
238
+ auto proto = make_object({});
239
+ proto.define_data_property("constructor", AnyValue::make_data_descriptor(v, true, false, false));
240
+ v.define_data_property("prototype", AnyValue::make_data_descriptor(proto, false, false, false));
241
+
242
+ return v;
243
+ }
244
+ static AnyValue make_generator(const JsFunctionCallable &call, const std::optional<std::string> &name = std::nullopt) noexcept
245
+ {
246
+ AnyValue v;
247
+ // use Constructor B with is_gen = true
248
+ v.storage = std::make_shared<JsFunction>(call, true, name);
249
+
250
+ auto proto = make_object({});
251
+ proto.define_data_property("constructor", AnyValue::make_data_descriptor(v, true, false, false));
252
+ v.define_data_property("prototype", AnyValue::make_data_descriptor(proto, false, false, false));
253
+
254
+ return v;
255
+ }
256
+ static AnyValue make_async_function(const JsFunctionCallable &call, const std::optional<std::string> &name = std::nullopt) noexcept
257
+ {
258
+ AnyValue v;
259
+ // use Constructor C with is_async_func = true
260
+ v.storage = std::make_shared<JsFunction>(call, false, true, name);
261
+
262
+ auto proto = make_object({});
263
+ proto.define_data_property("constructor", AnyValue::make_data_descriptor(v, true, false, false));
264
+ v.define_data_property("prototype", AnyValue::make_data_descriptor(proto, false, false, false));
265
+
266
+ return v;
267
+ }
268
+ static AnyValue make_async_generator(const JsFunctionCallable &call, const std::optional<std::string> &name = std::nullopt) noexcept
269
+ {
270
+ AnyValue v;
271
+ // use Constructor C with is_gen = true and is_async_func = true
272
+ v.storage = std::make_shared<JsFunction>(call, true, true, name);
273
+
274
+ auto proto = make_object({});
275
+ proto.define_data_property("constructor", AnyValue::make_data_descriptor(v, true, false, false));
276
+ v.define_data_property("prototype", AnyValue::make_data_descriptor(proto, false, false, false));
277
+
278
+ return v;
279
+ }
280
+ static AnyValue make_symbol(const std::string &description = "") noexcept
281
+ {
282
+ AnyValue v;
283
+ v.storage = std::make_shared<JsSymbol>(description);
284
+ return v;
285
+ }
286
+ static AnyValue make_promise(const JsPromise &promise) noexcept
287
+ {
288
+ AnyValue v;
289
+ v.storage = std::make_shared<JsPromise>(promise);
290
+ return v;
291
+ }
292
+ static AnyValue make_data_descriptor(const AnyValue &value, bool writable, bool enumerable, bool configurable) noexcept
293
+ {
294
+ AnyValue v;
295
+ v.storage = std::make_shared<DataDescriptor>(std::make_shared<AnyValue>(value), writable, enumerable, configurable);
296
+ return v;
297
+ }
298
+ static AnyValue make_accessor_descriptor(const std::optional<std::function<AnyValue(const AnyValue &, std::span<const AnyValue>)>> &get,
299
+ const std::optional<std::function<AnyValue(const AnyValue &, std::span<const AnyValue>)>> &set,
300
+ bool enumerable,
301
+ bool configurable) noexcept
302
+ {
303
+ AnyValue v;
304
+ v.storage = std::make_shared<AccessorDescriptor>(get, set, enumerable, configurable);
305
+ return v;
306
+ }
307
+
308
+ static AnyValue from_symbol(std::shared_ptr<JsSymbol> sym) noexcept
309
+ {
310
+ AnyValue v;
311
+ v.storage = std::move(sym);
312
+ return v;
313
+ }
314
+ static AnyValue from_string(std::shared_ptr<JsString> str) noexcept
315
+ {
316
+ AnyValue v;
317
+ v.storage = std::move(str);
318
+ return v;
319
+ }
320
+ static AnyValue from_iterator(JsIterator<AnyValue> &&iterator) noexcept
321
+ {
322
+ AnyValue v;
323
+ v.storage = std::make_shared<JsIterator<AnyValue>>(std::move(iterator));
324
+ return v;
325
+ }
326
+ static AnyValue from_iterator_ref(JsIterator<AnyValue> *iterator) noexcept
327
+ {
328
+ AnyValue v;
329
+ v.storage = std::shared_ptr<JsIterator<AnyValue>>(iterator, [](JsIterator<AnyValue> *) {});
330
+ return v;
331
+ }
332
+
333
+ // PROPERTY RESOLUTION HELPERS ---------------------------------------
334
+ static AnyValue resolve_property_for_read(const AnyValue &val, const AnyValue &thisVal, const std::string &propName) noexcept
335
+ {
336
+ switch (val.get_type())
337
+ {
338
+ case JsType::DataDescriptor:
339
+ {
340
+ return *(val.as_data_descriptor()->value);
341
+ }
342
+ case JsType::AccessorDescriptor:
343
+ {
344
+ const auto &accessor = val.as_accessor_descriptor();
345
+ if (accessor->get.has_value())
346
+ return accessor->get.value()(thisVal, std::span<const AnyValue>{});
347
+ else
348
+ {
349
+ static AnyValue undefined = AnyValue{};
350
+ return undefined;
351
+ }
352
+ }
353
+ default:
354
+ {
355
+ return val;
356
+ }
357
+ }
358
+ }
359
+ static AnyValue resolve_property_for_write(AnyValue &val, const AnyValue &thisVal, const AnyValue &new_val, const std::string &propName)
360
+ {
361
+ switch (val.get_type())
362
+ {
363
+ case JsType::DataDescriptor:
364
+ {
365
+ const auto &data = val.as_data_descriptor();
366
+ if (data->writable)
367
+ {
368
+ *(data->value) = new_val;
369
+ return new_val;
370
+ }
371
+ else
372
+ {
373
+ throw Exception::make_exception("Cannot assign to read only property '" + propName + "' of object '#<Object>'", "TypeError");
374
+ }
375
+ }
376
+ case JsType::AccessorDescriptor:
377
+ {
378
+ const auto &accessor = val.as_accessor_descriptor();
379
+ if (accessor->set.has_value())
380
+ {
381
+ const AnyValue args[] = {new_val};
382
+ accessor->set.value()(thisVal, args);
383
+ return new_val;
384
+ }
385
+ else
386
+ {
387
+ throw Exception::make_exception("Cannot set property of #<Object> which has only a getter", "TypeError");
388
+ }
389
+ }
390
+ default:
391
+ {
392
+ val = new_val;
393
+ return new_val;
394
+ }
395
+ }
396
+ }
397
+
398
+ // TYPE CHECKERS AND ACCESSORS ---------------------------------------
399
+ JsType get_type() const noexcept { return static_cast<JsType>(storage.index()); }
400
+ bool is_number() const noexcept { return storage.index() == 4; }
401
+ bool is_string() const noexcept { return storage.index() == 5; }
402
+ bool is_object() const noexcept { return storage.index() == 6; }
403
+ bool is_array() const noexcept { return storage.index() == 7; }
404
+ bool is_function() const noexcept { return storage.index() == 8; }
405
+ bool is_iterator() const noexcept { return storage.index() == 9; }
406
+ bool is_boolean() const noexcept { return storage.index() == 3; }
407
+ bool is_symbol() const noexcept { return storage.index() == 10; }
408
+ bool is_promise() const noexcept { return storage.index() == 11; }
409
+ bool is_null() const noexcept { return storage.index() == 1; }
410
+ bool is_undefined() const noexcept { return storage.index() == 0; }
411
+ bool is_uninitialized() const noexcept { return storage.index() == 2; }
412
+ bool is_data_descriptor() const noexcept { return storage.index() == 12; }
413
+ bool is_accessor_descriptor() const noexcept { return storage.index() == 13; }
414
+ bool is_generator() const noexcept { return is_function() && as_function()->is_generator; }
415
+
416
+ // --- TYPE CASTERS
417
+ double as_double() const noexcept
418
+ {
419
+ return std::get<double>(storage);
420
+ }
421
+ bool as_boolean() const noexcept
422
+ {
423
+ return std::get<bool>(storage);
424
+ }
425
+ JsString *as_string() const noexcept
426
+ {
427
+ return std::get<std::shared_ptr<JsString>>(storage).get();
428
+ }
429
+ JsObject *as_object() const noexcept
430
+ {
431
+ return std::get<std::shared_ptr<JsObject>>(storage).get();
432
+ }
433
+ JsArray *as_array() const noexcept
434
+ {
435
+ return std::get<std::shared_ptr<JsArray>>(storage).get();
436
+ }
437
+ JsFunction *as_function() const noexcept
438
+ {
439
+ return std::get<std::shared_ptr<JsFunction>>(storage).get();
440
+ }
441
+ JsSymbol *as_symbol() const noexcept
442
+ {
443
+ return std::get<std::shared_ptr<JsSymbol>>(storage).get();
444
+ }
445
+ JsPromise *as_promise() const noexcept
446
+ {
447
+ return std::get<std::shared_ptr<JsPromise>>(storage).get();
448
+ }
449
+ std::shared_ptr<JsIterator<AnyValue>> as_iterator() const
450
+ {
451
+ return std::get<std::shared_ptr<JsIterator<AnyValue>>>(storage);
452
+ }
453
+ DataDescriptor *as_data_descriptor() const noexcept
454
+ {
455
+ return std::get<std::shared_ptr<DataDescriptor>>(storage).get();
456
+ }
457
+ AccessorDescriptor *as_accessor_descriptor() const noexcept
458
+ {
459
+ return std::get<std::shared_ptr<AccessorDescriptor>>(storage).get();
460
+ }
461
+
462
+ // --- CO_AWAIT Operator ---
463
+ auto operator co_await() const;
464
+
465
+ // --- PROPERTY ACCESS OPERATORS
466
+ bool has_property(const std::string &key) const;
467
+ AnyValue get_own_property(const std::string &key) const;
468
+ AnyValue get_own_property(uint32_t idx) const;
469
+ AnyValue get_own_property(const AnyValue &key) const;
470
+ // for getting values with a specific receiver (used in inheritance chains)
471
+ AnyValue get_property_with_receiver(const std::string &key, const AnyValue &receiver) const;
472
+ // for setting values
473
+ AnyValue set_own_property(const std::string &key, const AnyValue &value) const;
474
+ AnyValue set_own_property(uint32_t idx, const AnyValue &value) const;
475
+ AnyValue set_own_property(const AnyValue &key, const AnyValue &value) const;
476
+
477
+ // --- DEFINERS (Object.defineProperty semantics)
478
+ void define_data_property(const std::string &key, const AnyValue &value);
479
+ void define_data_property(const AnyValue &key, const AnyValue &value);
480
+ void define_data_property(const std::string &key, const AnyValue &value, bool writable, bool enumerable, bool configurable);
481
+ void define_getter(const std::string &key, const AnyValue &getter);
482
+ void define_getter(const AnyValue &key, const AnyValue &getter);
483
+ void define_setter(const std::string &key, const AnyValue &setter);
484
+ void define_setter(const AnyValue &key, const AnyValue &setter);
485
+
486
+ // --- HELPERS
487
+ const AnyValue call(const AnyValue &thisVal, std::span<const AnyValue> args, const std::optional<std::string> &expr) const;
488
+ const AnyValue construct(std::span<const AnyValue> args, const std::optional<std::string> &name) const;
489
+ void set_prototype(const AnyValue &proto);
490
+ std::string to_std_string() const;
491
+ };
492
+
493
+ // Inline implementation of operator co_await
494
+ inline auto AnyValue::operator co_await() const
495
+ {
496
+ return AnyValueAwaiter{*this};
497
+ }
498
+
499
+ // Global Constants for Optimization
500
+ namespace Constants
501
+ {
502
+ inline const AnyValue UNINITIALIZED = AnyValue::make_uninitialized();
503
+ inline const AnyValue UNDEFINED = AnyValue::make_undefined();
504
+ inline const AnyValue Null = AnyValue::make_null();
505
+ inline const AnyValue NaN = AnyValue::make_nan();
506
+ inline const AnyValue TRUE = AnyValue::make_boolean(true);
507
+ inline const AnyValue FALSE = AnyValue::make_boolean(false);
508
+ inline const AnyValue ZERO = AnyValue::make_number(0.0);
509
+ inline const AnyValue ONE = AnyValue::make_number(1.0);
510
+ }
634
511
  }