primitiveObj.hpp
Go to the documentation of this file.
1
2#pragma once
3
5#include "core/ast/func.hpp"
6#include "core/ast/scope.hpp"
10
11namespace by {
12
13 template <typename T> class primitiveObj: public arithmeticObj {
15 typedef T trait;
16
17 protected:
18 template <typename E, typename RAW> class asPrimitive: public tas<E> {
19 BY(CLASS(asPrimitive, tas<E>))
20
21 public:
22 str as(const node& me, const type& to) const override { return str(new E(*me.cast<RAW>())); }
23 };
24
25 public:
26 primitiveObj(): _val() {}
27
28 primitiveObj(const T& val): _val(val) {}
29
30 public:
31 T& get() { return _val; }
32
33 const T& get() const { return _val; }
34
35 using super::cast;
36
37 void* cast(const type& to) override {
38 WHEN(to == ttype<T>::get()) .ret(&_val);
39
40 return super::cast(to);
41 }
42
43 protected:
44 nbool _onSame(const typeProvidable& rhs) const override {
45 const me& cast = (const me&) rhs;
46 return _val == cast._val;
47 }
48
49 private:
50 T _val;
51 };
52
53 template <> class primitiveObj<void>: public arithmeticObj {
55
56 protected:
57 nbool _onSame(const typeProvidable& rhs) const override { return true; }
58 };
59} // namespace by
Base class for arithmetic operations on primitive types.
Definition: arithmeticObj.hpp:13
Base class for all AST nodes in byeol language.
Definition: node.hpp:30
Definition: primitiveObj.hpp:18
Definition: primitiveObj.hpp:13
Base class for runtime type information in byeol language.
Definition: type.hpp:12
Interface for objects that can provide their type information.
Definition: typeProvidable.hpp:12
Definition: tas.hpp:9