Merge branch 'fjsc' of git://double.co.nz/git/factor
commit
59221714de
|
@ -336,7 +336,7 @@ M: wrapper (parse-factor-quotation) ( object -- ast )
|
||||||
GENERIC: fjsc-parse ( object -- ast )
|
GENERIC: fjsc-parse ( object -- ast )
|
||||||
|
|
||||||
M: string fjsc-parse ( object -- ast )
|
M: string fjsc-parse ( object -- ast )
|
||||||
'expression' parse ast>> ;
|
'expression' parse ;
|
||||||
|
|
||||||
M: quotation fjsc-parse ( object -- ast )
|
M: quotation fjsc-parse ( object -- ast )
|
||||||
[
|
[
|
||||||
|
@ -353,11 +353,11 @@ M: quotation fjsc-parse ( object -- ast )
|
||||||
] with-string-writer ;
|
] with-string-writer ;
|
||||||
|
|
||||||
: fjsc-compile* ( string -- string )
|
: fjsc-compile* ( string -- string )
|
||||||
'statement' parse ast>> fjsc-compile ;
|
'statement' parse fjsc-compile ;
|
||||||
|
|
||||||
: fc* ( string -- )
|
: fc* ( string -- )
|
||||||
[
|
[
|
||||||
'statement' parse ast>> values>> do-expressions
|
'statement' parse values>> do-expressions
|
||||||
] { } make [ write ] each ;
|
] { } make [ write ] each ;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ Factor.prototype.make_quotation = function(source, func) {
|
||||||
|
|
||||||
Factor.prototype.server_eval = function(text, handler, next) {
|
Factor.prototype.server_eval = function(text, handler, next) {
|
||||||
var self = this;
|
var self = this;
|
||||||
$.post("/responder/fjsc/compile", { code: text }, function(result) {
|
$.post("compile", { code: text }, function(result) {
|
||||||
factor.run_eval = function(func) {
|
factor.run_eval = function(func) {
|
||||||
factor.cont.next = function() { handler(text,result); }
|
factor.cont.next = function() { handler(text,result); }
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
! Copyright (C) 2008 Chris Double. All Rights Reserved.
|
||||||
|
USING:
|
||||||
|
accessors
|
||||||
|
fjsc
|
||||||
|
furnace
|
||||||
|
furnace.actions
|
||||||
|
furnace.boilerplate
|
||||||
|
furnace.redirection
|
||||||
|
furnace.utilities
|
||||||
|
html.forms
|
||||||
|
http
|
||||||
|
http.client
|
||||||
|
http.server
|
||||||
|
http.server.dispatchers
|
||||||
|
http.server.responses
|
||||||
|
http.server.static
|
||||||
|
io
|
||||||
|
io.pathnames
|
||||||
|
io.streams.string
|
||||||
|
kernel
|
||||||
|
namespaces
|
||||||
|
peg
|
||||||
|
sequences
|
||||||
|
urls
|
||||||
|
validators
|
||||||
|
;
|
||||||
|
IN: webapps.fjsc
|
||||||
|
|
||||||
|
TUPLE: fjsc < dispatcher ;
|
||||||
|
|
||||||
|
: absolute-url ( url -- url )
|
||||||
|
"http://" request get "host" header append
|
||||||
|
over "/" head? [ "/" append ] unless
|
||||||
|
swap append ;
|
||||||
|
|
||||||
|
: do-compile-url ( url -- response )
|
||||||
|
[
|
||||||
|
absolute-url http-get nip 'expression' parse fjsc-compile write "();" write
|
||||||
|
] with-string-writer
|
||||||
|
"application/javascript" <content> ;
|
||||||
|
|
||||||
|
: v-local ( string -- string )
|
||||||
|
dup "http:" head? [ "Unable to compile code from remote sites" throw ] when ;
|
||||||
|
|
||||||
|
: validate-compile-url ( -- )
|
||||||
|
{
|
||||||
|
{ "url" [ v-required v-local ] }
|
||||||
|
} validate-params ;
|
||||||
|
|
||||||
|
: <compile-url-action> ( -- action )
|
||||||
|
<action>
|
||||||
|
[ validate-compile-url ] >>validate
|
||||||
|
[ "url" value do-compile-url ] >>submit
|
||||||
|
[ validate-compile-url "url" value do-compile-url ] >>display ;
|
||||||
|
|
||||||
|
: do-compile ( code -- response )
|
||||||
|
[
|
||||||
|
'expression' parse fjsc-compile write
|
||||||
|
] with-string-writer
|
||||||
|
"application/javascript" <content> ;
|
||||||
|
|
||||||
|
: validate-compile ( -- )
|
||||||
|
{
|
||||||
|
{ "code" [ v-required ] }
|
||||||
|
} validate-params ;
|
||||||
|
|
||||||
|
: <compile-action> ( -- action )
|
||||||
|
<action>
|
||||||
|
[ validate-compile ] >>validate
|
||||||
|
[ "code" value do-compile ] >>submit
|
||||||
|
[ validate-compile "code" value do-compile ] >>display ;
|
||||||
|
|
||||||
|
: <main-action> ( -- action )
|
||||||
|
<page-action>
|
||||||
|
{ fjsc "main" } >>template ;
|
||||||
|
|
||||||
|
: <fjsc> ( -- fjsc )
|
||||||
|
dispatcher new-dispatcher
|
||||||
|
"extra/webapps/fjsc/www" resource-path <static> "static" add-responder
|
||||||
|
"extra/fjsc/resources" resource-path <static> "fjsc" add-responder
|
||||||
|
fjsc new-dispatcher
|
||||||
|
<main-action> "" add-responder
|
||||||
|
<compile-action> "compile" add-responder
|
||||||
|
<compile-url-action> "compile-url" add-responder
|
||||||
|
<boilerplate>
|
||||||
|
{ fjsc "fjsc" } >>template
|
||||||
|
>>default ;
|
||||||
|
|
||||||
|
: activate-fjsc ( -- )
|
||||||
|
<fjsc> main-responder set-global ;
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version='1.0' ?>
|
||||||
|
<t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<title><t:write-title/></title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="static/termlib/term_styles.css"/>
|
||||||
|
<script type="text/javascript" src="static/termlib/termlib.js"></script>
|
||||||
|
<script type="text/javascript" src="fjsc/jquery.js"></script>
|
||||||
|
<script type="text/javascript" src="fjsc/bootstrap.js"></script>
|
||||||
|
<script type="text/javascript" src="static/repl.js"></script>
|
||||||
|
<script type="text/javascript" src="compile-url?url=fjsc/bootstrap.factor"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="content"><t:call-next-template /></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
</t:chloe>
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?xml version='1.0' ?>
|
||||||
|
<t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
|
||||||
|
<t:title>Factor to JavaScript REPL</t:title>
|
||||||
|
<table border="0">
|
||||||
|
<tr>
|
||||||
|
<td valign="top">
|
||||||
|
<div id="repl" style="position:relative;"></div>
|
||||||
|
<p>More information on the Factor to Javascript compiler can be found at these blog posts:</p>
|
||||||
|
<ul>
|
||||||
|
<li><a href="http://www.bluishcoder.co.nz/2006/12/compiling-factor-to-javascript.html">Factor to Javascript Compiler</a></li>
|
||||||
|
<li><a href="http://www.bluishcoder.co.nz/2006/12/factor-to-javascript-compiler-updates.html">Factor to Javascript Compiler Updates</a></li>
|
||||||
|
<li><a href="http://www.bluishcoder.co.nz/2006/12/continuations-added-to-fjsc.html">Continuations added to fjsc</a></li>
|
||||||
|
<li><a href="http://www.bluishcoder.co.nz/2006/12/cross-domain-json-with-fjsc.html">Cross Domain JSON with fjsc</a></li>
|
||||||
|
<li><a href="http://www.bluishcoder.co.nz/2007/02/factor-to-javascript-compiler-makeover.html">Factor to Javascript Compiler Makeover</a></li>
|
||||||
|
</ul>
|
||||||
|
<p>The terminal emulation code for the Factor REPL is provided by the awesome <a href="http://www.masswerk.at/termlib/index.html">termlib</a> library by Norbert Landsteiner. Documentation for termlib is <a href="static/termlib/">available here</a>. Please note the license of 'termlib':</p>
|
||||||
|
<blockquote>This JavaScript-library is free for private and academic use. Please include a readable copyright statement and a backlink to <a href="http://www.masswerk.at">http://www.masswerk.at</a> in the web page. The library should always be accompanied by the "readme.txt" and the sample HTML-documents.
|
||||||
|
|
||||||
|
The term "private use" includes any personal or non-commercial use, which is not related to commercial activites, but excludes intranet, extranet and/or public net applications that are related to any kind of commercial or profit oriented activity.
|
||||||
|
|
||||||
|
For commercial use see <a href="http://www.masswerk.at">http://www.masswerk.at</a> for contact information.</blockquote>
|
||||||
|
</td>
|
||||||
|
<td valign="top">
|
||||||
|
<p><b>Stack</b></p>
|
||||||
|
<div id="stack">
|
||||||
|
</div>
|
||||||
|
<p><b>Playground</b></p>
|
||||||
|
<div id="playground"></div>
|
||||||
|
<h3>Compiled Code</h3>
|
||||||
|
<textarea id="compiled" cols="40" rows="10">
|
||||||
|
</textarea>
|
||||||
|
<p>Some useful words:</p>
|
||||||
|
<dl>
|
||||||
|
<dt>vocabs ( -- seq )</dt>
|
||||||
|
<dd>Return a sequence of available vocabularies</dd>
|
||||||
|
<dt>words ( string -- seq )</dt>
|
||||||
|
<dd>Return a sequence of words in the given vocabulary</dd>
|
||||||
|
<dt>all-words ( -- seq )</dt>
|
||||||
|
<dd>Return a sequence of all words</dd>
|
||||||
|
</dl>
|
||||||
|
<p>The contents of <a href="fjsc/bootstrap.factor">bootstrap.factor</a> have been loaded on startup.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</t:chloe>
|
|
@ -1,70 +0,0 @@
|
||||||
! Copyright (C) 2006 Chris Double. All Rights Reserved.
|
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
|
||||||
!
|
|
||||||
USING: kernel furnace fjsc peg namespaces
|
|
||||||
lazy-lists io io.files furnace.validator sequences
|
|
||||||
http.client http.server http.server.responders
|
|
||||||
webapps.file html ;
|
|
||||||
IN: webapps.fjsc
|
|
||||||
|
|
||||||
: compile ( code -- )
|
|
||||||
#! Compile the factor code as a string, outputting the http
|
|
||||||
#! response containing the javascript.
|
|
||||||
serving-text
|
|
||||||
'expression' parse parse-result-ast fjsc-compile
|
|
||||||
write flush ;
|
|
||||||
|
|
||||||
! The 'compile' action results in an URL that looks like
|
|
||||||
! 'responder/fjsc/compile'. It takes one query or post
|
|
||||||
! parameter called 'code'. It calls the 'compile' word
|
|
||||||
! passing the parameter to it on the stack.
|
|
||||||
\ compile {
|
|
||||||
{ "code" v-required }
|
|
||||||
} define-action
|
|
||||||
|
|
||||||
: compile-url ( url -- )
|
|
||||||
#! Compile the factor code at the given url, return the javascript.
|
|
||||||
dup "http:" head? [ "Unable to access remote sites." throw ] when
|
|
||||||
"http://" "host" header-param rot 3append http-get compile "();" write flush ;
|
|
||||||
|
|
||||||
\ compile-url {
|
|
||||||
{ "url" v-required }
|
|
||||||
} define-action
|
|
||||||
|
|
||||||
: render-page* ( model body-template head-template -- )
|
|
||||||
[
|
|
||||||
[ render-component ] [ f rot render-component ] html-document
|
|
||||||
] serve-html ;
|
|
||||||
|
|
||||||
: repl ( -- )
|
|
||||||
#! The main 'repl' page.
|
|
||||||
f "repl" "head" render-page* ;
|
|
||||||
|
|
||||||
! An action called 'repl'
|
|
||||||
\ repl { } define-action
|
|
||||||
|
|
||||||
: fjsc-web-app ( -- )
|
|
||||||
! Create the web app, providing access
|
|
||||||
! under '/responder/fjsc' which calls the
|
|
||||||
! 'repl' action.
|
|
||||||
"fjsc" "repl" "extra/webapps/fjsc" web-app
|
|
||||||
|
|
||||||
! An URL to the javascript resource files used by
|
|
||||||
! the 'fjsc' responder.
|
|
||||||
"fjsc-resources" [
|
|
||||||
[
|
|
||||||
"extra/fjsc/resources/" resource-path doc-root set
|
|
||||||
file-responder
|
|
||||||
] with-scope
|
|
||||||
] add-simple-responder
|
|
||||||
|
|
||||||
! An URL to the resource files used by
|
|
||||||
! 'termlib'.
|
|
||||||
"fjsc-repl-resources" [
|
|
||||||
[
|
|
||||||
"extra/webapps/fjsc/resources/" resource-path doc-root set
|
|
||||||
file-responder
|
|
||||||
] with-scope
|
|
||||||
] add-simple-responder ;
|
|
||||||
|
|
||||||
MAIN: fjsc-web-app
|
|
|
@ -1,7 +0,0 @@
|
||||||
<title>Factor to Javascript REPL</title>
|
|
||||||
<link rel="stylesheet" type="text/css" href="/responder/fjsc-repl-resources/termlib/term_styles.css"/>
|
|
||||||
<script type="text/javascript" src="/responder/fjsc-repl-resources/termlib/termlib.js"></script>
|
|
||||||
<script type="text/javascript" src="/responder/fjsc-resources/jquery.js"></script>
|
|
||||||
<script type="text/javascript" src="/responder/fjsc-resources/bootstrap.js"></script>
|
|
||||||
<script type="text/javascript" src="/responder/fjsc-repl-resources/repl.js"></script>
|
|
||||||
<script type="text/javascript" src="/responder/fjsc/compile-url?url=/responder/fjsc-resources/bootstrap.factor"></script>
|
|
|
@ -1,43 +0,0 @@
|
||||||
<table border="0">
|
|
||||||
<tr><td valign="top">
|
|
||||||
<div id="repl" style="position:relative;"></div>
|
|
||||||
<p>More information on the Factor to Javascript compiler can be found at these blog posts:
|
|
||||||
<ul>
|
|
||||||
<li><a href="http://www.bluishcoder.co.nz/2006/12/compiling-factor-to-javascript.html">Factor to Javascript Compiler</a></li>
|
|
||||||
<li><a href="http://www.bluishcoder.co.nz/2006/12/factor-to-javascript-compiler-updates.html">Factor to Javascript Compiler Updates</a></li>
|
|
||||||
<li><a href="http://www.bluishcoder.co.nz/2006/12/continuations-added-to-fjsc.html">Continuations added to fjsc</a></li>
|
|
||||||
<li><a href="http://www.bluishcoder.co.nz/2006/12/cross-domain-json-with-fjsc.html">Cross Domain JSON with fjsc</a></li>
|
|
||||||
<li><a href="http://www.bluishcoder.co.nz/2007/02/factor-to-javascript-compiler-makeover.html">Factor to Javascript Compiler Makeover</a></li>
|
|
||||||
</ul>
|
|
||||||
</p>
|
|
||||||
<p>The terminal emulation code for the Factor REPL is provided by the awesome <a href="http://www.masswerk.at/termlib/index.html">termlib</a> library by Norbert Landsteiner. Documentation for termlib is <a href="/responder/fjsc-repl-resources/termlib/">available here</a>. Please note the license of 'termlib':</p>
|
|
||||||
<blockquote>This JavaScript-library is free for private and academic use. Please include a readable copyright statement and a backlink to <http://www.masswerk.at> in the web page. The library should always be accompanied by the "readme.txt" and the sample HTML-documents.
|
|
||||||
|
|
||||||
The term "private use" includes any personal or non-commercial use, which is not related to commercial activites, but excludes intranet, extranet and/or public net applications that are related to any kind of commercial or profit oriented activity.
|
|
||||||
|
|
||||||
For commercial use see <a href="http://www.masswerk.at">http://www.masswerk.at</a> for contact information.</blockquote>
|
|
||||||
</td>
|
|
||||||
<td valign="top">
|
|
||||||
<p><b>Stack</b></p>
|
|
||||||
<div id="stack">
|
|
||||||
</div>
|
|
||||||
<p><b>Playground</b></p>
|
|
||||||
<div id="playground">
|
|
||||||
</div>
|
|
||||||
<h3>Compiled Code</h3>
|
|
||||||
<textarea id="compiled" cols="40" rows="10">
|
|
||||||
</textarea>
|
|
||||||
<p>Some useful words:
|
|
||||||
<dl>
|
|
||||||
<dt>vocabs ( -- seq )</dt>
|
|
||||||
<dd>Return a sequence of available vocabularies</dd>
|
|
||||||
<dt>words ( string -- seq )</dt>
|
|
||||||
<dd>Return a sequence of words in the given vocabulary</dd>
|
|
||||||
<dt>all-words ( -- seq )</dt>
|
|
||||||
<dd>Return a sequence of all words</dd>
|
|
||||||
</dl>
|
|
||||||
</p>
|
|
||||||
<p>The contents of <a href="/responder/fjsc-resources/bootstrap.factor">bootstrap.factor</a> have been loaded on startup.</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
Loading…
Reference in New Issue