lispToMmix/js/nativefunc.js
2022-10-14 19:30:47 +02:00

37 lines
1.4 KiB
JavaScript

import { createType, error, LISPcmd } from "./lexer.js";
import { convertType, getOutType } from "./types.js"
export default {
"+": ({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),
` ${(["ADDU","ADD","FADD"])[outType]} $${target},$${target},$${target+1}`
];
}).flat(Infinity).join("\n")
}
},
defvar: ({ execute, data, target, nid, ctx })=>{
let param = data[3];
let [type,d] = createType(param);
if(type == "var" || type == "code"){
error("devfar with input is not implemented yet.",...param.pos)
}else{
ctx.add({ name: data[1]+"V", size: (Number(data[2].substring(1)) ?? 64) / 8, amount: 1, type: (((["u","i","f"]).indexOf(data[2].substring(0,1))+1)||1)-1,content:param });
return {
code:"",
type:0
}
}
}
}