citrus-compiler 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,7 +10,7 @@ Being linear, it could be called very c-like, but it has been written to have a
10
10
 
11
11
  * Dynamically typed
12
12
  * Extremely ruby-like syntax
13
- * Integer, Float, String, Boolean, Array, and Range types
13
+ * Integer, Float, String, Symbol, Boolean, Array, and Range types
14
14
  * Easy integration of C functions into the API
15
15
 
16
16
  It's prime examples are in the example directory, but here is an excerpt from factorial.ct:
data/example/simple.ct CHANGED
@@ -31,7 +31,7 @@ def iterate
31
31
  iteration = 10
32
32
  while iteration >= 0
33
33
  printf("%d ", iteration)
34
- iteration = iteration - 1
34
+ iteration -= 1
35
35
  end
36
36
  puts("")
37
37
  array = ["lift", "off", "and", "away"]
@@ -1,6 +1,7 @@
1
1
  module Citrus
2
2
  class Array
3
3
 
4
+ attr_writer :length
4
5
  attr_accessor :pointer
5
6
 
6
7
  def self.create(values, builder)
@@ -12,16 +13,16 @@ module Citrus
12
13
  self.new(ary)
13
14
  end
14
15
 
15
- def initialize(pointer, props={})
16
+ def initialize(pointer, length=nil)
16
17
  @pointer = pointer
17
- @length = props[:length]
18
+ @length = length
18
19
  end
19
20
 
20
21
  def length
21
22
  unless @length.nil?
22
23
  return @length
23
24
  else
24
- return INT.from_i(LLVM::C.LLVMGetArrayLength(LLVM::Type(@pointer).element_type))
25
+ return @length = INT.from_i(LLVM::C.LLVMGetArrayLength(LLVM::Type(@pointer).element_type))
25
26
  end
26
27
  end
27
28
 
@@ -17,6 +17,10 @@ module Citrus
17
17
  return @generator.locals
18
18
  end
19
19
 
20
+ def method_missing(symbol, *args, &block)
21
+ @generator.send(symbol, *args, &block)
22
+ end
23
+
20
24
  private
21
25
 
22
26
  def build_block
@@ -28,9 +28,7 @@ module Citrus
28
28
  @builder.store(first, iteration)
29
29
  index = @builder.alloca(INT)
30
30
  @builder.store(INT.from_i(0), index)
31
- ib = @builder.insert_block
32
31
  self.preploop(:while)
33
- lb = @builder.insert_block
34
32
  self.while(self.compare(full ? :<= : :<, @builder.load(iteration), last)) do |gw|
35
33
  ival = gw.builder.load(index)
36
34
  val = gw.builder.load(iteration)
@@ -40,7 +38,7 @@ module Citrus
40
38
  gw.builder.store(gw.equate(:+, ival, gw.number(1)), index)
41
39
  end
42
40
  ival = @builder.load(index)
43
- return Array.new(ary, :length => ival)
41
+ return Array.new(ary, ival)
44
42
  end
45
43
 
46
44
  def string(value)
@@ -123,8 +121,16 @@ module Citrus
123
121
  end
124
122
 
125
123
  def assign_index(name, index, value)
126
- ary = self.load(name).pointer
127
- ptr = @builder.gep(ary, [INT.from_i(0), index])
124
+ ary = self.load(name)
125
+ length = @builder.alloca(INT)
126
+ @builder.store(ary.length, length)
127
+ tb = self.block do |gb|
128
+ gb.builder.store(gb.equate(:+, index, gb.number(1)), length)
129
+ end
130
+ cond = gb.compare(:<=, ary.length, index)
131
+ self.condition(cond, tb.bb, self.block.bb)
132
+ ary.length = @builder.load(length)
133
+ ptr = @builder.gep(ary.pointer, [INT.from_i(0), index])
128
134
  @builder.store(value, ptr)
129
135
  end
130
136
 
@@ -226,7 +232,7 @@ module Citrus
226
232
  def case(val, cases, elseblock)
227
233
  ncases = {}
228
234
  for pair in cases
229
- ncases[pair[0].bb] = pair[1]
235
+ ncases[pair[0]] = pair[1].bb
230
236
  end
231
237
  switch = @builder.switch(val, elseblock.bb, ncases)
232
238
  @basic_block = self.block.bb
@@ -2,7 +2,7 @@ module Citrus
2
2
  class Variable
3
3
 
4
4
  attr_reader :type
5
- #attr_reader :pointer
5
+ attr_reader :pointer
6
6
 
7
7
  def initialize(value, builder)
8
8
  @value = nil
data/lib/citrus/nodes.rb CHANGED
@@ -26,19 +26,32 @@ module Citrus
26
26
 
27
27
  class Assign < Node
28
28
  def codegen(g)
29
- g.assign(var.value, expression.codegen(g).last)
29
+ val = expression.codegen(g).last
30
+ unless op.value.empty?
31
+ val = g.equate(op.value, g.load(var.value), expression.codegen(g).last)
32
+ end
33
+ g.assign(var.value, val)
30
34
  end
31
35
  end
32
36
 
33
37
  class GlobalEq < Node
34
38
  def codegen(g)
35
- g.assign_global(globalvar.value, expression.codegen(g).last)
39
+ val = expression.codegen(g).last
40
+ unless op.value.empty?
41
+ val = g.load_index(op.value, g.load_global(globalvar.value), expression.codegen(g).last)
42
+ end
43
+ g.assign_global(globalvar.value, val)
36
44
  end
37
45
  end
38
46
 
39
47
  class IndexEq < Node
40
48
  def codegen(g)
41
- g.assign_index(index.var.value, index.expression.codegen(g).last, expression.codegen(g).last)
49
+ val = expression.codegen(g).last
50
+ unless op.value.empty?
51
+ ival = g.load_index(index.var.value, index.expression.codegen(g).last)
52
+ val = g.equate(op.value, ival, expression.codegen(g).last)
53
+ end
54
+ g.assign_index(index.var.value, index.expression.codegen(g).last, val)
42
55
  end
43
56
  end
44
57
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citrus-compiler
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 57
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 2
10
- version: 0.8.2
9
+ - 3
10
+ version: 0.8.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mac Malone
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-04 00:00:00 Z
18
+ date: 2011-05-07 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: treetop