Converting MINI-BASIC in MASM over to C++?

This is a discussion on Converting MINI-BASIC in MASM over to C++? within the Projects and Job Recruitment forums, part of the Community Boards category; I don't understand why [...] the proper function? Had to be changed... didn't have to be changed... does it make ...

  1. #271
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    3,802
    I don't understand why [...] the proper function?
    Had to be changed... didn't have to be changed... does it make a difference? I'm honestly not sure about the details myself, but the source as I posted it pacifies a few compilers--preventing warnings and in one case an error.

    I still don't get [...] before outputting something?
    It seems that it is basically the "minibasic" variation of the C++ stream `width' functionality.

    The problem with that [...] seems to have vanished.
    True, but it would still be faster than the current approach. Don't worry about it for now, I'll see what I can do with this as my next pass.

    Trivial (it was actually implemented in the source I pushed yesterday).
    ^_^

    Not sure what I was thinking there.
    *shrug*

    I may have been the one to do it the first place.

    We can probably just [...] setting for the visibility.
    Better. Much better...

    the huge number of calls [...] to support multiple variants.
    Agreed. The instance should be stored in a member and set once in the constructor. If nothing else, if we clean that up now if/when we are able to move to a different implementation that isn't an implicit singleton we will already have the relevant portions of the source free of such issues.

    But shouldn't it also [...] may need a little reworking.
    See my notes within the source... I just don't know what to set the `split' variable to or what logic to apply for text. And now that I'm sure what it does, if not the exact expectations, we really need to rename `split' to something more illustrative.

    I'm willing to take a vote on that, but I [...] switching to a "HAS A" design.
    In my opinion, the class should be a member of the various classes that depend on it.

    But you can't have multiple consoles, can you?
    That depends exclusively on the platform, and I do hope to have a GUI eventually.

    Come to think of it, it might [...] a sense it "IS A" console.
    You could argue this for the current design, but this is solely because the class functions as glue between various other classes.

    I would say that the class is an interface to a console, but not the console itself.

    And we certainly shouldn't really [...] do you think?
    If I manage to port my syntax highlighting over we would, in a way, have three. (At the least, three clients of the class.)

    Inheriting certainly will [...] that there is a pointer stored somewhere.
    *shrug*

    There is also my hopes of having a GUI eventually. Of course, more primitives would be available to a GUI so it could be two different "minibasic" classes, but that strikes me as a wrongheaded approach to something that can be done without inheritance.

    Soma

  2. #272
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    >> But it's still WRONG to do it that way, even if it's easier/cleaner. minibasic still isn't "IS-A" token_scanner, per se.

    Having minibasic derive from token_scanner isn't necessarily saying that it "IS A" token_scanner so much as it is simply "importing" the object into it's namespace, so to speak. Parsers written in C employ this technique quite often, in fact: rather than passing a parameter to the scanner routines, they define global pointers to the text being parsed, so that instead of having to use constucts such as parse_expression(char**), they can omit the parameter altogether. The point is, the object-oriented "IS A" relationship shouldn't be taken to far here - it's just a matter of convenience.

    >> And we certainly shouldn't really have two (different ones) of them when "compiling", do you think?

    How so? As far as I can tell, the compiler just needs one. Can you elaborate?

    >> Inheriting certainly will fail the "multiple types of console" thingy

    In that case, it makes more sense to keep the singleton accesses as is, make the console class a virtual base class, define whatever console classes are needed and then in the minibasic constuctor, have the proper one instantiated, something to the effect:

    Code:
    class minibasic
    {
    	std::auto_ptr<console*> the_console;
    	
    	minibasic(int, char**)
    	{
    		// ...stuff...
    		while (*(++argv))
    		{
    			// ...stuff...
    			if (string(*argv) == "-s")
    				the_console = new studio_console();
    			else if (string(*argv) == "-c")
    				the_console = new normal_console();				
    		}
    		if (the_console.get() == 0)
    			the_console = new normal_console();
    		// ...stuff...
    	}	
    };
    Note that no other changes would be necessary in the rest of the code.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  3. #273
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    OK, I've pushed an update. For now, I've changed PRINT_TEXT to do exactly what PRINT_NUMBER does, although I'm not sure if that's 100% correct. And I did remove the padding reset within show_pad, since the setting should remain in effect until the entire print statement has been executed.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  4. #274
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    OK, it seems by fixing one bug I created another. I've pushed the newest bugfix.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  5. #275
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    There were just a few more functions that haven't been implemented yet. I've added 'NEW' (just unloads the program from memory). 'SIZE" seems to be meaningless in this context, so I simply return numeric_limits<int32>::max() (any better ideas?). I'm not yet sure how to implement 'EDIT', though. Besides that, it there anything I've missed?
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  6. #276
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ok, I'll leave the inheriting of token_scanner as is for now. (By having two, by the way, I mean that there is one in minibasic itself and another in the compiler).

    I'll be looking at having long variable names.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #277
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I've pushed up some minor "fix warnings" changes - I'm using Visual Studio 2008 Express edition as well as gcc-mingw 3.4.5, and VS is stricter on some things - so I fixed those.

    It also asserts on this bit:

    Code:
    			pchar end = pchar(&buffer[size]);
    so I made it:
    Code:
    			pchar end = pchar(&buffer[0] + size);
    I still get another assert [I just discovered when test-loading pitman] that has to do with accessing outside of a string in "empty" - I will try to fix that too.

    Edit: fixed several minor "trying to go past end of string" and similar problems.

    --
    Mats
    Last edited by matsp; 04-23-2009 at 02:13 PM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #278
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    >> I still get another assert [I just discovered when test-loading pitman] that has to do with accessing outside of a string in "empty" - I will try to fix that too.

    I just found that, too. I just changed the line in empty() to: if (skip_ahead && seq != fin), and it seems to work fine.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  9. #279
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Or maybe not. More testing needed, I guess.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  10. #280
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    OK, never mind, that was the problem, sorry.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  11. #281
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Have you push your latest changes? I just want to pull them so that I can incorporate what you've done before I push my changes.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  12. #282
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I think I've fixed those asserts and a few others, yes.

    I also refactored a bit of the compile-code [as I was trying to understand it to enable long variable names]. So, I moved the for and next generation out into separate functions.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #283
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    OK, great. I'll go ahead and pull it now.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  14. #284
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    OK, the only change I made to your update was in the current() function: I had it throw an exception rather than return 0 (ie: if we get to that point it indicates a premature end-of-input condition).

    The latest update implements the last functions that I know of.

    EDIT works, if only slightly different from the original program: the existing line is not printed simply because that would require a major (and unecessary) overhaul of console::get(string). As it is, the user simply needs to use the LIST function to view the existing line. Does there need to be an escape mechanism, though, in case the user wants to abort the edit?

    Also fixed the way the console is reset after a program is run (before it was clearing the screen), as well as a few other minor changes.

    The current version is at 1.99, so I guess the next change should bring it to 1.991.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  15. #285
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Well, I undid the change I made - seems you had it right.

    I'll go ahead and push the latest update.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting textBox1->Text into a basic string.
    By azjherben in forum C++ Programming
    Replies: 5
    Last Post: 06-07-2009, 08:27 PM
  2. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 09:28 AM
  3. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  4. VC++ 6 & MASM (eek)
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 07-16-2005, 10:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21