funcs, import
This commit is contained in:
parent
16e08bded6
commit
389afbe8e5
17 changed files with 1344 additions and 889 deletions
272
.gitignore
vendored
272
.gitignore
vendored
|
@ -1,135 +1,139 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
test.lisp
|
test.lisp
|
||||||
test.mms
|
test.mms
|
||||||
test.mmo
|
test.mmo
|
||||||
|
|
||||||
# Logs
|
testfun.lisp
|
||||||
logs
|
testfun.mms
|
||||||
*.log
|
testfun.mmo
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
# Logs
|
||||||
yarn-error.log*
|
logs
|
||||||
lerna-debug.log*
|
*.log
|
||||||
.pnpm-debug.log*
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
yarn-error.log*
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
lerna-debug.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
# Runtime data
|
|
||||||
pids
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
*.pid
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
*.seed
|
|
||||||
*.pid.lock
|
# Runtime data
|
||||||
|
pids
|
||||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
*.pid
|
||||||
lib-cov
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
# Coverage directory used by tools like istanbul
|
|
||||||
coverage
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
*.lcov
|
lib-cov
|
||||||
|
|
||||||
# nyc test coverage
|
# Coverage directory used by tools like istanbul
|
||||||
.nyc_output
|
coverage
|
||||||
|
*.lcov
|
||||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
||||||
.grunt
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
# Bower dependency directory (https://bower.io/)
|
|
||||||
bower_components
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
# node-waf configuration
|
|
||||||
.lock-wscript
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
||||||
build/Release
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
# Dependency directories
|
|
||||||
node_modules/
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
jspm_packages/
|
build/Release
|
||||||
|
|
||||||
# Snowpack dependency directory (https://snowpack.dev/)
|
# Dependency directories
|
||||||
web_modules/
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
# TypeScript cache
|
|
||||||
*.tsbuildinfo
|
# Snowpack dependency directory (https://snowpack.dev/)
|
||||||
|
web_modules/
|
||||||
# Optional npm cache directory
|
|
||||||
.npm
|
# TypeScript cache
|
||||||
|
*.tsbuildinfo
|
||||||
# Optional eslint cache
|
|
||||||
.eslintcache
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
# Optional stylelint cache
|
|
||||||
.stylelintcache
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
# Microbundle cache
|
|
||||||
.rpt2_cache/
|
# Optional stylelint cache
|
||||||
.rts2_cache_cjs/
|
.stylelintcache
|
||||||
.rts2_cache_es/
|
|
||||||
.rts2_cache_umd/
|
# Microbundle cache
|
||||||
|
.rpt2_cache/
|
||||||
# Optional REPL history
|
.rts2_cache_cjs/
|
||||||
.node_repl_history
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
# Output of 'npm pack'
|
|
||||||
*.tgz
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
# Yarn Integrity file
|
|
||||||
.yarn-integrity
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
# dotenv environment variable files
|
|
||||||
.env
|
# Yarn Integrity file
|
||||||
.env.development.local
|
.yarn-integrity
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
# dotenv environment variable files
|
||||||
.env.local
|
.env
|
||||||
|
.env.development.local
|
||||||
# parcel-bundler cache (https://parceljs.org/)
|
.env.test.local
|
||||||
.cache
|
.env.production.local
|
||||||
.parcel-cache
|
.env.local
|
||||||
|
|
||||||
# Next.js build output
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
.next
|
.cache
|
||||||
out
|
.parcel-cache
|
||||||
|
|
||||||
# Nuxt.js build / generate output
|
# Next.js build output
|
||||||
.nuxt
|
.next
|
||||||
dist
|
out
|
||||||
|
|
||||||
# Gatsby files
|
# Nuxt.js build / generate output
|
||||||
.cache/
|
.nuxt
|
||||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
dist
|
||||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
||||||
# public
|
# Gatsby files
|
||||||
|
.cache/
|
||||||
# vuepress build output
|
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||||
.vuepress/dist
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
# public
|
||||||
# vuepress v2.x temp and cache directory
|
|
||||||
.temp
|
# vuepress build output
|
||||||
.cache
|
.vuepress/dist
|
||||||
|
|
||||||
# Docusaurus cache and generated files
|
# vuepress v2.x temp and cache directory
|
||||||
.docusaurus
|
.temp
|
||||||
|
.cache
|
||||||
# Serverless directories
|
|
||||||
.serverless/
|
# Docusaurus cache and generated files
|
||||||
|
.docusaurus
|
||||||
# FuseBox cache
|
|
||||||
.fusebox/
|
# Serverless directories
|
||||||
|
.serverless/
|
||||||
# DynamoDB Local files
|
|
||||||
.dynamodb/
|
# FuseBox cache
|
||||||
|
.fusebox/
|
||||||
# TernJS port file
|
|
||||||
.tern-port
|
# DynamoDB Local files
|
||||||
|
.dynamodb/
|
||||||
# Stores VSCode versions used for testing VSCode extensions
|
|
||||||
.vscode-test
|
# TernJS port file
|
||||||
|
.tern-port
|
||||||
# yarn v2
|
|
||||||
.yarn/cache
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
.yarn/unplugged
|
.vscode-test
|
||||||
.yarn/build-state.yml
|
|
||||||
.yarn/install-state.gz
|
# yarn v2
|
||||||
|
.yarn/cache
|
||||||
|
.yarn/unplugged
|
||||||
|
.yarn/build-state.yml
|
||||||
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
266
js/ctx.js
266
js/ctx.js
|
@ -1,99 +1,169 @@
|
||||||
import { link } from "fs";
|
import { error } from "./lexer.js";
|
||||||
import { error } from "./lexer.js";
|
|
||||||
|
let count = 0;
|
||||||
let count = 0;
|
|
||||||
|
export class context{
|
||||||
export class context{
|
#list = {
|
||||||
#list = {};
|
V:[]
|
||||||
#types = {
|
};
|
||||||
u8: { size: 1,type: 0, content: false },
|
#functions = {
|
||||||
u16: { size: 2,type: 0, content: false },
|
|
||||||
u32: { size: 4,type: 0, content: false },
|
};
|
||||||
u64: { size: 8,type: 0, content: false },
|
#types = {
|
||||||
i8: { size: 1,type: 1, content: false },
|
v: { size: 1,type: 0, content: false },
|
||||||
i16: { size: 2,type: 1, content: false },
|
u8: { size: 1,type: 0, content: false },
|
||||||
i32: { size: 4,type: 1, content: false },
|
u16: { size: 2,type: 0, content: false },
|
||||||
i64: { size: 8,type: 1, content: false },
|
u32: { size: 4,type: 0, content: false },
|
||||||
f32: { size: 4,type: 2, content: false },
|
u64: { size: 8,type: 0, content: false },
|
||||||
f64: { size: 8,type: 2, content: false },
|
i8: { size: 1,type: 1, content: false },
|
||||||
char: {link:"u8"},
|
i16: { size: 2,type: 1, content: false },
|
||||||
c: {link:"u8"},
|
i32: { size: 4,type: 1, content: false },
|
||||||
bool: {link:"u8"},
|
i64: { size: 8,type: 1, content: false },
|
||||||
b: {link:"bool"},
|
f32: { size: 4,type: 2, content: false },
|
||||||
};
|
f64: { size: 8,type: 2, content: false },
|
||||||
#upper = [];
|
void: {link: "v"},
|
||||||
constructor(upper = null){
|
char: {link:"u8"},
|
||||||
this.#upper = upper;
|
c: {link:"u8"},
|
||||||
}
|
bool: {link:"u8"},
|
||||||
nextLevel(){
|
boolean: {link:"bool"},
|
||||||
return new context(this);
|
b: {link:"bool"},
|
||||||
}
|
uint8_t: { link:"u8" },
|
||||||
add({name,vType,size,amount=1,type = 0, content = 0,config = [1]}){
|
uint16_t: { link:"u16" },
|
||||||
if (!this.#list[vType]) this.#list[vType] = {};
|
uint32_t: { link:"u32" },
|
||||||
this.#list[vType][name+""] = {name: vType+(count++),size,amount,type,content,config};
|
uint64_t: { link:"u64" },
|
||||||
}
|
int8_t: { link:"i8" },
|
||||||
find(name, vType,pos=name.pos,quit=true){
|
int16_t: { link:"i16" },
|
||||||
let elem = (this.#list[vType]??{})[name+""]??null;
|
int32_t: { link:"i32" },
|
||||||
|
int64_t: { link:"i64" },
|
||||||
if (!elem && this.#upper){
|
float: { link:"f32" },
|
||||||
elem = this.#upper.find(name+"",vType,pos,false);
|
double: { link:"f64" },
|
||||||
}
|
};
|
||||||
if(!elem&&quit) error("Can not find '"+name+"' in context!",...pos);
|
#upper = [];
|
||||||
return elem;
|
#lower = [];
|
||||||
}
|
#isLocal = false;
|
||||||
|
constructor(upper = null,local = false){
|
||||||
getType(name,pos=name.pos, quit = true){
|
this.#upper = upper;
|
||||||
let lastName = name;
|
this.#isLocal = local;
|
||||||
let type = this.#types[name+""];
|
}
|
||||||
|
get local(){
|
||||||
if(!type){
|
return this.#isLocal;
|
||||||
if(this.#upper) type = this.#upper.getType(name+"", pos, false);
|
}
|
||||||
if (!type) error("Can not find '" + name + "' in context", ...pos);
|
nextLevel(local = true){
|
||||||
return type;
|
let newCon = new context(this,local||this.#isLocal);
|
||||||
}else{
|
if(!local)this.#lower.push(newCon);
|
||||||
if(type.link){
|
return newCon;
|
||||||
type = this.getType(type.link,pos,false);
|
}
|
||||||
if (!type) error("Can not find '" + name + "' in context", ...pos);
|
add({name,vType,size,amount=1,type = 0, content = 0,config = [1]}){
|
||||||
return type;
|
if (!this.#list[vType]) this.#list[vType] = [];
|
||||||
}else{
|
let nowid = this.#list[vType].push({varName:name+"",name: vType+(count++),size,amount,type,content,config,pos:()=>{
|
||||||
return type;
|
return this.#list[vType].reduce((v,e,i)=>v+(i<nowid?(e.size*e.amount):0),0);
|
||||||
}
|
},used:false})-1;
|
||||||
}
|
return this.#list[vType][this.#list[vType].length-1];
|
||||||
|
}
|
||||||
/*do{
|
find(name, vType,pos=name.pos,quit=true){
|
||||||
|
let nowId = (this.#list[vType] ?? []).findIndex((v)=>{
|
||||||
if (type) type = this.#types[type.link]
|
if(v.varName==name+"")return true;
|
||||||
else type = this.#types[name];
|
});
|
||||||
}while(type&&type.link);*/
|
//let elem = (this.#list[vType]??{})[name+""]??null;
|
||||||
|
let elem = (this.#list[vType] ?? [])[nowId]??null;
|
||||||
|
if (nowId==-1 && this.#upper){
|
||||||
}
|
elem = this.#upper.find(name+"",vType,pos,false);
|
||||||
addLinkType(name,link){
|
}
|
||||||
this.#types[name] = {link};
|
if(!elem&&quit) error("Can not find '"+name+"' in Variable context!",...pos);
|
||||||
}
|
elem.used = true;
|
||||||
|
return elem;
|
||||||
build(){
|
}
|
||||||
let out = `
|
|
||||||
LOC Data_Segment
|
getType(name,pos=name.pos, quit = true){
|
||||||
GREG @
|
let lastName = name;
|
||||||
|
let type = this.#types[name+""];
|
||||||
`;
|
|
||||||
|
if(!type){
|
||||||
for(let vType in this.#list){
|
if(this.#upper) type = this.#upper.getType(name+"", pos, false);
|
||||||
for(let UName in this.#list[vType]){
|
if (!type) error("Can not find '" + name + "' in Type context", ...pos);
|
||||||
let { size, amount, type, content, name } = this.#list[vType][UName];
|
return type;
|
||||||
if (!isNaN(content)) content = Number(content);
|
}else{
|
||||||
if (size <= 8 && amount == 1) {
|
if(type.link){
|
||||||
out += `${name} ${(["BYTE", "WYDE", "TETRA", "TETRA", "OCTA", "OCTA", "OCTA", "OCTA"])[size - 1]} ${content}\n`;
|
type = this.getType(type.link,pos,false);
|
||||||
} else {
|
if (!type) error("Can not find '" + name + "' in Type context", ...pos);
|
||||||
out += `
|
return type;
|
||||||
${name} BYTE ${content}
|
}else{
|
||||||
LOC ${name}+${size * amount + 1}\n`;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
addLinkType(name,link){
|
||||||
out +=" LOC #100\nMain SWYM\n";
|
this.#types[name] = {link};
|
||||||
return out;
|
}
|
||||||
}
|
size(){
|
||||||
|
let size = Object.entries(this.#list).reduce((va,tt)=>va+tt[1].reduce((v, e) => v + (e.size * e.amount), 0),0);
|
||||||
|
size+=8-size%8;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
addFunction({ name, code, type = 0,args=[] }){
|
||||||
|
this.#functions[name+""] = {name:"F"+(count++),code,type,args,used:false};
|
||||||
|
return this.#functions[name+""];
|
||||||
|
}
|
||||||
|
findFunction(name){
|
||||||
|
let elem = this.#functions[name+""] ?? null;
|
||||||
|
if (!elem && this.#upper) {
|
||||||
|
elem = this.#upper.findFunction(name);
|
||||||
|
}
|
||||||
|
if (!elem) return false;
|
||||||
|
elem.used = true;
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildFunctions(){
|
||||||
|
let code = "";
|
||||||
|
for(let funName in this.#functions){
|
||||||
|
const fun = this.#functions[funName];
|
||||||
|
if(!fun.used)continue;
|
||||||
|
code += `
|
||||||
|
${fun.name} SWYM
|
||||||
|
${fun.code}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < this.#lower.length; i++) {
|
||||||
|
const e = this.#lower[i];
|
||||||
|
code+=e.buildFunctions();
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
build(varsonly=false){
|
||||||
|
if(this.#isLocal) return "";
|
||||||
|
let out = ` LOC Data_Segment
|
||||||
|
GREG @
|
||||||
|
`;
|
||||||
|
if(varsonly)out="";
|
||||||
|
for(let vType in this.#list){
|
||||||
|
for(let id = 0;id<this.#list[vType].length;id++){
|
||||||
|
let { size, amount, type, content, name ,used} = this.#list[vType][id];
|
||||||
|
if(!used)continue;
|
||||||
|
if (!isNaN(content)) content = Number(content);
|
||||||
|
if (size <= 8 && amount == 1) {
|
||||||
|
out += `${name} ${(["BYTE", "WYDE", "TETRA", "TETRA", "OCTA", "OCTA", "OCTA", "OCTA"])[size - 1]} ${content}\n`;
|
||||||
|
} else {
|
||||||
|
out += `
|
||||||
|
${name} BYTE ${content}
|
||||||
|
LOC ${name}+${size * amount + 1}\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i = 0; i < this.#lower.length; i++) {
|
||||||
|
const e = this.#lower[i];
|
||||||
|
out+=e.build(true);
|
||||||
|
}
|
||||||
|
if(varsonly)return out
|
||||||
|
|
||||||
|
out += "intMask OCTA #7fffffffffffffff\n";
|
||||||
|
out += "HEAPpoint OCTA 0\n";
|
||||||
|
out += "HEAP BYTE 0\n";
|
||||||
|
out += " LOC #100\n"
|
||||||
|
out+= "Main LDA $0,HEAP\n";
|
||||||
|
out+= " STOU $0,HEAPpoint\n";
|
||||||
|
return out;
|
||||||
|
}
|
||||||
}
|
}
|
18
js/errors.js
18
js/errors.js
|
@ -1,9 +1,9 @@
|
||||||
import { error } from "./lexer.js"
|
import { error } from "./lexer.js"
|
||||||
|
|
||||||
|
|
||||||
export const argsCount = (name,num,pos)=>{
|
export const argsCount = (name,num,pos)=>{
|
||||||
error(`The native function '${name}' needs at least ${num} Arguments!`, ...pos);
|
error(`The native function '${name}' needs at least ${num} Arguments!`, ...pos);
|
||||||
}
|
}
|
||||||
export const argCount = (name,num,pos)=>{
|
export const argCount = (name,num,pos)=>{
|
||||||
error(`The native function '${name}' needs ${num} Arguments!`, ...pos);
|
error(`The native function '${name}' needs ${num} Arguments!`, ...pos);
|
||||||
}
|
}
|
||||||
|
|
205
js/execute.js
205
js/execute.js
|
@ -1,65 +1,142 @@
|
||||||
import { context } from "./ctx.js";
|
import { context } from "./ctx.js";
|
||||||
import { createType, error } from "./lexer.js";
|
import { createType, error } from "./lexer.js";
|
||||||
import nativefunc from "./nativefunc.js";
|
import nativefunc from "./nativefunc.js";
|
||||||
import { COMPUTE_TYPES } from "./types.js";
|
import { COMPUTE_TYPES, convertType } from "./types.js";
|
||||||
|
|
||||||
let nid = 0;
|
let nid = 0;
|
||||||
|
|
||||||
|
|
||||||
export function execute({ data, target = 0, ctx = new context()}){
|
export function execute({ data, target = 0, ctx = new context()}){
|
||||||
if(target > 255) error("To much registers are required to run this. Support for this case will be build in later!",...data.pos);
|
if(target > 255) error("To much registers are required to run this. Support for this case will be build in later!",...data.pos);
|
||||||
let [type, d] = createType(data);
|
let [type, d] = createType(data);
|
||||||
if(type == "code"){
|
if(type == "code"){
|
||||||
try {
|
let userFunc = ctx.findFunction(data[0]);
|
||||||
let { type, code } = nativefunc[data[0]]({
|
|
||||||
execute: ({ data, target = 0, ctx:contx = ctx }) => execute({ data, target, ctx:contx }),
|
if(userFunc){
|
||||||
data,
|
let params = data.array.slice(1,userFunc.args.length+1).map((d, i) => execute({ data: d, target,ctx}));
|
||||||
target,
|
if(params.length<userFunc.args.length)error("function '"+data[0]+"' is called with to less Arguments!",...data[data.length-1].pos);
|
||||||
nid: () => nid++,
|
let ctxSize = ctx.size();
|
||||||
ctx
|
let code = `
|
||||||
});
|
${params.map((p,i)=>{
|
||||||
return {code,type};
|
let arg = userFunc.args[i];
|
||||||
} catch (e) {
|
return [
|
||||||
console.log(e);
|
p.code,
|
||||||
error(`'${data[0]}' is not a function`,...data.pos);
|
convertType(p.type,arg.type,target),
|
||||||
}
|
` LDOU $${target + 1},HEAPpoint`,
|
||||||
}else if (type == "var"){
|
` SET $${target + 2},${ctxSize+arg.pos()}`,
|
||||||
let { size, amount, type, name } = ctx.find(d,"V",data.pos);
|
` ${arg.type == COMPUTE_TYPES.FLOAT?(arg.size > 4 ? "STOU" : "STSF"):("ST"+("BWTTOOOO")[arg.size - 1])+(arg.type == 0 ? "U" : "")} $${target},$${target + 1},$${target + 2}`
|
||||||
if (size <= 8 && amount == 1){
|
]
|
||||||
if(type == COMPUTE_TYPES.FLOAT){
|
}).flat(Infinity).join("\n")}
|
||||||
return {
|
|
||||||
type: 2,
|
LDOU $${target},HEAPpoint
|
||||||
code: ` ${size > 4 ? "LDOU" :"LDSF"} $${target},${name}`
|
ADDU $${target},$${target},${ctxSize}
|
||||||
}
|
STOU $${target},HEAPpoint
|
||||||
}else{
|
|
||||||
return {
|
GET $${target},rJ
|
||||||
type: type,
|
PUSHJ $${target+1},${userFunc.name}
|
||||||
code: ` LD${(["B", "W", "T", "T", "O", "O", "O", "O"])[size-1]}${type==0?"U":""} $${target},${name}`
|
PUT rJ,$${target}
|
||||||
}
|
|
||||||
}
|
LDOU $${target},HEAPpoint
|
||||||
}else{
|
SUBU $${target},$${target},${ctxSize}
|
||||||
return {
|
STOU $${target},HEAPpoint
|
||||||
type: 0,
|
|
||||||
code: ` LDA $${target},${name}`
|
SET $${target},$${target+1}
|
||||||
}
|
`;
|
||||||
}
|
return {
|
||||||
|
code,
|
||||||
}else if (type == "bool"){
|
type:userFunc.type.type
|
||||||
return {
|
}
|
||||||
code: ` SET $${target},${d}`,
|
}
|
||||||
type: COMPUTE_TYPES.UINT
|
try {
|
||||||
}
|
let { type, code } = nativefunc[data[0]]({
|
||||||
}else if (type == "num"){
|
execute: ({ data, target = 0, ctx:contx = ctx }) => execute({ data, target, ctx:contx }),
|
||||||
return {
|
data,
|
||||||
code: ` SET $${target},${d}`,
|
target,
|
||||||
type: COMPUTE_TYPES.UINT
|
nid: () => nid++,
|
||||||
}
|
ctx
|
||||||
}else if (type == "str"){
|
});
|
||||||
|
return {code,type};
|
||||||
return {
|
} catch (e) {
|
||||||
code: ` SET $${target},"${d}"`,
|
console.log(e);
|
||||||
type: COMPUTE_TYPES.UINT
|
error(`'${data[0]}' is not a function`,...data.pos);
|
||||||
}
|
}
|
||||||
}
|
}else if (type == "var"){
|
||||||
throw new Error("nothing found");
|
let { size, amount, type, name,pos } = ctx.find(d,"V",data.pos);
|
||||||
|
if(ctx.local){
|
||||||
|
if (size <= 8 && amount == 1) {
|
||||||
|
if (type == COMPUTE_TYPES.FLOAT) {
|
||||||
|
return {
|
||||||
|
type: 2,
|
||||||
|
code: ` LDOU $${target},HEAPpoint
|
||||||
|
SET $${target + 1},${pos()}
|
||||||
|
${size > 4 ? "LDOU" : "LDSF"} $${target},$${target},$${target+1}`
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
type: type,
|
||||||
|
code: ` LDOU $${target },HEAPpoint
|
||||||
|
SET $${target + 1},${pos()}
|
||||||
|
LD${("BWTTOOOO")[size - 1]}${type == 0 ? "U" : ""} $${target},$${target},$${target + 1}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
type: 0,
|
||||||
|
code: ` LDOU $${target},HEAPpoint
|
||||||
|
SET $${target + 1},${pos()}
|
||||||
|
ADDU $${target},$${target},$${target + 1}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if (size <= 8 && amount == 1) {
|
||||||
|
if (type == COMPUTE_TYPES.FLOAT) {
|
||||||
|
return {
|
||||||
|
type: 2,
|
||||||
|
code: ` ${size > 4 ? "LDOU" : "LDSF"} $${target},${name}`
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
type: type,
|
||||||
|
code: ` LD${("BWTTOOOO")[size - 1]}${type == 0 ? "U" : ""} $${target},${name}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
type: 0,
|
||||||
|
code: ` LDA $${target},${name}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}else if (type == "bool"){
|
||||||
|
return {
|
||||||
|
code: ` SET $${target},${d}`,
|
||||||
|
type: COMPUTE_TYPES.UINT
|
||||||
|
}
|
||||||
|
}else if (type == "num"){
|
||||||
|
let hex = "";
|
||||||
|
if(Number.isInteger(d)){
|
||||||
|
hex = d;
|
||||||
|
}else{
|
||||||
|
var buf = new ArrayBuffer(8);
|
||||||
|
(new Float64Array(buf))[0] = d;
|
||||||
|
let ddd = (new Uint32Array(buf));
|
||||||
|
hex ="#";
|
||||||
|
hex+=ddd[0].toString(16);
|
||||||
|
hex+=ddd[1].toString(16);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: ` SET $${target},${hex}`,
|
||||||
|
type: COMPUTE_TYPES.UINT
|
||||||
|
}
|
||||||
|
}else if (type == "str"){
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: ` SET $${target},"${d}"`,
|
||||||
|
type: COMPUTE_TYPES.UINT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error("nothing found");
|
||||||
}
|
}
|
362
js/lexer.js
362
js/lexer.js
|
@ -1,182 +1,182 @@
|
||||||
export class LISPstring extends String {
|
export class LISPstring extends String {
|
||||||
#l;
|
#l;
|
||||||
#c;
|
#c;
|
||||||
constructor(string, line, char) {
|
constructor(string, line, char) {
|
||||||
super(string);
|
super(string);
|
||||||
this.#l = line;
|
this.#l = line;
|
||||||
this.#c = char;
|
this.#c = char;
|
||||||
}
|
}
|
||||||
get lineCount() {
|
get lineCount() {
|
||||||
return this.#l;
|
return this.#l;
|
||||||
}
|
}
|
||||||
get charCount() {
|
get charCount() {
|
||||||
return this.#l;
|
return this.#l;
|
||||||
}
|
}
|
||||||
get pos() {
|
get pos() {
|
||||||
return [this.#l, this.#c];
|
return [this.#l, this.#c];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LISPcmd extends Array {
|
export class LISPcmd extends Array {
|
||||||
#l;
|
#l;
|
||||||
#c;
|
#c;
|
||||||
|
|
||||||
constructor(code, line, char) {
|
constructor(code, line, char) {
|
||||||
var childs = cutCmd(code, line, char);
|
var childs = cutCmd(code, line, char);
|
||||||
|
|
||||||
super(...childs);
|
super(...childs);
|
||||||
this.#l = line;
|
this.#l = line;
|
||||||
this.#c = char;
|
this.#c = char;
|
||||||
}
|
}
|
||||||
get lineCount() {
|
get lineCount() {
|
||||||
return this.#l;
|
return this.#l;
|
||||||
}
|
}
|
||||||
get charCount() {
|
get charCount() {
|
||||||
return this.#l;
|
return this.#l;
|
||||||
}
|
}
|
||||||
get pos() {
|
get pos() {
|
||||||
return [this.#l, this.#c];
|
return [this.#l, this.#c];
|
||||||
}
|
}
|
||||||
get array(){
|
get array(){
|
||||||
return new Array(...this);
|
return new Array(...this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function error(msg, l = null, c = null) {
|
export function error(msg, l = null, c = null) {
|
||||||
var out = "Error"
|
var out = "Error"
|
||||||
if (l != null && c != null) out += ` in line ${l} and character ${c}`;
|
if (l != null && c != null) out += ` in line ${l} and character ${c}`;
|
||||||
out += ": " + msg;
|
out += ": " + msg;
|
||||||
console.log("\x1b[31m", out, "\x1b[0m");
|
console.log("\x1b[31m", out, "\x1b[0m");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var lispSeperator = [" ", ":", "\n"];
|
var lispSeperator = [" ", ":", "\n"];
|
||||||
|
|
||||||
function cutCmd(code, line, chars) {
|
function cutCmd(code, line, chars) {
|
||||||
if (!code.startsWith("(")) return ["", error("Compiler Error", line, chars)];
|
if (!code.startsWith("(")) return ["", error("Compiler Error", line, chars)];
|
||||||
|
|
||||||
if (!code.endsWith(")")) return ["", error("Compiler Error", line, chars)];
|
if (!code.endsWith(")")) return ["", error("Compiler Error", line, chars)];
|
||||||
|
|
||||||
code = code.substring(1, code.length - 1);
|
code = code.substring(1, code.length - 1);
|
||||||
|
|
||||||
var countLinesBegin = line;
|
var countLinesBegin = line;
|
||||||
var countCharsBegin = chars;
|
var countCharsBegin = chars;
|
||||||
|
|
||||||
var countLines = line;
|
var countLines = line;
|
||||||
var countChars = chars;
|
var countChars = chars;
|
||||||
var inC = 0;
|
var inC = 0;
|
||||||
var wasinC = false;
|
var wasinC = false;
|
||||||
var inStr = 0;
|
var inStr = 0;
|
||||||
var buffer = "";
|
var buffer = "";
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var out = [];
|
var out = [];
|
||||||
|
|
||||||
function finishBuff() {
|
function finishBuff() {
|
||||||
out.push(
|
out.push(
|
||||||
wasinC ?
|
wasinC ?
|
||||||
new LISPcmd(buffer.trim(), countLinesBegin, countCharsBegin)
|
new LISPcmd(buffer.trim(), countLinesBegin, countCharsBegin)
|
||||||
:
|
:
|
||||||
new LISPstring(buffer.trim(), countLinesBegin, countCharsBegin)
|
new LISPstring(buffer.trim(), countLinesBegin, countCharsBegin)
|
||||||
);
|
);
|
||||||
countLinesBegin = countLines;
|
countLinesBegin = countLines;
|
||||||
countCharsBegin = countChars;
|
countCharsBegin = countChars;
|
||||||
buffer = "";
|
buffer = "";
|
||||||
wasinC = false;
|
wasinC = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < code.length; i++) {
|
for (var i = 0; i < code.length; i++) {
|
||||||
|
|
||||||
countChars++;
|
countChars++;
|
||||||
//console.log(code,countLines,countChars);
|
//console.log(code,countLines,countChars);
|
||||||
let c = code[i];
|
let c = code[i];
|
||||||
if (!inC && !inStr) {
|
if (!inC && !inStr) {
|
||||||
countLinesBegin = countLines;
|
countLinesBegin = countLines;
|
||||||
countCharsBegin = countChars;
|
countCharsBegin = countChars;
|
||||||
}
|
}
|
||||||
if (c == "\\") {
|
if (c == "\\") {
|
||||||
buffer += code[++i];
|
buffer += code[++i];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (inStr) {
|
if (inStr) {
|
||||||
if (c == "\n") {
|
if (c == "\n") {
|
||||||
countLines++;
|
countLines++;
|
||||||
countChars = 0;
|
countChars = 0;
|
||||||
} else if (c == '"') {
|
} else if (c == '"') {
|
||||||
buffer += c;
|
buffer += c;
|
||||||
if (!inC) finishBuff();
|
if (!inC) finishBuff();
|
||||||
inStr = false;
|
inStr = false;
|
||||||
} else {
|
} else {
|
||||||
buffer += c;
|
buffer += c;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c == '"') {
|
if (c == '"') {
|
||||||
inStr = true;
|
inStr = true;
|
||||||
buffer += c;
|
buffer += c;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c == ";" && !inC) {
|
if (c == ";" && !inC) {
|
||||||
while (code[++i] != "\n") { }
|
while (code[++i] != "\n") { }
|
||||||
countLines++;
|
countLines++;
|
||||||
countChars = 0;
|
countChars = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c == "\n") {
|
if (c == "\n") {
|
||||||
countLines++;
|
countLines++;
|
||||||
countChars = 0;
|
countChars = 0;
|
||||||
}
|
}
|
||||||
if (/*(c == " "||c=="\n")*/lispSeperator.includes(c) && !inC) {
|
if (/*(c == " "||c=="\n")*/lispSeperator.includes(c) && !inC) {
|
||||||
if (buffer.trim() != "") {
|
if (buffer.trim() != "") {
|
||||||
finishBuff();
|
finishBuff();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c == "(") {
|
if (c == "(") {
|
||||||
if (!inC && buffer.trim() != "") {
|
if (!inC && buffer.trim() != "") {
|
||||||
finishBuff();
|
finishBuff();
|
||||||
}
|
}
|
||||||
inC++;
|
inC++;
|
||||||
wasinC = true;
|
wasinC = true;
|
||||||
}
|
}
|
||||||
if (c == ")") {
|
if (c == ")") {
|
||||||
inC--;
|
inC--;
|
||||||
if (inC < 0) error("Closing braket to much!", countLines, countChars);
|
if (inC < 0) error("Closing braket to much!", countLines, countChars);
|
||||||
if (!inC) {
|
if (!inC) {
|
||||||
buffer += c;
|
buffer += c;
|
||||||
finishBuff();
|
finishBuff();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer += c;
|
buffer += c;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (inStr) error("Missing closing quotation mark!", countLines, countChars);
|
if (inStr) error("Missing closing quotation mark!", countLines, countChars);
|
||||||
if (inC) error("Missing closing braket!", countLines, countChars);
|
if (inC) error("Missing closing braket!", countLines, countChars);
|
||||||
|
|
||||||
if (buffer.trim() != "") finishBuff();
|
if (buffer.trim() != "") finishBuff();
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function createType(data) {
|
export function createType(data) {
|
||||||
if (data == "true") {
|
if (data == "true") {
|
||||||
return ["bool", 1];
|
return ["bool", 1];
|
||||||
}
|
}
|
||||||
if (data == "false") {
|
if (data == "false") {
|
||||||
return ["bool", 0];
|
return ["bool", 0];
|
||||||
}
|
}
|
||||||
/*if (data == "NaN") {
|
/*if (data == "NaN") {
|
||||||
return ["num", NaN];
|
return ["num", NaN];
|
||||||
}*/
|
}*/
|
||||||
if ((data instanceof LISPstring)&&data.startsWith('"') && data.endsWith('"')){
|
if ((data instanceof LISPstring)&&data.startsWith('"') && data.endsWith('"')){
|
||||||
return ["str", data.slice(1,-1)];
|
return ["str", data.slice(1,-1)];
|
||||||
}
|
}
|
||||||
if ((data instanceof LISPstring) && !isNaN(data)) {
|
if ((data instanceof LISPstring) && !isNaN(data)) {
|
||||||
return ["num", Number(data)];
|
return ["num", Number(data)];
|
||||||
}
|
}
|
||||||
if (data instanceof LISPcmd) {
|
if (data instanceof LISPcmd) {
|
||||||
return ["code", data];
|
return ["code", data];
|
||||||
}
|
}
|
||||||
return ["var", data];
|
return ["var", data];
|
||||||
}
|
}
|
|
@ -1,13 +1,13 @@
|
||||||
import bool from "./nativefuncs/bool.js";
|
import bool from "./nativefuncs/bool.js";
|
||||||
import lanes from "./nativefuncs/lanes.js";
|
import lanes from "./nativefuncs/lanes.js";
|
||||||
import math from "./nativefuncs/math.js";
|
import math from "./nativefuncs/math.js";
|
||||||
import sys from "./nativefuncs/sys.js";
|
import sys from "./nativefuncs/sys.js";
|
||||||
import vars from "./nativefuncs/vars.js";
|
import vars from "./nativefuncs/vars.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
...math,
|
...math,
|
||||||
...vars,
|
...vars,
|
||||||
...lanes,
|
...lanes,
|
||||||
...sys,
|
...sys,
|
||||||
...bool,
|
...bool,
|
||||||
};
|
};
|
|
@ -1,116 +1,116 @@
|
||||||
import { argCount } from "../errors.js";
|
import { argCount } from "../errors.js";
|
||||||
import { COMPUTE_TYPES, convertType, getOutType } from "../types.js";
|
import { COMPUTE_TYPES, convertType, getOutType } from "../types.js";
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
"<": ({ execute, data, target, nid, ctx }) => {
|
"<": ({ execute, data, target, nid, ctx }) => {
|
||||||
if (data.length != 3) argCount("<",2,data.pos);
|
if (data.length != 3) argCount("<",2,data.pos);
|
||||||
let param1 = execute({ data: data[1], target});
|
let param1 = execute({ data: data[1], target});
|
||||||
let param2 = execute({ data: data[2], target:target+1});
|
let param2 = execute({ data: data[2], target:target+1});
|
||||||
let outType = getOutType(param1.type,param2.type);
|
let outType = getOutType(param1.type,param2.type);
|
||||||
return {
|
return {
|
||||||
type: COMPUTE_TYPES.UINT,
|
type: COMPUTE_TYPES.UINT,
|
||||||
code: `${param1.code}
|
code: `${param1.code}
|
||||||
${convertType(param1.type, outType, target) }
|
${convertType(param1.type, outType, target) }
|
||||||
${param2.code}
|
${param2.code}
|
||||||
${convertType(param2.type, outType, target+1)}
|
${convertType(param2.type, outType, target+1)}
|
||||||
${ (["CMPU", "CMP", "FCMP"])[outType] } $${ target },$${ target },$${ target + 1 }
|
${ (["CMPU", "CMP", "FCMP"])[outType] } $${ target },$${ target },$${ target + 1 }
|
||||||
ZSN $${target},$${target},1`
|
ZSN $${target},$${target},1`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"<=": ({ execute, data, target, nid, ctx }) => {
|
"<=": ({ execute, data, target, nid, ctx }) => {
|
||||||
if (data.length != 3) argCount("<=",2,data.pos);
|
if (data.length != 3) argCount("<=",2,data.pos);
|
||||||
let param1 = execute({ data: data[1], target});
|
let param1 = execute({ data: data[1], target});
|
||||||
let param2 = execute({ data: data[2], target:target+1});
|
let param2 = execute({ data: data[2], target:target+1});
|
||||||
let outType = getOutType(param1.type,param2.type);
|
let outType = getOutType(param1.type,param2.type);
|
||||||
return {
|
return {
|
||||||
type: COMPUTE_TYPES.UINT,
|
type: COMPUTE_TYPES.UINT,
|
||||||
code: `${param1.code}
|
code: `${param1.code}
|
||||||
${convertType(param1.type, outType, target) }
|
${convertType(param1.type, outType, target) }
|
||||||
${param2.code}
|
${param2.code}
|
||||||
${convertType(param2.type, outType, target+1)}
|
${convertType(param2.type, outType, target+1)}
|
||||||
${ (["CMPU", "CMP", "FCMP"])[outType] } $${ target },$${ target },$${ target + 1 }
|
${ (["CMPU", "CMP", "FCMP"])[outType] } $${ target },$${ target },$${ target + 1 }
|
||||||
ZSNP $${target},$${target},1`
|
ZSNP $${target},$${target},1`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"=": ({ execute, data, target, nid, ctx }) => {
|
"=": ({ execute, data, target, nid, ctx }) => {
|
||||||
if (data.length != 3) argCount("=",2,data.pos);
|
if (data.length != 3) argCount("=",2,data.pos);
|
||||||
let param1 = execute({ data: data[1], target});
|
let param1 = execute({ data: data[1], target});
|
||||||
let param2 = execute({ data: data[2], target:target+1});
|
let param2 = execute({ data: data[2], target:target+1});
|
||||||
let outType = getOutType(param1.type,param2.type);
|
let outType = getOutType(param1.type,param2.type);
|
||||||
return {
|
return {
|
||||||
type: COMPUTE_TYPES.UINT,
|
type: COMPUTE_TYPES.UINT,
|
||||||
code: `${param1.code}
|
code: `${param1.code}
|
||||||
${convertType(param1.type, outType, target) }
|
${convertType(param1.type, outType, target) }
|
||||||
${param2.code}
|
${param2.code}
|
||||||
${convertType(param2.type, outType, target+1)}
|
${convertType(param2.type, outType, target+1)}
|
||||||
${ (["CMPU", "CMP", "FCMP"])[outType] } $${ target },$${ target },$${ target + 1 }
|
${ (["CMPU", "CMP", "FCMP"])[outType] } $${ target },$${ target },$${ target + 1 }
|
||||||
ZSZ $${target},$${target},1`
|
ZSZ $${target},$${target},1`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
">=": ({ execute, data, target, nid, ctx }) => {
|
">=": ({ execute, data, target, nid, ctx }) => {
|
||||||
if (data.length != 3) argCount(">=",2,data.pos);
|
if (data.length != 3) argCount(">=",2,data.pos);
|
||||||
let param1 = execute({ data: data[1], target});
|
let param1 = execute({ data: data[1], target});
|
||||||
let param2 = execute({ data: data[2], target:target+1});
|
let param2 = execute({ data: data[2], target:target+1});
|
||||||
let outType = getOutType(param1.type,param2.type);
|
let outType = getOutType(param1.type,param2.type);
|
||||||
return {
|
return {
|
||||||
type: COMPUTE_TYPES.UINT,
|
type: COMPUTE_TYPES.UINT,
|
||||||
code: `${param1.code}
|
code: `${param1.code}
|
||||||
${convertType(param1.type, outType, target) }
|
${convertType(param1.type, outType, target) }
|
||||||
${param2.code}
|
${param2.code}
|
||||||
${convertType(param2.type, outType, target+1)}
|
${convertType(param2.type, outType, target+1)}
|
||||||
${ (["CMPU", "CMP", "FCMP"])[outType] } $${ target },$${ target },$${ target + 1 }
|
${ (["CMPU", "CMP", "FCMP"])[outType] } $${ target },$${ target },$${ target + 1 }
|
||||||
ZSNN $${target},$${target},1`
|
ZSNN $${target},$${target},1`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
">": ({ execute, data, target, nid, ctx }) => {
|
">": ({ execute, data, target, nid, ctx }) => {
|
||||||
if (data.length != 3) argCount(">",2,data.pos);
|
if (data.length != 3) argCount(">",2,data.pos);
|
||||||
let param1 = execute({ data: data[1], target});
|
let param1 = execute({ data: data[1], target});
|
||||||
let param2 = execute({ data: data[2], target:target+1});
|
let param2 = execute({ data: data[2], target:target+1});
|
||||||
let outType = getOutType(param1.type,param2.type);
|
let outType = getOutType(param1.type,param2.type);
|
||||||
return {
|
return {
|
||||||
type: COMPUTE_TYPES.UINT,
|
type: COMPUTE_TYPES.UINT,
|
||||||
code: `${param1.code}
|
code: `${param1.code}
|
||||||
${convertType(param1.type, outType, target) }
|
${convertType(param1.type, outType, target) }
|
||||||
${param2.code}
|
${param2.code}
|
||||||
${convertType(param2.type, outType, target+1)}
|
${convertType(param2.type, outType, target+1)}
|
||||||
${ (["CMPU", "CMP", "FCMP"])[outType] } $${ target },$${ target },$${ target + 1 }
|
${ (["CMPU", "CMP", "FCMP"])[outType] } $${ target },$${ target },$${ target + 1 }
|
||||||
ZSP $${target},$${target},1`
|
ZSP $${target},$${target},1`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"!=": ({ execute, data, target, nid, ctx }) => {
|
"!=": ({ execute, data, target, nid, ctx }) => {
|
||||||
if (data.length != 3) argCount("!=",2,data.pos);
|
if (data.length != 3) argCount("!=",2,data.pos);
|
||||||
let param1 = execute({ data: data[1], target});
|
let param1 = execute({ data: data[1], target});
|
||||||
let param2 = execute({ data: data[2], target:target+1});
|
let param2 = execute({ data: data[2], target:target+1});
|
||||||
let outType = getOutType(param1.type,param2.type);
|
let outType = getOutType(param1.type,param2.type);
|
||||||
return {
|
return {
|
||||||
type: COMPUTE_TYPES.UINT,
|
type: COMPUTE_TYPES.UINT,
|
||||||
code: `${param1.code}
|
code: `${param1.code}
|
||||||
${convertType(param1.type, outType, target) }
|
${convertType(param1.type, outType, target) }
|
||||||
${param2.code}
|
${param2.code}
|
||||||
${convertType(param2.type, outType, target+1)}
|
${convertType(param2.type, outType, target+1)}
|
||||||
${ (["CMPU", "CMP", "FCMP"])[outType] } $${ target },$${ target },$${ target + 1 }
|
${ (["CMPU", "CMP", "FCMP"])[outType] } $${ target },$${ target },$${ target + 1 }
|
||||||
ZSNZ $${target},$${target},1`
|
ZSNZ $${target},$${target},1`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"!": ({ execute, data, target, nid, ctx }) => {
|
"!": ({ execute, data, target, nid, ctx }) => {
|
||||||
if (data.length != 2) argCount("!", 1, data.pos);
|
if (data.length != 2) argCount("!", 1, data.pos);
|
||||||
let param = execute({ data: data[1], target });
|
let param = execute({ data: data[1], target });
|
||||||
return {
|
return {
|
||||||
type: COMPUTE_TYPES.UINT,
|
type: COMPUTE_TYPES.UINT,
|
||||||
code: `${param.code}
|
code: `${param.code}
|
||||||
${(["CMPU", "CMP", "FCMP"])[param.type]} $${target},$${target},0
|
${(["CMPU", "CMP", "FCMP"])[param.type]} $${target},$${target},0
|
||||||
ZSZ $${target},$${target},1`
|
ZSZ $${target},$${target},1`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"!!": ({ execute, data, target, nid, ctx }) => {
|
"!!": ({ execute, data, target, nid, ctx }) => {
|
||||||
if (data.length != 2) argCount("!!", 1, data.pos);
|
if (data.length != 2) argCount("!!", 1, data.pos);
|
||||||
let param = execute({ data: data[1], target });
|
let param = execute({ data: data[1], target });
|
||||||
return {
|
return {
|
||||||
type: COMPUTE_TYPES.UINT,
|
type: COMPUTE_TYPES.UINT,
|
||||||
code: `${param.code}
|
code: `${param.code}
|
||||||
${(["CMPU", "CMP", "FCMP"])[param.type]} $${target},$${target},0
|
${(["CMPU", "CMP", "FCMP"])[param.type]} $${target},$${target},0
|
||||||
ZSNZ $${target},$${target},1`
|
ZSNZ $${target},$${target},1`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
|
@ -1,33 +1,91 @@
|
||||||
import { argsCount } from "../errors.js";
|
import { argsCount } from "../errors.js";
|
||||||
|
import { createType, error } from "../lexer.js";
|
||||||
|
|
||||||
export default {
|
|
||||||
progn: ({ execute, data, target, nid, ctx }) => {
|
export default {
|
||||||
if (data.length < 2) argsCount("progn", 1, data.pos);
|
progn: ({ execute, data, target, nid, ctx }) => {
|
||||||
let newctx = ctx.nextLevel();
|
if (data.length < 2) argsCount("progn", 1, data.pos);
|
||||||
return {
|
let newctx = ctx.nextLevel(false);
|
||||||
type: 0,
|
let content = data.array.slice(1).map(d => execute({ data: d, target: target, ctx: newctx }).code).join("\n")
|
||||||
code: `//new code Block
|
return {
|
||||||
${data.array.slice(1).map(d => execute({ data: d, target, ctx: newctx })).join("\n")}
|
type: 0,
|
||||||
//end Code Block`
|
code: `//new code Block
|
||||||
}
|
${content}
|
||||||
},
|
//end Code Block`
|
||||||
if: ({ execute, data, target, nid, ctx }) => {
|
}
|
||||||
if (data.length < 3) argsCount("if", 2, data.pos);
|
},
|
||||||
let condition = execute({ data: data[1], target });
|
defun: ({ execute, data, target, nid, ctx }) => {
|
||||||
let id1 = nid();
|
if(data.length < 5)argsCount("defun",4,...data[0].pos);
|
||||||
let id2 = nid();
|
let newctx = ctx.nextLevel(true);
|
||||||
return {
|
let type = ctx.getType(data[2]);
|
||||||
type: 0,
|
let [argType,argsList] = createType(data[3]);
|
||||||
code: `//if
|
if(argType!="code")error("The third Argument of defun must contain the args!",...data[3].pos);
|
||||||
${condition.code}
|
let args = [];
|
||||||
BZ $${target},else${id1}
|
if(argsList.length%2!=0)error("The Argument List must cotain an even amount of Names + Types",...data[3].pos);
|
||||||
${execute({ data: data[2] }).code}
|
for (let i = 0; i < argsList.length; i+=2) {
|
||||||
${data.length > 3 ? "JMP fi" + id2 : ""}
|
let name = argsList[i];
|
||||||
else${id1} SWYM
|
let type = ctx.getType(argsList[i+1]);
|
||||||
${data.length > 3 ? execute({ data: data[2] }).code : ""}
|
args.push(newctx.add({name,vType:"V",size:8,type:type.type}));
|
||||||
fi${id2} SWYM
|
|
||||||
`
|
}
|
||||||
}
|
|
||||||
},
|
let fun = ctx.addFunction({name:data[1],code:"",type,args:args});
|
||||||
|
|
||||||
|
let code = data.array.slice(4).map(l=>{
|
||||||
|
let {type,code} = execute({data:l,target:0,ctx:newctx});
|
||||||
|
return code;
|
||||||
|
}).join("\n");
|
||||||
|
|
||||||
|
fun.code = code;
|
||||||
|
fun.code += "\n POP 1,0";
|
||||||
|
|
||||||
|
return {
|
||||||
|
code:"",
|
||||||
|
type: 0
|
||||||
|
};
|
||||||
|
},
|
||||||
|
return:({ execute, data, target, nid, ctx })=>{
|
||||||
|
if(data.length == 1){
|
||||||
|
return {
|
||||||
|
type:0,
|
||||||
|
code:` POP 1,0
|
||||||
|
`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let {type,code} = execute({ data: data[1], target:0});
|
||||||
|
return {
|
||||||
|
type:0,
|
||||||
|
code:`
|
||||||
|
${code}
|
||||||
|
POP 1,0
|
||||||
|
`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
if: ({ execute, data, target, nid, ctx }) => {
|
||||||
|
if (data.length < 3) argsCount("if", 2, data.pos);
|
||||||
|
let condition = execute({ data: data[1], target });
|
||||||
|
let id1 = nid();
|
||||||
|
let id2 = nid();
|
||||||
|
if(data.length == 3){
|
||||||
|
return {
|
||||||
|
type: 0,
|
||||||
|
code: `//if
|
||||||
|
${condition.code}
|
||||||
|
BZ $${target},fi${id1}
|
||||||
|
${execute({ data: data[2],target }).code}
|
||||||
|
fi${id1} SWYM`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
type: 0,
|
||||||
|
code: `//if
|
||||||
|
${condition.code}
|
||||||
|
BZ $${target},else${id1}
|
||||||
|
${execute({ data: data[2],target }).code}
|
||||||
|
JMP fi${id2}
|
||||||
|
else${id1} SWYM
|
||||||
|
${data.length > 3 ? execute({ data: data[2],target }).code : ""}
|
||||||
|
fi${id2} SWYM`
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
|
@ -1,81 +1,155 @@
|
||||||
import { argsCount } from "../errors.js";
|
import { argCount, argsCount } from "../errors.js";
|
||||||
import { convertType, getOutType } from "../types.js"
|
import { error } from "../lexer.js";
|
||||||
|
import { convertType, getOutType } from "../types.js"
|
||||||
export default {
|
|
||||||
"+": ({ execute, data, target, nid, ctx }) => {
|
export default {
|
||||||
if (data.length < 3) argsCount("+",2,data.pos);
|
"+": ({ execute, data, target, nid, ctx }) => {
|
||||||
let params = data.array.slice(1).map((d, i) => execute({ data: d, target: target + (i ? 0 : 1) }));
|
if (data.length < 3) argsCount("+",2,data.pos);
|
||||||
let outType = getOutType(...params.map(d => d.type));
|
let params = data.array.slice(1).map((d, i) => execute({ data: d, target: target + (i==0 ? 0 : 1) }));
|
||||||
return {
|
let outType = getOutType(...params.map(d => d.type));
|
||||||
type: outType,
|
return {
|
||||||
code: params.map((d, i) => {
|
type: outType,
|
||||||
if (i == 0) return [
|
code: params.map((d, i) => {
|
||||||
d.code,
|
if (i == 0) return [
|
||||||
convertType(d.type, outType, target)
|
d.code,
|
||||||
];
|
convertType(d.type, outType, target)
|
||||||
return [
|
];
|
||||||
d.code,
|
return [
|
||||||
convertType(d.type, outType, target + 1),
|
d.code,
|
||||||
` ${(["ADDU", "ADD", "FADD"])[outType]} $${target},$${target},$${target + 1}`
|
convertType(d.type, outType, target + 1),
|
||||||
];
|
` ${(["ADDU", "ADD", "FADD"])[outType]} $${target},$${target},$${target + 1}`
|
||||||
}).flat(Infinity).join("\n")
|
];
|
||||||
}
|
}).flat(Infinity).join("\n")
|
||||||
},
|
}
|
||||||
"-": ({ execute, data, target, nid, ctx }) => {
|
},
|
||||||
if (data.length < 3) argsCount("-", 2, data.pos);
|
"-": ({ execute, data, target, nid, ctx }) => {
|
||||||
let params = data.array.slice(1).map((d, i) => execute({ data: d, target: target + (i ? 0 : 1) }));
|
if (data.length < 3) argsCount("-", 2, data.pos);
|
||||||
let outType = getOutType(...params.map(d => d.type));
|
let params = data.array.slice(1).map((d, i) => execute({ data: d, target: target + (i==0 ? 0 : 1) }));
|
||||||
return {
|
let outType = getOutType(...params.map(d => d.type));
|
||||||
type: outType,
|
return {
|
||||||
code: params.map((d, i) => {
|
type: outType,
|
||||||
if (i == 0) return [
|
code: params.map((d, i) => {
|
||||||
d.code,
|
if (i == 0) return [
|
||||||
convertType(d.type, outType, target)
|
d.code,
|
||||||
];
|
convertType(d.type, outType, target)
|
||||||
return [
|
];
|
||||||
d.code,
|
return [
|
||||||
convertType(d.type, outType, target + 1),
|
d.code,
|
||||||
` ${(["SUBU", "SUB", "FSUB"])[outType]} $${target},$${target},$${target + 1}`
|
convertType(d.type, outType, target + 1),
|
||||||
];
|
` ${(["SUBU", "SUB", "FSUB"])[outType]} $${target},$${target},$${target + 1}`
|
||||||
}).flat(Infinity).join("\n")
|
];
|
||||||
}
|
}).flat(Infinity).join("\n")
|
||||||
},
|
}
|
||||||
"*": ({ execute, data, target, nid, ctx }) => {
|
},
|
||||||
if (data.length < 3) argsCount("*", 2, data.pos);
|
"*": ({ execute, data, target, nid, ctx }) => {
|
||||||
let params = data.array.slice(1).map((d, i) => execute({ data: d, target: target + (i ? 0 : 1) }));
|
if (data.length < 3) argsCount("*", 2, data.pos);
|
||||||
let outType = getOutType(...params.map(d => d.type));
|
let params = data.array.slice(1).map((d, i) => execute({ data: d, target: target + (i==0 ? 0 : 1) }));
|
||||||
return {
|
let outType = getOutType(...params.map(d => d.type));
|
||||||
type: outType,
|
return {
|
||||||
code: params.map((d, i) => {
|
type: outType,
|
||||||
if (i == 0) return [
|
code: params.map((d, i) => {
|
||||||
d.code,
|
if (i == 0) return [
|
||||||
convertType(d.type, outType, target)
|
d.code,
|
||||||
];
|
convertType(d.type, outType, target)
|
||||||
return [
|
];
|
||||||
d.code,
|
return [
|
||||||
convertType(d.type, outType, target + 1),
|
d.code,
|
||||||
` ${(["MULU", "MUL", "FMUL"])[outType]} $${target},$${target},$${target + 1}`
|
convertType(d.type, outType, target + 1),
|
||||||
];
|
` ${(["MULU", "MUL", "FMUL"])[outType]} $${target},$${target},$${target + 1}`
|
||||||
}).flat(Infinity).join("\n")
|
];
|
||||||
}
|
}).flat(Infinity).join("\n")
|
||||||
},
|
}
|
||||||
"/": ({ execute, data, target, nid, ctx }) => {
|
},
|
||||||
if (data.length < 3) argsCount("/", 2, data.pos);
|
"/": ({ execute, data, target, nid, ctx }) => {
|
||||||
let params = data.array.slice(1).map((d, i) => execute({ data: d, target: target + (i ? 0 : 1) }));
|
if (data.length < 3) argsCount("/", 2, data.pos);
|
||||||
let outType = getOutType(...params.map(d => d.type));
|
let params = data.array.slice(1).map((d, i) => execute({ data: d, target: target + (i==0 ? 0 : 1) }));
|
||||||
return {
|
let outType = getOutType(...params.map(d => d.type));
|
||||||
type: outType,
|
return {
|
||||||
code: params.map((d, i) => {
|
type: outType,
|
||||||
if (i == 0) return [
|
code: params.map((d, i) => {
|
||||||
d.code,
|
if (i == 0) return [
|
||||||
convertType(d.type, outType, target)
|
d.code,
|
||||||
];
|
convertType(d.type, outType, target)
|
||||||
return [
|
];
|
||||||
d.code,
|
return [
|
||||||
convertType(d.type, outType, target + 1),
|
d.code,
|
||||||
` ${(["DIVU", "DIV", "FDIV"])[outType]} $${target},$${target},$${target + 1}`
|
convertType(d.type, outType, target + 1),
|
||||||
];
|
` ${(["DIVU", "DIV", "FDIV"])[outType]} $${target},$${target},$${target + 1}`
|
||||||
}).flat(Infinity).join("\n")
|
];
|
||||||
}
|
}).flat(Infinity).join("\n")
|
||||||
},
|
}
|
||||||
|
},
|
||||||
|
"round": ({ execute, data, target, nid, ctx }) => {
|
||||||
|
if (data.length < 2) argCount("round", 1, data.pos);
|
||||||
|
let param = execute({ data: data[1], target: target });
|
||||||
|
return {
|
||||||
|
type: 1,
|
||||||
|
code: `${param.code}
|
||||||
|
${convertType(param.type,2,target)}
|
||||||
|
FINT $${target}$${target}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sqrt": ({ execute, data, target, nid, ctx }) => {
|
||||||
|
if (data.length < 2) argCount("sqrt", 1, data.pos);
|
||||||
|
let param = execute({ data: data[1], target: target });
|
||||||
|
return {
|
||||||
|
type: 1,
|
||||||
|
code: `${param.code}
|
||||||
|
${convertType(param.type,2,target)}
|
||||||
|
FSQRT $${target}$${target}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"uint": ({ execute, data, target, nid, ctx }) => {
|
||||||
|
if (data.length < 2) argCount("int", 1, data.pos);
|
||||||
|
let param = execute({ data: data[1], target: target });
|
||||||
|
return {
|
||||||
|
type: 1,
|
||||||
|
code: `${param.code}
|
||||||
|
${convertType(param.type,0,target)}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"int": ({ execute, data, target, nid, ctx }) => {
|
||||||
|
if (data.length < 2) argCount("uint", 1, data.pos);
|
||||||
|
let param = execute({ data: data[1], target: target });
|
||||||
|
return {
|
||||||
|
type: 1,
|
||||||
|
code: `${param.code}
|
||||||
|
${convertType(param.type,1,target)}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"float": ({ execute, data, target, nid, ctx }) => {
|
||||||
|
if (data.length < 2) argCount("float", 1, data.pos);
|
||||||
|
let param = execute({ data: data[1], target: target });
|
||||||
|
return {
|
||||||
|
type: 1,
|
||||||
|
code: `${param.code}
|
||||||
|
${convertType(param.type,2,target)}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mod": ({ execute, data, target, nid, ctx }) => {
|
||||||
|
if (data.length < 3) argCount("mod", 2, data.pos);
|
||||||
|
let param1 = execute({ data: data[1], target });
|
||||||
|
let param2 = execute({ data: data[2], target: target+1 });
|
||||||
|
let outType = getOutType(param1.type,param2.type);
|
||||||
|
let code = `${param1.code}
|
||||||
|
${convertType(param1.type,outType,target)}
|
||||||
|
${param2.code}
|
||||||
|
${convertType(param2.type,outType,target+1)}
|
||||||
|
`;
|
||||||
|
if(outType == 0){
|
||||||
|
code+=` DIVU $${target},$${target},$${target+1}
|
||||||
|
GET $${target},rR`;
|
||||||
|
}else if(outType == 1){
|
||||||
|
code+=` DIV $${target},${target},$${target+1}
|
||||||
|
GET $${target},rR`;
|
||||||
|
}else if(outType == 2){
|
||||||
|
code+=` FREM $${target},$${target},$${target+1}`;
|
||||||
|
}else{
|
||||||
|
error("Unexpected Type: "+outType,...data[1].pos);
|
||||||
|
}
|
||||||
|
return{
|
||||||
|
type:outType,
|
||||||
|
code
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
|
@ -1,40 +1,47 @@
|
||||||
|
export default {
|
||||||
|
assm: ({ execute, data, target, nid, ctx }) => {
|
||||||
export default {
|
let cmds = data.array.slice(1, -1);
|
||||||
assm: ({ execute, data, target, nid, ctx }) => {
|
let type = data.array.slice(-1)[0];
|
||||||
let cmds = data.array.slice(1, -1);
|
return {
|
||||||
let type = data.array.slice(-1)[0];
|
code: "\n" + cmds.map(d => {
|
||||||
return {
|
let out = d.slice(1, -1);
|
||||||
code: "\n" + cmds.map(d => {
|
([["?7", 7], ["?6", 6], ["?5", 5], ["?4", 4], ["?3", 3], ["?2", 2], ["?1", 1], ["?0", 0]]).map(a => {
|
||||||
let out = d.slice(1, -1);
|
out = out.split(a[0]).join("$" + (target + a[1]));
|
||||||
([["?7", 7], ["?6", 6], ["?5", 5], ["?4", 4], ["?3", 3], ["?2", 2], ["?1", 1], ["?0", 0]]).map(a => {
|
});
|
||||||
out = out.split(a[0]).join("$" + (target + a[1]));
|
return out;
|
||||||
});
|
}).join("\n") + "\n",
|
||||||
return out;
|
type
|
||||||
}).join("\n") + "\n",
|
};
|
||||||
type
|
},
|
||||||
};
|
printRaw: ({ execute, data, target, nid, ctx }) => {
|
||||||
},
|
let { code, type } = execute({ data: data[1], target: target });
|
||||||
printRaw: ({ execute, data, target, nid, ctx }) => {
|
return {
|
||||||
let { code, type } = execute({ data: data[1], target: target });
|
code: `${code}
|
||||||
return {
|
SET $255,$${target}
|
||||||
code: `${code}
|
TRAP 0,Fputs,StdOut`,
|
||||||
SET $255,$${target}
|
type
|
||||||
TRAP 0,Fputs,StdOut`,
|
};
|
||||||
type
|
},
|
||||||
};
|
addr: ({ execute, data, target, nid, ctx }) => {
|
||||||
},
|
let nv = ctx.find(data[1], "V");
|
||||||
addr: ({ execute, data, target, nid, ctx }) => {
|
if(ctx.local){
|
||||||
let nv = ctx.find(data[1], "V");
|
return {
|
||||||
return {
|
code: ` LDOU $${target},HEAPpoint
|
||||||
code: ` LDA $${target},${nv.name}`,
|
SET $${target + 1},${nv.pos()}
|
||||||
type: 0
|
ADDU $${target},$${target},$${target + 1 }`,
|
||||||
};
|
type: 0
|
||||||
},
|
};
|
||||||
exit: () => {
|
|
||||||
return {
|
}
|
||||||
code: " TRAP 0,Halt,0",
|
return {
|
||||||
type: 0
|
code: ` LDA $${target},${nv.name}`,
|
||||||
}
|
type: 0
|
||||||
},
|
};
|
||||||
|
},
|
||||||
|
exit: () => {
|
||||||
|
return {
|
||||||
|
code: " TRAP 0,Halt,0",
|
||||||
|
type: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
|
@ -1,56 +1,113 @@
|
||||||
import { createType, error, LISPcmd } from "../lexer.js";
|
import { createType, error, LISPcmd } from "../lexer.js";
|
||||||
import { COMPUTE_TYPES, convertType } from "../types.js";
|
import { COMPUTE_TYPES, convertType } from "../types.js";
|
||||||
|
|
||||||
export default {
|
const vars = {
|
||||||
defvar: ({ execute, data, target, nid, ctx }) => {
|
defvar: ({ execute, data, target, nid, ctx }) => {
|
||||||
let param = data[3];
|
let param = data[3];
|
||||||
let [type, d] = createType(param);
|
let [type, d] = createType(param);
|
||||||
|
|
||||||
let varType = ctx.getType(data[2]);
|
let varType = ctx.getType(data[2]);
|
||||||
if (varType.content) error("A variable only can be created with a primitive Type.", ...data[2].pos);
|
if (varType.content) error("A variable only can be created with a primitive Type.", ...data[2].pos);
|
||||||
|
|
||||||
if (type == "var" || type == "code") {
|
if (type == "var" || type == "code" || ctx.local) {
|
||||||
error("devfar with input is not implemented yet.", ...param.pos)
|
ctx.add({ name: data[1], vType: "V", size: varType.size, amount: 1, type: varType.type, content: 0 });
|
||||||
} else {
|
let{code,type} = vars.set({execute,data:["set", data[1], data[3]],target,nid,ctx});
|
||||||
ctx.add({ name: data[1], vType: "V", size: varType.size, amount: 1, type: varType.type, content: param });
|
return {
|
||||||
return {
|
code: code,
|
||||||
code: "",
|
type: type
|
||||||
type: 0
|
}
|
||||||
}
|
} else {
|
||||||
}
|
let content = "0";
|
||||||
},
|
if(type == "num"){
|
||||||
set: ({ execute, data, target, nid, ctx }) => {
|
if(Number.isInteger(d)){
|
||||||
let toSet = ctx.find(data[1],"V");
|
content = d;
|
||||||
let { code, type } = execute({ data: data[2], target });
|
}else{
|
||||||
if(toSet.type == COMPUTE_TYPES.FLOAT){
|
var buf = new ArrayBuffer(8);
|
||||||
return {
|
(new Float64Array(buf))[0] = d;
|
||||||
code: `${code}
|
let ddd = (new Uint32Array(buf));
|
||||||
${convertType(type, toSet.type, target)}
|
content ="#";
|
||||||
${toSet.size > 4 ? "STOU" : "STSF"} $${target},${toSet.name}`,
|
content+=ddd[1].toString(16);
|
||||||
type: toSet.type
|
content+=ddd[0].toString(16);
|
||||||
};
|
}
|
||||||
|
}else{
|
||||||
}else{
|
content=param;
|
||||||
return {
|
}
|
||||||
code: `${code}
|
ctx.add({ name: data[1], vType: "V", size: varType.size, amount: 1, type: varType.type, content });
|
||||||
${convertType(type, toSet.type, target)}
|
|
||||||
ST${(["B", "W", "T", "T", "O", "O", "O", "O"])[toSet.size - 1]}${type == 0 ? "U" : ""} $${target},${toSet.name}`,
|
|
||||||
type: toSet.type
|
return {
|
||||||
};
|
code: "",
|
||||||
}
|
type: 0
|
||||||
|
}
|
||||||
},
|
}
|
||||||
defarr: ({ execute, data, target, nid, ctx }) => {
|
},
|
||||||
let param = data.array.slice(3, -1).map(d => Number(d));
|
set: ({ execute, data, target, nid, ctx }) => {
|
||||||
|
let toSet = ctx.find(data[1],"V");
|
||||||
let varType = ctx.getType(data[2]);
|
let { code, type } = execute({ data: data[2], target });
|
||||||
let amount = param.reduce((v, c) => v * c, 1);
|
if(ctx.local){
|
||||||
|
if (toSet.type == COMPUTE_TYPES.FLOAT) {
|
||||||
ctx.add({ name: data[1], vType:"V", size: varType.size, amount: amount, type: varType.type, config: param, content: data.array.slice(-1)[0] });
|
return {
|
||||||
|
code: `${code}
|
||||||
return {
|
${convertType(type, toSet.type, target)}
|
||||||
code: "",
|
LDOU $${target + 1},HEAPpoint
|
||||||
type: 0
|
SET $${target + 2},${toSet.pos()}
|
||||||
};
|
${toSet.size > 4 ? "STOU" : "STSF"} $${target},$${target+1},$${target + 2}`,
|
||||||
},
|
type: toSet.type
|
||||||
}
|
};
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
code: `${code}
|
||||||
|
${convertType(type, toSet.type, target)}
|
||||||
|
LDOU $${target + 1},HEAPpoint
|
||||||
|
SET $${target + 2},${toSet.pos()}
|
||||||
|
ST${("BWTTOOOO")[toSet.size - 1]}${toSet.type == 0 ? "U" : ""} $${target},$${target + 1},$${target + 2}`,
|
||||||
|
type: toSet.type
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if (toSet.type == COMPUTE_TYPES.FLOAT) {
|
||||||
|
return {
|
||||||
|
code: `${code}
|
||||||
|
${convertType(type, toSet.type, target)}
|
||||||
|
${toSet.size > 4 ? "STOU" : "STSF"} $${target},${toSet.name}`,
|
||||||
|
type: toSet.type
|
||||||
|
};
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
code: `${code}
|
||||||
|
${convertType(type, toSet.type, target)}
|
||||||
|
ST${("BWTTOOOO")[toSet.size - 1]}${toSet.type == 0 ? "U" : ""} $${target},${toSet.name}`,
|
||||||
|
type: toSet.type
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
defarr: ({ execute, data, target, nid, ctx }) => {
|
||||||
|
let param = data.array.slice(3, -1).map(d => Number(d));
|
||||||
|
|
||||||
|
let varType = ctx.getType(data[2]);
|
||||||
|
let amount = param.reduce((v, c) => v * c, 1);
|
||||||
|
|
||||||
|
ctx.add({ name: data[1], vType:"V", size: varType.size, amount: amount, type: varType.type, config: param, content: data.array.slice(-1)[0] });
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: "",
|
||||||
|
type: 0
|
||||||
|
};
|
||||||
|
},
|
||||||
|
readarr: ({ execute, data, target, nid, ctx })=>{
|
||||||
|
let arr = ctx.find(data[1],"V");
|
||||||
|
if (arr.config.length > data.length - 2) error(data[1] + " is a " + arr.config.length +"dim Array. You have to provide at least this much Arguments beside the Array name!",...data[1].pos);
|
||||||
|
let params = data.array.slice(2).map((d, i) => execute({ data: d, target: target }));
|
||||||
|
return{
|
||||||
|
code:`
|
||||||
|
|
||||||
|
`,
|
||||||
|
type:arr.type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default vars;
|
37
js/preprocessor.js
Normal file
37
js/preprocessor.js
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import * as path from "path";
|
||||||
|
|
||||||
|
function join(p1,p2){
|
||||||
|
if(p2.startsWith("/"))return p2;
|
||||||
|
return path.join(p1,"..",p2);
|
||||||
|
}
|
||||||
|
function unComment(str){
|
||||||
|
let out = "";
|
||||||
|
let inK = false;
|
||||||
|
for (let i = 0; i < str.length; i++) {
|
||||||
|
if(str[i] == "\\"){
|
||||||
|
out+=str[i+1]??"";
|
||||||
|
i+=2;
|
||||||
|
}else if(str[i] == "\""){
|
||||||
|
inK = !inK;
|
||||||
|
out += str[i];
|
||||||
|
}else if(str[i] == ";" || str[i] == " "){
|
||||||
|
if(inK)out += str[i];
|
||||||
|
else break;
|
||||||
|
}else{
|
||||||
|
out += str[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default (str,filename,readFile)=>str.split("\n").map(d=>d.trim()).map((l,i)=>{
|
||||||
|
if(!l.startsWith("#"))return l;
|
||||||
|
if(l.startsWith("#import")){
|
||||||
|
let toImport = unComment(l.substring(8).trim());
|
||||||
|
if(toImport.startsWith("\"") && toImport.startsWith("\"")){
|
||||||
|
return readFile(join(filename,toImport.slice(1,-1)),i);
|
||||||
|
}else{
|
||||||
|
return readFile("lisp/"+toImport+".lisp",i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).join("\n");
|
76
js/types.js
76
js/types.js
|
@ -1,38 +1,38 @@
|
||||||
import { error } from "./lexer.js";
|
import { error } from "./lexer.js";
|
||||||
|
|
||||||
export const COMPUTE_TYPES = {
|
export const COMPUTE_TYPES = {
|
||||||
UINT: 0,
|
UINT: 0,
|
||||||
INT: 1,
|
INT: 1,
|
||||||
FLOAT: 2
|
FLOAT: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getOutType = (...types)=>Math.max(...types);
|
export const getOutType = (...types)=>Math.max(...types);
|
||||||
|
|
||||||
export const convertType = (typein,typeout,reg) => {
|
export const convertType = (typein,typeout,reg) => {
|
||||||
if(typein == typeout) return "//no type conversion nessesary";
|
if(typein == typeout) return "//no type conversion nessesary";
|
||||||
if(typein == COMPUTE_TYPES.UINT && typeout == COMPUTE_TYPES.INT){
|
if(typein == COMPUTE_TYPES.UINT && typeout == COMPUTE_TYPES.INT){
|
||||||
return "//no type conversion nessesary (u -> i)";
|
return "//no type conversion nessesary (u -> i)";
|
||||||
}
|
}
|
||||||
if(typein == COMPUTE_TYPES.INT && typeout == COMPUTE_TYPES.UINT){
|
if(typein == COMPUTE_TYPES.INT && typeout == COMPUTE_TYPES.UINT){
|
||||||
return `SET $${reg + 1},#7fffffffffffffff
|
return ` LDOU $${reg + 1},intMask
|
||||||
AND $${reg},$${reg},$${reg + 1} convert i -> u`;
|
AND $${reg},$${reg},$${reg + 1} //convert i -> u`;
|
||||||
}
|
}
|
||||||
if(typein == COMPUTE_TYPES.INT && typeout == COMPUTE_TYPES.FLOAT){
|
if(typein == COMPUTE_TYPES.INT && typeout == COMPUTE_TYPES.FLOAT){
|
||||||
return ` FLOT $${reg},$${reg} convert i -> f`;
|
return ` FLOT $${reg},$${reg} //convert i -> f`;
|
||||||
}
|
}
|
||||||
if(typein == COMPUTE_TYPES.UINT && typeout == COMPUTE_TYPES.FLOAT){
|
if(typein == COMPUTE_TYPES.UINT && typeout == COMPUTE_TYPES.FLOAT){
|
||||||
return `SET $${reg + 1},#7fffffffffffffff
|
return ` LDOU $${reg + 1},intMask
|
||||||
AND $${reg},$${reg},$${reg + 1}
|
AND $${reg},$${reg},$${reg + 1}
|
||||||
FLOT $${reg},$${reg} convert i -> f`;
|
FLOT $${reg},$${reg} //convert u -> f`;
|
||||||
}
|
}
|
||||||
if(typein == COMPUTE_TYPES.FLOAT && typeout == COMPUTE_TYPES.INT){
|
if(typein == COMPUTE_TYPES.FLOAT && typeout == COMPUTE_TYPES.INT){
|
||||||
return ` FIX $${reg},$${reg} convert f -> i`;
|
return ` FIX $${reg},$${reg} //convert f -> i`;
|
||||||
}
|
}
|
||||||
if(typein == COMPUTE_TYPES.FLOAT && typeout == COMPUTE_TYPES.UINT){
|
if(typein == COMPUTE_TYPES.FLOAT && typeout == COMPUTE_TYPES.UINT){
|
||||||
return ` FLOT $${reg},$${reg} convert i -> f
|
return ` FIX $${reg},$${reg} //convert f -> u
|
||||||
SET $${reg + 1},#7fffffffffffffff
|
LDOU $${reg + 1},intMask
|
||||||
AND $${reg},$${reg},$${reg+1}`;
|
AND $${reg},$${reg},$${reg+1}`;
|
||||||
}
|
}
|
||||||
error("[System error] Could not find a possible Type conversion.")
|
error("[System error] Could not find a possible Type conversion. ("+typein+", "+typeout+")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
lisp/math.lisp
Normal file
3
lisp/math.lisp
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
(defvar pi:f64 3.14159265358979323846)
|
||||||
|
(defvar e:f64 2.71828182845904523536)
|
||||||
|
|
63
main.js
63
main.js
|
@ -1,27 +1,36 @@
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { context } from "./js/ctx.js";
|
import { context } from "./js/ctx.js";
|
||||||
import { execute } from "./js/execute.js";
|
import { execute } from "./js/execute.js";
|
||||||
import { LISPcmd, LISPstring, createType } from "./js/lexer.js";
|
import { LISPcmd, LISPstring, createType, error } from "./js/lexer.js";
|
||||||
var path = process.argv[2];
|
import preprocessor from "./js/preprocessor.js";
|
||||||
var pathout = process.argv[3];
|
var path = process.argv[2];
|
||||||
if (!path || !pathout) {
|
var pathout = process.argv[3];
|
||||||
console.log("PLease this Schema: node ToAs.js [path] [pathout]");
|
if (!path || !pathout) {
|
||||||
process.exit();
|
console.log("PLease this Schema: node ToAs.js [path] [pathout]");
|
||||||
}
|
process.exit();
|
||||||
var file = fs.readFileSync(path).toString();
|
}
|
||||||
|
var file = fs.readFileSync(path).toString();
|
||||||
var data = new LISPcmd("(\n" + file + "\n)", 0, 0);
|
|
||||||
|
let strcode = preprocessor(file,path,(path,line)=>{
|
||||||
|
try{
|
||||||
let code = "";
|
return fs.readFileSync(path).toString();
|
||||||
var ctx = new context();
|
}catch(_){
|
||||||
for (var i = 0; i < data.length; i++) {
|
error("Can not import file: "+path+" -> "+_, line, 0);
|
||||||
let { code: c, type } = execute({ data: data[i], ctx });
|
}
|
||||||
if(c=="")continue;
|
});
|
||||||
code += c+"\n";
|
var data = new LISPcmd("(\n" + strcode + "\n)", 0, 0);
|
||||||
}
|
|
||||||
|
|
||||||
let result = ctx.build();
|
let code = "";
|
||||||
result+=code;
|
var ctx = new context();
|
||||||
fs.writeFileSync(pathout, result);
|
for (var i = 0; i < data.length; i++) {
|
||||||
console.log(`Finished compiling in ${Math.round(performance.now()) / 1000}sec. Assembly saved to: ${pathout}`);
|
let { code: c, type } = execute({ data: data[i], ctx });
|
||||||
|
if(c=="")continue;
|
||||||
|
code += c+"\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = ctx.build();
|
||||||
|
result+=code;
|
||||||
|
result+=ctx.buildFunctions();
|
||||||
|
fs.writeFileSync(pathout, result);
|
||||||
|
console.log(`Finished compiling in ${Math.round(performance.now()) / 1000}sec. Assembly saved to: ${pathout}`);
|
||||||
|
|
60
package-lock.json
generated
60
package-lock.json
generated
|
@ -9,13 +9,44 @@
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fs": "^0.0.1-security"
|
"fs": "^0.0.1-security",
|
||||||
|
"path": "^0.12.7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/fs": {
|
"node_modules/fs": {
|
||||||
"version": "0.0.1-security",
|
"version": "0.0.1-security",
|
||||||
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
|
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
|
||||||
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
|
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
|
||||||
|
},
|
||||||
|
"node_modules/inherits": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw=="
|
||||||
|
},
|
||||||
|
"node_modules/path": {
|
||||||
|
"version": "0.12.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz",
|
||||||
|
"integrity": "sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==",
|
||||||
|
"dependencies": {
|
||||||
|
"process": "^0.11.1",
|
||||||
|
"util": "^0.10.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/process": {
|
||||||
|
"version": "0.11.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
|
||||||
|
"integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/util": {
|
||||||
|
"version": "0.10.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz",
|
||||||
|
"integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==",
|
||||||
|
"dependencies": {
|
||||||
|
"inherits": "2.0.3"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -23,6 +54,33 @@
|
||||||
"version": "0.0.1-security",
|
"version": "0.0.1-security",
|
||||||
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
|
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
|
||||||
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
|
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
|
||||||
|
},
|
||||||
|
"inherits": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw=="
|
||||||
|
},
|
||||||
|
"path": {
|
||||||
|
"version": "0.12.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz",
|
||||||
|
"integrity": "sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==",
|
||||||
|
"requires": {
|
||||||
|
"process": "^0.11.1",
|
||||||
|
"util": "^0.10.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"process": {
|
||||||
|
"version": "0.11.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
|
||||||
|
"integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A=="
|
||||||
|
},
|
||||||
|
"util": {
|
||||||
|
"version": "0.10.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz",
|
||||||
|
"integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==",
|
||||||
|
"requires": {
|
||||||
|
"inherits": "2.0.3"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"type":"module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"run": "node . test.lisp test.mms && mmixal test.mms && mmix test.mmo"
|
"run": "node . testfun.lisp testfun.mms && mmixal testfun.mms && mmix testfun.mmo"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
"author": "jusax23",
|
"author": "jusax23",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fs": "^0.0.1-security"
|
"fs": "^0.0.1-security",
|
||||||
|
"path": "^0.12.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue