2022-10-14 19:30:47 +02:00
|
|
|
import { createType, error, LISPcmd } from "./lexer.js";
|
|
|
|
import { convertType, getOutType } from "./types.js"
|
|
|
|
|
|
|
|
export default {
|
2022-10-15 11:15:20 +02:00
|
|
|
"+": ({ execute, data, target, nid, ctx }) => {
|
|
|
|
let params = data.array.slice(1).map((d, i) => execute({ data: d, target: target + (i ? 0 : 1) }));
|
2022-10-14 19:30:47 +02:00
|
|
|
let outType = getOutType(...params.map(d => d.type));
|
|
|
|
return {
|
|
|
|
type: outType,
|
|
|
|
code: params.map((d, i) => {
|
|
|
|
if (i == 0) return [
|
|
|
|
d.code,
|
|
|
|
convertType(d.type, outType, target)
|
|
|
|
];
|
|
|
|
return [
|
|
|
|
d.code,
|
|
|
|
convertType(d.type, outType, target + 1),
|
2022-10-15 11:15:20 +02:00
|
|
|
` ${(["ADDU", "ADD", "FADD"])[outType]} $${target},$${target},$${target + 1}`
|
2022-10-14 19:30:47 +02:00
|
|
|
];
|
|
|
|
}).flat(Infinity).join("\n")
|
|
|
|
}
|
|
|
|
},
|
2022-10-15 11:15:20 +02:00
|
|
|
"-": ({ execute, data, target, nid, ctx }) => {
|
|
|
|
let params = data.array.slice(1).map((d, i) => execute({ data: d, target: target + (i ? 0 : 1) }));
|
|
|
|
let outType = getOutType(...params.map(d => d.type));
|
|
|
|
return {
|
|
|
|
type: outType,
|
|
|
|
code: params.map((d, i) => {
|
|
|
|
if (i == 0) return [
|
|
|
|
d.code,
|
|
|
|
convertType(d.type, outType, target)
|
|
|
|
];
|
|
|
|
return [
|
|
|
|
d.code,
|
|
|
|
convertType(d.type, outType, target + 1),
|
|
|
|
` ${(["SUBU", "SUB", "FSUB"])[outType]} $${target},$${target},$${target + 1}`
|
|
|
|
];
|
|
|
|
}).flat(Infinity).join("\n")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
defvar: ({ execute, data, target, nid, ctx }) => {
|
2022-10-14 19:30:47 +02:00
|
|
|
let param = data[3];
|
2022-10-15 11:15:20 +02:00
|
|
|
let [type, d] = createType(param);
|
2022-10-14 19:30:47 +02:00
|
|
|
|
2022-10-15 11:15:20 +02:00
|
|
|
let varType = ctx.getType(data[2]);
|
|
|
|
if (varType.content) error("A variable only can be created with a primitive Type.", ...data[2].pos);
|
|
|
|
|
|
|
|
if (type == "var" || type == "code") {
|
|
|
|
error("devfar with input is not implemented yet.", ...param.pos)
|
|
|
|
} else {
|
|
|
|
ctx.add({ name: data[1] + "V", size: varType.size, amount: 1, type: varType.type, content: param });
|
2022-10-14 19:30:47 +02:00
|
|
|
return {
|
2022-10-15 11:15:20 +02:00
|
|
|
code: "",
|
|
|
|
type: 0
|
2022-10-14 19:30:47 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-15 11:15:20 +02:00
|
|
|
},
|
|
|
|
defarr: ({ execute, data, target, nid, ctx }) => {
|
|
|
|
let param = data.slice(3).map(d => Number(d));
|
|
|
|
let varType = ctx.getType(data[2]);
|
|
|
|
let amount = param.reduce((v, c) => v * c, 1);
|
|
|
|
|
|
|
|
ctx.add({ name: data[1] + "V", size: varType.size, amount: amount, type: varType.type, content: param });
|
|
|
|
|
|
|
|
return {
|
|
|
|
code: "",
|
|
|
|
type: 0
|
|
|
|
};
|
2022-10-14 19:30:47 +02:00
|
|
|
}
|
|
|
|
}
|