Giter Club home page Giter Club logo

qbjc's Introduction

build

qbjc

qbjc is a QBasic to JavaScript compiler. It can compile a QBasic / QuickBASIC program to:

  • A standalone executable Node.js script, with zero external dependencies; or
  • An ES6 module that can be imported and executed in both Node.js and browser environments.

Try it out in the qbjc playground: ๐Ÿ‘‰ qbjc.dev ๐Ÿ‘ˆ

Usage

qbjc playground

The qbjc playground (๐Ÿ‘‰ qbjc.dev ๐Ÿ‘ˆ) allows you to edit and run QBasic / QuickBASIC programs directly in the browser, no installation required.

qbjc playground screenshot

Command line usage

# Install qbjc from NPM
npm install -g qbjc

# Compile hello.bas and write output to hello.bas.js
qbjc hello.bas

# Run the compiled program
./hello.bas.js

# ...or run hello.bas directly:
qbjc --run hello.bas

# See all command line options
qbjc --help

Compiling and running a simple program

API usage

Compiling a QBasic program:

import {compile} from 'qbjc';

...
const {
  // Compiled JavaScript code.
  code,
  // Sourcemap for the compiled JavaScript code.
  map,
  // Abstract syntax tree representing the compiled code.
  astModule,
} = await compile({
  // QBasic source code.
  source: 'PRINT "HELLO WORLD"',
  // Optional - Source file name (for debugging information).
  sourceFileName: 'hello.bas',
  // Optional - Whether to bundle with Node.js runtime code in order
  // to produce a standalone script.
  enableBundling: true,
  // Optional - Whether to minify the output.
  enableMinify: false,
});

Executing the compiled code:

  • In browsers (using xterm.js):

    import {Terminal} from 'xterm';
    import {BrowserExecutor} from 'qbjc/browser';
    import {compiledModule} from './hello.bas.js';
    
    // Set up xterm.js Terminal instance
    const terminal = new Terminal(...);
    
    await new BrowserExecutor(terminal).executeModule(compiledModule);
  • In Node.js:

    import {NodeExecutor} from 'qbjc/node';
    import {compiledModule} from './hello.bas.js';
    
    await new NodeExecutor().executeModule(compiledModule);
  • In Node.js with bundling enabled (i.e. compiled with enableBundling: true):

    import {run} from './hello.bas.js';
    await run();

Compatibility

For detailed compatibility information on individual commands and functions, see ๐Ÿ‘‰ Implementation Status.

What works:

  • Core language features

    • Control flow structures - loops, conditionals, GOTO, GOSUB etc.
    • Data types - primitive types, arrays and user-defined types (a.k.a. records)
    • Expressions - arithmetic, string, comparison, boolean
    • SUBs and FUNCTIONs
    • DATA constants
    • Many built-in commands and functions like VAL, STR$, INSTR, MID$
  • Text mode

    • Basic text mode I/O - PRINT, INPUT, INKEY$, INPUT$ etc.
    • Text mode screen manipulation - COLOR, LOCATE etc.
    • Note that the current implementation depends on a VT100-compatible terminal emulator.
      • On Windows, this means using WSL or something like PuTTY.
      • In the browser, the implementation uses xterm.js.
  • It's just enough to run the original NIBBLES.BAS game that shipped with QBasic: Compiling and running NIBBLES.BAS

What doesn't work (yet):

  • Graphics and audio
  • Events - ON ERROR, ON TIMER etc.
  • OS APIs like file I/O, CALL INTERRUPT etc.
  • Direct memory access - PEEK, POKE etc.
  • Less common syntax, inputs or options
  • ...and more - contributions are welcome!

About

qbjc is distributed under the Apache License v2.

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.