Skip to content

Commit

Permalink
Showing 9 changed files with 753 additions and 763 deletions.
4 changes: 2 additions & 2 deletions src/compiler/crystal/program.cr
Original file line number Diff line number Diff line change
@@ -190,8 +190,8 @@ module Crystal
types["Union"] = @union = GenericUnionType.new self, self, "Union", value, ["T"]
types["Crystal"] = @crystal = NonGenericModuleType.new self, self, "Crystal"

types["ARGC_UNSAFE"] = @argc = argc_unsafe = Const.new self, self, "ARGC_UNSAFE", Primitive.new(:argc, int32)
types["ARGV_UNSAFE"] = @argv = argv_unsafe = Const.new self, self, "ARGV_UNSAFE", Primitive.new(:argv, pointer_of(pointer_of(uint8)))
types["ARGC_UNSAFE"] = @argc = argc_unsafe = Const.new self, self, "ARGC_UNSAFE", Primitive.new("argc", int32)
types["ARGV_UNSAFE"] = @argv = argv_unsafe = Const.new self, self, "ARGV_UNSAFE", Primitive.new("argv", pointer_of(pointer_of(uint8)))

# Make sure to initialize ARGC and ARGV as soon as the program starts
class_var_and_const_initializers << argc_unsafe
745 changes: 6 additions & 739 deletions src/compiler/crystal/semantic/ast.cr

Large diffs are not rendered by default.

714 changes: 714 additions & 0 deletions src/compiler/crystal/semantic/bindings.cr

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/compiler/crystal/semantic/filters.cr
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ module Crystal
update(@node)
end

def update(from)
from_type = from.type?
def update(from = nil)
from_type = from.try &.type?

if from_type
self.type = @filter.apply(from_type)
11 changes: 7 additions & 4 deletions src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
@@ -1058,7 +1058,8 @@ module Crystal
end

node.call = call
node.bind_to call
call.add_observer node
node.update

false
end
@@ -1988,7 +1989,6 @@ module Crystal
bind_vars @vars, block.after_vars, block.args
elsif target_while = @while_stack.last?
node.target = target_while
target_while.has_breaks = true

break_vars = (target_while.break_vars ||= [] of MetaVars)
break_vars.push @vars.dup
@@ -2220,6 +2220,8 @@ module Crystal
end

def visit(node : PointerOf)
node.exp.accept self

var = case node_exp = node.exp
when Var
meta_var = @meta_vars[node_exp.name]
@@ -2232,7 +2234,6 @@ module Crystal
when Global
visit_global node_exp
when Path
node_exp.accept self
if const = node_exp.target_const
const.value
else
@@ -2245,6 +2246,7 @@ module Crystal
node_exp.raise "can't take address of #{node_exp}"
end
node.bind_to var
false
end

def visit(node : TypeOf)
@@ -2263,7 +2265,8 @@ module Crystal

@in_type_args = old_in_type_args

node.bind_to node.expressions
node.expressions.each &.add_observer(node)
node.update

@vars = old_vars

6 changes: 1 addition & 5 deletions src/compiler/crystal/semantic/top_level_visitor.cr
Original file line number Diff line number Diff line change
@@ -144,10 +144,7 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor
attach_doc type, node

pushing_type(type) do
if created_new_type
run_hooks(superclass.metaclass, type, :inherited, node)
end

run_hooks(superclass.metaclass, type, :inherited, node) if created_new_type
node.body.accept self
end

@@ -447,7 +444,6 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor
end

scope.types[name] = enum_type
node.created_new_type = true
end

false
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/type_declaration_visitor.cr
Original file line number Diff line number Diff line change
@@ -205,7 +205,7 @@ class Crystal::TypeDeclarationVisitor < Crystal::SemanticVisitor

def declare_c_struct_or_union_field(type, field_name, var)
type.instance_vars[var.name] = var
type.add_def Def.new("#{field_name}=", [Arg.new("value")], Primitive.new(type.extern_union? ? :union_set : :struct_set))
type.add_def Def.new("#{field_name}=", [Arg.new("value")], Primitive.new(type.extern_union? ? "union_set" : "struct_set"))
type.add_def Def.new(field_name, body: InstanceVar.new(var.name))
end

18 changes: 14 additions & 4 deletions src/compiler/crystal/semantic/type_merge.cr
Original file line number Diff line number Diff line change
@@ -3,8 +3,13 @@ require "../program"
module Crystal
class Program
def type_merge(types : Array(Type?))
# Merging two types is the most common case, so we optimize it
if types.size == 2
case types.size
when 0
return nil
when 1
return types.first
when 2
# Merging two types is the most common case, so we optimize it
first, second = types
did_merge, merged_type = type_merge_two(first, second)
return merged_type if did_merge
@@ -14,8 +19,13 @@ module Crystal
end

def type_merge(nodes : Array(ASTNode))
# Merging two types is the most common case, so we optimize it
if nodes.size == 2
case nodes.size
when 0
return nil
when 1
return nodes.first.type?
when 2
# Merging two types is the most common case, so we optimize it
first, second = nodes
did_merge, merged_type = type_merge_two(first.type?, second.type?)
return merged_type if did_merge
12 changes: 6 additions & 6 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
@@ -1100,7 +1100,7 @@ module Crystal
include DefInstanceContainer

def initialize_metaclass(metaclass)
metaclass.add_def Def.new("allocate", body: Primitive.new(:allocate))
metaclass.add_def Def.new("allocate", body: Primitive.new("allocate"))
end

def virtual_type
@@ -1466,7 +1466,7 @@ module Crystal
end

def initialize_metaclass(metaclass)
metaclass.add_def Def.new("allocate", body: Primitive.new(:allocate))
metaclass.add_def Def.new("allocate", body: Primitive.new("allocate"))
end

def type_desc
@@ -2023,11 +2023,11 @@ module Crystal
end

def add_var(name, type, real_name, thread_local)
setter = External.new("#{name}=", [Arg.new("value", type: type)], Primitive.new(:external_var_set, type), real_name)
setter = External.new("#{name}=", [Arg.new("value", type: type)], Primitive.new("external_var_set", type), real_name)
setter.set_type(type)
setter.thread_local = thread_local

getter = External.new("#{name}", [] of Arg, Primitive.new(:external_var_get, type), real_name)
getter = External.new("#{name}", [] of Arg, Primitive.new("external_var_get", type), real_name)
getter.set_type(type)
getter.thread_local = thread_local

@@ -2156,8 +2156,8 @@ module Crystal

@flags = !!flags

add_def Def.new("value", [] of Arg, Primitive.new(:enum_value, @base_type))
metaclass.add_def Def.new("new", [Arg.new("value", type: @base_type)], Primitive.new(:enum_new, self))
add_def Def.new("value", [] of Arg, Primitive.new("enum_value", @base_type))
metaclass.add_def Def.new("new", [Arg.new("value", type: @base_type)], Primitive.new("enum_new", self))
end

def parents

0 comments on commit 1a8495a

Please sign in to comment.