~ubuntu-branches/ubuntu/trusty/dvd95/trusty

« back to all changes in this revision

Viewing changes to dvdauthor/dvdvm.h

  • Committer: Bazaar Package Importer
  • Author(s): Cyrille Grosdemange
  • Date: 2007-02-05 18:54:41 UTC
  • Revision ID: james.westby@ubuntu.com-20070205185441-cwq1wff0pglujg2e
Tags: upstream-1.2p0
ImportĀ upstreamĀ versionĀ 1.2p0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <string.h>
 
3
 
 
4
#ifdef YY_END_OF_BUFFER_CHAR
 
5
#define dvdvm_buffer_state YY_BUFFER_STATE
 
6
#else
 
7
typedef void *dvdvm_buffer_state;
 
8
#endif
 
9
 
 
10
extern void dvdvmerror(char *s);
 
11
extern int dvdvmlex(void);
 
12
extern dvdvm_buffer_state dvdvm_scan_string(const char *s);
 
13
extern int dvdvmparse(void);
 
14
 
 
15
struct vm_statement {
 
16
    int op;
 
17
    int i1,i2,i3,i4;
 
18
    char *s1,*s2,*s3,*s4;
 
19
    struct vm_statement *param;
 
20
    struct vm_statement *next;
 
21
};
 
22
 
 
23
extern struct vm_statement *dvd_vm_parsed_cmd;
 
24
 
 
25
enum { VM_NOP=0,
 
26
       VM_JUMP,
 
27
       VM_CALL,
 
28
       VM_EXIT,
 
29
       VM_RESUME,
 
30
 
 
31
       VM_SET,
 
32
       VM_IF,
 
33
       VM_ADD,
 
34
       VM_SUB,
 
35
       VM_MUL,
 
36
 
 
37
       VM_DIV,
 
38
       VM_MOD,
 
39
       VM_AND,
 
40
       VM_OR,
 
41
       VM_XOR,
 
42
 
 
43
       VM_VAL,
 
44
       VM_EQ, // EQ .. LT are all in a specific order
 
45
       VM_NE,
 
46
       VM_GTE,
 
47
       VM_GT,
 
48
 
 
49
       VM_LTE,
 
50
       VM_LT,
 
51
       VM_LAND,
 
52
       VM_LOR,
 
53
       VM_NOT,
 
54
       
 
55
       VM_MAX_OPCODE
 
56
};
 
57
 
 
58
static inline struct vm_statement *statement_new()
 
59
{
 
60
    struct vm_statement *s=malloc(sizeof(struct vm_statement));
 
61
    memset(s,0,sizeof(struct vm_statement));
 
62
    return s;
 
63
}
 
64
 
 
65
static inline struct vm_statement *statement_expression(struct vm_statement *v1,int op,struct vm_statement *v2)
 
66
{
 
67
    struct vm_statement *v;
 
68
 
 
69
    if( v1->op==op ) {
 
70
        v=v1->param;
 
71
        while(v->next) v=v->next;
 
72
        v->next=v2;
 
73
        return v1;
 
74
    } else {
 
75
        v=statement_new();
 
76
        v->op=op;
 
77
        v->param=v1;
 
78
        v1->next=v2;
 
79
        return v;
 
80
    }
 
81
}
 
82
 
 
83
static inline struct vm_statement *statement_setop(int reg,int op,struct vm_statement *vp)
 
84
{
 
85
    struct vm_statement *v,*v2;
 
86
 
 
87
    v=statement_new();
 
88
    v->op=VM_SET;
 
89
    v->i1=reg;
 
90
    v2=statement_new();
 
91
    v2->op=VM_VAL;
 
92
    v2->i1=reg-256;
 
93
    v->param=statement_expression(v2,op,vp);
 
94
    return v;
 
95
}
 
96
 
 
97
static inline void statement_free(struct vm_statement *s)
 
98
{
 
99
    if( s->s1 ) free(s->s1);
 
100
    if( s->s2 ) free(s->s2);
 
101
    if( s->s3 ) free(s->s3);
 
102
    if( s->s4 ) free(s->s4);
 
103
    if( s->param ) statement_free(s->param);
 
104
    if( s->next ) statement_free(s->next);
 
105
    free(s);
 
106
}