@ugo-studio/jspp 0.2.9 → 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.
Files changed (35) hide show
  1. package/dist/core/codegen/class-handlers.js +6 -6
  2. package/dist/core/codegen/statement-handlers.js +1 -1
  3. package/package.json +1 -1
  4. package/src/prelude/any_value.hpp +362 -362
  5. package/src/prelude/any_value_access.hpp +170 -170
  6. package/src/prelude/any_value_defines.hpp +189 -189
  7. package/src/prelude/any_value_helpers.hpp +374 -374
  8. package/src/prelude/library/array.hpp +185 -185
  9. package/src/prelude/library/console.hpp +111 -111
  10. package/src/prelude/library/error.hpp +112 -112
  11. package/src/prelude/library/function.hpp +10 -10
  12. package/src/prelude/library/math.hpp +307 -307
  13. package/src/prelude/library/object.hpp +275 -275
  14. package/src/prelude/library/process.hpp +39 -39
  15. package/src/prelude/library/promise.hpp +123 -123
  16. package/src/prelude/library/symbol.hpp +52 -52
  17. package/src/prelude/library/timer.hpp +91 -91
  18. package/src/prelude/types.hpp +178 -178
  19. package/src/prelude/utils/access.hpp +411 -411
  20. package/src/prelude/utils/operators.hpp +336 -336
  21. package/src/prelude/values/array.hpp +0 -1
  22. package/src/prelude/values/async_iterator.hpp +83 -83
  23. package/src/prelude/values/function.hpp +82 -82
  24. package/src/prelude/values/helpers/array.hpp +198 -208
  25. package/src/prelude/values/helpers/async_iterator.hpp +275 -275
  26. package/src/prelude/values/helpers/function.hpp +108 -108
  27. package/src/prelude/values/helpers/iterator.hpp +144 -144
  28. package/src/prelude/values/helpers/promise.hpp +253 -253
  29. package/src/prelude/values/helpers/string.hpp +37 -61
  30. package/src/prelude/values/promise.hpp +72 -72
  31. package/src/prelude/values/prototypes/array.hpp +14 -2
  32. package/src/prelude/values/prototypes/iterator.hpp +201 -201
  33. package/src/prelude/values/prototypes/promise.hpp +196 -196
  34. package/src/prelude/values/prototypes/string.hpp +564 -542
  35. 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,83 +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
- : 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
+ #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(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
- }
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
+ }