Assemble kernel on the client #1
22
asm.js
22
asm.js
@@ -91,6 +91,7 @@ const State = Object.freeze({
|
|||||||
AT_ADDR: 19,
|
AT_ADDR: 19,
|
||||||
BYTE: 20,
|
BYTE: 20,
|
||||||
WORD: 21,
|
WORD: 21,
|
||||||
|
UTF8: 22,
|
||||||
});
|
});
|
||||||
|
|
||||||
const Action = Object.freeze({
|
const Action = Object.freeze({
|
||||||
@@ -135,7 +136,8 @@ const const_opcodes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Parser {
|
class Parser {
|
||||||
constructor() {
|
constructor(encoder) {
|
||||||
|
this.encoder = encoder;
|
||||||
this.tokens = [];
|
this.tokens = [];
|
||||||
this.tokenizer = new Tokenizer();
|
this.tokenizer = new Tokenizer();
|
||||||
this.state = State.TOP;
|
this.state = State.TOP;
|
||||||
@@ -151,6 +153,7 @@ class Parser {
|
|||||||
".at": State.AT_MEM,
|
".at": State.AT_MEM,
|
||||||
".byte": State.BYTE,
|
".byte": State.BYTE,
|
||||||
".word": State.WORD,
|
".word": State.WORD,
|
||||||
|
".utf8": State.UTF8,
|
||||||
};
|
};
|
||||||
this.handlers = {
|
this.handlers = {
|
||||||
[State.TOP]: (token) => this.token_top(token),
|
[State.TOP]: (token) => this.token_top(token),
|
||||||
@@ -175,6 +178,7 @@ class Parser {
|
|||||||
[State.AT_ADDR]: (token) => this.token_at_addr(token),
|
[State.AT_ADDR]: (token) => this.token_at_addr(token),
|
||||||
[State.BYTE]: (token) => this.token_byte(token),
|
[State.BYTE]: (token) => this.token_byte(token),
|
||||||
[State.WORD]: (token) => this.token_word(token),
|
[State.WORD]: (token) => this.token_word(token),
|
||||||
|
[State.UTF8]: (token) => this.token_utf8(token),
|
||||||
};
|
};
|
||||||
|
|
||||||
this.results = [];
|
this.results = [];
|
||||||
@@ -499,6 +503,20 @@ class Parser {
|
|||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
token_utf8(token) {
|
||||||
|
if (token == LINE_END) {
|
||||||
|
this.state = State.TOP;
|
||||||
|
return;
|
||||||
|
} else if (token.string == undefined) {
|
||||||
|
console.error(
|
||||||
|
`ERROR: unexpected token ${token}, expected string`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const value = this.encoder.encode(token.string);
|
||||||
|
const action = { type: Action.DATA, size: value.length, value };
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
mem_action() {
|
mem_action() {
|
||||||
const action = {
|
const action = {
|
||||||
type: Action.MEM,
|
type: Action.MEM,
|
||||||
@@ -539,7 +557,7 @@ export class Assembler {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.encoder = new TextEncoder("utf-8");
|
this.encoder = new TextEncoder("utf-8");
|
||||||
this.decoder = new TextDecoder("utf-8");
|
this.decoder = new TextDecoder("utf-8");
|
||||||
this.parser = new Parser();
|
this.parser = new Parser(this.encoder);
|
||||||
this.handlers = {
|
this.handlers = {
|
||||||
[Action.APPEND]: (action) => this.action_append(action),
|
[Action.APPEND]: (action) => this.action_append(action),
|
||||||
[Action.EXPORT]: (action) => this.action_export(action),
|
[Action.EXPORT]: (action) => this.action_export(action),
|
||||||
|
|||||||
Reference in New Issue
Block a user