Compare commits
3 Commits
902404cb10
...
9fb3910a16
| Author | SHA1 | Date | |
|---|---|---|---|
|
9fb3910a16
|
|||
|
22dc1fc0ca
|
|||
|
cc51b2d7be
|
29
asm.js
29
asm.js
@@ -112,6 +112,7 @@ const Action = Object.freeze({
|
||||
DATA: 11,
|
||||
ALIGN: 12,
|
||||
DEF: 13,
|
||||
LABEL: 14,
|
||||
});
|
||||
|
||||
const types = {
|
||||
@@ -224,6 +225,8 @@ class Parser {
|
||||
this.state = state;
|
||||
return;
|
||||
}
|
||||
if (token.endsWith(":"))
|
||||
return { type: Action.LABEL, name: token.slice(0, -1) };
|
||||
const code = this.translate_code(token);
|
||||
if (code)
|
||||
return { type: Action.APPEND, code };
|
||||
@@ -497,7 +500,7 @@ class Parser {
|
||||
this.state = State.TOP;
|
||||
return;
|
||||
}
|
||||
const action = { type: Action.DATA, size: 2 };
|
||||
const action = { type: Action.DATA, size: 4 };
|
||||
const value = this.integer(token);
|
||||
if (value == null) {
|
||||
action.symbol = token;
|
||||
@@ -557,18 +560,15 @@ class Parser {
|
||||
this.state = State.TOP;
|
||||
return;
|
||||
}
|
||||
const value = this.integer(token);
|
||||
if (value == null) {
|
||||
console.error(
|
||||
`ERROR: Unexpected token ${token}, expected value`);
|
||||
this.def_name = undefined;
|
||||
this.state = State.TOP;
|
||||
return;
|
||||
}
|
||||
const action = {
|
||||
type: Action.DEF,
|
||||
def: { name: this.def_name, value },
|
||||
def: { name: this.def_name },
|
||||
};
|
||||
const value = this.integer(token);
|
||||
if (value != null)
|
||||
action.def.value = value;
|
||||
else
|
||||
action.def.symbol = token;
|
||||
this.def_name = undefined;
|
||||
this.state = State.TOP;
|
||||
return action;
|
||||
@@ -630,6 +630,7 @@ export class Assembler {
|
||||
[Action.DATA]: (action) => this.action_data(action),
|
||||
[Action.ALIGN]: (action) => this.action_align(action),
|
||||
[Action.DEF]: (action) => this.action_def(action),
|
||||
[Action.LABEL]: (action) => this.action_label(action),
|
||||
};
|
||||
|
||||
this.exports = [];
|
||||
@@ -738,7 +739,13 @@ export class Assembler {
|
||||
}
|
||||
|
||||
action_def(action) {
|
||||
this.defs[action.def.name] = action.def.value;
|
||||
const value = action.def.value
|
||||
?? this.lookup_def(action.def.symbol);
|
||||
this.defs[action.def.name] = value;
|
||||
}
|
||||
|
||||
action_label(action) {
|
||||
this.defs[action.name] = this.pos.addr;
|
||||
}
|
||||
|
||||
push(chunk) {
|
||||
|
||||
Reference in New Issue
Block a user