rlang 0.4.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -3
  3. data/Gemfile.lock +4 -6
  4. data/README +11 -0
  5. data/README.md +18 -10
  6. data/bin/rlang +17 -5
  7. data/docs/RlangCompiler.md +5 -1
  8. data/docs/RlangManual.md +98 -20
  9. data/examples/fib/fib.rb +5 -1
  10. data/lib/builder/rlang/compiler.rb +2 -21
  11. data/lib/rlang/lib/array/array32.rb +59 -0
  12. data/lib/rlang/lib/array/array64.rb +56 -0
  13. data/lib/rlang/lib/array.rb +6 -0
  14. data/lib/rlang/lib/base64.rb +223 -0
  15. data/lib/rlang/lib/io.rb +75 -0
  16. data/lib/rlang/lib/kernel.rb +23 -0
  17. data/lib/rlang/lib/malloc.rb +12 -8
  18. data/lib/rlang/lib/memory.rb +102 -2
  19. data/lib/rlang/lib/object.rb +40 -4
  20. data/lib/rlang/lib/rlang.rb +29 -0
  21. data/lib/rlang/lib/rlang_core.rb +15 -0
  22. data/lib/rlang/lib/string.rb +106 -8
  23. data/lib/rlang/lib/type/i32.rb +43 -0
  24. data/lib/rlang/lib/type/i64.rb +2 -0
  25. data/lib/rlang/lib/unistd.rb +1 -2
  26. data/lib/rlang/lib/wasi.rb +184 -0
  27. data/lib/rlang/parser/attr.rb +9 -13
  28. data/lib/rlang/parser/const.rb +105 -1
  29. data/lib/rlang/parser/cvar.rb +11 -7
  30. data/lib/rlang/parser/data.rb +17 -6
  31. data/lib/rlang/parser/export.rb +4 -3
  32. data/lib/rlang/parser/ext/integer.rb +3 -1
  33. data/lib/rlang/parser/ext/type.rb +30 -1
  34. data/lib/rlang/parser/global.rb +10 -2
  35. data/lib/rlang/parser/ivar.rb +3 -7
  36. data/lib/rlang/parser/klass.rb +8 -35
  37. data/lib/rlang/parser/method.rb +36 -12
  38. data/lib/rlang/parser/module.rb +143 -0
  39. data/lib/rlang/parser/wgenerator.rb +462 -168
  40. data/lib/rlang/parser/wnode.rb +387 -142
  41. data/lib/rlang/parser/wtype.rb +30 -7
  42. data/lib/rlang/parser.rb +506 -231
  43. data/lib/rlang/version.rb +1 -1
  44. data/lib/rlang.rb +3 -0
  45. data/lib/ruby/mirror/rstring.rb +16 -0
  46. data/lib/utils/exceptions.rb +12 -0
  47. data/rlang.gemspec +4 -4
  48. metadata +25 -13
  49. data/lib/rlang/lib.rb +0 -11
@@ -18,17 +18,18 @@ class WType
18
18
  include Log
19
19
 
20
20
  WASM_TYPE_MAP = {
21
- I64: Type::I64,
22
- I32: Type::I32,
23
- F64: Type::F64,
24
- F32: Type::F32
21
+ UI64: Type::UI64,
22
+ I64: Type::I64,
23
+ UI32: Type::UI32,
24
+ I32: Type::I32,
25
+ F64: Type::F64,
26
+ F32: Type::F32
25
27
  }
26
28
 
27
29
  # Implicit Type cast order in decreasing order of precedence
28
30
  # Class types have precedence over default integer type
29
31
  # because of pointer arithmetics
30
- # TODO: :Class should be inserted before WType::DEFAULT
31
- CAST_PRECEDENCE = [:F64, :F32, :I64, :Class, :I32]
32
+ CAST_PRECEDENCE = [:F64, :F32, :UI64, :I64, :Class, :UI32, :I32]
32
33
 
33
34
  attr_reader :name
34
35
 
@@ -45,11 +46,28 @@ class WType
45
46
  wtypes[leading_idx]
46
47
  end
47
48
 
49
+ # Name is a symbol of the form :A or :"A::B" or :"A::B::C"
50
+ # or a string "A" or "A::B" or "A::B::C"
51
+ # or it can also be an array of symbols [:A], [:A, :B] or [:A, :B, :C]
52
+ # (It is not a class object)
48
53
  def initialize(name)
49
- @name = name.to_sym
54
+ if name.is_a? Symbol
55
+ @name = name
56
+ elsif name.is_a? String
57
+ @name = name.to_sym
58
+ elsif name.is_a? Array
59
+ @name = name.map(&:to_s).join('::').to_sym
60
+ else
61
+ raise "Unknown type for WType name (got #{name}, class: #{name.class}"
62
+ end
50
63
  raise "Invalid WType #{name.inspect}" unless self.valid?
51
64
  end
52
65
 
66
+ def class_path
67
+ return [] if self.blank?
68
+ name.to_s.split('::').map(&:to_sym)
69
+ end
70
+
53
71
  def default?
54
72
  @name == WType::DEFAULT.name
55
73
  end
@@ -62,6 +80,10 @@ class WType
62
80
  WASM_TYPE_MAP.has_key? @name
63
81
  end
64
82
 
83
+ def signed?
84
+ self.native? && WASM_TYPE_MAP[@name].signed?
85
+ end
86
+
65
87
  def blank?
66
88
  @name == :none || @name == :nil
67
89
  end
@@ -111,6 +133,7 @@ class WType
111
133
  end
112
134
 
113
135
  DEFAULT = self.new(WASM_TYPE_MAP.key(Type::DEFAULT))
136
+ UNSIGNED_DEFAULT = self.new(WASM_TYPE_MAP.key(Type::UNSIGNED_DEFAULT))
114
137
 
115
138
  end
116
139