Tiny Basic Compiler

You need an actual VIC.

Moderator: Moderators

User avatar
plbyrd
Vic 20 Hobbyist
Posts: 135
Joined: Tue Jun 01, 2010 9:32 pm
Website: http://thesharp.ninja
Location: Clarksville, TN
Occupation: Software Engineer

Post by plbyrd »

I'm joining this conversation late, but I have to say that this feels to me like a lot of redundant effort. I believe that if you were to create a BASIC compiler that targets the cc65 assembly and linkage stack that you'd have a far more robust environment to work with. All of the library functions are already written and you could have hybrid projects with code in C, BASIC and Assembler all running together.
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

I already pointed out to CurtisP, that TCB as is now presents a rather thin abstraction layer over machine language. In fact, only a small subset of BASIC would be translated into another, also small, subset of constructs available in 6502 code.

In the end, it appeared to me more difficult to find the right expression of a non-trivial algorithm in the current version of TCB (if such one even exists!) rather than making a straightforward direct implementation in ML.

Of course, any extension of TCB to a richer expressiveness (including bigger integers - at least 32 bits, and strings) ultimately leads to something quite much resembling Quetzalcoatl (C/UPL) or cc65. Nothing wrong about that, building a language gives one a lot to learn from. But for this goal it is also necessary to follow through with such a big project.

A full BASIC compiler even for the rather small V2 dialect is already a monumental task. I know of one such compiler for the C64, HYPRA COMP, mostly written in BASIC - save for a small ML runtime library -, supporting nearly 99% of all commands, and indeed able to compile itself! It spanned 6 small printed pages with two columns each as BASIC listing for typing it in (75 blocks on disk), and the runtime ML was roughly 2K in length (and printed as hexdump).

Not something to implement quickly between breakfast and dinner. ;)
CurtisP
Vic 20 Dabbler
Posts: 99
Joined: Tue Mar 08, 2005 8:24 pm

Post by CurtisP »

Out of curiosity, if you compile a simple "Hello World" program in CC65, what will be the size of the resulting object code?
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

I downloaded the three files

cc65-doc-2.13.2-1.zip
cc65-vic20-2.13.2-1.zip
cc65-win32-2.13.2-1.zip

from ftp://ftp.musoftware.de/pub/uz/cc65/ and decompressed them into a single directory. I then wrote following batch-file to set up the environment ('setenv.cmd', on Vista, BTW), and saved that into the same directory:

Code: Select all

ECHO OFF
IF NOT DEFINED CC65_INC (
  SET CC65_INC=%CD%\include
  SET LD65_LIB=%CD%\lib
  SET LD65_CFG=%CD%\cfg
  PATH %PATH%;%CD%\bin
)
Here's 'hello.c':

Code: Select all

#include <stdio.h>

int main(void)
{
  puts("Hello, World!\n");
  return(0);
}
Compile with:

Code: Select all

[... change to cc65 directory ...]
setenv
cl65 -O -tvic20 hello.c
CurtisP wrote:Out of curiosity, if you compile a simple "Hello World" program in CC65, what will be the size of the resulting object code?
731 Bytes.
CurtisP
Vic 20 Dabbler
Posts: 99
Joined: Tue Mar 08, 2005 8:24 pm

Post by CurtisP »

Thanks for testing, and the quick intro to cc64. I figured that since other people are using it they would have an easier time doing the test than me.

As for TCB02, the code in question would be.

Code: Select all

INCLUDE "HEADER"
INCLUDE "CONSOLE"
INCLUDE "PRINT"

PRINT "HELLO, WORLD!"

EXIT
and compiled to 180 bytes (including the 2 byte load address).
Post Reply