Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I refer to self? #61

Open
ledsun opened this issue Jun 5, 2018 · 2 comments
Open

How can I refer to self? #61

ledsun opened this issue Jun 5, 2018 · 2 comments

Comments

@ledsun
Copy link
Contributor

ledsun commented Jun 5, 2018

Tutorial sample fast_blank is

class String
  def blank?(string)
    char *s = string
    int i = 0
    int a = string.size

    while i < a do
      return false if s[i] != ' '
      i += 1
    end

    return true
  end
end

This code define String#blank?(string) method.
But I think the fast_blank evaluates value of self, not argument.
I tried below:

class String
  def blank?
    char *s = self
  end
end

I got error below:

~ rubex fast_blank.rubex

PARSE ERROR:
Line:     char *s = self
Location: fast_blank.rubex:3
Error:

parse error on value "self" (kSELF)
Traceback (most recent call last):
	7: from /Users/shigerunakajima/rubex/bin/rubex:7:in `<main>'
	6: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
	5: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	4: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	3: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	2: from /Users/shigerunakajima/rubex/lib/rubex/cli.rb:21:in `generate'
	1: from /Users/shigerunakajima/rubex/lib/rubex/compiler.rb:48:in `compile'
/Users/shigerunakajima/rubex/lib/rubex/compiler.rb:105:in `generate_code': Must be a Rubex::AST::Node::MainNode, not NilClass (RuntimeError)

Tried version is 'bf5ee9365e1b93ae58c97827c1a6ef6c04cb5f33' of the mater branch.

@v0dro
Copy link
Member

v0dro commented Jun 27, 2018

Hmmm good point. Currently there is no support for self. I will add it in future versions.

@TommasoMascioli
Copy link

Hi, I'm using rubex for the first time today (2019), I think that is the golden gate for ruby performances!!! Please, not abandon this amazing project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants