Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial commit
  • Loading branch information
asterite committed Jun 21, 2011
0 parents commit 50db229
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 0 deletions.
1 change: 1 addition & 0 deletions .rvmrc
@@ -0,0 +1 @@
rvm use 1.9.2@crystal
5 changes: 5 additions & 0 deletions Gemfile
@@ -0,0 +1,5 @@
source :rubygems

gem 'ruby-llvm'
gem 'rltk', '1.0.0', :path => 'vendor/gems'
gem 'rspec'
28 changes: 28 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,28 @@
PATH
remote: vendor/gems
specs:
rltk (1.0.0)

GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.2)
ffi (1.0.9)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
ruby-llvm (2.9.1)
ffi (>= 1.0.0)

PLATFORMS
ruby

DEPENDENCIES
rltk (= 1.0.0)!
rspec
ruby-llvm
54 changes: 54 additions & 0 deletions README.markdown
@@ -0,0 +1,54 @@
Joy
===

Joy is a programming language that compiles to native code.
It has a syntax strongly inspired by Ruby:
* No need to declare types: everything is inferred.
* Classes and Modules can be opened: at compile time everything is mixed together
* String interpolation
* Regular expression interpolation
* Instance variables start with @
* Global variables start with $
* Constants start with Capital Letters
* Functions can be evaluated at compile time as long as they are assigned to a Constant.

Examples:

1. Hello World

puts "Hello World"

2. Fibbonacci

def fib n
if n <= 2
1
else
fib(n - 1) + fib(n - 2)
end
end

Value = fib 6
puts Value

# Compiles to...
# puts 8

3. Constants as arguments

def static N, x
if N == 1
2 * x
else
3 * x
end
end

puts static(2, 6)

# Compiles to...
def static_2 x
3 * x
end

puts static_2(6)
6 changes: 6 additions & 0 deletions lib/joy.rb
@@ -0,0 +1,6 @@
require 'rubygems'
['lexer'].each do |filename|
require(File.expand_path("../#{filename}", __FILE__))
end

p Lexer.lex('def').map(&:type)
7 changes: 7 additions & 0 deletions lib/lexer.rb
@@ -0,0 +1,7 @@
require 'rltk/lexer'

class Lexer < RLTK::Lexer
rule(/\s/)
rule(/def/) { [:IDENT, :def] }
rule(/\w+/) { |id| [:IDENT, id] }
end
10 changes: 10 additions & 0 deletions spec/lexer_spec.rb
@@ -0,0 +1,10 @@
require 'test/unit'
require(File.expand_path("../../lib/lexer", __FILE__))

describe Lexer do
it "lexes def" do
token = Lexer.lex('def').first
token.type.should eq(:IDENT)
token.value.should eq(:def)
end
end
Binary file added vendor/gems/rltk-1.0.0.gem
Binary file not shown.

0 comments on commit 50db229

Please sign in to comment.