Permalink
Browse files

Basic working demo!

  • Loading branch information...
gonzojive committed Jul 1, 2010
1 parent 0d3cc85 commit 2feca7d74cf133a2ad5b06bd8de9ecd3889c3604
Showing with 171 additions and 8 deletions.
  1. +29 −0 cl-spidermonkey.asd
  2. +1 −0 src/c/compile.sh
  3. +35 −0 src/c/example.c
  4. +1 −0 src/c/libjs.so
  5. +9 −0 src/port.lisp
  6. +10 −8 src/spidermonkey-bindings.lisp
  7. +86 −0 src/util.lisp
View
@@ -0,0 +1,29 @@
+(defpackage org.iodb.cl-spidermonkey.system
+ (:use :common-lisp :asdf))
+(in-package :org.iodb.cl-spidermonkey-system)
+
+(defsystem cl-spidermonkey
+ :description "."
+ :version "0.2.1"
+ :author "Red Daly <reddaly at gmail>"
+ :license "MIT/X11 License. See LICENSE file"
+ :components ((:module "src"
+ :components
+ ((:file "package")
+ (:file "spidermonkey-bindings")
+ (:file "port" :depends-on ("package"))))))
+
+#+nil
+(defsystem cl-spidermonkey-tests
+ :name "cl-spidermonkey-tests"
+ :author "Red Daly <reddaly@gmail.com>"
+ :version "0.0.1"
+ :licence "MIT"
+ :description "CL-SPIDERMONKEY test suite."
+ :components ((:static-file "cl-spidermonkey.asd")
+ (:module "test"
+ :components
+ ((:file "package")
+ (:file "all-tests" :depends-on ("package"))
+ (:parenscript-file "cl-spidermonkey-test" :depends-on ("package")))))
+ :depends-on ("stefil" "cl-spidermonkey" "paren-test" "paren-util"))
View
@@ -0,0 +1 @@
+gcc -I ../../include/ -l js -L ../../lib/ example.c -o example
View
@@ -0,0 +1,35 @@
+#define XP_UNIX
+#include "jsapi.h"
+
+/* The class of the global object. */
+static JSClass global_class = {
+ "global",
+ JSCLASS_GLOBAL_FLAGS,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_EnumerateStub,
+ JS_ResolveStub,
+ JS_ConvertStub,
+ JS_FinalizeStub,
+ JSCLASS_NO_OPTIONAL_MEMBERS
+};
+
+/* The error reporter callback. */
+void reportError(JSContext *cx, const char *message, JSErrorReport *report)
+{
+ fprintf(stderr, "%s:%u:%s\n",
+ report->filename ? report->filename : "<no filename>",
+ (unsigned int) report->lineno,
+ message);
+}
+
+int main(int argc, const char *argv[])
+{
+ printf("Global flags: %i\n", JSCLASS_GLOBAL_FLAGS);
+ printf("JSCLASS_RESERVED_SLOTS_MASK: %i\n", JSCLASS_RESERVED_SLOTS_MASK);
+ printf("reserved: %i\n", JSCLASS_HAS_RESERVED_SLOTS(JSProto_LIMIT));
+
+ return 0;
+}
View
View
@@ -0,0 +1,9 @@
+(in-package :cl-spidermonkey)
+
+(defmacro with-float-traps-masked (ignored &body body)
+ (declare (ignore ignored))
+ #+sbcl
+ `(sb-int:with-float-traps-masked (:invalid :divide-by-zero)
+ ,@body)
+ #-sbcl
+ `(progn ,@body))
@@ -604,11 +604,12 @@
(cl:in-package :spidermonkey-bindings)
-(cl:defun js-bit (n)
- (cl:ash 1 n))
+(cl:eval-when (:compile-toplevel :load-toplevel :execute)
+ (cl:defun js-bit (n)
+ (cl:ash 1 n))
-(cl:defun js-bitmask (n)
- (cl:- n 1))
+ (cl:defun js-bitmask (n)
+ (cl:- (js-bit n) 1)))
(cl:defconstant +jsoption-strict+ (js-bit 0))
(cl:defconstant +jsoption-werror+ (js-bit 1))
@@ -639,9 +640,10 @@
(cl:defconstant +jsclass-is-global+ (js-bit (cl:+ 2 +jsclass-high-flags-shift+)))
(cl:defconstant +jsclass-mark-is-trace+ (js-bit (cl:+ 3 +jsclass-high-flags-shift+)))
-(cl:defun jsclass-has-reserved-slots (n)
- (cl:ash (cl:logand n +jsclass-reserved-slots-mask+)
- +jsclass-reserved-slots-shift+))
+(cl:eval-when (:compile-toplevel :load-toplevel :execute)
+ (cl:defun jsclass-has-reserved-slots (n)
+ (cl:ash (cl:logand n +jsclass-reserved-slots-mask+)
+ +jsclass-reserved-slots-shift+)))
(cl:defconstant +jsclass-global-flags+ (cl:logior +jsclass-is-global+
(jsclass-has-reserved-slots
@@ -1113,7 +1115,7 @@
(mark js-mark-op)
(reserve-slots js-reserve-slots-op))
-(cl:defun make-js-class (&key
+
(cffi:defcfun ("JS_SetOptions" js-set-options) uint-32 (cx :pointer)
(options uint-32))
View
@@ -0,0 +1,86 @@
+(in-package :cl-spidermonkey)
+
+(cffi:defcallback my-report-error :void ((context smlib:js-context)
+ (message :string)
+ (report smlib:js-error-report))
+ (format t "My report error: ~A" message))
+
+#+nil
+(cffi:load-foreign-library "libjs.so" :search-path "/git/cl-spidermonkey/lib/")
+
+(defparameter *rt* nil)
+(defparameter *js-context* nil)
+(defparameter *js-global-class* nil)
+(defparameter *global* nil)
+
+(defun demo()
+ (defparameter *rt* (smlib:js-init (* 1024 1024 8)))
+ (defparameter *js-context* (smlib:js-new-context *rt* (* 1024 1024 8)))
+
+ (smlib:js-set-options *js-context* smlib:+jsoption-var-obj-fix+)
+ (smlib:js-set-version *js-context* :jsversion-latest)
+
+
+ (smlib:js-set-error-reporter *js-context* (cffi:callback my-report-error))
+
+ (defparameter *js-global-class* (smlib:js-malloc *js-context*
+ (cffi:foreign-type-size 'smlib:js-class)))
+
+ (make-js-class *js-global-class*)
+
+ (defparameter *global*
+ (smlib:js-new-object *js-context* *js-global-class*
+ (cffi:null-pointer)
+ (cffi:null-pointer)))
+
+ (with-float-traps-masked ()
+ (smlib:js-init-standard-classes *js-context* *global*))
+
+ (smlib:js-destroy-context *js-context*)
+ (smlib:js-finish *rt*)
+ #+nil
+ (smlib:js-shut-down))
+
+(defun make-js-class (class)
+ (cffi:with-foreign-slots ((smlib:name
+ smlib:flags
+ smlib:add-property
+ smlib:del-property
+ smlib:get-property
+ smlib:set-property
+ smlib:enumerate
+ smlib:resolve
+ smlib:convert
+ smlib:finalize
+ smlib:get-object-ops
+ smlib:check-access
+ smlib:call
+ smlib:construct
+ smlib:xdr-object
+ smlib:has-instance
+ smlib:mark
+ smlib:reserve-slots)
+ class
+ smlib:js-class)
+ (cffi:with-foreign-string (global-str "global")
+ (setf smlib:name global-str
+ smlib:flags smlib:+jsclass-global-flags+
+ smlib:add-property (cffi:foreign-symbol-pointer "JS_PropertyStub")
+ smlib:del-property (cffi:foreign-symbol-pointer "JS_PropertyStub")
+ smlib:get-property (cffi:foreign-symbol-pointer "JS_PropertyStub")
+ smlib:set-property (cffi:foreign-symbol-pointer "JS_PropertyStub")
+ smlib:enumerate (cffi:foreign-symbol-pointer "JS_EnumerateStub")
+ smlib:resolve (cffi:foreign-symbol-pointer "JS_ResolveStub")
+ smlib:convert (cffi:foreign-symbol-pointer "JS_ConvertStub")
+ smlib:finalize (cffi:foreign-symbol-pointer "JS_FinalizeStub")
+ smlib:get-object-ops (cffi:null-pointer)
+ smlib:check-access (cffi:null-pointer)
+ smlib:call (cffi:null-pointer)
+ smlib:construct (cffi:null-pointer)
+ smlib:xdr-object (cffi:null-pointer)
+ smlib:has-instance (cffi:null-pointer)
+ smlib:mark (cffi:null-pointer)
+ smlib:reserve-slots (cffi:null-pointer)))
+
+ class))
+

0 comments on commit 2feca7d

Please sign in to comment.