@ugo-studio/jspp 0.1.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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +162 -0
  3. package/dist/analysis/scope.js +77 -0
  4. package/dist/analysis/typeAnalyzer.js +224 -0
  5. package/dist/ast/types.js +1 -0
  6. package/dist/cli.js +63 -0
  7. package/dist/core/codegen/declaration-handlers.js +49 -0
  8. package/dist/core/codegen/expression-handlers.js +333 -0
  9. package/dist/core/codegen/function-handlers.js +94 -0
  10. package/dist/core/codegen/helpers.js +83 -0
  11. package/dist/core/codegen/index.js +54 -0
  12. package/dist/core/codegen/literal-handlers.js +32 -0
  13. package/dist/core/codegen/statement-handlers.js +485 -0
  14. package/dist/core/codegen/visitor.js +86 -0
  15. package/dist/core/parser.js +6 -0
  16. package/dist/core/traverser.js +19 -0
  17. package/dist/index.js +16 -0
  18. package/package.json +41 -0
  19. package/src/prelude/access.hpp +86 -0
  20. package/src/prelude/any_value.hpp +734 -0
  21. package/src/prelude/descriptors.hpp +25 -0
  22. package/src/prelude/error.hpp +31 -0
  23. package/src/prelude/error_helpers.hpp +59 -0
  24. package/src/prelude/index.hpp +29 -0
  25. package/src/prelude/library/console.hpp +111 -0
  26. package/src/prelude/library/global.hpp +10 -0
  27. package/src/prelude/library/symbol.hpp +8 -0
  28. package/src/prelude/log_string.hpp +403 -0
  29. package/src/prelude/operators.hpp +256 -0
  30. package/src/prelude/types.hpp +50 -0
  31. package/src/prelude/values/array.hpp +50 -0
  32. package/src/prelude/values/function.hpp +19 -0
  33. package/src/prelude/values/non_values.hpp +20 -0
  34. package/src/prelude/values/object.hpp +17 -0
  35. package/src/prelude/values/operators/array.hpp +165 -0
  36. package/src/prelude/values/operators/function.hpp +34 -0
  37. package/src/prelude/values/operators/object.hpp +34 -0
  38. package/src/prelude/values/prototypes/array.hpp +228 -0
  39. package/src/prelude/values/prototypes/function.hpp +0 -0
  40. package/src/prelude/values/prototypes/object.hpp +0 -0
  41. package/src/prelude/values/prototypes/string.hpp +357 -0
  42. package/src/prelude/well_known_symbols.hpp +10 -0
@@ -0,0 +1,86 @@
1
+ #pragma once
2
+
3
+ #include "types.hpp"
4
+ #include "values/function.hpp"
5
+ #include "error.hpp"
6
+ #include <ranges>
7
+
8
+ namespace jspp
9
+ {
10
+ namespace Access
11
+ {
12
+ // Helper function to check for TDZ and deref variables
13
+ inline const AnyValue &deref(const std::shared_ptr<AnyValue> &var, const std::string &name)
14
+ {
15
+ if ((*var).is_uninitialized()) [[unlikely]]
16
+ {
17
+ RuntimeError::throw_uninitialized_reference_error(name);
18
+ }
19
+ return *var;
20
+ }
21
+ inline AnyValue &deref(std::shared_ptr<AnyValue> &var, const std::string &name)
22
+ {
23
+ if ((*var).is_uninitialized()) [[unlikely]]
24
+ {
25
+ RuntimeError::throw_uninitialized_reference_error(name);
26
+ }
27
+ return *var;
28
+ }
29
+ inline const AnyValue &deref(const std::unique_ptr<AnyValue> &var, const std::string &name)
30
+ {
31
+ if ((*var).is_uninitialized()) [[unlikely]]
32
+ {
33
+ RuntimeError::throw_uninitialized_reference_error(name);
34
+ }
35
+ return *var;
36
+ }
37
+ inline AnyValue &deref(std::unique_ptr<AnyValue> &var, const std::string &name)
38
+ {
39
+ if ((*var).is_uninitialized()) [[unlikely]]
40
+ {
41
+ RuntimeError::throw_uninitialized_reference_error(name);
42
+ }
43
+ return *var;
44
+ }
45
+
46
+ inline std::vector<std::string> get_object_keys(const AnyValue &obj)
47
+ {
48
+ std::vector<std::string> keys;
49
+
50
+ if (obj.is_object())
51
+ {
52
+ auto ptr = obj.as_object();
53
+ for (const auto &pair : ptr->props)
54
+ {
55
+ keys.push_back(pair.first);
56
+ }
57
+ }
58
+ if (obj.is_function())
59
+ {
60
+ auto ptr = obj.as_function();
61
+ for (const auto &pair : ptr->props)
62
+ {
63
+ keys.push_back(pair.first);
64
+ }
65
+ }
66
+ if (obj.is_array())
67
+ {
68
+ auto len = obj.as_array()->length;
69
+ for (auto i = 0; i < len; ++i)
70
+ {
71
+ keys.push_back(std::to_string(i));
72
+ }
73
+ }
74
+ if (obj.is_string())
75
+ {
76
+ auto len = obj.as_string()->length();
77
+ for (auto i = 0; i < len; ++i)
78
+ {
79
+ keys.push_back(std::to_string(i));
80
+ }
81
+ }
82
+
83
+ return keys;
84
+ }
85
+ }
86
+ }