[javascriptlint-commit] SF.net SVN: javascriptlint: [200] trunk
Status: Beta
Brought to you by:
matthiasmiller
From: <mat...@us...> - 2008-05-06 15:59:49
|
Revision: 200 http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=200&view=rev Author: matthiasmiller Date: 2008-05-06 08:59:24 -0700 (Tue, 06 May 2008) Log Message: ----------- Move NodePos into the C module. Modified Paths: -------------- trunk/pyjsl/jsparse.py trunk/pyspidermonkey/pyspidermonkey.c trunk/setup.py Added Paths: ----------- trunk/pyspidermonkey/nodepos.c trunk/pyspidermonkey/nodepos.h Modified: trunk/pyjsl/jsparse.py =================================================================== --- trunk/pyjsl/jsparse.py 2008-04-26 05:14:50 UTC (rev 199) +++ trunk/pyjsl/jsparse.py 2008-05-06 15:59:24 UTC (rev 200) @@ -13,23 +13,7 @@ ['tok.%s' % prop for prop in dir(tok)] )) -class NodePos: - " Represents zero-based line and column number. " - def __init__(self, line, col): - self.line = line - self.col = col - def __cmp__(self, other): - if self.line < other.line: - return -1 - if self.line > other.line: - return 1 - if self.col < other.col: - return -1 - if self.col > other.col: - return 1 - return 0 - def __str__(self): - return '(line %i, col %i)' % (self.line+1, self.col+1) +NodePos = pyspidermonkey.NodePos class NodePositions: " Given a string, allows [x] lookups for NodePos line and column numbers." Added: trunk/pyspidermonkey/nodepos.c =================================================================== --- trunk/pyspidermonkey/nodepos.c (rev 0) +++ trunk/pyspidermonkey/nodepos.c 2008-05-06 15:59:24 UTC (rev 200) @@ -0,0 +1,117 @@ +/* vim: ts=4 sw=4 expandtab + */ +#include <Python.h> +#include "structmember.h" + +#include "nodepos.h" + +typedef struct { + PyObject_HEAD + int line; + int col; +} NodePosObject; + +static PyObject* +NodePos_new(PyTypeObject* type, PyObject* args, PyObject* kwds) +{ + NodePosObject* self; + + self = (NodePosObject*)type->tp_alloc(type, 0); + if (self == NULL) + return NULL; + + self->line = -1; + self->col = -1; + + return (PyObject*)self; +} + +static int +NodePos_init(NodePosObject* self, PyObject* args, PyObject* kwds) +{ + static char* kwlist[] = {"line", "col", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwlist, &self->line, &self->col)) + return -1; + + return 0; +} + +static PyObject* +NodePos_str(NodePosObject* self) +{ + return PyString_FromFormat("(line %i, col %i)", self->line+1, self->col+1); +} + +static int +NodePos_compare(NodePosObject* left, NodePosObject* right) +{ + if (left->line < right->line) + return -1; + if (left->line > right->line) + return 1; + if (left->col < right->col) + return -1; + if (left->col > right->col) + return 1; + return 0; +} + +static PyMemberDef +NodePos_members[] = { + {"line", T_INT, offsetof(NodePosObject, line), 0, "zero-based line number"}, + {"col", T_INT, offsetof(NodePosObject, col), 0, "zero-based column number"}, + {NULL} /* Sentinel */ +}; + +PyTypeObject NodePosType = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "pyspidermonkey.NodePos", /*tp_name*/ + sizeof(NodePosObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + 0, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + (cmpfunc)NodePos_compare, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + (reprfunc)NodePos_str, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "Represents zero-based line and column number.", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + NodePos_members, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)NodePos_init, /* tp_init */ + 0, /* tp_alloc */ + NodePos_new, /* tp_new */ +}; + +void +RegisterNodePosType(PyObject* module) +{ + if (PyType_Ready(&NodePosType) < 0) + return; + + Py_INCREF(&NodePosType); + PyModule_AddObject(module, "NodePos", (PyObject*)&NodePosType); +} + Property changes on: trunk/pyspidermonkey/nodepos.c ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/pyspidermonkey/nodepos.h =================================================================== --- trunk/pyspidermonkey/nodepos.h (rev 0) +++ trunk/pyspidermonkey/nodepos.h 2008-05-06 15:59:24 UTC (rev 200) @@ -0,0 +1,10 @@ +/* vim: ts=4 sw=4 expandtab + */ +#ifndef NODEPOS_H +#define NODEPOS_H + +void +RegisterNodePosType(PyObject* module); + +#endif + Property changes on: trunk/pyspidermonkey/nodepos.h ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/pyspidermonkey/pyspidermonkey.c =================================================================== --- trunk/pyspidermonkey/pyspidermonkey.c 2008-04-26 05:14:50 UTC (rev 199) +++ trunk/pyspidermonkey/pyspidermonkey.c 2008-05-06 15:59:24 UTC (rev 200) @@ -15,6 +15,7 @@ #include <jsscope.h> #include <jsstr.h> +#include "nodepos.h" #define ARRAY_COUNT(a) (sizeof(a) / sizeof(a[0])) @@ -107,6 +108,8 @@ if (PyObject_SetAttrString(op, opcode, PyLong_FromLong(OPCODE_TO_NUM(i))) == -1) return; } + + RegisterNodePosType(module); } PyMODINIT_FUNC Modified: trunk/setup.py =================================================================== --- trunk/setup.py 2008-04-26 05:14:50 UTC (rev 199) +++ trunk/setup.py 2008-05-06 15:59:24 UTC (rev 200) @@ -22,7 +22,10 @@ include_dirs = ['spidermonkey/src', 'build/spidermonkey'], library_dirs = ['build/spidermonkey'], libraries = [library], - sources = ['pyspidermonkey/pyspidermonkey.c'] + sources = [ + 'pyspidermonkey/pyspidermonkey.c', + 'pyspidermonkey/nodepos.c' + ] ) args = {} args.update( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |