Comments (6)
I don't know whether you have seen it or not, but I have just found it and it's kind of baffling:
int nelua_main(int argc, char** argv) {
{
nelua_print_1(tmp_f(5));
{
nlmulret_nlint64_nlboolean _tmp1 = tmp_g(5);
nelua_print_2(_tmp1.r1, _tmp1.r2);
}
}
return 0;
}
Should not this code be
int nelua_main(int argc, char** argv) {
{
nelua_print_1(tmp_f(5));
}
{
nlmulret_nlint64_nlboolean _tmp1 = tmp_g(5);
nelua_print_2(_tmp1.r1, _tmp1.r2);
}
return 0;
}
because print(f(5))
and print(g(5))
are executed as two separate defer
s behind the scenes, correct?
from nelua-lang.
The braces around nelua_print_2()
are probably there to quickly free _tmp1
from occupying stack space - it's about multiple value returns from g()
rather than anything getting deferred.
from nelua-lang.
OK, I have found the bug; the generated C code for defer
takes place in wrong line(s):
/* Buggy version */
nlmulret_nlint64_nlboolean tmp_g(int64_t n) {
nlmulret_nlint64_nlboolean _mulret_1;
_mulret_1.r1 = n;
_mulret_1.r2 = true;
{ /* defer */
n = (n + 1);
}
return _mulret_1;
}
It should be
/* Fixed version*/
nlmulret_nlint64_nlboolean tmp_g(int64_t n) {
nlmulret_nlint64_nlboolean _mulret_1;
{ /* defer */
n = (n + 1);
}
_mulret_1.r1 = n;
_mulret_1.r2 = true;
return _mulret_1;
}
Update: After thinking about it, my fix violates the logic of defer
mechanism that is supposed to take place as last. I wonder how @edubart could solve this peculiar case...maybe with the use of GOTO
labels? 🤔
Update 2: On second thought, the code below should work too:
nlmulret_nlint64_nlboolean tmp_g(int64_t n) {
nlmulret_nlint64_nlboolean _mulret_1;
{ /* defer */
n = (n + 1);
}
return _mulret_1 = (nlmulret_nlint64_nlboolean){.r1=n, .r2=true};
}
Since we are deferring n
only and then return n, true
, a compound literal should work as shown above.
from nelua-lang.
This is a serious bug, I try to fix it next weekend. Thanks for reporting!
from nelua-lang.
@edubart keep up the good work brother 👍
@jrfondren Good job my friend with your thorough investigation; that makes us two now! 😃
from nelua-lang.
I fixed the misbehavior in dc479bf, by definition defer
should only execute after evaluating all function statements, including return expressions.
from nelua-lang.
Related Issues (20)
- (@span(byte)){...} ordered field cast permits invalid, rejects valid construction HOT 1
- Executables reflect compile-time isatty conditions HOT 3
- <comptime> record parameters can't be provided; fields can't be used in runtime code HOT 1
- Copyright timespan needs update HOT 3
- Invalid unitname generated for directories that look like numeric literals HOT 1
- No line number in error if a hashmap index has a type error
- Range check error messages point to library code (point of check) rather than user code (point of error) HOT 1
- Function variables can collide with C identifiers HOT 1
- Confusing errors with varargs
- Permit function returns in generic instantiation, not just types
- Broken preprocessor after 9faaa66e HOT 3
- Comparison of a pointer with nil generates unexpected C code HOT 2
- we need nelua debugger(vscode) or tell us how to debug my app? HOT 2
- Compatible with Lua C plug-in HOT 2
- LFS: can't change directory with `lfs.chdir` HOT 1
- error while compiling when a source file starts with a number HOT 1
- Compiler hangs when cgenerator.lua errors
- Can't compile fibonacci example
- Can't compile fibonacci example
- Support actual closures via struct
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nelua-lang.