Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/compiler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,9 @@ module Mint
id =
type.name + type.parameters.size.to_s

case tag = @tags[id]?
when Nil
if tag = @tags[id]?
artifacts.references.replace(node, tag.node)
else
tag =
Tag.new(id, node)

Expand All @@ -527,8 +528,6 @@ module Mint
add(node, tag, js.call(Builtin::Variant, args))

@tags[id] = tag
else
artifacts.references.replace(node, tag.node)
end

[@tags[id]] of Item
Expand Down
33 changes: 16 additions & 17 deletions src/compilers/access.cr
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
module Mint
class Compiler
private def compile_access_item(item)
case item
when Ast::Get
js.call(item, [] of Compiled)
when Ast::State, Ast::Signal
[Signal.new(item)] of Item
else
[item] of Item
end
end

def compile(node : Ast::Access) : Compiled
compile node do
if items = variables[node]?
case item = items[0]
when Ast::TypeVariant
case type = cache[node]?
when nil
[] of Item
else
if type = cache[node]?
if type.name == "Function"
js.call(Builtin::NewVariant, [tag(item, cache[item])] of Compiled)
else
js.new(tag(item, cache[item]), [] of Compiled)
end
else
[] of Item
end
else
# `subscriptions` is a special case: both the parent and the entity
Expand All @@ -26,14 +36,7 @@ module Mint
end
end

case item = items[0]
when Ast::Get
js.call(item, [] of Compiled)
when Ast::State, Ast::Signal
[Signal.new(item)] of Item
else
[item] of Item
end
compile_access_item(items[0])
end
elsif record_field_lookup[node.field]?
compile(node.expression) + ["."] + [node.field.value] of Item
Expand All @@ -44,13 +47,9 @@ module Mint
item =
case field = lookup[0]
when Ast::Variable
[Signal.new(lookup[0])] of Item
when Ast::Get
js.call(field, [] of Compiled)
when Ast::State, Ast::Signal
[Signal.new(field)] of Item
else
[field] of Item
compile_access_item(field)
end

compile(node.expression) + ["."] + item
Expand Down
9 changes: 4 additions & 5 deletions src/formatters/statement.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ module Mint
[" or return "] + format(item)
end

case node.target
when Nil
expression + return_call
else
if target = node.target
target =
format node.target
format target

if newline
["let "] + target + [" =", Nest.new([Line.new(1)] + expression)] + return_call
else
["let "] + target + [" = "] + expression + return_call
end
else
expression + return_call
end
end
end
Expand Down
18 changes: 8 additions & 10 deletions src/ls/definitions/variable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ module Mint
class Definitions
def definition(node : Ast::Variable)
if lookup = @type_checker.variables[node]?
entity, parent = lookup

case {entity, parent}
when {Ast::TypeDefinition, _}
case entity = lookup[0]
when Ast::TypeDefinition
location_link node, entity.name, entity
when {Ast::TypeVariant, _}
when Ast::TypeVariant
location_link node, entity.value, entity
when {Ast::Component, _},
{Ast::Store, _}
when Ast::Component,
Ast::Store
location_link node, entity.name, entity
when {Ast::Module, _}
when Ast::Module
links =
@type_checker.artifacts.ast.modules
.select(&.name.value.==(node.value))
Expand All @@ -25,7 +23,7 @@ module Mint

return links.first if links.size == 1
links unless links.empty?
when {Ast::Variable, _}
when Ast::Variable
variable_lookup_parent(node, entity)
else
variable_lookup(node, entity)
Expand All @@ -37,7 +35,7 @@ module Mint
end

def variable_lookup_parent(node : Ast::Variable, variable : Ast::Variable)
# For some variables in the .variables` cache, we only have access to the
# For some variables in the `.variables` cache, we only have access to the
# target Ast::Variable and not its containing node, so we must search for it
return unless parent =
@type_checker.artifacts.ast.nodes
Expand Down
Loading