• Stars
    star
    375
  • Rank 114,096 (Top 3 %)
  • Language
    C++
  • License
    GNU General Publi...
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A wicked-powerful text macro language for building binary files.

t2b

A wicked-powerful text macro language for building binary files. Supports comments, looping, Unicode, variables, conditionals, macros and recursion.

TLDR; Check out example/.

Pre-built binaries are available for Win64 and MacOS64.

Usage

$ t2b <filename> here
$ t2b # Read directly from stdin

t2b always writes to stdout. To output to a file, simply use a greater-than sign (>).

Language

Newlines are solely for the sake of readability; all whitespace is the same.

# This is a comment!
#
# Comments must be on their own line.

# Emit a byte. In DECIMAL.
u8 10

# Emit a byte in hex.
u8 0xa

# Octal
u16 0o777

# And, of course, binary.
u8 0b00001110

# Spit out a signed integer.
i64 25677

# Print a string (no line break)
str hello

# Print with a line break.
strl hello

# Wrap in quotes to capture whitespace.
strl "hello world!"

# Escapes are supported.
str "hello, world!\n"

# Unicode?
str "\u{1234}"

# Print a newline.
endl

# Do something 5 times.
# Indentation is purely for readability.
times 5
    u8 23
    u32 24
    times 10
        # We can nest loops
        str "50 times!!!"
    endtimes
endtimes

# Capture the output of another command.
# Oh, and store it into a variable.
set foo (u8 33)

# Access its value.
set bar (get foo)

# Emit its value 3 times.
times 3 get foo endtimes

# Create a simple macro.
macro emit_twice x
begin
    times 2 (get x)
endmacro

# Call it!
emit_twice 24

Why?

The need for such a program arose when I was working on writing a simple VM. Manually hex-editing files for an ever changing bytecode spec is tedious, error-prone, and most of all - sucky.

Now there's a lightweight way to do just that.

Supported Commands

  • u8...u64 - Emit unsigned integer
  • i8...i64 - Emit signed integer
  • f - Emit float
  • d - Emit double
  • hex - Toggle hex mode on/off (defaults to OFF)
  • str <expr> - Write a string
  • strl <expr> - Write a string AND newline
  • endl - Write a newline
  • not <expr> Boolean NOT a char
  • if <cond> <pred> endif Execute <pred> if <cond> == 1
  • get <expr> - Fetch the global variable named expr
  • set <expr1> <expr2> - Assign the global variable named expr1 to expr2
  • = - Compare two values, return 0 or 1
  • times <count> <pred> endtimes - Execute <pred> <count> times. i is always set to the current iteration's index.
  • macro <name> <param-names...> begin <pred> endmacro - Declare a custom macro named <name>.
  • return - End termination of the current macro. Exits the script if not in a macro.
  • size - Return the size of an item
  • len - Equivalent to C strlen

What's next?

It's now feasible to write a machine code compiler in shell. Hooray. Not sure why you would ever do that to yourself, though.

More Repositories

1

vim-flutter

Vim commands for Flutter, including hot-reload-on-save and more. 🦋
Vim Script
412
star
2

flutter_music_player

A music player component for Flutter (i.e. Spotify, Apple Music, etc.) [AGPL/example/no longer maintaining]
Dart
224
star
3

bullseye

[WIP] A pure functional language that compiles to Dart.
Dart
76
star
4

tensorflow.dart

Dart bindings for Tensorflow.
Dart
74
star
5

feathers-seeder

Straightforward data seeder for Feathers.js services. Promise-based.
JavaScript
38
star
6

prompts

Rich, simple, synchronous command-line prompt library for Dart.
Dart
37
star
7

samurai

JS Interpreter in Dart.
Dart
34
star
8

dart_electron_starter_kit

Boilerplate project for building Electron apps with Dart.
JavaScript
31
star
9

immutable_state

🎯 A lightweight framework for stateless UI in Flutter and Dart, and an alternative to Redux.
Dart
30
star
10

shell

Wrapper over dart:io [Process] API's that supports features like environment management, user switches, and more.
Dart
16
star
11

blm-blackout

Spread awareness of American police brutality - change your landing page to this blackout until justice is served. #BLMBlackout
HTML
15
star
12

dart_scripts

Run commands upon installing Dart packages, and more.
Dart
14
star
13

http2_client

A `package:http` `BaseClient` that speaks HTTP/2, and can maintain connections between requests.
Dart
12
star
14

pub_mediator

[ARCHIVED] Diagnoses version conflicts between dependencies in Dart packages.
Dart
12
star
15

feathers-validator

WIP. A validator for Feathers services, or any service.
JavaScript
11
star
16

combinator

Parser combinators that support static typing, file spans, and more.
Dart
10
star
17

instagram_dart

Dart Instagram client library.
Dart
6
star
18

polymer-semantic-ui

[WIP] Native Polymer elements for Semantic UI
HTML
4
star
19

fray

Interpreter/compiler with an emphasis on code transformation and reflection. Compiles to JS + JVM.
Java
2
star
20

paypal_dart

Unofficial Dart bindings for the PayPal REST API.
Dart
2
star
21

shrub

🌳 (Yet another) compile-to-WebAssembly language.
Dart
2
star
22

dartmonit

Monitor Dart scripts, and run them on startup.
Dart
2
star
23

graphql_schema

Moved to angel-dart/graphql mono-repo
Dart
1
star
24

hello_haskell

Haskell beginner projects and practice
Haskell
1
star
25

cassandra

Cassandra driver for the Dart VM.
Dart
1
star
26

arriba

Instant file transfer. Won best Newbie submission at FSU's MakeBuild 2019.
Dart
1
star