summaryrefslogtreecommitdiff
path: root/src/bytecode/bytecode.h
blob: be163b157fd9f5b2b0acef00e0c31a09387653df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * This file is part of LibCSS.
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
 */

#ifndef css_bytecode_bytecode_h_
#define css_bytecode_bytecode_h_

#include <inttypes.h>
#include <stdio.h>

#include <libcss/types.h>
#include <libcss/properties.h>

typedef uint32_t css_code_t;

typedef enum css_properties_e opcode_t;

enum flag {
	FLAG_IMPORTANT			= (1<<0),
	FLAG_INHERIT			= (1<<1)
};

enum calc_opcodes {
	CALC_PUSH_VALUE = 'V',
	CALC_ADD        = '+',
	CALC_SUBTRACT   = '-',
	CALC_MULTIPLY   = '*',
	CALC_DIVIDE     = '/',
	CALC_FINISH     = '=',
};

typedef enum unit {
	UNIT_LENGTH = (1u << 8),
	UNIT_PX   = (1u << 8) + 0,
	UNIT_EX   = (1u << 8) + 1,
	UNIT_EM   = (1u << 8) + 2,
	UNIT_IN   = (1u << 8) + 3,
	UNIT_CM   = (1u << 8) + 4,
	UNIT_MM   = (1u << 8) + 5,
	UNIT_PT   = (1u << 8) + 6,
	UNIT_PC   = (1u << 8) + 7,
	UNIT_CH   = (1u << 8) + 8,
	UNIT_REM  = (1u << 8) + 9,
	UNIT_LH   = (1u << 8) + 10,
	UNIT_VH   = (1u << 8) + 11,
	UNIT_VW   = (1u << 8) + 12,
	UNIT_VI   = (1u << 8) + 13,
	UNIT_VB   = (1u << 8) + 14,
	UNIT_VMIN = (1u << 8) + 15,
	UNIT_VMAX = (1u << 8) + 16,
	UNIT_Q    = (1u << 8) + 17,

	UNIT_PCT = (1 << 9),

	UNIT_ANGLE = (1 << 10),
	UNIT_DEG  = (1 << 10) + 0,
	UNIT_GRAD = (1 << 10) + 1,
	UNIT_RAD  = (1 << 10) + 2,
	UNIT_TURN = (1 << 10) + 3,

	UNIT_TIME = (1 << 11),
	UNIT_MS = (1 << 11) + 0,
	UNIT_S  = (1 << 11) + 1,

	UNIT_FREQ = (1 << 12),
	UNIT_HZ  = (1 << 12) + 0,
	UNIT_KHZ = (1 << 12) + 1,

	UNIT_RESOLUTION = (1 << 13),
	UNIT_DPI  = (1 << 13) + 0,
	UNIT_DPCM = (1 << 13) + 1,
	UNIT_DPPX = (1 << 13) + 2,

	/* These are special only to the CALC bytecodes */
	UNIT_CALC_ANY = (1 << 20),
	UNIT_CALC_NUMBER = (1 << 20) + 1,
} unit;

typedef uint32_t colour;

typedef enum shape {
	SHAPE_RECT = 0
} shape;

static inline css_code_t buildOPV(opcode_t opcode, uint8_t flags, uint16_t value)
{
	return (opcode & 0x3ff) | (flags << 10) | ((value & 0x3fff) << 18);
}

static inline opcode_t getOpcode(css_code_t OPV)
{
	return (OPV & 0x3ff);
}

static inline uint8_t getFlags(css_code_t OPV)
{
	return ((OPV >> 10) & 0xff);
}

static inline uint16_t getValue(css_code_t OPV)
{
	return (OPV >> 18);
}

static inline bool isImportant(css_code_t OPV)
{
	return getFlags(OPV) & 0x1;
}

static inline bool isInherit(css_code_t OPV)
{
	return getFlags(OPV) & 0x2;
}

static inline bool isCalc(css_code_t OPV)
{
	/* Note, this relies on all _CALC values being the same ultimately */
	return getValue(OPV) == 0x7f;
}

#endif