Assemble kernel on the client #1
22
asm.js
22
asm.js
@@ -90,6 +90,7 @@ const State = Object.freeze({
|
||||
AT_MEM: 18,
|
||||
AT_ADDR: 19,
|
||||
BYTE: 20,
|
||||
WORD: 21,
|
||||
});
|
||||
|
||||
const Action = Object.freeze({
|
||||
@@ -149,6 +150,7 @@ class Parser {
|
||||
".global": State.GLOBAL_NAME,
|
||||
".at": State.AT_MEM,
|
||||
".byte": State.BYTE,
|
||||
".word": State.WORD,
|
||||
};
|
||||
this.handlers = {
|
||||
[State.TOP]: (token) => this.token_top(token),
|
||||
@@ -172,6 +174,7 @@ class Parser {
|
||||
[State.AT_MEM]: (token) => this.token_at_mem(token),
|
||||
[State.AT_ADDR]: (token) => this.token_at_addr(token),
|
||||
[State.BYTE]: (token) => this.token_byte(token),
|
||||
[State.WORD]: (token) => this.token_word(token),
|
||||
};
|
||||
|
||||
this.results = [];
|
||||
@@ -477,6 +480,25 @@ class Parser {
|
||||
return action;
|
||||
}
|
||||
|
||||
token_word(token) {
|
||||
if (token == LINE_END) {
|
||||
this.state = State.TOP;
|
||||
return;
|
||||
}
|
||||
const action = { type: Action.DATA, size: 2 };
|
||||
const value = this.integer(token);
|
||||
if (value == null) {
|
||||
console.error(
|
||||
`ERROR: Unexpected token ${token}, expected value`);
|
||||
return;
|
||||
} else {
|
||||
if (value > 0xffff)
|
||||
console.error(`WARNING: Value ${token} is truncated`);
|
||||
action.value = [ value & 0xff, (value >> 8) & 0xff ];
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
mem_action() {
|
||||
const action = {
|
||||
type: Action.MEM,
|
||||
|
||||
Reference in New Issue
Block a user