Giter Site home page Giter Site logo

Comments (3)

rversteegen avatar rversteegen commented on May 30, 2024

OPEN ... FOR INPUT has nothing to do with fb_InputByte and fb_InputInt. The latter two are part of the implementations of the INPUT and INPUT # statements, which get translated to multiple rtl calls. There are multiple INPUT/WINPUT/LINE INPUT functions and statements. FB has a lot of quirky syntax like this. See the 'See also' section at https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgInput

Because of all the quirks, the surest way to figure out what rtl functions a FB statement/expression translates to is to compile a test program and inspect the generated assembly/C. Nearly all functions in the runtime are called either only from FB code (calls generated from the compiler) which are usually but not always marked with FBCALL, or only from other runtime functions. fb_hStr2Double has an 'h' prefix for 'hidden', so that one is definitely called from the runtime only. I suggest you use gdb to find out the call chain to it.

But if you want to find out why a function gets called, you'll want to look at the compiler source. The AST building code makes tangled decisions about which rtl functions to call based on things like syntax and argument types.
A single FB statement is translated to an AST which may contain some calls to runtime functions. The easiest thing to do is use grep to find the relevant code. If you grep for INPUT, you'll find multiple places where INPUT tokens (FB_TK_INPUT) can be accepted. INPUT statements are handled by cInputStmt in parser-quirk-file.bas (called fromcQuirkStmt()), which calls rtlFileInputGet to generate the ASTNODE for the rtl call to read a single value from a file (including stdin).
Because there are so many different forms of INPUT, it's easier to go backwards, grepping for InputByte instead (do a case-insensitive search and remove the fb_ prefix). In rtlFileInputGet you'll find PROCLOOKUP( INPUTBYTE ) which is the point that a call to this specific rtl function is actually added to the AST. You'll see (both in rtl.bi, which lists the function names, and at the top of rtl-file.bas, which gives the detailed call signature for this function) that the function is called fb_InputByte.

from fbc.

rversteegen avatar rversteegen commented on May 30, 2024

Oh turns out there is one fb_h function called by the compiler: fb_hStrDelTemp, plus also a set of fb_hPut* blend operation functions in the graphics library.

from fbc.

CharlesDDNoble avatar CharlesDDNoble commented on May 30, 2024

@rversteegen Thanks a lot for this information!

Oh, I see what you are saying about the "open ... for input" statement. That's my fault, I am actually interested in the input # statement.

As you suggested, I dug into the .asm file generated using fbc (using the -R flag for the compiler) and I now see that input # has a call to fb_FileInput and fb_Input* (based on the data type of the dst variable). This has saved me so much time!

Thanks again

from fbc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.