-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbac81f
commit e4ff7de
Showing
15 changed files
with
890 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <karm-base/res.h> | ||
|
||
#include "gc.h" | ||
|
||
namespace Vaev::Script { | ||
|
||
// https://tc39.es/ecma262/#agent | ||
struct Agent { | ||
Gc::Gc &gc; | ||
}; | ||
|
||
} // namespace Vaev::Script |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#pragma once | ||
|
||
#include <karm-base/res.h> | ||
|
||
#include "value.h" | ||
|
||
namespace Vaev::Script { | ||
|
||
// https://tc39.es/ecma262/#sec-completion-record-specification-type | ||
struct [[nodiscard]] Completion { | ||
enum struct _Type { | ||
NORMAL, | ||
BREAK, | ||
CONTINUE, | ||
RETURN, | ||
THROW, | ||
}; | ||
|
||
using enum _Type; | ||
|
||
_Type type = _Type::NORMAL; | ||
Value value = UNDEFINED; | ||
String target = u""_s16; | ||
|
||
static Completion normal(Value value) { | ||
return {NORMAL, value}; | ||
} | ||
|
||
static Completion break_(String target) { | ||
return {BREAK, UNDEFINED, target}; | ||
} | ||
|
||
static Completion continue_(String target) { | ||
return {CONTINUE, UNDEFINED, target}; | ||
} | ||
|
||
static Completion return_(Value value) { | ||
return {RETURN, value}; | ||
} | ||
|
||
static Completion throw_(Value value) { | ||
return {THROW, value}; | ||
} | ||
|
||
bool operator==(_Type t) const { | ||
return type == t; | ||
} | ||
|
||
void repr(Io::Emit& e) const { | ||
switch (type) { | ||
case NORMAL: | ||
e("normal({})", value); | ||
break; | ||
|
||
case BREAK: | ||
e("break({})", target); | ||
break; | ||
|
||
case CONTINUE: | ||
e("continue({})", target); | ||
break; | ||
|
||
case RETURN: | ||
e("return({})", value); | ||
break; | ||
|
||
case THROW: | ||
e("throw({})", value); | ||
break; | ||
} | ||
} | ||
}; | ||
|
||
template <typename T = None> | ||
using Except = Res<T, Completion>; | ||
|
||
} // namespace Vaev::Script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#pragma once | ||
|
||
#include <karm-base/base.h> | ||
#include <karm-base/panic.h> | ||
#include <karm-io/emit.h> | ||
|
||
namespace Karm::Gc { | ||
|
||
template <typename T> | ||
struct Ref { | ||
T* _ptr = nullptr; | ||
|
||
Ref() = default; | ||
|
||
Ref(T* ptr) : _ptr{ptr} { | ||
if (not _ptr) | ||
panic("null pointer"); | ||
} | ||
|
||
T const* operator->() const { | ||
return _ptr; | ||
} | ||
|
||
T* operator->() { | ||
return _ptr; | ||
} | ||
|
||
T const& operator*() const { | ||
return *_ptr; | ||
} | ||
|
||
T& operator*() { | ||
return *_ptr; | ||
} | ||
|
||
void repr(Io::Emit& e) const { | ||
e("{}", *_ptr); | ||
} | ||
}; | ||
|
||
// Nullable reference | ||
template <typename T> | ||
struct Ptr { | ||
T* _ptr = nullptr; | ||
|
||
Ptr() = default; | ||
|
||
Ptr(T* ptr) : _ptr{ptr} { | ||
} | ||
|
||
T const* operator->() const { | ||
if (not _ptr) | ||
panic("trying to dereference a null pointer"); | ||
return _ptr; | ||
} | ||
|
||
T* operator->() { | ||
if (not _ptr) | ||
panic("trying to dereference a null pointer"); | ||
return _ptr; | ||
} | ||
|
||
T const& operator*() const { | ||
if (not _ptr) | ||
panic("trying to dereference a null pointer"); | ||
return *_ptr; | ||
} | ||
|
||
T& operator*() { | ||
if (not _ptr) | ||
panic("trying to dereference a null pointer"); | ||
return *_ptr; | ||
} | ||
|
||
bool operator==(None) const { | ||
return not _ptr; | ||
} | ||
|
||
void repr(Io::Emit& e) const { | ||
if (not _ptr) | ||
e("nullptr"); | ||
else | ||
e("{}", *_ptr); | ||
} | ||
|
||
explicit operator bool() const { | ||
return _ptr != nullptr; | ||
} | ||
}; | ||
|
||
struct Gc { | ||
template <typename T, typename... Args> | ||
Ref<T> alloc(Args&&... args) { | ||
return new T{std::forward<Args>(args)...}; | ||
} | ||
}; | ||
|
||
} // namespace Karm::Gc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <karm-sys/entry.h> | ||
#include <vaev-script/object.h> | ||
#include <vaev-script/realm.h> | ||
|
||
using namespace Vaev; | ||
|
||
Async::Task<> entryPointAsync(Sys::Context&) { | ||
Gc::Gc gc; | ||
|
||
auto agent = gc.alloc<Script::Agent>(gc); | ||
auto realm = gc.alloc<Script::Realm>(agent); | ||
|
||
(void)realm->initializeHostDefinedRealm(agent); | ||
|
||
auto object1 = Script::Object::create(*agent); | ||
(void)object1->defineOwnProperty(Script::PropertyKey::from(u"foo"_s16), {.value = 42.}); | ||
|
||
auto object2 = Script::Object::create(*agent, {.prototype = object1}); | ||
|
||
auto res = object2->get(Script::PropertyKey::from(u"foo"_s16), object2); | ||
|
||
Sys::print("object2.foo = {}\n", res); | ||
|
||
co_return Ok(); | ||
} |
2 changes: 1 addition & 1 deletion
2
src/web/vaev-script/cli/manifest.json → src/web/vaev-script/main/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.