Giter VIP home page Giter VIP logo

cxw42 / do-not-self-host Goto Github PK

View Code? Open in Web Editor NEW
2.0 4.0 0.0 154 KB

A toolchain starting from assembly so you don't have to self-host your next programming language

License: Other

Python 45.59% C 14.87% Makefile 0.95% Perl 30.29% Raku 8.30%
programming-language programming-language-development self-hosting assembly vm virtual-machine bytecode bytecode-interpreter interpreter assembler

do-not-self-host's Issues

Add debug info to ngb, ngbasm

Because it would be nice to have while reading traces.

  • ngbasm: Emit the symbol<->address map
  • ngb: Read the map if present in an input file
  • ngb: while printing trace output, also print the symbol name if any matches.

Implement Minhi

  • Tokenizer (currently regex-based)
  • Table-driven parser
  • Bytecode generator

Add scopes to the assembler

E.g., so this will work:

:global_var
    .data 42
.scope
    :local1_var
         .data 1
    fetch &global_var    ; OK
    fetch &local1_var    ; OK
    fetch &local2_var    ; assembly-time error - not in scope
.endscope
.scope
    :local2_var
         .data 2
    fetch &global_var    ; OK
    fetch &local1_var    ; assembly-time error - not in scope
    fetch &local2_var    ; OK
.endscope

Make ngb VM and assembler

General:

  • Add Makefile

VM:

  • Rename nga->ngb (to avoid confusion). (Note: I'm basing ngb on nga rather than retro since nga is much simpler, and I will eventually be implementing the VM in x86 assembly.)
  • Add in, out instructions (currently in ngaita.c)
  • Add err instruction to output to stderr (since we're going to want that for the toolchain)
  • Add iseof (push (TOS == -1) ? -1 : 0); leave the character on the stack)
  • Rename cjump to ccall, since that's what it is in nga.c
  • Add real cjump
  • Add dedicated counter variable and setcount/getcount instructions
  • Add loop &label a la x86 (because it's a nice, convenient thing to have).
    • I think this should be loopcheck &done_label so you can put it at the top of the loop, since most of the loops I have written have been top-check. The resulting loop would look like:

          setcount 5
      :loop
          loopcheck &loop_done    ; branch if counter==0; otherwise, decrement counter.
          getcount
          outnum
          jump &loop
      :loop_done
      

Assembler:

  • Permit comments in asm source files
  • Add .include directive
  • Add .lit <n> directive that emits a lit <n> instruction.
  • Change syntax so that any operand becomes a lit <n> before the instruction. E.g., cjump &done is assembled to lit, &done, cjump. Or eq 32 becomes lit, 32, eq. (This requires more care on the programmer's part with stack discipline :) .)

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.