diff options
| author | Paolo Bosetti <[email protected]> | 2012-08-06 15:02:03 +0200 |
|---|---|---|
| committer | Paolo Bosetti <[email protected]> | 2012-08-06 15:02:56 +0200 |
| commit | aa0d2f91447c49363059f2e95cb9023f65a6fbef (patch) | |
| tree | 2cfa325956e62648f2161564adfdf6dddc45b737 /mrblib | |
| parent | fd097b8aff7b91bd105fc1daec5a4050a947b763 (diff) | |
| parent | 193c98ae540d43d082795fd77ea81a4f6f7fd0f6 (diff) | |
| download | mruby-aa0d2f91447c49363059f2e95cb9023f65a6fbef.tar.gz mruby-aa0d2f91447c49363059f2e95cb9023f65a6fbef.zip | |
Updated Xcode project build settings in conformity with 10.8/Xcode 4.4
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/Makefile | 17 | ||||
| -rw-r--r-- | mrblib/class.rb | 26 | ||||
| -rw-r--r-- | mrblib/error.rb | 50 | ||||
| -rw-r--r-- | mrblib/hash.rb | 56 | ||||
| -rw-r--r-- | mrblib/kernel.rb | 36 | ||||
| -rw-r--r-- | mrblib/print.rb | 105 | ||||
| -rw-r--r-- | mrblib/string.rb | 23 | ||||
| -rw-r--r-- | mrblib/struct.rb | 78 |
8 files changed, 274 insertions, 117 deletions
diff --git a/mrblib/Makefile b/mrblib/Makefile index c7226ddcd..01a5a6198 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -18,12 +18,19 @@ LIBR := ../lib/libmruby.a # libraries, includes INCLUDES = -I../src -I../include -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -else -CFLAGS = -O3 +ifeq ($(strip $(COMPILE_MODE)),) + # default compile option + COMPILE_MODE = debug +endif + +ifeq ($(COMPILE_MODE),debug) + CFLAGS = -g -O3 +else ifeq ($(COMPILE_MODE),release) + CFLAGS = -O3 +else ifeq ($(COMPILE_MODE),small) + CFLAGS = -Os endif + ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) ifeq ($(OS),Windows_NT) MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" diff --git a/mrblib/class.rb b/mrblib/class.rb new file mode 100644 index 000000000..4f268b6c8 --- /dev/null +++ b/mrblib/class.rb @@ -0,0 +1,26 @@ +class Module + # 15.2.2.4.13 + def attr_reader(*names) + names.each{|name| + name2 = ('@'+name.to_s).intern + define_method(name){self.instance_variable_get(name2)} + } + end + # 15.2.2.4.14 + def attr_writer(*names) + names.each{|name| + name2 = ('@'+name.to_s).intern + name = (name.to_s+"=").intern + define_method(name){|v|self.instance_variable_set(name2,v)} + } + end + # 15.2.2.4.12 + def attr_accessor(*names) + attr_reader(*names) + attr_writer(*names) + end + # 15.2.2.4.11 + def attr(name) + attr_reader(name) + end +end diff --git a/mrblib/error.rb b/mrblib/error.rb index 5660d8235..16e88eefb 100644 --- a/mrblib/error.rb +++ b/mrblib/error.rb @@ -12,3 +12,53 @@ class Exception self.new(*args, &block) end end + +# ISO 15.2.24 +class ArgumentError < StandardError +end + +# ISO 15.2.25 +class LocalJumpError < StandardError +end + +# ISO 15.2.26 +class RangeError < StandardError +end + +class FloatDomainError < RangeError +end + +# ISO 15.2.26 +class RegexpError < StandardError +end + +# ISO 15.2.29 +class TypeError < StandardError +end + +# ISO 15.2.31 +class NameError < StandardError +end + +# ISO 15.2.32 +class NoMethodError < NameError +end + +# ISO 15.2.33 +class IndexError < StandardError +end + +class KeyError < IndexError +end + +# ISO 15.2.37 +class ScriptError < Exception +end + +# ISO 15.2.38 +class SyntaxError < ScriptError +end + +class NotImplementedError < ScriptError +end + diff --git a/mrblib/hash.rb b/mrblib/hash.rb index d6ad55e47..7b7b3f8ac 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -80,6 +80,62 @@ class Hash end h end + + # 1.8/1.9 Hash#reject! returns Hash; ISO says nothing. + def reject!(&b) + keys = [] + self.each_key{|k| + v = self[k] + if b.call(k, v) + keys.push(k) + end + } + return nil if keys.size == 0 + keys.each{|k| + self.delete(k) + } + self + end + + # 1.8/1.9 Hash#reject returns Hash; ISO says nothing. + def reject(&b) + h = {} + self.each_key{|k| + v = self[k] + unless b.call(k, v) + h[k] = v + end + } + h + end + + # 1.9 Hash#select! returns Hash; ISO says nothing. + def select!(&b) + keys = [] + self.each_key{|k| + v = self[k] + unless b.call(k, v) + keys.push(k) + end + } + return nil if keys.size == 0 + keys.each{|k| + self.delete(k) + } + self + end + + # 1.9 Hash#select returns Hash; ISO says nothing. + def select(&b) + h = {} + self.each_key{|k| + v = self[k] + if b.call(k, v) + h[k] = v + end + } + h + end end ## diff --git a/mrblib/kernel.rb b/mrblib/kernel.rb index e769741b7..ad3bc72f7 100644 --- a/mrblib/kernel.rb +++ b/mrblib/kernel.rb @@ -3,17 +3,6 @@ # # ISO 15.3.1 module Kernel - - ## - # Takes the given block, create a lambda - # out of it and +call+ it. - # - # ISO 15.3.1.2.6 - def self.lambda(&block) - ### *** TODO *** ### - block # dummy - end - ## # Calls the given block repetitively. # @@ -24,27 +13,14 @@ module Kernel end end - ## - # Alias for +send+. - # - # ISO 15.3.1.3.4 - #def __send__(symbol, *args, &block) - ### *** TODO *** ### - #end - - # 15.3.1.3.18 - def instance_eval(string=nil, &block) - ### *** TODO *** ### - raise "Not implemented yet" + # 15.3.1.2.3 + def self.eval(s) + raise NotImplementedError.new("eval not implemented") end - ## - # Alias for +Kernel.lambda+. - # - # ISO 15.3.1.3.27 - def lambda(&block) - ### *** TODO *** ### - block # dummy + # 15.3.1.3.12 + def eval(s) + Kernel.eval(s) end ## diff --git a/mrblib/print.rb b/mrblib/print.rb index 52beb26cb..dea088e2b 100644 --- a/mrblib/print.rb +++ b/mrblib/print.rb @@ -3,47 +3,76 @@ # # ISO 15.3.1 module Kernel + unless Kernel.respond_to?(:__printstr__) + def print(*a) + raise NotImplementedError.new('print not available') + end + def puts(*a) + raise NotImplementedError.new('puts not available') + end + def p(*a) + raise NotImplementedError.new('p not available') + end + def printf(*args) + raise NotImplementedError.new('printf not available') + end + else + unless Kernel.respond_to?(:sprintf) + def printf(*args) + raise NotImplementedError.new('printf not available') + end + def sprintf(*args) + raise NotImplementedError.new('sprintf not available') + end + end + - ## - # Invoke method +print+ on STDOUT and passing +*args+ - # - # ISO 15.3.1.2.10 - def print(*args) - i = 0 - len = args.size - while i < len - __printstr__ args[i].to_s - i += 1 + ## + # Invoke method +print+ on STDOUT and passing +*args+ + # + # ISO 15.3.1.2.10 + def print(*args) + i = 0 + len = args.size + while i < len + __printstr__ args[i].to_s + i += 1 + end end - end - ## - # Invoke method +puts+ on STDOUT and passing +*args*+ - # - # ISO 15.3.1.2.11 - def puts(*args) - i = 0 - len = args.size - while i < len - __printstr__ args[i].to_s - __printstr__ "\n" - i += 1 - end - __printstr__ "\n" if len == 0 - end + ## + # Invoke method +puts+ on STDOUT and passing +*args*+ + # + # ISO 15.3.1.2.11 + def puts(*args) + i = 0 + len = args.size + while i < len + __printstr__ args[i].to_s + __printstr__ "\n" + i += 1 + end + __printstr__ "\n" if len == 0 + nil + end - ## - # Print human readable object description - # - # ISO 15.3.1.3.34 - def p(*args) - i = 0 - len = args.size - while i < len - __printstr__ args[i].inspect - __printstr__ "\n" - i += 1 - end - args[0] + ## + # Print human readable object description + # + # ISO 15.3.1.3.34 + def p(*args) + i = 0 + len = args.size + while i < len + __printstr__ args[i].inspect + __printstr__ "\n" + i += 1 + end + args[0] + end + + def printf(*args) + __printstr__(sprintf(*args)) + end end end diff --git a/mrblib/string.rb b/mrblib/string.rb index ad7e1fca1..d09b787da 100644 --- a/mrblib/string.rb +++ b/mrblib/string.rb @@ -33,12 +33,15 @@ class String end ### *** TODO *** ### + unless Object.const_defined?(:Regexp) + raise NotImplementedError, "gsub not available (yet)" + end end ## # Replace all matches of +pattern+ with +replacement+. # Call block (if given) for each match and replace - # +pattern+ with the value of the block. Modify + # +pattern+ with the value of the block. Modify # +self+ with the final value. # # ISO 15.2.10.5.19 @@ -56,15 +59,18 @@ class String # Calls the given block for each match of +pattern+ # If no block is given return an array with all # matches of +pattern+. - # + # # ISO 15.2.10.5.32 def scan(reg, &block) ### *** TODO *** ### + unless Object.const_defined?(:Regexp) + raise NotImplementedError, "scan not available (yet)" + end end ## - # Replace only the first match of +pattern+ with - # +replacement+. Call block (if given) for each + # Replace only the first match of +pattern+ with + # +replacement+. Call block (if given) for each # match and replace +pattern+ with the value of the # block. Return the final value. # @@ -75,12 +81,15 @@ class String end ### *** TODO *** ### + unless Object.const_defined?(:Regexp) + raise NotImplementedError, "sub not available (yet)" + end end ## - # Replace only the first match of +pattern+ with - # +replacement+. Call block (if given) for each - # match and replace +pattern+ with the value of the + # Replace only the first match of +pattern+ with + # +replacement+. Call block (if given) for each + # match and replace +pattern+ with the value of the # block. Modify +self+ with the final value. # # ISO 15.2.10.5.37 diff --git a/mrblib/struct.rb b/mrblib/struct.rb index 4b6d767a9..5d0ede90f 100644 --- a/mrblib/struct.rb +++ b/mrblib/struct.rb @@ -2,45 +2,49 @@ # Struct # # ISO 15.2.18 -class Struct - ## - # Calls the given block for each element of +self+ - # and pass the respective element. - # - # ISO 15.2.18.4.4 - def each(&block) - self.class.members.each{|field| - block.call(self[field]) - } - self - end +if Object.const_defined?(:Struct) + class Struct - ## - # Calls the given block for each element of +self+ - # and pass the name and value of the respectiev - # element. - # - # ISO 15.2.18.4.5 - def each_pair(&block) - self.class.members.each{|field| - block.call(field.to_sym, self[field]) - } - self - end + ## + # Calls the given block for each element of +self+ + # and pass the respective element. + # + # ISO 15.2.18.4.4 + def each(&block) + self.class.members.each{|field| + block.call(self[field]) + } + self + end - ## - # Calls the given block for each element of +self+ - # and returns an array with all elements of which - # block is not false. - # - # ISO 15.2.18.4.7 - def select(&block) - ary = [] - self.class.members.each{|field| - val = self[field] - ary.push(val) if block.call(val) - } - ary + ## + # Calls the given block for each element of +self+ + # and pass the name and value of the respectiev + # element. + # + # ISO 15.2.18.4.5 + def each_pair(&block) + self.class.members.each{|field| + block.call(field.to_sym, self[field]) + } + self + end + + ## + # Calls the given block for each element of +self+ + # and returns an array with all elements of which + # block is not false. + # + # ISO 15.2.18.4.7 + def select(&block) + ary = [] + self.class.members.each{|field| + val = self[field] + ary.push(val) if block.call(val) + } + ary + end end end + |
