koi-lang 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/.gitignore +3 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +95 -0
  4. data/Rakefile +46 -0
  5. data/VERSION +1 -0
  6. data/bin/koi +17 -0
  7. metadata +111 -0
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ *.gemspec
3
+ *.swp
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Aaron Gough (http://thingsaaronmade.com/)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,95 @@
1
+ = Koi
2
+
3
+ Koi is a small programming language that is designed to be easy to use, easy to understand and easy to implement. Koi is an imperative, dynamic, weakly-typed language with first-class functions. Koi's syntax is influenced by JavaScript, Lua and Ruby, but works very hard to be unambiguous so that it is easy to write parsers for (in stark contrast with Ruby).
4
+
5
+ === Example
6
+
7
+ This is an old-school 'Blast Off!' program written in Koi:
8
+
9
+ countdown = function( count )
10
+ print( to_string( count ))
11
+ print( ", " )
12
+ if( count == 0 )
13
+ return()
14
+ end
15
+ count = count - 1
16
+ call( countdown, count )
17
+ end
18
+
19
+ call( countdown, 10 )
20
+
21
+ print( "Blast Off!" )
22
+
23
+ #=> 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, Blast Off!
24
+
25
+ === Installation
26
+
27
+ For ease of installation the default installation of Koi is packaged as a RubyGem. Providing you have Ruby and RubyGems installed installing Koi is as easy as entering the following command in a terminal:
28
+
29
+ gem install koi-lang
30
+
31
+ Mac OS X and most Unix/Linux distributions come with an installation of Ruby and RubyGems. If you do not have Ruby and RubyGems installed please check the {Ruby website for instructions}[http://www.ruby-lang.org/en/downloads/].
32
+
33
+ === Usage
34
+
35
+ After Koi is installed you can run a program by typing the following on the command line:
36
+
37
+ koi /path/to/program
38
+
39
+ == Koi Fundamentals
40
+
41
+ === Data types
42
+
43
+ Koi features a full set of basic and compound data types including:
44
+
45
+ * Nil
46
+ * Boolean
47
+ * Integer
48
+ * Float
49
+ * String
50
+ * Hash
51
+ * Function
52
+
53
+ === Flow control
54
+
55
+ Koi currently only implements a minimal set of flow control operators:
56
+
57
+ if( expression )
58
+ call( do_work )
59
+ endif
60
+
61
+ unless( expression )
62
+ call( do_other_work )
63
+ endunless
64
+
65
+ === Built-in functions
66
+
67
+ print( string ):: Writes a string to STDOUT.
68
+ gets():: Fetches a newline delimited string from STDIN.
69
+ call( identifier [, parameter]):: Calls the function that is stored in 'identifier'.
70
+ tailcall( identifier[, parameter]):: Performs a 'tailcall' to the function stored in 'identifier'. This type of call is used when recursing heavily to improve performance and to facilitate the use of functions as iterators.
71
+ return( [value] ):: Return a value from a function.
72
+ to_string( value/identifier ):: Converts the given value to a representative string.
73
+ type_of( value ):: Returns a string representing the type of the value given, eg: "integer".
74
+
75
+ === Reserved words
76
+
77
+ if, unless, function, end, call, tailcall, print, gets, return, to_string, type_of, nil, true, false
78
+
79
+ === Components
80
+
81
+ The default installation of Koi consists of the following discrete components:
82
+
83
+ * The reference parser: {koi-reference-parser}[http://github.com/aarongough/koi-reference-parser]
84
+ * The reference compiler: {koi-reference-compiler}[http://github.com/aarongough/koi-reference-compiler]
85
+ * The standard Virtual Machine: {koi-vm-ruby}[http://github.com/aarongough/koi-vm-ruby]
86
+
87
+ Each of these components are completely stand-alone and are specifically designed to be as simple as possible. I strongly encourage pulling them apart to see how they tick, and changing them if you see fit! Just make sure if to contribute any improvements back to the main repository!
88
+
89
+ ==== Hope you enjoy Koi!
90
+
91
+ === Author & Credits
92
+
93
+ Author:: {Aaron Gough}[mailto:aaron@aarongough.com]
94
+
95
+ Copyright (c) 2010 {Aaron Gough}[http://thingsaaronmade.com/] ({thingsaaronmade.com}[http://thingsaaronmade.com/]), released under the MIT license
@@ -0,0 +1,46 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ begin
9
+ require 'jeweler'
10
+ Jeweler::Tasks.new do |gemspec|
11
+ gemspec.name = "koi-lang"
12
+ gemspec.summary = "A parser, compiler and virtual machine toolchain for the Koi programming language."
13
+ gemspec.description = "This package provides the reference implementations of the parser and compiler for Koi, as well as a basic virtual machine. This is the official package for installing Koi."
14
+ gemspec.email = "aaron@aarongough.com"
15
+ gemspec.homepage = "http://github.com/aarongough/koi"
16
+ gemspec.authors = ["Aaron Gough"]
17
+ gemspec.rdoc_options << '--line-numbers' << '--inline-source'
18
+ gemspec.extra_rdoc_files = ['README.rdoc', 'MIT-LICENSE']
19
+ gemspec.add_dependency('koi-vm')
20
+ gemspec.add_dependency('koi-reference-parser')
21
+ gemspec.add_dependency('koi-reference-compiler')
22
+ gemspec.executables << 'koi'
23
+ end
24
+ rescue LoadError
25
+ puts "Jeweler not available. Install it with: gem install jeweler"
26
+ end
27
+
28
+
29
+ desc 'Test koi-lang.'
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib/*.rb'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = true
35
+ end
36
+
37
+
38
+ desc 'Generate documentation for koi-lang.'
39
+ Rake::RDocTask.new(:rdoc) do |rdoc|
40
+ rdoc.rdoc_dir = 'rdoc'
41
+ rdoc.title = 'Koi'
42
+ rdoc.options << '--line-numbers' << '--inline-source'
43
+ rdoc.rdoc_files.include('README.rdoc')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ rdoc.rdoc_files.include('app/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/koi ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ require 'koi-reference-parser'
6
+ require 'koi-reference-compiler'
7
+ require 'koi-vm-ruby'
8
+
9
+ include KoiReferenceParser
10
+ include KoiReferenceCompiler
11
+ include KoiVMRuby
12
+
13
+ program_text = ARGF.read
14
+
15
+ ast_hash = Parser.parse( program_text ).to_hash
16
+ bytecode = Compiler.compile( ast_hash )
17
+ VM.new.run( bytecode )
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: koi-lang
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Aaron Gough
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-31 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: koi-vm
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: koi-reference-parser
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: koi-reference-compiler
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :runtime
58
+ version_requirements: *id003
59
+ description: This package provides the reference implementations of the parser and compiler for Koi, as well as a basic virtual machine. This is the official package for installing Koi.
60
+ email: aaron@aarongough.com
61
+ executables:
62
+ - koi
63
+ - koi
64
+ extensions: []
65
+
66
+ extra_rdoc_files:
67
+ - MIT-LICENSE
68
+ - README.rdoc
69
+ files:
70
+ - .gitignore
71
+ - MIT-LICENSE
72
+ - README.rdoc
73
+ - Rakefile
74
+ - VERSION
75
+ - bin/koi
76
+ has_rdoc: true
77
+ homepage: http://github.com/aarongough/koi
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ - --line-numbers
84
+ - --inline-source
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.3.7
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: A parser, compiler and virtual machine toolchain for the Koi programming language.
110
+ test_files: []
111
+