Module: Rlang::Parser

Defined in:
lib/rlang/parser/data.rb,
lib/rlang/parser/attr.rb,
lib/rlang/parser/cvar.rb,
lib/rlang/parser/ivar.rb,
lib/rlang/parser/lvar.rb,
lib/rlang/parser/marg.rb,
lib/rlang/parser/const.rb,
lib/rlang/parser/const.rb,
lib/rlang/parser/klass.rb,
lib/rlang/parser/wnode.rb,
lib/rlang/parser/wtree.rb,
lib/rlang/parser/export.rb,
lib/rlang/parser/global.rb,
lib/rlang/parser/method.rb,
lib/rlang/parser/module.rb,
lib/rlang/parser/wgenerator.rb,
lib/rlang/parser.rb

Overview

Constants and Class variables are managed in exactly the same way

Defined Under Namespace

Classes: Attr, CVar, Const, DAta, Export, Global, IVar, Klass, LVar, MArg, MEthod, Module, Parser, WGenerator, WNode, WTree

Constant Summary collapse

ARITHMETIC_OPS_MAP =
{
  :+  => :add,
  :-  => :sub,
  :*  => :mul,
  :&  => :and,
  :|  => :or,
  :^  => :xor,
  :<< => :shl
}
ARITHMETIC_SIGNED_OPS_MAP =
{
  :/  => :div_x,
  :%  => :rem_x,
  :>> => :shr_x
}
RELATIONAL_OPS_MAP =
{
  :==    => :eq,
  :!=    => :ne,

}
RELATIONAL_SIGNED_OPS_MAP =
{
  :<     => :lt_x,
  :>     => :gt_x,
  :<=    => :le_x,
  :>=    => :ge_x
}
BOOLEAN_OPS_MAP =
{
  :and   => :and,
  :or    => :or
}
UNARY_OPS_MAP =
{
  :'!'   => :eqz,
  :'-@'  => :sub  # special case for unary - turned into (sub 0 x)
}
SIGNED_OPS =
{
  signed: {div_x: :div_s, rem_x: :rem_s, shr_x: :shr_s, lt_x: :lt_s, gt_x: :gt_s,
    le_x: :le_s, ge_x: :ge_s},
  unsigned: {div_x: :div_u, rem_x: :rem_u, shr_x: :shr_u, lt_x: :lt_u, gt_x: :gt_u,
      le_x: :le_u, ge_x: :ge_u},
}
[:eq, :ne, :lt_u, :gt_u, :le_u, :ge_u, :add, :sub]
ALL_SIGNED_OPS_MAP =

All operators with signed / unsigned variants

[*ARITHMETIC_SIGNED_OPS_MAP, *RELATIONAL_SIGNED_OPS_MAP].to_h
ALL_OPS_MAP =

All operators in on hash

[*ARITHMETIC_OPS_MAP, *ARITHMETIC_SIGNED_OPS_MAP, *RELATIONAL_OPS_MAP, *RELATIONAL_SIGNED_OPS_MAP,
*BOOLEAN_OPS_MAP, *UNARY_OPS_MAP].to_h
CAST_OPS =

Matrix of how to cast a WASM type to another

{
  UI32:  { UI32: :cast_nope,   I32: :cast_wtype,  UI64: :cast_extend, I64: :cast_extend, F32: :cast_notyet, F64: :cast_notyet, Class: :cast_wtype, none: :cast_error},
  I32:   { UI32: :cast_wtype,  I32: :cast_nope,   UI64: :cast_extend, I64: :cast_extend, F32: :cast_notyet, F64: :cast_notyet, Class: :cast_wtype, none: :cast_error},
  UI64:  { UI32: :cast_wrap,   I32: :cast_wrap,   UI64: :cast_nope,   I64: :cast_wtype,  F32: :cast_notyet, F64: :cast_notyet, Class: :cast_error, none: :cast_error},    
  I64:   { UI32: :cast_wrap,   I32: :cast_wrap,   UI64: :cast_wtype,   I64: :cast_nope,   F32: :cast_notyet, F64: :cast_notyet, Class: :cast_error, none: :cast_error},    
  F32:   { UI32: :cast_notyet, I32: :cast_notyet, UI64: :cast_notyet, I64: :cast_notyet, F32: :cast_nope,   F64: :cast_notyet, Class: :cast_error, none: :cast_error},    
  F64:   { UI32: :cast_notyet, I32: :cast_notyet, UI64: :cast_notyet, I64: :cast_notyet, F32: :cast_notyet, F64: :cast_nope,   Class: :cast_error, none: :cast_error},    
  Class: { UI32: :cast_wtype,  I32: :cast_wtype,  UI64: :cast_extend, I64: :cast_extend, F32: :cast_error,  F64: :cast_error,  Class: :cast_wtype, none: :cast_error},
  none:  { UI32: :cast_error,  I32: :cast_error,  UI64: :cast_error,  I64: :cast_error,  F32: :cast_error,  F64: :cast_error,  Class: :cast_error, none: :cast_error},
}
SIZE_METHOD =

Rlang class size method name

:_size_
NEW_TMPL =

new template when object size > 0

%q{
result :Object, :allocate, :%{default_wtype}
def self.new(%{margs})
  result :"%{class_name}"
  object_ptr = Object.allocate(%{class_name}._size_).cast_to(:"%{class_name}")
  object_ptr.initialize(%{margs})
  return object_ptr
end
}
NEW_ZERO_TMPL =

new template when object size is 0 (no instance var) use 0 as the self address in memory. It should never be used anyway

%q{
def self.new(%{margs})
  result :"%{class_name}"
  object_ptr = 0.cast_to(:"%{class_name}")
  object_ptr.initialize(%{margs})
  return object_ptr
end
}
DUMB_INIT_TMPL =

Do nothing initialize method

%q{
def initialize()
  result :nil
end
}
STRING_NEW_TMPL =

Dynamically allocate a string object

%q{
  String.new(%{ptr}, %{length})
}
ARRAY_NEW_TMPL =

Dynamically allocate a string object

%q{
  Array%{elt_size_in_bits}.new(%{ptr}, %{length})
}