Permalink
Browse files

Created gh-pages branch via GitHub

  • Loading branch information...
indutny committed Apr 2, 2012
0 parents commit ef8e2739a73dc37b03063e13258c78b07c788fb7
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,342 @@
+<!DOCTYPE html>
+<html>
+
+ <head>
+ <meta charset='utf-8' />
+ <meta http-equiv="X-UA-Compatible" content="chrome=1" />
+ <meta name="description" content="Candor : Experimental VM for a `Candor` language" />
+
+ <link rel="stylesheet" type="text/css" media="screen" href="stylesheets/stylesheet.css">
+
+ <title>Candor</title>
+ </head>
+
+ <body>
+
+ <!-- HEADER -->
+ <div id="header_wrap" class="outer">
+ <header class="inner">
+ <a id="forkme_banner" href="https://github.com/indutny/candor">Fork Me on GitHub</a>
+
+ <h1 id="project_title">Candor</h1>
+ <h2 id="project_tagline">Experimental VM for a `Candor` language</h2>
+
+ <section id="downloads">
+ <a class="zip_download_link" href="https://github.com/indutny/candor/zipball/master">Download this project as a .zip file</a>
+ <a class="tar_download_link" href="https://github.com/indutny/candor/tarball/master">Download this project as a tar.gz file</a>
+ </section>
+ </header>
+ </div>
+
+ <!-- MAIN CONTENT -->
+ <div id="main_content_wrap" class="outer">
+ <section id="main_content" class="inner">
+ <h1>Candor</h1>
+
+<p>Candor is a language inspired by javascript, but with less features and,
+therefore, less complexity. So no semicolons, no exceptions and simplified
+anonymous function syntax (dart-like).</p>
+
+<p>Main goal of Candor is to provide a powerful and developer-friendly language
+that can be easily optimized by compiler.</p>
+
+<h2>Description</h2>
+
+<p>Experimental implementation of Candor language VM. Join #candor channel on
+irc.freenode.net and
+<a href="https://groups.google.com/forum/?fromgroups&amp;hl=en#!forum/candorlang">official google group</a>
+to discuss language features.</p>
+
+<p><strong>Danger! This whole project is not stable at all, many things are broken and
+may/will change in future</strong></p>
+
+<p>Note: only x64 is supported now.</p>
+
+<h2>Example</h2>
+
+<pre lang="candor"><code>// Defining a recursive function
+factorial(x) {
+ if (x == 1) return 1
+ return x * factorial(x - 1)
+}
+
+factorial(10)
+
+// Implementing a forEach function
+forEach(array, callback) {
+ if (typeof array != "array") return
+ length = sizeof array
+ i = 0
+ while (i &lt; length) {
+ callback(i, array[i])
+ i++
+ }
+}
+
+// Implementing switch with chained if..else
+type = typeof value
+if (type == "nil") handleNil(value)
+else if (type == "boolean") handleBoolean(value)
+else if (type == "number") handleNumber(value)
+else if (type == "string") handleString(value)
+else handleObject(value)
+
+// Implementing switch using objects
+handlers = {
+ "nil": handleNil,
+ "boolean": handleBoolean,
+ "number": handleNumber,
+ "string": handleString
+}
+handler = handlers[typeof value]
+if (handler) handler(value)
+else handleObject(value)
+
+</code></pre>
+
+<p>As you can see, there're no semicolons, statements are separated by newline
+symbols (whitespace is ignored).</p>
+
+<h2>Language basics</h2>
+
+<p>Candor is essentially inspired by the <a href="http://www.ecmascript.org/">ECMA-script</a>,
+but has much less features and complexity (for compiler).</p>
+
+<p>Functions are declared in <a href="http://www.dartlang.org/">dart</a>-like style, variables
+are implicitly scoped (i.e. if variable has no use in outer scopes, it'll be
+allocated in one where you declared it).</p>
+
+<pre lang="candor"><code>// Keywords: nil, true, false, typeof, sizeof, keysof, if, else, while,
+// for, break, continue, return, new
+
+// Primitives
+nil
+true
+false
+NaN
+1
+'abc'
+"abc"
+[1, 2, 3]
+{ a: 1, 'b': 2, "c": 3 }
+
+// Variables and objects
+a = 1
+a.b = "abc"
+a.b.c = a
+a[b()][c] = x
+
+delete a[b] // removes key and value from object
+
+// While object literals are restricted to declaring strings as keys, any value
+// can be used as a key. This allows for all kinds of interesting data
+// structures like efficient sets and unique unguessable keys.
+a = { "5": "five" }
+a[5] = 5
+a["5"] // -&gt; "five"
+a[5] // -&gt; 5
+a[{ hello: "World" }] = "key is object, value is string!"
+
+// Functions
+a() {
+ return 1
+}
+a()
+// Functions are also objects and can have properties
+a.b = "foo"
+
+// Arrays are also objects, except they internally keep track of the largest
+// integer index so that sizeof works with them.
+a = [1,2,3]
+a.foo = true
+sizeof a // -&gt; 3
+a.foo // -&gt; true
+
+// typeof. Sometimes it's useful to know what type a variable is
+
+typeof nil // -&gt; "nil"
+typeof true // -&gt; "boolean"
+typeof false // -&gt; "boolean"
+typeof 42 // -&gt; "number"
+typeof "Hello" // -&gt; "string"
+typeof [1,2,3] // -&gt; "array"
+typeof {a: 5} // -&gt; "object"
+typeof (){} // -&gt; "function"
+
+// sizeof gives the size of an array (max integer key + 1) or string (number of bytes)
+// gives nil for other types
+
+sizeof "Hello" // -&gt; 5
+sizeof [1,2,3] // -&gt; 3
+sizeof {} // -&gt; 0
+
+// keysof returns an array of all the keys in an object
+keys = keysof { name: "Tim", age: 29 }
+keys // -&gt; ["name", "age"]
+
+// Control flow
+
+// The variables in the condition head are scoped with the condition, not the
+// optional body block.
+
+// Conditionals
+person = { age: 29, name: "Tim" }
+
+// With block
+if (person.age &gt; 18) {
+ person.name // -&gt; "Tim"
+}
+
+// Without block
+if (person.age &gt; 18) person.name
+
+// using else
+if (person.age &gt; 18) {
+ // do something with `person`
+} else {
+ // do something else
+}
+
+if (person.age &gt; 18) action(person)
+else otherAction()
+
+// While loops
+i = 0
+sum = 0
+while (i &lt; 10) {
+ sum = sum + i
+ i++
+}
+
+// break and continue. `while` loop can have `break` and `continue`
+// break exits a loop immediately, continue, skips to the next iteration
+
+// Object Oriented Programming
+
+// There are no dynamic prototypes in candor, but there is a fast-clone
+// operation and special method calling syntax to make OOP style programming
+// possible if you prefer that style.
+
+// Create a prototype object
+Rectangle = {
+ getArea: (self) {
+ return self.w * self.h
+ },
+ initialize: (self, w, h) {
+ self.w = w
+ self.h = h
+ }
+}
+
+// First create a fast shallow clone of the Rectangle prototype
+rect = clone Rectangle
+
+// Then initialize it using a one of the functions
+rect.initialize(rect, 3, 5)
+
+// Now we can use this object
+rect.getArea(rect) // -&gt; 15
+
+// To make calling methods easier, there is special syntax sugar using `:`
+// instead of `.` for function calls. It means to call the function with
+// whatever is left of the `:` as the first argument.
+
+// The previous two calls can be written as:
+rect:initialize(3, 5)
+rect:getArea() // -&gt; 15
+</code></pre>
+
+<h2>Building</h2>
+
+<div class="highlight">
+<pre>git clone git://github.com/indutny/candor.git
+<span class="nb">cd </span>candor
+make <span class="nb">test</span>
+</pre>
+</div>
+
+
+<h2>Status of project</h2>
+
+<p>Things that are implemented currently:</p>
+
+<ul>
+<li>Language lexer and parser</li>
+<li>Assigning on-stack and context variables</li>
+<li>Binary and unary operations</li>
+<li>Unboxing of heap numbers</li>
+<li>Floating point operations</li>
+<li>Function calls, passing arguments and using returned value</li>
+<li>Stop-the-world copying two-space garbage collector</li>
+<li>Hash-maps (objects), numeric and string keys</li>
+<li>Arrays</li>
+<li>Typeof, Sizeof, Keysof</li>
+<li>String concatenation</li>
+<li>Parser/lexer/compiler errors</li>
+<li>Break/Continue statements</li>
+<li>C++/C bindings support for candor</li>
+<li>C++/C bindings documentation</li>
+<li>Dense arrays</li>
+</ul><p>Things to come:</p>
+
+<ul>
+<li>Cons strings</li>
+<li>On-stack replacement and profile-based optimizations</li>
+<li>Incremental GC</li>
+<li>Usage in multiple-threads (aka isolates)</li>
+<li>See <a href="https://github.com/indutny/candor/blob/master/TODO">TODO</a> for more
+up-to-date tasks</li>
+</ul><h2>Contributing</h2>
+
+<p>Any bug-fixes or feature implementations are always welcome! Only one
+restriction is applied to the code - it should follow
+<a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml">Google C++ Style Guide</a>.</p>
+
+<p>Want to get in, but don't feel like you know a lot about designing compilers?
+No problem at all - I prepared a list of papers that may help you understand
+things going in Candor better:
+<a href="https://github.com/indutny/candor/wiki/Compiler-papers">Compiler-papers</a>.</p>
+
+<p><em>Please keep in mind, that at the moment all development is going in
+<a href="https://github.com/indutny/candor/tree/feature-ssa">feature-ssa</a> branch.</em></p>
+
+<h2>Credits</h2>
+
+<p>Special thanks to <a href="https://github.com/creationix">creationix</a> for suggesting the
+name of this project!</p>
+
+<h4>LICENSE</h4>
+
+<p>Copyright (c) 2012, Fedor Indutny.</p>
+
+<p>Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:</p>
+
+<p>The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.</p>
+
+<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
+ </section>
+ </div>
+
+ <!-- FOOTER -->
+ <div id="footer_wrap" class="outer">
+ <footer class="inner">
+ <p class="copyright">Candor maintained by <a href="https://github.com/indutny">indutny</a></p>
+ <p>Published with <a href="http://pages.github.com">GitHub Pages</a></p>
+ </footer>
+ </div>
+
+
+
+ </body>
+</html>
@@ -0,0 +1 @@
+console.log('This would be the main JS file.');
@@ -0,0 +1 @@
+{"name":"Candor","body":"# Candor\r\n\r\nCandor is a language inspired by javascript, but with less features and,\r\ntherefore, less complexity. So no semicolons, no exceptions and simplified\r\nanonymous function syntax (dart-like).\r\n\r\nMain goal of Candor is to provide a powerful and developer-friendly language\r\nthat can be easily optimized by compiler.\r\n\r\n## Description\r\n\r\nExperimental implementation of Candor language VM. Join #candor channel on\r\nirc.freenode.net and\r\n[official google group](https://groups.google.com/forum/?fromgroups&hl=en#!forum/candorlang)\r\nto discuss language features.\r\n\r\n**Danger! This whole project is not stable at all, many things are broken and\r\nmay/will change in future**\r\n\r\nNote: only x64 is supported now.\r\n\r\n## Example\r\n\r\n```candor\r\n// Defining a recursive function\r\nfactorial(x) {\r\n if (x == 1) return 1\r\n return x * factorial(x - 1)\r\n}\r\n\r\nfactorial(10)\r\n\r\n// Implementing a forEach function\r\nforEach(array, callback) {\r\n if (typeof array != \"array\") return\r\n length = sizeof array\r\n i = 0\r\n while (i < length) {\r\n callback(i, array[i])\r\n i++\r\n }\r\n}\r\n\r\n// Implementing switch with chained if..else\r\ntype = typeof value\r\nif (type == \"nil\") handleNil(value)\r\nelse if (type == \"boolean\") handleBoolean(value)\r\nelse if (type == \"number\") handleNumber(value)\r\nelse if (type == \"string\") handleString(value)\r\nelse handleObject(value)\r\n\r\n// Implementing switch using objects\r\nhandlers = {\r\n \"nil\": handleNil,\r\n \"boolean\": handleBoolean,\r\n \"number\": handleNumber,\r\n \"string\": handleString\r\n}\r\nhandler = handlers[typeof value]\r\nif (handler) handler(value)\r\nelse handleObject(value)\r\n\r\n```\r\n\r\nAs you can see, there're no semicolons, statements are separated by newline\r\nsymbols (whitespace is ignored).\r\n\r\n## Language basics\r\n\r\nCandor is essentially inspired by the [ECMA-script](http://www.ecmascript.org/),\r\nbut has much less features and complexity (for compiler).\r\n\r\nFunctions are declared in [dart](http://www.dartlang.org/)-like style, variables\r\nare implicitly scoped (i.e. if variable has no use in outer scopes, it'll be\r\nallocated in one where you declared it).\r\n\r\n```candor\r\n// Keywords: nil, true, false, typeof, sizeof, keysof, if, else, while,\r\n// for, break, continue, return, new\r\n\r\n// Primitives\r\nnil\r\ntrue\r\nfalse\r\nNaN\r\n1\r\n'abc'\r\n\"abc\"\r\n[1, 2, 3]\r\n{ a: 1, 'b': 2, \"c\": 3 }\r\n\r\n// Variables and objects\r\na = 1\r\na.b = \"abc\"\r\na.b.c = a\r\na[b()][c] = x\r\n\r\ndelete a[b] // removes key and value from object\r\n\r\n// While object literals are restricted to declaring strings as keys, any value\r\n// can be used as a key. This allows for all kinds of interesting data\r\n// structures like efficient sets and unique unguessable keys.\r\na = { \"5\": \"five\" }\r\na[5] = 5\r\na[\"5\"] // -> \"five\"\r\na[5] // -> 5\r\na[{ hello: \"World\" }] = \"key is object, value is string!\"\r\n\r\n// Functions\r\na() {\r\n return 1\r\n}\r\na()\r\n// Functions are also objects and can have properties\r\na.b = \"foo\"\r\n\r\n// Arrays are also objects, except they internally keep track of the largest\r\n// integer index so that sizeof works with them.\r\na = [1,2,3]\r\na.foo = true\r\nsizeof a // -> 3\r\na.foo // -> true\r\n\r\n// typeof. Sometimes it's useful to know what type a variable is\r\n\r\ntypeof nil // -> \"nil\"\r\ntypeof true // -> \"boolean\"\r\ntypeof false // -> \"boolean\"\r\ntypeof 42 // -> \"number\"\r\ntypeof \"Hello\" // -> \"string\"\r\ntypeof [1,2,3] // -> \"array\"\r\ntypeof {a: 5} // -> \"object\"\r\ntypeof (){} // -> \"function\"\r\n\r\n// sizeof gives the size of an array (max integer key + 1) or string (number of bytes)\r\n// gives nil for other types\r\n\r\nsizeof \"Hello\" // -> 5\r\nsizeof [1,2,3] // -> 3\r\nsizeof {} // -> 0\r\n\r\n// keysof returns an array of all the keys in an object\r\nkeys = keysof { name: \"Tim\", age: 29 }\r\nkeys // -> [\"name\", \"age\"]\r\n\r\n// Control flow\r\n\r\n// The variables in the condition head are scoped with the condition, not the\r\n// optional body block.\r\n\r\n// Conditionals\r\nperson = { age: 29, name: \"Tim\" }\r\n\r\n// With block\r\nif (person.age > 18) {\r\n person.name // -> \"Tim\"\r\n}\r\n\r\n// Without block\r\nif (person.age > 18) person.name\r\n\r\n// using else\r\nif (person.age > 18) {\r\n // do something with `person`\r\n} else {\r\n // do something else\r\n}\r\n\r\nif (person.age > 18) action(person)\r\nelse otherAction()\r\n\r\n// While loops\r\ni = 0\r\nsum = 0\r\nwhile (i < 10) {\r\n sum = sum + i\r\n i++\r\n}\r\n\r\n// break and continue. `while` loop can have `break` and `continue`\r\n// break exits a loop immediately, continue, skips to the next iteration\r\n\r\n// Object Oriented Programming\r\n\r\n// There are no dynamic prototypes in candor, but there is a fast-clone\r\n// operation and special method calling syntax to make OOP style programming\r\n// possible if you prefer that style.\r\n\r\n// Create a prototype object\r\nRectangle = {\r\n getArea: (self) {\r\n return self.w * self.h\r\n },\r\n initialize: (self, w, h) {\r\n self.w = w\r\n self.h = h\r\n }\r\n}\r\n\r\n// First create a fast shallow clone of the Rectangle prototype\r\nrect = clone Rectangle\r\n\r\n// Then initialize it using a one of the functions\r\nrect.initialize(rect, 3, 5)\r\n\r\n// Now we can use this object\r\nrect.getArea(rect) // -> 15\r\n\r\n// To make calling methods easier, there is special syntax sugar using `:`\r\n// instead of `.` for function calls. It means to call the function with\r\n// whatever is left of the `:` as the first argument.\r\n\r\n// The previous two calls can be written as:\r\nrect:initialize(3, 5)\r\nrect:getArea() // -> 15\r\n```\r\n\r\n## Building\r\n\r\n```bash\r\ngit clone git://github.com/indutny/candor.git\r\ncd candor\r\nmake test\r\n```\r\n\r\n## Status of project\r\n\r\nThings that are implemented currently:\r\n\r\n* Language lexer and parser\r\n* Assigning on-stack and context variables\r\n* Binary and unary operations\r\n* Unboxing of heap numbers\r\n* Floating point operations\r\n* Function calls, passing arguments and using returned value\r\n* Stop-the-world copying two-space garbage collector\r\n* Hash-maps (objects), numeric and string keys\r\n* Arrays\r\n* Typeof, Sizeof, Keysof\r\n* String concatenation\r\n* Parser/lexer/compiler errors\r\n* Break/Continue statements\r\n* C++/C bindings support for candor\r\n* C++/C bindings documentation\r\n* Dense arrays\r\n\r\nThings to come:\r\n\r\n* Cons strings\r\n* On-stack replacement and profile-based optimizations\r\n* Incremental GC\r\n* Usage in multiple-threads (aka isolates)\r\n* See [TODO](https://github.com/indutny/candor/blob/master/TODO) for more\r\n up-to-date tasks\r\n\r\n## Contributing\r\n\r\nAny bug-fixes or feature implementations are always welcome! Only one\r\nrestriction is applied to the code - it should follow\r\n[Google C++ Style Guide](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml).\r\n\r\nWant to get in, but don't feel like you know a lot about designing compilers?\r\nNo problem at all - I prepared a list of papers that may help you understand\r\nthings going in Candor better:\r\n[Compiler-papers](https://github.com/indutny/candor/wiki/Compiler-papers).\r\n\r\n*Please keep in mind, that at the moment all development is going in\r\n[feature-ssa](https://github.com/indutny/candor/tree/feature-ssa) branch.*\r\n\r\n## Credits\r\n\r\nSpecial thanks to [creationix](https://github.com/creationix) for suggesting the\r\nname of this project!\r\n\r\n#### LICENSE\r\n\r\nCopyright (c) 2012, Fedor Indutny.\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of\r\nthis software and associated documentation files (the \"Software\"), to deal in\r\nthe Software without restriction, including without limitation the rights to\r\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r\nthe Software, and to permit persons to whom the Software is furnished to do so,\r\nsubject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","tagline":"Experimental VM for a `Candor` language","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}
Oops, something went wrong.

0 comments on commit ef8e273

Please sign in to comment.