aboutsummaryrefslogtreecommitdiffgithub
diff options
context:
space:
mode:
authorAustin Adams <git@austinjadams.com>2019-01-09 13:48:21 -0800
committerAustin Adams <git@austinjadams.com>2019-01-09 13:48:21 -0800
commitbe9d89521567d72a1fed3866540c16d4a30d69ed (patch)
tree7afc5e37693be591bdf36033e756d2da7ea572bd
parent1a98ccc56688057ebacf92060a5e2f8a4ba9e4e3 (diff)
downloadnovice-be9d89521567d72a1fed3866540c16d4a30d69ed.tar.gz
novice-be9d89521567d72a1fed3866540c16d4a30d69ed.tar.xz
Add beginnings of PsuedoOp spec
-rw-r--r--novice/assembler/opspec/complx.ts36
-rw-r--r--novice/assembler/opspec/opspec.ts29
2 files changed, 65 insertions, 0 deletions
diff --git a/novice/assembler/opspec/complx.ts b/novice/assembler/opspec/complx.ts
new file mode 100644
index 0000000..e59e752
--- /dev/null
+++ b/novice/assembler/opspec/complx.ts
@@ -0,0 +1,36 @@
+import { AsmContext, OpOperands, PseudoOpSpec } from './opspec';
+
+const complxOpSpec: PseudoOpSpec = {
+ ops: [
+ {name: 'fill',
+ operands: [{kind: 'int', name: 'num'}],
+ asm: (ctx: AsmContext, operands: OpOperands) =>
+ // TODO: complain if too big
+ [operands.ints.num & ~(-1 << ctx.isa.mem.addressability)]},
+
+ {name: 'fill',
+ operands: [{kind: 'label', name: 'label'}],
+ asm: (ctx: AsmContext, operands: OpOperands) =>
+ // TODO: complain if nonexistent
+ [ctx.symbtable[operands.labels.label]]},
+
+ {name: 'stringz',
+ operands: [{kind: 'string', name: 'str'}],
+ asm: (ctx: AsmContext, operands: OpOperands) =>
+ // TODO: how is non-ascii handled? probably blow up
+ operands.strings.str.split('').map(c => c.charCodeAt(0)).concat([0])},
+
+ {name: 'blkw',
+ operands: [{kind: 'int', name: 'count'}],
+ asm: (ctx: AsmContext, operands: OpOperands) => {
+ // TODO: needs to be randomized
+ const result = new Array<number>(operands.ints.count);
+ for (let i = 0; i < result.length; i++) {
+ result[i] = 0;
+ }
+ return result;
+ }},
+ ],
+};
+
+export { complxOpSpec };
diff --git a/novice/assembler/opspec/opspec.ts b/novice/assembler/opspec/opspec.ts
new file mode 100644
index 0000000..16986c2
--- /dev/null
+++ b/novice/assembler/opspec/opspec.ts
@@ -0,0 +1,29 @@
+import { Isa } from '../isa';
+
+interface AsmContext {
+ isa: Isa;
+ symbtable: {[s: string]: number};
+}
+
+interface OpOperandSpec {
+ kind: 'int'|'label'|'string';
+ name: string;
+}
+
+interface OpOperands {
+ ints: {[s: string]: number};
+ labels: {[s: string]: string};
+ strings: {[s: string]: string};
+}
+
+interface OpSpec {
+ name: string;
+ operands: OpOperandSpec[];
+ asm: (ctx: AsmContext, operands: OpOperands) => number[];
+}
+
+interface PseudoOpSpec {
+ ops: OpSpec[];
+}
+
+export { AsmContext, OpOperands, PseudoOpSpec };