<commit_before>= koi-reference-compiler

This is the reference compiler implementation for the programming language {Koi}[http://github.com/aarongough/koi]. This is a very simple compiler that does no optimization, but because of this remains very easy to understand. The compiler is implemented using the {delegation pattern}[http://en.wikipedia.org/wiki/Delegation_pattern] in that a tree representing the program is built up out of subclasses of the SyntaxNode class, each of which knows how to compile it's own specific instruction and nothing more.

=== Example

Take, for example, a very simple (and incorrect!) program that just pushes an integer onto the stack. The {Abstract Syntax Tree (AST)}[http://en.wikipedia.org/wiki/Abstract_syntax_tree] for such a program might look like this:

  <IntegerLiteral "1">
  
In order to compile this program we might create an instance method on the IntegerLiteral class that looks like this:

  class IntegerLiteral < SyntaxNode
    def compile
      return [PUSH_INT, self.text_value.to_i]
    end
  end
  
This is obviously a minimal case, but it demonstrates the principal in a straight-forward way.

=== Abstract Syntax Tree Format

The compiler expects the AST to be passed to it in the form of a nested hash which represents the program structure. The AST hash for the program:

  test = 1
  
would look like so:<commit_msg>Added further clarifications to README.<commit_after>= koi-reference-compiler

This is the reference compiler implementation for the programming language {Koi}[http://github.com/aarongough/koi]. This is a very simple compiler that does no optimization, and because of this remains very easy to understand. The compiler is implemented using the {delegation pattern}[http://en.wikipedia.org/wiki/Delegation_pattern] in that a tree representing the program is built up out of subclasses of the SyntaxNode class, each of which knows how to compile it's own specific instruction and nothing more.

=== Example

Take, for example, a very simple (and incorrect!) program that just pushes an integer onto the stack. The {Abstract Syntax Tree (AST)}[http://en.wikipedia.org/wiki/Abstract_syntax_tree] for such a program might look like this:

  <IntegerLiteral "1">
  
In order to compile this program we might create an instance method on the IntegerLiteral class that looks like this:

  class IntegerLiteral < SyntaxNode
    def compile
      return [PUSH_INT, self.text_value.to_i]
    end
  end
  
This method simply produces the opcode PUSH_INT and provides the integer value of the text_value of the syntax node, in this case "1". This is obviously a minimal case, but it demonstrates the principal in a straight-forward way.

=== Abstract Syntax Tree Format

The compiler expects the AST to be passed to it in the form of a nested hash which represents the program structure. The AST hash for the program:

  test = 1
  
would look like so:
{'fraction_non_alphanumeric': 0.054508056222146044, 'fraction_numerical': 0.0017140898183064792, 'mean_word_length': 4.363970588235294, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4569982', 'n_tokens_mistral': 737, 'n_tokens_neox': 716, 'n_words': 400}