@ugo-studio/jspp 0.2.8 → 0.3.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/analysis/typeAnalyzer.js +42 -27
- package/dist/core/codegen/class-handlers.js +6 -6
- package/dist/core/codegen/control-flow-handlers.js +4 -4
- package/dist/core/codegen/declaration-handlers.js +21 -3
- package/dist/core/codegen/destructuring-handlers.js +187 -0
- package/dist/core/codegen/expression-handlers.js +7 -0
- package/dist/core/codegen/function-handlers.js +58 -36
- package/dist/core/codegen/helpers.js +288 -52
- package/dist/core/codegen/index.js +7 -4
- package/dist/core/codegen/statement-handlers.js +43 -23
- package/package.json +1 -1
- package/scripts/precompile-headers.ts +13 -5
- package/src/prelude/any_value.hpp +362 -361
- package/src/prelude/any_value_access.hpp +170 -170
- package/src/prelude/any_value_defines.hpp +189 -189
- package/src/prelude/any_value_helpers.hpp +374 -365
- package/src/prelude/library/array.hpp +185 -185
- package/src/prelude/library/console.hpp +111 -111
- package/src/prelude/library/error.hpp +112 -112
- package/src/prelude/library/function.hpp +10 -10
- package/src/prelude/library/math.hpp +307 -307
- package/src/prelude/library/object.hpp +275 -275
- package/src/prelude/library/performance.hpp +1 -1
- package/src/prelude/library/process.hpp +39 -39
- package/src/prelude/library/promise.hpp +123 -123
- package/src/prelude/library/symbol.hpp +52 -52
- package/src/prelude/library/timer.hpp +91 -91
- package/src/prelude/types.hpp +178 -178
- package/src/prelude/utils/access.hpp +411 -393
- package/src/prelude/utils/operators.hpp +336 -329
- package/src/prelude/values/array.hpp +0 -1
- package/src/prelude/values/async_iterator.hpp +83 -81
- package/src/prelude/values/function.hpp +82 -82
- package/src/prelude/values/helpers/array.hpp +198 -208
- package/src/prelude/values/helpers/async_iterator.hpp +275 -271
- package/src/prelude/values/helpers/function.hpp +108 -108
- package/src/prelude/values/helpers/iterator.hpp +144 -107
- package/src/prelude/values/helpers/promise.hpp +253 -253
- package/src/prelude/values/helpers/string.hpp +37 -47
- package/src/prelude/values/iterator.hpp +32 -5
- package/src/prelude/values/promise.hpp +72 -72
- package/src/prelude/values/prototypes/array.hpp +54 -42
- package/src/prelude/values/prototypes/iterator.hpp +201 -74
- package/src/prelude/values/prototypes/promise.hpp +196 -196
- package/src/prelude/values/prototypes/string.hpp +564 -542
- package/src/prelude/values/string.hpp +25 -26
|
@@ -23,7 +23,6 @@ namespace jspp
|
|
|
23
23
|
JsType get_heap_type() const override { return JsType::Array; }
|
|
24
24
|
|
|
25
25
|
std::string to_std_string() const;
|
|
26
|
-
JsIterator<AnyValue> get_iterator();
|
|
27
26
|
|
|
28
27
|
bool has_property(const std::string &key) const;
|
|
29
28
|
AnyValue get_property(const std::string &key, const AnyValue &thisVal);
|
|
@@ -1,81 +1,83 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
#include <coroutine>
|
|
5
|
-
#include <optional>
|
|
6
|
-
#include <queue>
|
|
7
|
-
#include <iostream>
|
|
8
|
-
#include <utility>
|
|
9
|
-
#include <exception>
|
|
10
|
-
#include "values/promise.hpp"
|
|
11
|
-
#include "scheduler.hpp"
|
|
12
|
-
|
|
13
|
-
namespace jspp
|
|
14
|
-
{
|
|
15
|
-
// Forward declaration of AnyValue
|
|
16
|
-
class AnyValue;
|
|
17
|
-
|
|
18
|
-
template <typename T>
|
|
19
|
-
class JsAsyncIterator : public HeapObject
|
|
20
|
-
{
|
|
21
|
-
public:
|
|
22
|
-
JsType get_heap_type() const override { return JsType::AsyncIterator; }
|
|
23
|
-
|
|
24
|
-
struct promise_type
|
|
25
|
-
{
|
|
26
|
-
std::queue<std::pair<JsPromise, T>> pending_calls;
|
|
27
|
-
bool is_awaiting = false;
|
|
28
|
-
bool is_running = false;
|
|
29
|
-
T current_input;
|
|
30
|
-
|
|
31
|
-
JsAsyncIterator get_return_object()
|
|
32
|
-
{
|
|
33
|
-
return JsAsyncIterator{
|
|
34
|
-
std::coroutine_handle<promise_type>::from_promise(*this)};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
std::suspend_always initial_suspend() noexcept { return {}; }
|
|
38
|
-
|
|
39
|
-
std::suspend_always final_suspend() noexcept { return {}; }
|
|
40
|
-
|
|
41
|
-
// Declarations
|
|
42
|
-
template <typename From>
|
|
43
|
-
auto yield_value(From &&from);
|
|
44
|
-
|
|
45
|
-
template <typename From>
|
|
46
|
-
void return_value(From &&from);
|
|
47
|
-
|
|
48
|
-
void unhandled_exception();
|
|
49
|
-
|
|
50
|
-
void fail_all(const AnyValue &reason);
|
|
51
|
-
|
|
52
|
-
auto await_transform(AnyValue value);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
using handle_type = std::coroutine_handle<promise_type>;
|
|
56
|
-
handle_type handle;
|
|
57
|
-
|
|
58
|
-
explicit JsAsyncIterator(handle_type h) : handle(h) {}
|
|
59
|
-
JsAsyncIterator(JsAsyncIterator &&other) noexcept
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
std::string
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include <coroutine>
|
|
5
|
+
#include <optional>
|
|
6
|
+
#include <queue>
|
|
7
|
+
#include <iostream>
|
|
8
|
+
#include <utility>
|
|
9
|
+
#include <exception>
|
|
10
|
+
#include "values/promise.hpp"
|
|
11
|
+
#include "scheduler.hpp"
|
|
12
|
+
|
|
13
|
+
namespace jspp
|
|
14
|
+
{
|
|
15
|
+
// Forward declaration of AnyValue
|
|
16
|
+
class AnyValue;
|
|
17
|
+
|
|
18
|
+
template <typename T>
|
|
19
|
+
class JsAsyncIterator : public HeapObject
|
|
20
|
+
{
|
|
21
|
+
public:
|
|
22
|
+
JsType get_heap_type() const override { return JsType::AsyncIterator; }
|
|
23
|
+
|
|
24
|
+
struct promise_type
|
|
25
|
+
{
|
|
26
|
+
std::queue<std::pair<JsPromise, T>> pending_calls;
|
|
27
|
+
bool is_awaiting = false;
|
|
28
|
+
bool is_running = false;
|
|
29
|
+
T current_input;
|
|
30
|
+
|
|
31
|
+
JsAsyncIterator get_return_object()
|
|
32
|
+
{
|
|
33
|
+
return JsAsyncIterator{
|
|
34
|
+
std::coroutine_handle<promise_type>::from_promise(*this)};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
std::suspend_always initial_suspend() noexcept { return {}; }
|
|
38
|
+
|
|
39
|
+
std::suspend_always final_suspend() noexcept { return {}; }
|
|
40
|
+
|
|
41
|
+
// Declarations
|
|
42
|
+
template <typename From>
|
|
43
|
+
auto yield_value(From &&from);
|
|
44
|
+
|
|
45
|
+
template <typename From>
|
|
46
|
+
void return_value(From &&from);
|
|
47
|
+
|
|
48
|
+
void unhandled_exception();
|
|
49
|
+
|
|
50
|
+
void fail_all(const AnyValue &reason);
|
|
51
|
+
|
|
52
|
+
auto await_transform(AnyValue value);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
using handle_type = std::coroutine_handle<promise_type>;
|
|
56
|
+
handle_type handle;
|
|
57
|
+
|
|
58
|
+
explicit JsAsyncIterator(handle_type h) : handle(h) {}
|
|
59
|
+
JsAsyncIterator(JsAsyncIterator &&other) noexcept
|
|
60
|
+
: handle(std::exchange(other.handle, nullptr)),
|
|
61
|
+
props(std::move(other.props)) {}
|
|
62
|
+
|
|
63
|
+
JsAsyncIterator(const JsAsyncIterator &) = delete;
|
|
64
|
+
JsAsyncIterator &operator=(const JsAsyncIterator &) = delete;
|
|
65
|
+
|
|
66
|
+
~JsAsyncIterator()
|
|
67
|
+
{
|
|
68
|
+
if (handle)
|
|
69
|
+
handle.destroy();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
std::unordered_map<std::string, AnyValue> props;
|
|
73
|
+
|
|
74
|
+
std::string to_std_string() const;
|
|
75
|
+
|
|
76
|
+
JsPromise next(const T &val = T());
|
|
77
|
+
|
|
78
|
+
AnyValue get_property(const std::string &key, AnyValue thisVal);
|
|
79
|
+
AnyValue set_property(const std::string &key, AnyValue value, AnyValue thisVal);
|
|
80
|
+
|
|
81
|
+
void resume_next();
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "types.hpp"
|
|
4
|
-
#include <optional>
|
|
5
|
-
|
|
6
|
-
namespace jspp
|
|
7
|
-
{
|
|
8
|
-
// Forward declaration of AnyValue
|
|
9
|
-
class AnyValue;
|
|
10
|
-
|
|
11
|
-
struct JsFunction : HeapObject
|
|
12
|
-
{
|
|
13
|
-
JsFunctionCallable callable;
|
|
14
|
-
std::optional<std::string> name;
|
|
15
|
-
std::unordered_map<std::string, AnyValue> props;
|
|
16
|
-
AnyValue proto;
|
|
17
|
-
bool is_generator;
|
|
18
|
-
bool is_async;
|
|
19
|
-
bool is_class;
|
|
20
|
-
bool is_constructor;
|
|
21
|
-
|
|
22
|
-
// ---- Constructor A: infer flags ----
|
|
23
|
-
JsFunction(const JsFunctionCallable &c,
|
|
24
|
-
std::optional<std::string> n = std::nullopt,
|
|
25
|
-
std::unordered_map<std::string, AnyValue> p = {},
|
|
26
|
-
bool is_cls = false,
|
|
27
|
-
bool is_ctor = true)
|
|
28
|
-
: callable(c),
|
|
29
|
-
name(std::move(n)),
|
|
30
|
-
props(std::move(p)),
|
|
31
|
-
is_generator(callable.index() == 1),
|
|
32
|
-
is_async(callable.index() == 2),
|
|
33
|
-
is_class(is_cls),
|
|
34
|
-
is_constructor(is_ctor && !is_generator && !is_async) // Generators and asyncs are never constructors
|
|
35
|
-
{
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// ---- Constructor B: explicit generator flag (backward compat) ----
|
|
39
|
-
JsFunction(const JsFunctionCallable &c,
|
|
40
|
-
bool is_gen,
|
|
41
|
-
std::optional<std::string> n = std::nullopt,
|
|
42
|
-
std::unordered_map<std::string, AnyValue> p = {},
|
|
43
|
-
bool is_cls = false,
|
|
44
|
-
bool is_ctor = true)
|
|
45
|
-
: callable(c),
|
|
46
|
-
name(std::move(n)),
|
|
47
|
-
props(std::move(p)),
|
|
48
|
-
is_generator(is_gen),
|
|
49
|
-
is_async(callable.index() == 2),
|
|
50
|
-
is_class(is_cls),
|
|
51
|
-
is_constructor(is_ctor && !is_gen && !is_async)
|
|
52
|
-
{
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// ---- Constructor C: explicit async flag ----
|
|
56
|
-
JsFunction(const JsFunctionCallable &c,
|
|
57
|
-
bool is_gen,
|
|
58
|
-
bool is_async_func,
|
|
59
|
-
std::optional<std::string> n = std::nullopt,
|
|
60
|
-
std::unordered_map<std::string, AnyValue> p = {},
|
|
61
|
-
bool is_cls = false,
|
|
62
|
-
bool is_ctor = true)
|
|
63
|
-
: callable(c),
|
|
64
|
-
name(std::move(n)),
|
|
65
|
-
props(std::move(p)),
|
|
66
|
-
is_generator(is_gen),
|
|
67
|
-
is_async(is_async_func),
|
|
68
|
-
is_class(is_cls),
|
|
69
|
-
is_constructor(is_ctor && !is_gen && !is_async_func)
|
|
70
|
-
{
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
JsType get_heap_type() const override { return JsType::Function; }
|
|
74
|
-
|
|
75
|
-
std::string to_std_string() const;
|
|
76
|
-
AnyValue call(
|
|
77
|
-
|
|
78
|
-
bool has_property(const std::string &key) const;
|
|
79
|
-
AnyValue get_property(const std::string &key,
|
|
80
|
-
AnyValue set_property(const std::string &key,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.hpp"
|
|
4
|
+
#include <optional>
|
|
5
|
+
|
|
6
|
+
namespace jspp
|
|
7
|
+
{
|
|
8
|
+
// Forward declaration of AnyValue
|
|
9
|
+
class AnyValue;
|
|
10
|
+
|
|
11
|
+
struct JsFunction : HeapObject
|
|
12
|
+
{
|
|
13
|
+
JsFunctionCallable callable;
|
|
14
|
+
std::optional<std::string> name;
|
|
15
|
+
std::unordered_map<std::string, AnyValue> props;
|
|
16
|
+
AnyValue proto;
|
|
17
|
+
bool is_generator;
|
|
18
|
+
bool is_async;
|
|
19
|
+
bool is_class;
|
|
20
|
+
bool is_constructor;
|
|
21
|
+
|
|
22
|
+
// ---- Constructor A: infer flags ----
|
|
23
|
+
JsFunction(const JsFunctionCallable &c,
|
|
24
|
+
std::optional<std::string> n = std::nullopt,
|
|
25
|
+
std::unordered_map<std::string, AnyValue> p = {},
|
|
26
|
+
bool is_cls = false,
|
|
27
|
+
bool is_ctor = true)
|
|
28
|
+
: callable(c),
|
|
29
|
+
name(std::move(n)),
|
|
30
|
+
props(std::move(p)),
|
|
31
|
+
is_generator(callable.index() == 1),
|
|
32
|
+
is_async(callable.index() == 2),
|
|
33
|
+
is_class(is_cls),
|
|
34
|
+
is_constructor(is_ctor && !is_generator && !is_async) // Generators and asyncs are never constructors
|
|
35
|
+
{
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ---- Constructor B: explicit generator flag (backward compat) ----
|
|
39
|
+
JsFunction(const JsFunctionCallable &c,
|
|
40
|
+
bool is_gen,
|
|
41
|
+
std::optional<std::string> n = std::nullopt,
|
|
42
|
+
std::unordered_map<std::string, AnyValue> p = {},
|
|
43
|
+
bool is_cls = false,
|
|
44
|
+
bool is_ctor = true)
|
|
45
|
+
: callable(c),
|
|
46
|
+
name(std::move(n)),
|
|
47
|
+
props(std::move(p)),
|
|
48
|
+
is_generator(is_gen),
|
|
49
|
+
is_async(callable.index() == 2),
|
|
50
|
+
is_class(is_cls),
|
|
51
|
+
is_constructor(is_ctor && !is_gen && !is_async)
|
|
52
|
+
{
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ---- Constructor C: explicit async flag ----
|
|
56
|
+
JsFunction(const JsFunctionCallable &c,
|
|
57
|
+
bool is_gen,
|
|
58
|
+
bool is_async_func,
|
|
59
|
+
std::optional<std::string> n = std::nullopt,
|
|
60
|
+
std::unordered_map<std::string, AnyValue> p = {},
|
|
61
|
+
bool is_cls = false,
|
|
62
|
+
bool is_ctor = true)
|
|
63
|
+
: callable(c),
|
|
64
|
+
name(std::move(n)),
|
|
65
|
+
props(std::move(p)),
|
|
66
|
+
is_generator(is_gen),
|
|
67
|
+
is_async(is_async_func),
|
|
68
|
+
is_class(is_cls),
|
|
69
|
+
is_constructor(is_ctor && !is_gen && !is_async_func)
|
|
70
|
+
{
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
JsType get_heap_type() const override { return JsType::Function; }
|
|
74
|
+
|
|
75
|
+
std::string to_std_string() const;
|
|
76
|
+
AnyValue call(AnyValue thisVal, std::span<const AnyValue> args);
|
|
77
|
+
|
|
78
|
+
bool has_property(const std::string &key) const;
|
|
79
|
+
AnyValue get_property(const std::string &key, AnyValue thisVal);
|
|
80
|
+
AnyValue set_property(const std::string &key, AnyValue value, AnyValue thisVal);
|
|
81
|
+
};
|
|
82
|
+
}
|