Comments (2)
TL;DR: there is a possible cause for this at the bottom of this update.
If I start with the r599 code base and edit parse.c to remove 4 lines of code,
the problem goes away. Functions ParseFor() and ParseBlock() contain the
following pattern at the head/tail; removing them suppresses the problem.
Head: int PrevScopeID = 0, ScopeID = VariableScopeBegin(Parser, &PrevScopeID);
Tail: VariableScopeEnd(Parser, ScopeID, PrevScopeID);
If I reenable those lines and add #define VAR_SCOPE_DEBUG to interpreter.h, I
get the following edited output:
Marks-iMac:picoc-test heilpern$ ./picoc -i
def uid_t 0 (unistd.h:1:12)
def gid_t 0 (unistd.h:1:31)
def pid_t 0 (unistd.h:1:50)
def off_t 0 (unistd.h:1:69)
def size_t 0 (unistd.h:1:88)
def ssize_t 0 (unistd.h:1:108)
def useconds_t 0 (unistd.h:1:129)
def intptr_t 0 (unistd.h:1:152)
def time_t 56957788 (time.h:1:12)
def clock_t 56957788 (time.h:1:32)
def va_list dac0dbf0 (stdio.h:1:31)
def FILE dac0dbf0 (stdio.h:1:68)
def bool 92c4ae4 (stdbool.h:1:12)
starting picoc v2.2 beta r599M
picoc> void a() {}
^
:1:
>>> out of scope: optopt 0 0
>>> out of scope: EIDRM 0 90
>>> out of scope: remove 0 1452638800
>>> out of scope: SEEK_CUR 0 1
[ many other symbols removed from this list, for brevity]
>>> out of scope: BUFSIZ 0 1024
>>> out of scope: clock 0 1452638800
>>> out of scope: setreuid 0 1452638800
picoc> printf("test\n");
^
:2: 'printf' is out of scope
picoc>
Probable root cause: in VariableScopeBegin, a "ScopeID" is generated and
returned. When run in interactive mode, Parser->SourceText (which is used to
generate the ID) is 0, leading to a 0 ScopeID. I am assuming that this is an
invalid scope ID and is instead assigned to all globals -- causing them to go
out of scope when the current scope (intended to be some block with a non-zero
scope id) closes its scope.
The full block of code at that location is:
Parser->ScopeID = (int)(intptr_t)(Parser->SourceText) * ((int)(intptr_t)(Parser->Pos) / sizeof(char*));
/* or maybe a more human-readable hash for debugging? */
/* Parser->ScopeID = Parser->Line * 0x10000 + Parser->CharacterPos; */
If I comment out the first line assigning the (0) ScopeID, and instead remove
the comments around the "human readable" line, my problem goes away.
Original comment by [email protected]
on 30 Oct 2013 at 7:04
from picoc.
One more comment… the code seems to want to set the ScopeID as a hash and
"hope for no collisions". It seems to me that the most straight forward way to
do this is to simply let Parser->ScopeID = OldScopeID. That is, since we can't
have two scopes using the same address for saving the previous scope (since the
only way to get that would include invalidating an old scope), there's no fancy
computation needed.
Original comment by [email protected]
on 30 Oct 2013 at 7:08
from picoc.
Related Issues (20)
- Ternary operator executes both sides
- r581 and later failing on OS X HOT 4
- if ( somepointer) fails
- Can't assign struct coordinates from array initializer HOT 1
- Implement coma operator in for loops
- #define within a #include file from interactive mode crashes HOT 2
- Invalid return point HOT 3
- Define macro inside a function block will crash picoc HOT 4
- Issue 192 revisited -- still broken in interactive mode. HOT 4
- Patch for /trunk/clibrary.c
- Patch suggestion
- Had very minor issue compiling on Solaris 10 spardc
- Github migration HOT 2
- Support for dirent.h
- Picoc -i on OSX gives SIGABRT
- Shift operators ignore the unsigned type HOT 1
- Variable scope not always respected
- Executions speed decreased HOT 1
- Migration to anoher project hosting site HOT 2
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 picoc.