-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
The Global AST node is still around, and code associated to it too, because it's used internally by the compiler to store pre-compiled regexes. The special $~ and $! are also represented as globals, in the syntax. We can improve this in the future.
- v0.24.1
- 1.15.1
- 1.15.0
- 1.14.1
- 1.14.0
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.0
- 0.36.1
- 0.36.0
- 0.35.1
- 0.35.0
- 0.34.0
- 0.33.0
- 0.32.1
- 0.32.0
- 0.31.1
- 0.31.0
- 0.30.1
- 0.30.0
- 0.29.0
- 0.28.0
- 0.27.2
- 0.27.1
- 0.27.0
- 0.26.1
- 0.26.0
- 0.25.1
- 0.25.0
- 0.24.2
- 0.24.1
- 0.24.0
- 0.23.1
- 0.23.0
- 0.22.0
- 0.21.1
- 0.21.0
- 0.20.5
- 0.20.4
- 0.20.3
- 0.20.2
- 0.20.1
- 0.20.0
- 0.19.4
- 0.19.3
- 0.19.2
- 0.19.1
- 0.19.0
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -563,18 +563,27 @@ describe "Code gen: block" do | |
class Bar < Foo | ||
end | ||
$x : Int32? | ||
class Global | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jhass
Member
|
||
@@x = 0 | ||
def self.x=(@@x) | ||
end | ||
def self.x | ||
@@x | ||
end | ||
end | ||
struct Int | ||
def foo | ||
x = Foo.new | ||
x = Bar.new | ||
x.do { $x = self } | ||
x.do { Global.x = self } | ||
end | ||
end | ||
123.foo | ||
$x.to_i | ||
Global.x.to_i | ||
").to_i.should eq(123) | ||
end | ||
|
||
|
@@ -1220,40 +1229,58 @@ describe "Code gen: block" do | |
|
||
it "codegens block bug with conditional next and unconditional break (3)" do | ||
run(%( | ||
$x = 0 | ||
class Global | ||
@@x = 0 | ||
def self.x=(@@x) | ||
end | ||
def self.x | ||
@@x | ||
end | ||
end | ||
def foo | ||
a = 1234 | ||
a = yield 1 | ||
$x = a | ||
Global.x = a | ||
a | ||
end | ||
foo do |x| | ||
next x if 1 == 1 | ||
break 0 | ||
end | ||
$x | ||
Global.x | ||
)).to_i.should eq(1) | ||
end | ||
|
||
it "codegens block bug with conditional next and unconditional break (4)" do | ||
run(%( | ||
$x = 0 | ||
class Global | ||
@@x = 0 | ||
def self.x=(@@x) | ||
end | ||
def self.x | ||
@@x | ||
end | ||
end | ||
def foo | ||
bar(yield 1) | ||
end | ||
def bar(x) | ||
$x = x | ||
Global.x = x | ||
end | ||
foo do |x| | ||
next x if 1 == 1 | ||
break 0 | ||
end | ||
$x | ||
Global.x | ||
)).to_i.should eq(1) | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,10 +34,8 @@ describe "Code gen: case" do | |
run(" | ||
require \"prelude\" | ||
$a = 0 | ||
def foo | ||
$a += 1 | ||
1 | ||
end | ||
case foo | ||
|
2 comments
on commit e872c71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@asterite you mention:
The Global AST node is still around, and code associated to it too, because it's used internally by the compiler to store pre-compiled regexes.
Any hint on what would take to get rid of that particular usage by the compiler?
Also, what are your thoughts on deprecation of $~
and $?
entirely?
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luislavena This is the piece of code that uses globals internally. It could be changed to use class variables of a non-accessible module (with a name that can't be typed), or maybe at a more low-level way, more intrinsic to the compiler. I'll change it later, shouldn't be hard (I just wanted to push because later it's hard to rebase against master).
About $~
and $!
: I don't know, I think they are pretty convenient. Consider this method, you would have to write it like described here. Maybe it doesn't matter much because doing a case over a regex might not be done all of the time.
If we remove them, we also need to remove backticks for process execution, for example:
output = `ls`
if $?.success?
puts output
else
puts "command failed"
end
or we'll have to make it return a tuple with the output and the status, or maybe another struct.
I think it's possible, I'm not sure they are that complex to understand and use. They will simplify the compiler's implementation, though. You can open an issue to discuss this, I'm open for a change :-)
Maybe we should add a macro for class properties. WDYT?