Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

init_pmc vtable, use in new keyed, implement in Exception and Integer

  • Loading branch information...
commit eadc620820f28daaf864cc76b63cbb29ef99d156 1 parent 967d537
NotFound authored
15 winxedxx.winxed
@@ -842,7 +842,20 @@ function emit_NewIndexedExpr(out, expr)
842 842
843 843 // TESTING
844 844 string name = key[0];
845   - out.print("wxx_new_string(\"", name, "\")");
  845 + out.print("wxx_new_string(\"", name, "\"");
  846 + var initializer = expr.initializer;
  847 + int numinits = initializer == null ? -1 : initializer.numargs();
  848 + switch (numinits) {
  849 + case -1:
  850 + break;
  851 + case 1:
  852 + out.print(ARGSEP);
  853 + emit_expr(out, initializer.getfreearg(0));
  854 + break;
  855 + default:
  856 + throw WxxError("Invalid initializer");
  857 + }
  858 + out.print(")");
846 859 }
847 860
848 861 function emit_OpAssignExpr(out, assignexpr)
5 winxedxx_default.cxx
@@ -30,6 +30,11 @@ WxxDefault::~WxxDefault()
30 30 //std::cerr << "~WxxDefault " << name << "\n";
31 31 }
32 32
  33 +void WxxDefault::init_pmc(const WxxObjectPtr &arg)
  34 +{
  35 + notimplemented("init_pmc");
  36 +}
  37 +
33 38 std::string WxxDefault::class_name() const
34 39 {
35 40 return name;
1  winxedxx_default.h
@@ -15,6 +15,7 @@ class WxxDefault : public WxxObject
15 15 WxxDefault(const std::string &name);
16 16 ~WxxDefault();
17 17 public:
  18 + void init_pmc(const WxxObjectPtr &arg);
18 19 std::string class_name() const;
19 20 int is_null() const;
20 21 std::string getname() const;
1  winxedxx_integer.h
@@ -31,6 +31,7 @@ class WxxInteger : public WxxDefault
31 31 {
32 32 public:
33 33 WxxInteger(int value);
  34 + void init_pmc(const WxxObjectPtr &arg);
34 35 std::string class_name() const;
35 36 int get_integer();
36 37 double get_number();
5 winxedxx_null.cxx
@@ -13,6 +13,11 @@ namespace WinxedXX
13 13
14 14 //*************************************************************
15 15
  16 +void WxxNull::init_pmc(const WxxObjectPtr &arg)
  17 +{
  18 + nullaccess("init_pmc");
  19 +}
  20 +
16 21 std::string WxxNull::class_name() const
17 22 {
18 23 return "Null";
1  winxedxx_null.h
@@ -11,6 +11,7 @@ namespace WinxedXX
11 11 class WxxNull : public WxxObject
12 12 {
13 13 public:
  14 + void init_pmc(const WxxObjectPtr &arg);
14 15 std::string class_name() const;
15 16 int is_null() const;
16 17 int instanceof(const std::string &type);
1  winxedxx_object.h
@@ -10,6 +10,7 @@ namespace WinxedXX
10 10 class WxxObject : public WxxRefcounted
11 11 {
12 12 public:
  13 + virtual void init_pmc(const WxxObjectPtr &arg) = 0;
13 14 virtual int is_null() const = 0;
14 15 virtual std::string class_name() const = 0;
15 16 virtual int instanceof(const std::string &type) = 0;
5 winxedxx_scalar.cxx
@@ -21,6 +21,11 @@ WxxInteger::WxxInteger(int value) : WxxDefault("Integer")
21 21 i = value;
22 22 }
23 23
  24 +void WxxInteger::init_pmc(const WxxObjectPtr &arg)
  25 +{
  26 + i = arg.get_integer();
  27 +}
  28 +
24 29 std::string WxxInteger::class_name() const
25 30 {
26 31 return "Integer";
1  winxedxx_types.h
@@ -152,6 +152,7 @@ std::string wxx_unescape(const std::string &src);
152 152 WxxObjectPtr wxx_new(const std::string &name);
153 153 WxxObjectPtr wxx_new(const std::string &name, WxxObjectArray args);
154 154 WxxObjectPtr wxx_new_string(const std::string &name);
  155 +WxxObjectPtr wxx_new_string(const std::string &name, WxxObjectPtr arg);
155 156
156 157 WxxObjectPtr wxx_open(const std::string &filename);
157 158 WxxObjectPtr wxx_open(const std::string &filename, const std::string &mode);
36 winxedxx_util.cxx
@@ -32,6 +32,7 @@ class WxxException : public WxxDefault
32 32 public:
33 33 WxxException(const std::string &message = "",
34 34 int severity = 2, int type = 0);
  35 + void init_pmc(const WxxObjectPtr &arg);
35 36 std::string get_string();
36 37 WxxObjectPtr get_pmc_keyed(const std::string &str);
37 38 private:
@@ -51,6 +52,20 @@ WxxException::WxxException(const std::string &message, int severity, int type) :
51 52 set_attr_str(std::string("type"), WxxObjectPtr(type));
52 53 }
53 54
  55 +void WxxException::init_pmc(const WxxObjectPtr &arg)
  56 +{
  57 + WxxObjectPtr aux;
  58 + aux = arg.get_pmc_keyed("message");
  59 + if (! aux.is_null())
  60 + set_attr_str(std::string("message"), aux);
  61 + aux = arg.get_pmc_keyed("severity");
  62 + if (! aux.is_null())
  63 + set_attr_str(std::string("severity"), aux);
  64 + aux = arg.get_pmc_keyed("type");
  65 + if (! aux.is_null())
  66 + set_attr_str(std::string("type"), aux);
  67 +}
  68 +
54 69 std::string WxxException::get_string()
55 70 { return msg; }
56 71
@@ -409,7 +424,7 @@ WxxObjectPtr wxx_new(const std::string &name, WxxObjectArray args)
409 424 return obj;
410 425 }
411 426
412   -WxxObjectPtr wxx_new_string(const std::string &name)
  427 +static WxxObject * new_string(const std::string name)
413 428 {
414 429 // Sepcial cases for parrot PMC names
415 430 if (name == "Integer")
@@ -426,8 +441,25 @@ WxxObjectPtr wxx_new_string(const std::string &name)
426 441 return new WxxFileHandle();
427 442 if (name == "ByteBuffer")
428 443 return new WxxByteBuffer();
  444 + return 0;
  445 +}
429 446
430   - return wxx_new(name);
  447 +WxxObjectPtr wxx_new_string(const std::string &name)
  448 +{
  449 + WxxObject * obj = new_string(name);
  450 + if (obj)
  451 + return WxxObjectPtr(obj);
  452 + else
  453 + return wxx_new(name);
  454 +}
  455 +
  456 +WxxObjectPtr wxx_new_string(const std::string &name, WxxObjectPtr arg)
  457 +{
  458 + WxxObject * obj = new_string(name);
  459 + if (! obj)
  460 + obj = new WxxInstance(name);
  461 + obj->init_pmc(arg);
  462 + return WxxObjectPtr(obj);
431 463 }
432 464
433 465 WxxObjectPtr wxx_open(const std::string &filename)

0 comments on commit eadc620

Please sign in to comment.
Something went wrong with that request. Please try again.