Module: Citrus

Defined in:
lib/citrus.rb,
lib/citrus/core.rb,
lib/citrus/nodes.rb,
lib/citrus/runtime.rb,
lib/citrus/compiler.rb,
lib/citrus/exceptions.rb,
lib/citrus/compiler/array.rb,
lib/citrus/compiler/block.rb,
lib/citrus/compiler/function.rb,
lib/citrus/compiler/variable.rb,
lib/citrus/compiler/generator.rb,
lib/citrus/compiler/global_strings.rb

Defined Under Namespace

Modules: Runtime Classes: ArgumentError, Array, ArrayNode, Assign, Begin, Block, BoolNode, Call, Case, Cmp, Compiler, Def, Equation, Expression, FloatNode, For, Function, Generator, GlobalEq, GlobalFunctions, GlobalStrings, GlobalVar, GlobalVariable, GlobalVariables, If, Index, IndexEq, NameError, Neg, Not, NotFoundError, NumberNode, RangeNode, Require, Return, Script, StandardError, StringNode, SymbolNode, SyntaxError, Unless, Var, Variable, While

Constant Summary collapse

PCHAR =
LLVM::Type.pointer(LLVM::Int8)
FLOAT =
LLVM::Double
INT =
LLVM::Int
BOOL =
LLVM::Int1
CMP_MAPPING =
{ "==" => :eq,  "!=" => :ne,  ">" => :gt, 
">=" => :ge,  "<" => :lt,  "<=" => :le }
EQU_MAPPING =
{ "+" => :add,  "-" => :sub,  "/" => :div, "*" => :mul }
DEC_MAPPING =
{ :bool => BOOL, :float => FLOAT, :int => INT, :string => PCHAR }
ERR_GLOBAL =
"$!"
STS_GLOBAL =
"$?"
Node =
Treetop::Runtime::SyntaxNode

Class Method Summary collapse

Class Method Details

.compile(code) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/citrus.rb', line 19

def self.compile(code)
  $compiler = Citrus::Compiler.new
  $parser   = CitrusParser.new
  
  if node = $parser.parse(code)
    node.compile($compiler)
  else
    error(SyntaxError.new)
  end
  
  $compiler
end

.compile_file(file) ⇒ Object



32
33
34
35
# File 'lib/citrus.rb', line 32

def self.compile_file(file)
  $file = file
  self.compile(File.read(file))
end

.error(error) ⇒ Object



35
36
37
38
# File 'lib/citrus/exceptions.rb', line 35

def self.error(error)
  puts("#{error.message} (#{error.class.to_s.split('::').last})")
  exit(1)
end