Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add some methodes

  • Loading branch information...
commit 0873fbd923046a222b6616c84afc590d449addaf 1 parent 34c25f8
miura1729 authored
View
6 MEMO
@@ -1,3 +1,9 @@
+2009-08-30 Hideki Miura
+
+* Array#at�Ȃǂ̃��\�b�h�͌Ăяo���ꏊ���ƂɌ^���قȂ肤��.�����S���������Ĉ�����
+ ���I�^�`�F�b�N�������Ⴄ�̂ŌĂяo�����Ɍ^�I�u�W�F�N�g��p�ӂ��ȁX�Ɍ^���_����
+ ���̗l�Ȍ^��ƒ��\�b�h�̃t���O����B
+
2009-07-08 <miura>
* type�I�u�W�F�N�g��constant��content��g�������邱�ƁBfunction, structure��
View
6 lib/llvmutil.rb
@@ -752,6 +752,12 @@ def do_function(receiver, info, ins, local_vars, args, mname, curlevel)
pppp "RubyMethod called #{mname.inspect}"
para = gen_arg_eval(args, receiver, ins, local_vars, info, minfo, mname)
+ if func == nil then
+ level = @expstack.size
+ if @array_alloca_size == nil or @array_alloca_size < 1 + level then
+ @array_alloca_size = 1 + level
+ end
+ end
@expstack.push [rettype,
lambda {|b, context|
recklass = receiver ? receiver[0].klass : nil
View
45 lib/methoddef.rb
@@ -267,10 +267,30 @@ module MethodDefinition
:& => {
:inline_proc =>
lambda {|para|
- gen_binary_operator(para,
- lambda {|v1, v2, b, context|
- b.and(v1, v2)
- })
+ arg1 = para[:receiver]
+ argt = arg1[0]
+ if argt.klass != :TrueClass and argt.klass != :FalseClass then
+ gen_binary_operator(para,
+ lambda {|v1, v2, b, context|
+ b.and(v1, v2)
+ })
+ else
+ arg2 = para[:args][0]
+ @expstack.push [RubyType.boolean,
+ lambda {|b, context|
+ context = arg1[1].call(b, context)
+ v1 = context.rc
+ v1 = arg1[0].type.to_value(v1, b, context)
+ context = arg2[1].call(b, context)
+ v2 = context.rc
+ v2 = arg2[0].type.to_value(v2, b, context)
+
+ vt = b.and(v1, v2)
+ vt = b.and(vt, (~4).llvm)
+ context.rc = b.icmp_eq(vt, 0.llvm)
+ context
+ }]
+ end
},
},
@@ -493,19 +513,19 @@ module MethodDefinition
args = para[:args].reverse
nargs = args.size
arraycurlevel = 0
- if nargs != 0 then
- arraycurlevel = @expstack.size
- if @array_alloca_size == nil or
- @array_alloca_size < nargs + arraycurlevel then
- @array_alloca_size = nargs + arraycurlevel
- end
- end
# This rb_class_new_instance needs stack area as arguments
# in spite of with no arguments.
if @array_alloca_size == nil then
@array_alloca_size = 1
end
+ if nargs != 0 then
+ arraycurlevel = @expstack.size
+ if @array_alloca_size < nargs + arraycurlevel then
+ @array_alloca_size = nargs + arraycurlevel
+ end
+ end
+
rettype = RubyType.from_sym(rec[0].klass, para[:info][3], rec[0].klass)
#=begin
recklass = rec[0].klass
@@ -650,8 +670,7 @@ module MethodDefinition
context}]
}
},
-
-
+
:at => {
:inline_proc =>
lambda {|para|
View
4 lib/type.rb
@@ -447,7 +447,9 @@ def self.from_sym(sym, lno, name)
when :Range
fst = RubyType.new(nil)
lst = RubyType.new(nil)
- excl = RubyType.new(nil)
+ fst.add_same_type(lst)
+ lst.add_same_type(fst)
+ excl = RubyType.boolean
RubyType.range(fst, lst, excl, lno, name)
else
View
2  lib/vmtraverse.rb
@@ -2328,6 +2328,7 @@ def visit_opt_plus(code, ins, local_vars, ln, info)
else
# Generic + dispatch else
p info
+ p s[0][0].conflicted_types.keys
raise "Unkown Type #{s[0][0].type.llvm}"
end
@@ -2385,6 +2386,7 @@ def visit_opt_minus(code, ins, local_vars, ln, info)
else
# Generic + dispatch
p info
+ p s[0][0].conflicted_types.keys
raise "Unkown Type #{s[0][0].type.llvm}"
end
View
93 runtime/prelude.rb
@@ -39,6 +39,83 @@ module YARV2LLVM
:rettype => rt,
}
+=begin
+ st = RubyType.array
+ rt = RubyType.new(nil)
+ rt.add_same_type(st.type.element_type)
+ st.type.element_type.add_same_type(rt)
+ MethodDefinition::RubyMethod[:first][:Array] = {
+ :self => st,
+ :argtype => [RubyType.new(nil)],
+ :rettype => rt,
+ }
+
+ st = RubyType.array
+ rt = RubyType.array
+ rt.add_same_type(st)
+ st.add_same_type(rt)
+ MethodDefinition::RubyMethod[:reverse][:Array] = {
+ :self => st,
+ :argtype => [],
+ :rettype => rt,
+ }
+
+
+ st = RubyType.array
+ rt = RubyType.array
+ rt.add_same_type(st)
+ st.add_same_type(rt)
+ MethodDefinition::RubyMethod[:slice!][:Array] = {
+ :self => st,
+ :argtype => [RubyType.new(nil), RubyType.new(nil)],
+ :rettype => rt,
+ }
+=end
+
+ MethodDefinition::RubyMethod[:"!~"][:String] = {
+ :argtype => [RubyType.new(nil)],
+ :rettype => RubyType.boolean,
+ }
+
+ MethodDefinition::RubyMethod[:"=~"][:String] = {
+ :argtype => [RubyType.new(nil)],
+ :rettype => RubyType.boolean,
+ }
+
+
+ MethodDefinition::RubyMethod[:"!~"][:Regexp] = {
+ :argtype => [RubyType.string],
+ :rettype => RubyType.boolean,
+ }
+
+ MethodDefinition::RubyMethod[:"=~"][:Regexp] = {
+ :argtype => [RubyType.string],
+ :rettype => RubyType.boolean,
+ }
+
+ fst = RubyType.new(nil)
+ lst = RubyType.new(nil)
+ fst.add_same_type(lst)
+ lst.add_same_type(fst)
+ excl = RubyType.boolean
+ rng = RubyType.range(fst, lst, excl)
+ MethodDefinition::RubyMethod[:first][:Range] = {
+ :self => rng,
+ :argtype => [],
+ :rettype => fst,
+ }
+
+ fst = RubyType.new(nil)
+ lst = RubyType.new(nil)
+ fst.add_same_type(lst)
+ lst.add_same_type(fst)
+ excl = RubyType.boolean
+ rng = RubyType.range(fst, lst, excl)
+ MethodDefinition::RubyMethod[:last][:Range] = {
+ :self => rng,
+ :argtype => [],
+ :rettype => lst,
+ }
#=end
end
@@ -125,6 +202,22 @@ def collect
end
class Range
+ def step(st)
+ i = self.first
+ ed = self.last
+ if st > 0 then
+ while i <= ed do
+ yield i
+ i = i + st
+ end
+ else
+ while ed <= i do
+ yield i
+ i = i + st
+ end
+ end
+ end
+
def collect
res = []
i = 0
Please sign in to comment.
Something went wrong with that request. Please try again.