Permalink
Browse files

Support LiveScript as an additional dialect.

LiveScript is yet another dialect of JavaScript, in a way we support
CoffeeScript.  Although we put this as additional change on top of the
existing CoffeeScript support, we will need to refactor the code so
that more dialects can be easily supported.
  • Loading branch information...
1 parent d77c2af commit fb120ab33a6f6d6a65626f1fddeea8bd3e5b628b @audreyt audreyt committed with umitanuki Sep 4, 2012
Showing with 152 additions and 42 deletions.
  1. +19 −4 Makefile
  2. +22 −5 README
  3. +5 −0 livescript.js
  4. +10 −0 plls--0.9.0.sql
  5. +7 −0 plls.control
  6. +87 −33 plv8.cc
  7. +2 −0 plv8.h
View
@@ -3,7 +3,7 @@ V8DIR = ../v8
# set your custom C++ compler
CUSTOM_CC = g++
-JSS = coffee-script.js
+JSS = coffee-script.js livescript.js
# .cc created from .js
JSCS = $(JSS:.js=.cc)
SRCS = plv8.cc plv8_type.cc plv8_func.cc plv8_param.cc $(JSCS)
@@ -26,9 +26,20 @@ CCFLAGS := -DPLV8_VERSION='"$(META_VER)"' $(CCFLAGS)
# plcoffee is available only when ENABLE_COFFEE is defined.
ifdef ENABLE_COFFEE
+ifdef ENABLE_LIVESCRIPT
+ CCFLAGS := -DENABLE_COFFEE -DENABLE_LIVESCRIPT $(CCFLAGS)
+ DATA = plcoffee.control plcoffee--0.9.0.sql plls.control plls--0.9.0.sql
+else
CCFLAGS := -DENABLE_COFFEE $(CCFLAGS)
DATA = plcoffee.control plcoffee--0.9.0.sql
endif
+else
+# plls is available only when ENABLE_LIVESCRIPT is defined.
+ifdef ENABLE_LIVESCRIPT
+ CCFLAGS := -DENABLE_LIVESCRIPT $(CCFLAGS)
+ DATA = plls.control plls--0.9.0.sql
+endif
+endif
all:
@@ -41,6 +52,11 @@ $(filter $(JSCS), $(SRCS)): %.cc: %.js
ifdef ENABLE_COFFEE
(od -txC -v $< | \
sed -e "s/^[0-9]*//" -e s"/ \([0-9a-f][0-9a-f]\)/0x\1,/g" -e"\$$d" ) >>$@
+else
+ifdef ENABLE_LIVESCRIPT
+ (od -txC -v $< | \
+ sed -e "s/^[0-9]*//" -e s"/ \([0-9a-f][0-9a-f]\)/0x\1,/g" -e"\$$d" ) >>$@
+endif
endif
echo "0x00};" >>$@
@@ -52,9 +68,8 @@ ifndef MAJORVERSION
MAJORVERSION := $(basename $(VERSION))
endif
-
-PG_VERSION_NUM := $(shell perl -ne 'print $$1 if /PG_VERSION_NUM\s+(\d+)/' \
- < `$(PG_CONFIG) --includedir`/pg_config.h)
+PG_VERSION_NUM := $(shell cat `$(PG_CONFIG) --includedir`/pg_config*.h \
+ | perl -ne 'print $$1 and exit if /PG_VERSION_NUM\s+(\d+)/')
# VERSION specific definitions
ifeq ($(shell test $(PG_VERSION_NUM) -ge 90100 && echo yes), yes)
View
27 README
@@ -20,13 +20,17 @@ INSTALL
-------
Make sure V8 include files are in the system include directories, or you can
-place them in $(PLV8DIR)/../v8/include. Run make
+place them in $(PLV8DIR)/../v8/include. Run make:
- $ make install
+ # Build with CoffeeScript and LiveScript
+ $ make ENABLE_COFFEE=1 ENABLE_LIVESCRIPT=1
+ $ sudo make install ENABLE_COFFEE=1 ENABLE_LIVESCRIPT=1
and create language via
$ psql -c 'CREATE EXTENSION plv8'
+ $ psql -c 'CREATE EXTENSION plls'
+ $ psql -c 'CREATE EXTENSION plcoffee'
in 9.1, or in the prior versions
@@ -42,8 +46,22 @@ in your postgresql.conf and
$ make installcheck
-EXAMPLE
--------
+EXAMPLE (LIVESCRIPT)
+--------------------
+
+ CREATE OR REPLACE FUNCTION plls_test(keys text[], vals text[])
+ RETURNS text AS $$
+ return JSON.stringify { [key, vals[idx]] for key, idx in keys }
+ $$ LANGUAGE plls IMMUTABLE STRICT;
+
+ SELECT plls_test(ARRAY['name', 'age'], ARRAY['Tom', '29']);
+ plls_test
+ ---------------------------
+ {"name":"Tom","age":"29"}
+ (1 row)
+
+EXAMPLE (JAVASCRIPT)
+--------------------
CREATE OR REPLACE FUNCTION plv8_test(keys text[], vals text[])
RETURNS text AS $$
@@ -55,7 +73,6 @@ EXAMPLE
$$ LANGUAGE plv8 IMMUTABLE STRICT;
SELECT plv8_test(ARRAY['name', 'age'], ARRAY['Tom', '29']);
- SELECT plv8_test(ARRAY['name', 'age'], ARRAY['Tom', '29']);
plv8_test
---------------------------
{"name":"Tom","age":"29"}
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,10 @@
+CREATE FUNCTION plls_call_handler() RETURNS language_handler
+ AS 'MODULE_PATHNAME' LANGUAGE C;
+CREATE FUNCTION plls_inline_handler(internal) RETURNS void
+ AS 'MODULE_PATHNAME' LANGUAGE C;
+CREATE FUNCTION plls_call_validator(oid) RETURNS void
+ AS 'MODULE_PATHNAME' LANGUAGE C;
+CREATE TRUSTED LANGUAGE plls
+ HANDLER plls_call_handler
+ INLINE plls_inline_handler
+ VALIDATOR plls_call_validator;
View
@@ -0,0 +1,7 @@
+# plls extension
+comment = 'PL/LiveScript (v8) trusted procedural language'
+default_version = '0.9.0'
+module_pathname = '$libdir/plv8'
+relocatable = false
+schema = pg_catalog
+superuser = true
Oops, something went wrong.

0 comments on commit fb120ab

Please sign in to comment.