diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c5f939a --- /dev/null +++ b/.gitignore @@ -0,0 +1,135 @@ +./node_modules/ +./test.lisp +./test.mms +./test.mmo + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* \ No newline at end of file diff --git a/js/ctx.js b/js/ctx.js index e487a0e..b9b5d8f 100644 --- a/js/ctx.js +++ b/js/ctx.js @@ -1,7 +1,23 @@ +import { link } from "fs"; import { error } from "./lexer.js"; export class context{ #list = {}; + #types = { + u8: { size: 1,type: 0, content: false }, + u16: { size: 2,type: 0, content: false }, + u32: { size: 4,type: 0, content: false }, + u64: { size: 8,type: 0, content: false }, + i8: { size: 1,type: 1, content: false }, + i16: { size: 2,type: 1, content: false }, + i32: { size: 4,type: 1, content: false }, + i64: { size: 8,type: 1, content: false }, + f32: { size: 4,type: 2, content: false }, + f64: { size: 8,type: 2, content: false }, + char: {link:"u8"}, + bool: {link:"u8"}, + b: {link:"bool"}, + }; constructor(){ console.log("create"); } @@ -18,6 +34,16 @@ export class context{ if(!elem) error("Can not find '"+name+"' in context!"); return elem; } + + getType(name){ + let type; + do{ + if (type) type = this.#types[type.link] + else type = this.#types[name]; + }while(type.link); + return type; + } + build(){ let out = ` LOC Data_Segment diff --git a/js/nativefunc.js b/js/nativefunc.js index 77ec4d4..05e657f 100644 --- a/js/nativefunc.js +++ b/js/nativefunc.js @@ -2,8 +2,8 @@ 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)})); + "+": ({ 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, @@ -15,23 +15,56 @@ export default { return [ d.code, convertType(d.type, outType, target + 1), - ` ${(["ADDU","ADD","FADD"])[outType]} $${target},$${target},$${target+1}` + ` ${(["ADDU", "ADD", "FADD"])[outType]} $${target},$${target},$${target + 1}` ]; }).flat(Infinity).join("\n") } }, - defvar: ({ execute, data, target, nid, ctx })=>{ + "-": ({ 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 }) => { 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{ + let [type, d] = createType(param); - 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 }); + 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 }); return { - code:"", - type:0 + code: "", + type: 0 } } + }, + 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 + }; } } diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json deleted file mode 100644 index d6b9ba7..0000000 --- a/node_modules/.package-lock.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "lisptommix", - "version": "0.0.1", - "lockfileVersion": 2, - "requires": true, - "packages": { - "node_modules/fs": { - "version": "0.0.1-security", - "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", - "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" - } - } -} diff --git a/node_modules/fs/README.md b/node_modules/fs/README.md deleted file mode 100644 index 5e9a74c..0000000 --- a/node_modules/fs/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Security holding package - -This package name is not currently in use, but was formerly occupied -by another package. To avoid malicious use, npm is hanging on to the -package name, but loosely, and we'll probably give it to you if you -want it. - -You may adopt this package by contacting support@npmjs.com and -requesting the name. diff --git a/node_modules/fs/package.json b/node_modules/fs/package.json deleted file mode 100644 index 11661b0..0000000 --- a/node_modules/fs/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "fs", - "version": "0.0.1-security", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/npm/security-holder.git" - }, - "keywords": [], - "author": "", - "license": "ISC", - "bugs": { - "url": "https://github.com/npm/security-holder/issues" - }, - "homepage": "https://github.com/npm/security-holder#readme" -} diff --git a/test.lisp b/test.lisp deleted file mode 100644 index af30cc1..0000000 --- a/test.lisp +++ /dev/null @@ -1,2 +0,0 @@ -(defvar x:u16 5) -(+ 5 x) \ No newline at end of file diff --git a/test.mmo b/test.mmo deleted file mode 100644 index 40d5803..0000000 Binary files a/test.mmo and /dev/null differ diff --git a/test.mms b/test.mms deleted file mode 100644 index 658487e..0000000 --- a/test.mms +++ /dev/null @@ -1,11 +0,0 @@ - - LOC Data_Segment - GREG @ - -xV WYDE 5 - LOC #100 -Main SET $1,5 -//no type conversion nessesary - LDWU $0,xV -//no type conversion nessesary - ADDU $0,$0,$1 \ No newline at end of file