Permalink
Browse files

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

  • Loading branch information...
1 parent 967d537 commit eadc620820f28daaf864cc76b63cbb29ef99d156 @NotFound committed Jun 4, 2012
Showing with 68 additions and 3 deletions.
  1. +14 −1 winxedxx.winxed
  2. +5 −0 winxedxx_default.cxx
  3. +1 −0 winxedxx_default.h
  4. +1 −0 winxedxx_integer.h
  5. +5 −0 winxedxx_null.cxx
  6. +1 −0 winxedxx_null.h
  7. +1 −0 winxedxx_object.h
  8. +5 −0 winxedxx_scalar.cxx
  9. +1 −0 winxedxx_types.h
  10. +34 −2 winxedxx_util.cxx
View
@@ -842,7 +842,20 @@ function emit_NewIndexedExpr(out, expr)
// TESTING
string name = key[0];
- out.print("wxx_new_string(\"", name, "\")");
+ out.print("wxx_new_string(\"", name, "\"");
+ var initializer = expr.initializer;
+ int numinits = initializer == null ? -1 : initializer.numargs();
+ switch (numinits) {
+ case -1:
+ break;
+ case 1:
+ out.print(ARGSEP);
+ emit_expr(out, initializer.getfreearg(0));
+ break;
+ default:
+ throw WxxError("Invalid initializer");
+ }
+ out.print(")");
}
function emit_OpAssignExpr(out, assignexpr)
View
@@ -30,6 +30,11 @@ WxxDefault::~WxxDefault()
//std::cerr << "~WxxDefault " << name << "\n";
}
+void WxxDefault::init_pmc(const WxxObjectPtr &arg)
+{
+ notimplemented("init_pmc");
+}
+
std::string WxxDefault::class_name() const
{
return name;
View
@@ -15,6 +15,7 @@ class WxxDefault : public WxxObject
WxxDefault(const std::string &name);
~WxxDefault();
public:
+ void init_pmc(const WxxObjectPtr &arg);
std::string class_name() const;
int is_null() const;
std::string getname() const;
View
@@ -31,6 +31,7 @@ class WxxInteger : public WxxDefault
{
public:
WxxInteger(int value);
+ void init_pmc(const WxxObjectPtr &arg);
std::string class_name() const;
int get_integer();
double get_number();
View
@@ -13,6 +13,11 @@ namespace WinxedXX
//*************************************************************
+void WxxNull::init_pmc(const WxxObjectPtr &arg)
+{
+ nullaccess("init_pmc");
+}
+
std::string WxxNull::class_name() const
{
return "Null";
View
@@ -11,6 +11,7 @@ namespace WinxedXX
class WxxNull : public WxxObject
{
public:
+ void init_pmc(const WxxObjectPtr &arg);
std::string class_name() const;
int is_null() const;
int instanceof(const std::string &type);
View
@@ -10,6 +10,7 @@ namespace WinxedXX
class WxxObject : public WxxRefcounted
{
public:
+ virtual void init_pmc(const WxxObjectPtr &arg) = 0;
virtual int is_null() const = 0;
virtual std::string class_name() const = 0;
virtual int instanceof(const std::string &type) = 0;
View
@@ -21,6 +21,11 @@ WxxInteger::WxxInteger(int value) : WxxDefault("Integer")
i = value;
}
+void WxxInteger::init_pmc(const WxxObjectPtr &arg)
+{
+ i = arg.get_integer();
+}
+
std::string WxxInteger::class_name() const
{
return "Integer";
View
@@ -152,6 +152,7 @@ std::string wxx_unescape(const std::string &src);
WxxObjectPtr wxx_new(const std::string &name);
WxxObjectPtr wxx_new(const std::string &name, WxxObjectArray args);
WxxObjectPtr wxx_new_string(const std::string &name);
+WxxObjectPtr wxx_new_string(const std::string &name, WxxObjectPtr arg);
WxxObjectPtr wxx_open(const std::string &filename);
WxxObjectPtr wxx_open(const std::string &filename, const std::string &mode);
View
@@ -32,6 +32,7 @@ class WxxException : public WxxDefault
public:
WxxException(const std::string &message = "",
int severity = 2, int type = 0);
+ void init_pmc(const WxxObjectPtr &arg);
std::string get_string();
WxxObjectPtr get_pmc_keyed(const std::string &str);
private:
@@ -51,6 +52,20 @@ WxxException::WxxException(const std::string &message, int severity, int type) :
set_attr_str(std::string("type"), WxxObjectPtr(type));
}
+void WxxException::init_pmc(const WxxObjectPtr &arg)
+{
+ WxxObjectPtr aux;
+ aux = arg.get_pmc_keyed("message");
+ if (! aux.is_null())
+ set_attr_str(std::string("message"), aux);
+ aux = arg.get_pmc_keyed("severity");
+ if (! aux.is_null())
+ set_attr_str(std::string("severity"), aux);
+ aux = arg.get_pmc_keyed("type");
+ if (! aux.is_null())
+ set_attr_str(std::string("type"), aux);
+}
+
std::string WxxException::get_string()
{ return msg; }
@@ -409,7 +424,7 @@ WxxObjectPtr wxx_new(const std::string &name, WxxObjectArray args)
return obj;
}
-WxxObjectPtr wxx_new_string(const std::string &name)
+static WxxObject * new_string(const std::string name)
{
// Sepcial cases for parrot PMC names
if (name == "Integer")
@@ -426,8 +441,25 @@ WxxObjectPtr wxx_new_string(const std::string &name)
return new WxxFileHandle();
if (name == "ByteBuffer")
return new WxxByteBuffer();
+ return 0;
+}
- return wxx_new(name);
+WxxObjectPtr wxx_new_string(const std::string &name)
+{
+ WxxObject * obj = new_string(name);
+ if (obj)
+ return WxxObjectPtr(obj);
+ else
+ return wxx_new(name);
+}
+
+WxxObjectPtr wxx_new_string(const std::string &name, WxxObjectPtr arg)
+{
+ WxxObject * obj = new_string(name);
+ if (! obj)
+ obj = new WxxInstance(name);
+ obj->init_pmc(arg);
+ return WxxObjectPtr(obj);
}
WxxObjectPtr wxx_open(const std::string &filename)

0 comments on commit eadc620

Please sign in to comment.