Permalink
Browse files

Add first trivial version of Range class + rewrite :range nodes in AS…

…T to Range.new(...)
  • Loading branch information...
vidarh committed Sep 11, 2014
1 parent e2f6b37 commit a18cdef75c4fec8240cb450cb33991e37858d471
Showing with 32 additions and 0 deletions.
  1. +1 −0 lib/core/core.rb
  2. +20 −0 lib/core/range.rb
  3. +11 −0 transform.rb
View
@@ -48,6 +48,7 @@
require 'core/struct'
require 'core/exception'
require 'core/pp'
require 'core/range'
# FIXME: This is of course just plain blatantly wrong, but
# the next goal is to get everything to link (and crash...)
View
@@ -0,0 +1,20 @@
# FIXME
# Initial implementation
# This implementation assumes simple ordering
class Range
def initialize _min, _max
@min = _min
@max = _max
end
# FIXME: This is hopelessly inadequate, but
# tolerable for the case where we only use integer
# ranges
def member? val
if !val
return false
end
return val >= @min && val <= @max
end
end
View
@@ -284,6 +284,16 @@ def rewrite_let_env(exp)
end
end
def rewrite_range(exp)
exp.depth_first do |e|
if e[0] == :range
STDERR.puts e.inspect
e.replace(E[:callm, :Range, :new, e[1..-1]])
end
:next
end
end
def create_concat(sub)
right = sub.pop
right = E[:callm,right,:to_s] if !right.is_a?(Array)
@@ -302,6 +312,7 @@ def rewrite_concat(exp)
def preprocess exp
rewrite_concat(exp)
rewrite_range(exp)
rewrite_strconst(exp)
rewrite_fixnumconst(exp)
rewrite_operators(exp)

0 comments on commit a18cdef

Please sign in to comment.