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

Code generation for cell class #6

Open
wukefe opened this issue May 16, 2016 · 2 comments
Open

Code generation for cell class #6

wukefe opened this issue May 16, 2016 · 2 comments
Labels

Comments

@wukefe
Copy link

wukefe commented May 16, 2016

Source code

a = {1, 'example'};
for i=1:2
  disp(a{i});
end

Generated TameIR

  mc_t24 = 1;
  mc_t25 = 2;
  for i = (mc_t24 : mc_t25);
    [CSL[mc_t14]] = a{i};
    disp(CSL[mc_t14]); % [] = ...
  end

Problems:

  • The variable mc_t14 has not been initialized before it is used as an index.
  • What does CSL mean? If it is okay, the following brackets don't make sense. (If it means indexing, we should use "()" instead of "[]".)
@wukefe wukefe added the bug label May 16, 2016
@isbadawi
Copy link
Member

mc_t14 is being defined here, not used. CSL means comma-separated list. This is a kind of IR node in McSAF (extends NameExpr) that gets created by some simplification transformations. This is described in Jesse Doherty's thesis (search for CSL). CSL[name] is how McSAF pretty prints a CSLExpr -- it's not intended to be valid MATLAB.

Tame IR also has a notion of comma-separated list (TIRCommaSeparatedList), and it does pretty-print as valid MATLAB. My guess is somehow a McSAF CSLExpr node made it into a Tame IR AST and the Tamer is not expecting it (treating it the same as a NameExpr).

I'm not sure what this means -- it's possible the Tamer is not supposed to deal with CSLExpr but some simplifications are being run that the Tamer is not expecting. Or maybe you just need to add code in the right place to explicitly handle CSLExpr.

Hope this helps...

@wukefe
Copy link
Author

wukefe commented May 17, 2016

Thanks for your reply.

From the McSAF thesis, the reason why we need CSL is probably the following special case in MATLAB. The c1{:} will return two values, while c1 returns one cell. If the expression is changed to c1{1:2} or c1{[1,1,2]}, the number of return values is 2 or 3. The exact number of return values is determined in run-time. That feature will confuse function calls, such as foo(c1{i}), so that we don't know the exact number of arguments passed into the function foo.

>> c1={1,5};
>> c1{:}
ans =
     1

ans =
     5
>> [t1,t2] = c1{:}
t1 =
     1

t2 =
     5

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

No branches or pull requests

2 participants