@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.
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/dist/analysis/scope.js +77 -0
- package/dist/analysis/typeAnalyzer.js +224 -0
- package/dist/ast/types.js +1 -0
- package/dist/cli.js +63 -0
- package/dist/core/codegen/declaration-handlers.js +49 -0
- package/dist/core/codegen/expression-handlers.js +333 -0
- package/dist/core/codegen/function-handlers.js +94 -0
- package/dist/core/codegen/helpers.js +83 -0
- package/dist/core/codegen/index.js +54 -0
- package/dist/core/codegen/literal-handlers.js +32 -0
- package/dist/core/codegen/statement-handlers.js +485 -0
- package/dist/core/codegen/visitor.js +86 -0
- package/dist/core/parser.js +6 -0
- package/dist/core/traverser.js +19 -0
- package/dist/index.js +16 -0
- package/package.json +41 -0
- package/src/prelude/access.hpp +86 -0
- package/src/prelude/any_value.hpp +734 -0
- package/src/prelude/descriptors.hpp +25 -0
- package/src/prelude/error.hpp +31 -0
- package/src/prelude/error_helpers.hpp +59 -0
- package/src/prelude/index.hpp +29 -0
- package/src/prelude/library/console.hpp +111 -0
- package/src/prelude/library/global.hpp +10 -0
- package/src/prelude/library/symbol.hpp +8 -0
- package/src/prelude/log_string.hpp +403 -0
- package/src/prelude/operators.hpp +256 -0
- package/src/prelude/types.hpp +50 -0
- package/src/prelude/values/array.hpp +50 -0
- package/src/prelude/values/function.hpp +19 -0
- package/src/prelude/values/non_values.hpp +20 -0
- package/src/prelude/values/object.hpp +17 -0
- package/src/prelude/values/operators/array.hpp +165 -0
- package/src/prelude/values/operators/function.hpp +34 -0
- package/src/prelude/values/operators/object.hpp +34 -0
- package/src/prelude/values/prototypes/array.hpp +228 -0
- package/src/prelude/values/prototypes/function.hpp +0 -0
- package/src/prelude/values/prototypes/object.hpp +0 -0
- package/src/prelude/values/prototypes/string.hpp +357 -0
- 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
|
+
}
|