Skip to content
This repository has been archived by the owner on Dec 24, 2023. It is now read-only.

Commit

Permalink
No return in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
deathbeam committed May 17, 2016
1 parent 8141f50 commit 17cd839
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/spoon/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Spoon
class Compiler
attr_reader :name
attr_reader :scope
attr_reader :class_scope
attr_reader :static_scope
attr_reader :instance_scope
attr_reader :class_names

Expand Down Expand Up @@ -33,7 +33,7 @@ def initialize(path = "main")
}

@scope = Spoon::Util::Namespace.new
@class_scope = Spoon::Util::Namespace.new
@static_scope = Spoon::Util::Namespace.new
@instance_scope = Spoon::Util::Namespace.new
end

Expand All @@ -48,7 +48,7 @@ def compile(node, parent = nil, tab = "")
def class_variables
result = ""

@class_scope.get.each do |key, value|
@static_scope.get.each do |key, value|
result << " static public var #{key};\n"
end

Expand Down Expand Up @@ -108,7 +108,7 @@ def compile
@compiler.scope.add
@compiler.scope.push @compiler.name
@compiler.class_names.push @compiler.name
@compiler.class_scope.add
@compiler.static_scope.add
@compiler.instance_scope.add

imports = ""
Expand All @@ -130,7 +130,7 @@ def compile
@content << "}\n#{classes}"

@compiler.scope.pop
@compiler.class_scope.pop
@compiler.static_scope.pop
@compiler.instance_scope.pop
@compiler.class_names.pop
super
Expand All @@ -150,15 +150,15 @@ def compile
@compiler.scope.add
@compiler.scope.push name
@compiler.class_names.push name
@compiler.class_scope.add
@compiler.static_scope.add
@compiler.instance_scope.add

@content << "class #{name} "
body = children.shift
@content << compile_next(body)

@compiler.scope.pop
@compiler.class_scope.pop
@compiler.static_scope.pop
@compiler.instance_scope.pop
@compiler.class_names.pop

Expand Down Expand Up @@ -244,7 +244,8 @@ def compile
value = compile_next(right)

if right.type == :closure
value = value.insert(8, " #{name}")
value = value.sub("return {", "{") if name == "new"
value[8] = " #{name}"
else
value = "var #{name} = #{value}"
end
Expand Down Expand Up @@ -290,12 +291,12 @@ def scope_name(node)

if is_self
raise ArgumentError, 'Self call cannot be used outside of class' unless @compiler.in_class
@compiler.class_scope.push name
@compiler.static_scope.push name
elsif is_this
if @compiler.in_class
@compiler.instance_scope.push name
else
@compiler.class_scope.push name
@compiler.static_scope.push name
end
end
elsif node.type == :value
Expand Down

0 comments on commit 17cd839

Please sign in to comment.