Giter Club home page Giter Club logo

eightball's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

eightball's Issues

Compile on linux, doesn't work right on Apple II

If I set the start address of the generated code to 0x5000 I should be able to compile EightBall code on Linux and run in the the VM on the Apple II. This works with some programs (sieve4.8b for example) but fails with unittest.8b. If I compile the failing chunk of the unit tests on Linux as a separate small program it still fails on the Apple II VM, so it is not memory exhaustion. If I compile the same chunk on Apple II it runs fine on Apple II VM. What else is different I wonder?

Full line comments

Right now the comment character ' is handled as a command, which means that a semicolon is needed to comment after a statement:

pr.msg  "Hello" ; ' Say hello

This is a bit ugly. The ' character should probably be handled in the parser itself so everything from ' to newline is ignored.

High performance VM

The reference implementation of the VM is not optimized for speed and has loads of paranoid checks.
Once things stabilize I will attempt an optimized version in 6502 assembly.

Reduce bloat, improve memory management

Compiler/interpreter code has some bloat that can be removed / refactored.

Compiler/interpreter memory management can be improved. Would be better if source code and variables were allocated in same block rather than two separate blocks, but this would be difficult on VIC20 (due to hole in the memory map.)

Way to pass string literals as argument

This would be nice:

call foo("Hello")
end
sub foo(byte s[])
 pr.str s; pr.nl
endsub

One fairly easy way to implement this:

  • New VM instruction to store string in program space. The string follows the instruction. The VM just skips until the NULL. (This is similar to the trick I do with PRSTR today.)
  • The compiler will put the address of the start of the string on the eval stack.

If we implement this, we can probably get rid of the PRMSG VM instruction and the pr.msg statement, since pr.str "xxxx" should work.

Error reporting sucks

Not all errors paths report an error.
Some errors paths report more than one error.
In general this is a mess!

Apple II keyboard buffering

The keyboard input on the Apple II is not buffered at present, which means that if a program is running and the user hits a key other than escape, and the Eightball program does not read that character with kbd.ch or kbd.ln then it will not be possible to interrupt the program with ESC. I probably need to implement a small keyboard buffer and handle ESC specially so it is not queued.

Implement support for constants

Would be nice to be able to define constants and use them in constant expressions.

For example

const size=10
word A[size*size] = {}
word i=0
for i=1:size
 A[i]=1
endfor

However we are super short of memory so we may need to implement this in a devious way.

Port tetris.8b to C64, VIC20

tetris.8b uses Apple II lo-res graphics and other Apple II specific low-level hardware access.

Should do a port to C64 and VIC20 also!

Compiler does not implement array pass by reference

I have not yet implemented the pass-by-reference semantics for passing arrays to subroutines as parameters in the compiler.

The tricks I use in the interpreter do not adapt so well to the compiler, so I am working out how to do this easily (and with little code.) For now this only works when interpreted (run) but not when using the comp command and the Virtual Machine.

recurse3() test case is failing when compiled

sub recurse3(word x)
  if x==0
    return 1;
  else
    return x*recurse2(x-1)
  endif
endsub

This works okay in the interpreter but the compiled code does not run. Swapping the order of the arguments to the multiplication resolves the issue!

Use LOADER.SYS for Apple II

cc65 provides LOADER.SYS which should allow me to access more main memory on Apple II. I need to experiment with this.

Implement compile direct from source file

Right now the source is always loaded into memory. It would be nice to be able to compile with source direct from disk (loading a line at a time, or using say a 256 byte buffer). This would allow larger programs to be compiled (at the expense of not being able to use the interpreter on such files.)

Interpreter does not zero fill arrays

Memory allocated by the compiler is always initialized, but this is not true for the compiler. As a result if an array is longer than its initializer, it is not guaranteed that the remaining elements are zero.

It would be handy if:

word xx[10]={}

ensured zero filled array in the interpreter, just as it does in the compiler.

Single line while loops compile incorrectly

Single line while loops:

while 1; pr.msg "Hello"; endwhile

Do not compile correctly. The endwhile seems to be skipped.

Works okay in interpreter though. I should also check single-line forms of if/else/endif and for/endfor for the same defect.

Compiler bug

Suppose we have a subroutine like this:

sub foo()
 word i=0
 for i=0:10
  if i%3
   return 1
  endif
 endfor
endsub

It works fine interpreted and compiled the first few times, but when compiled it leaks the eval stack each time we do the return 1. The reason for this is the for pushes some stuff to the eval stack which the endfor usually handles, but here we are jumping out. Need to re-work this code. Think it only applies to this specific case with for loops.

Relocatable bytecode

At present bytecode uses absolute addresses for branches / jumps and is not relocatable. It may be better to use relative branches / jumps so code can be readily relocated within VM memory.
Advantages:

  • Portability of bytecode from Linux to Apple II, VIC20, C64 etc.
  • Portability of bytecode between the 8 bit platforms.
  • Eventually, allows some sort of module loading system (a bit like PLASMA has).

Drawbacks:

  • Makes debugging bytecode more painful - this can be overcome with better tools though.

To implement this, we need to add new VM instructions and modify the compiler to use them.

Fix linker table location in memory

The compiler allocates the linker tables using the same heap as source code (and same allocator). Write an allocator to put them at the top of this heap instead of being interleaved with lines of source. This means they can be easily freed after compilation so we don't leak memory with every comp.

Storing bytecode to extended memory does not work

There is code in eightball.c (enabled by setting EXTMEMCODE) to store generated bytecode in extended memory. However it is currently disabled because emit_fixup() ends up corrupting the bytecode. This seems to be caused by an underlying bug in the cc65 extended memory driver for Apple //e aux memory (a2e.auxmem.emd). I will investigate further ... first step is a stand-alone demonstration of the problem.

More robust memory limits

At present I am setting memory limits manually. I review the cc65 .map file and find the upper limit of the memory used by cc65 and then set my HEAP1 and HEAP2 limits accordingly. Oliver Schmidt suggested a better way using malloc() and _heapmaxavail. See cc65 issue #655 for more details. This applies to Apple II only, as I am not linking in malloc() on VIC20/C64.

Array pass by reference does not work for local array

If the array is global, it works okay:

This is okay.

word A[10]=0
call foo(A)
end
sub foo(word A[])
  bar(A)
endsub
sub bar(word A[])
 ...
endsub

However, this fails:

call foo()
end
sub foo(word A[])
  word A[10]=0
  bar(A)
endsub
sub bar(word A[])
 ...
endsub

It is almost certainly a screwup with relative vs absolute addresses.

VM should use jump table

cc65 is not compiling the switch() statement that selects on the opcode into a jump table. This could be made much more efficient!

Commodore: can not overwrite bytecode file

On CBM you can't just blindly overwrite a file. Should issue code to delete ("scratch") it first. The Commodore DOS 'overwrite' prefix (which I recall is '@') is buggy on original Commodore drives and corrupts disks, so we shouldn't rely on that.

Zero page mapping for VIC20, C64

I am using zero page locations for the VM registers and evaluation stack on Apple II, but I have not done this for Commodore VIC20 and C64 yet.

Machine language interface

Need a way to invoke a machine language routine from EightBall. It would also be good to be able to pass in register values (A,X,Y). This should work for both interpreted and compiled code.

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.