Removing opcode references
This commit is contained in:
parent
7c77f5d6f4
commit
09e1d1a365
4
bp.c
4
bp.c
@ -365,11 +365,11 @@ int main(int argc, char *argv[])
|
||||
def_t *defs = NULL;
|
||||
file_t *loaded_files = NULL;
|
||||
|
||||
// Define an opcode that is just a reference to the rule `pattern`
|
||||
// Define a pattern that is just a reference to the rule `pattern`
|
||||
file_t *pat_file = spoof_file(&loaded_files, "<pattern>", "pattern");
|
||||
pat_t *pattern = bp_pattern(loaded_files, pat_file->contents);
|
||||
|
||||
// Define an opcode that is just a reference to the rule `replacement`
|
||||
// Define a pattern that is just a reference to the rule `replacement`
|
||||
file_t *rep_file = spoof_file(&loaded_files, "<replacement>", "replacement");
|
||||
pat_t *replacement = bp_pattern(rep_file, rep_file->contents);
|
||||
|
||||
|
20
compiler.c
20
compiler.c
@ -24,10 +24,10 @@ __attribute__((nonnull(1,2,3,6)))
|
||||
static pat_t *new_range(file_t *f, const char *start, const char *end, ssize_t min, ssize_t max, pat_t *pat, pat_t *sep);
|
||||
|
||||
//
|
||||
// Allocate a new opcode for this file (ensuring it will be automatically freed
|
||||
// when the file is freed)
|
||||
// Allocate a new pattern for this file (ensuring it will be automatically
|
||||
// freed when the file is freed)
|
||||
//
|
||||
pat_t *new_pat(file_t *f, const char *start, enum VMOpcode type)
|
||||
pat_t *new_pat(file_t *f, const char *start, enum pattype_e type)
|
||||
{
|
||||
allocated_op_t *tracker = new(allocated_op_t);
|
||||
tracker->next = f->ops;
|
||||
@ -63,7 +63,7 @@ static pat_t *new_range(file_t *f, const char *start, const char *end, ssize_t m
|
||||
}
|
||||
|
||||
//
|
||||
// Take an opcode and expand it into a chain of patterns if it's followed by
|
||||
// Take a pattern and expand it into a chain of patterns if it's followed by
|
||||
// any patterns (e.g. "`x `y"), otherwise return the original input.
|
||||
//
|
||||
static pat_t *expand_chain(file_t *f, pat_t *first)
|
||||
@ -78,7 +78,7 @@ static pat_t *expand_chain(file_t *f, pat_t *first)
|
||||
}
|
||||
|
||||
//
|
||||
// Take an opcode and parse any "=>" replacements and then expand it into a
|
||||
// Take a pattern and parse any "=>" replacements and then expand it into a
|
||||
// chain of choices if it's followed by any "/"-separated patterns (e.g.
|
||||
// "`x/`y"), otherwise return the original input.
|
||||
//
|
||||
@ -133,7 +133,7 @@ static pat_t *expand_choices(file_t *f, pat_t *first)
|
||||
}
|
||||
|
||||
//
|
||||
// Given two patterns, return a new opcode for the first pattern followed by
|
||||
// Given two patterns, return a new pattern for the first pattern followed by
|
||||
// the second. If either pattern is NULL, return the other.
|
||||
//
|
||||
static pat_t *chain_together(file_t *f, pat_t *first, pat_t *second)
|
||||
@ -188,7 +188,7 @@ pat_t *bp_simplepattern(file_t *f, const char *str)
|
||||
}
|
||||
|
||||
//
|
||||
// Compile a string of BP code into virtual machine opcodes
|
||||
// Compile a string of BP code into a BP pattern object.
|
||||
//
|
||||
static pat_t *_bp_simplepattern(file_t *f, const char *str)
|
||||
{
|
||||
@ -557,8 +557,8 @@ pat_t *bp_stringpattern(file_t *f, const char *str)
|
||||
}
|
||||
|
||||
//
|
||||
// Given a pattern and a replacement string, compile the two into a replacement
|
||||
// VM opcode.
|
||||
// Given a pattern and a replacement string, compile the two into a BP
|
||||
// replace pattern.
|
||||
//
|
||||
pat_t *bp_replacement(file_t *f, pat_t *pat, const char *replacement)
|
||||
{
|
||||
@ -583,7 +583,7 @@ pat_t *bp_replacement(file_t *f, pat_t *pat, const char *replacement)
|
||||
}
|
||||
|
||||
//
|
||||
// Compile a string representing a BP pattern into an opcode object.
|
||||
// Compile a string representing a BP pattern into a pattern object.
|
||||
//
|
||||
pat_t *bp_pattern(file_t *f, const char *str)
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "types.h"
|
||||
|
||||
__attribute__((nonnull))
|
||||
pat_t *new_pat(file_t *f, const char *start, enum VMOpcode type);
|
||||
pat_t *new_pat(file_t *f, const char *start, enum pattype_e type);
|
||||
__attribute__((nonnull(1,2)))
|
||||
pat_t *bp_simplepattern(file_t *f, const char *str);
|
||||
__attribute__((nonnull(1,2)))
|
||||
|
8
types.h
8
types.h
@ -8,10 +8,8 @@
|
||||
|
||||
#include "file_loader.h"
|
||||
|
||||
//
|
||||
// BP virtual machine opcodes (these must be kept in sync with the names in vm.c)
|
||||
//
|
||||
enum VMOpcode {
|
||||
// BP virtual machine pattern types
|
||||
enum pattype_e {
|
||||
VM_ANYCHAR = 1,
|
||||
VM_STRING,
|
||||
VM_RANGE,
|
||||
@ -38,7 +36,7 @@ struct match_s; // forward declared to resolve circular struct defs
|
||||
// A struct reperesenting a BP virtual machine operation
|
||||
//
|
||||
typedef struct pat_s {
|
||||
enum VMOpcode type;
|
||||
enum pattype_e type;
|
||||
const char *start, *end;
|
||||
// Length of the match, if constant, otherwise -1
|
||||
ssize_t len;
|
||||
|
Loading…
Reference in New Issue
Block a user