Code Monkey home page Code Monkey logo

hystricomorph's Introduction

hystricomorph

A 65816 string compiler

Generates code to match an input string against one or more target strings.

  • longest match wins
  • generally compared in the order specified
  • uses 16-bit comparisons when possible.
  • optional case insensitivity

Usage

python3 hystricomorph.py [-ilvE] [-o outfile_file] function_name [input_file]

-i case insensitive comparison
-E run input file through c pre-processor
-l return length of matched string in the lsb
-v be verbose
-c add implicit 0-terminator to strings

input file format:

  • a leading # or // indicates a line comment.
  • "string" : value
  • value may be base 10 or base 16 (0x prefix) 16-bit integer.
  • string may include standard C character escapes
  • no octal.

output file

python3 hystricomorph.py -c -i -l match
"ABC" : 1
"ABCD" : 2

This will generate a function (int match(const char *)) which is essentially:

int match(const char *cp) {
	if (!strcasecmp(cp, "abcd")) return (2 << 8) | 4;
	if (!strcasecmp(cp, "abc")) return (1 << 8) | 3;
	return 0;
}

(without the -c flag it would be more akin to memcmp than strcmp. Actual matching logic is based on the character count not a terminal character so embedded 0s match correctly.)

But hopefully more efficient...

* generated Sun Sep  1 22:34:34 2019

	case on

dummy	START
	END

match	START

cp	equ 5

	phb
	tsc
	phd
	tcd
	pei cp+1
	plb
	plb
	jsr _action
	rep #$20
	lda 1
	sta 5
	lda 3
	sta 7
	pld
	pla
	pla
	txa
	plb
	rtl

_action	anop
	ldx #0

	longi on
	longa on
	lda (cp)
	ora #$2020
	cmp #$6261	; 'ab'
	bne _4
	ldy #2
	lda (cp),y
	ora #$0020
	cmp #$0063	; 'c\x00'
	bne _2
	ldx #259	; 'abc\x00'
	rts
_2	anop
	ora #$2020
	cmp #$6463	; 'cd'
	bne _4
	longa off
	sep #$20
	ldy #4
	lda (cp),y
	cmp #$00	; '\x00'
	bne _4
	ldx #516	; 'abcd\x00'
_4	anop
	rts
	END

hystricomorph's People

Contributors

ksherlock avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.