-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
3 changed files
with
54 additions
and
0 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,30 @@ | ||
#ifndef VS_BYTES_H | ||
#define VS_BYTES_H | ||
|
||
#include <vector> | ||
|
||
#include "VSObject.hpp" | ||
|
||
extern VSObject *vs_bytes(VSObject *, VSObject *const *args, vs_size_t nargs); | ||
|
||
class VSBytesObject : public VSObject { | ||
private: | ||
static const str_func_map vs_bytes_methods; | ||
|
||
public: | ||
std::vector<cbyte_t> _value; | ||
|
||
VSBytesObject(vs_size_t len); | ||
~VSBytesObject(); | ||
|
||
bool hasattr(std::string &attrname) override; | ||
VSObject *getattr(std::string &attrname) override; | ||
void setattr(std::string &attrname, VSObject *attrvalue) override; | ||
}; | ||
|
||
inline void vs_bytes_append(vs_size_t len, ...); | ||
|
||
#define AS_BYTES(obj) ((VSBytesObject *)obj) | ||
#define BYTES_LEN(obj) (AS_BYTES(obj)->_value.size()) | ||
|
||
#endif |
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,23 @@ | ||
#include "objects/VSBytesObject.hpp" | ||
|
||
#include "error.hpp" | ||
#include "objects/VSFunctionObject.hpp" | ||
#include "objects/VSStringObject.hpp" | ||
#include "objects/VSTupleObject.hpp" | ||
|
||
NEW_IDENTIFIER(__bytes__); | ||
|
||
VSObject *vs_bytes(VSObject *, VSObject *const *args, vs_size_t nargs) { | ||
if (nargs != 1) { | ||
ERR_NARGS("bytes()", 1, nargs); | ||
terminate(TERM_ERROR); | ||
} | ||
|
||
VSObject *obj = args[0]; | ||
VSObject *res = CALL_ATTR(obj, ID___bytes__, EMPTY_TUPLE()); | ||
if (!IS_TYPE(res, T_BYTES)) { | ||
err("%s.__bytes__() returned \"%s\" object instead of bytes", TYPE_STR[obj->type], TYPE_STR[res->type]); | ||
terminate(TERM_ERROR); | ||
} | ||
INCREF_RET(res); | ||
} |