From b43d52bf2f0ce60265d597619ce783abe8b3d2ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86r=C3=BE?= <50090571+AlmiriQ@users.noreply.github.com> Date: Sat, 16 Apr 2022 01:22:30 +1000 Subject: [PATCH] Add files via upload --- device/rom.c | 10 ++++++---- faxm.lua | 10 +++++----- fraxinizator/fraCinize.lua | 5 +++++ fraxinizator/fraxevice.lua | 14 ++++++++++++++ fraxinizator/freeform.lua | 11 +++++++++++ fraxinizator/string.lua | 36 ++++++++++++++++++++++++++++++++++++ fraxinizator/ximplifier.lua | 9 +++++++++ livm.c | 2 +- main.c | 11 +++++++++++ main.faxm | 1 + out.fx | 2 +- 11 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 fraxinizator/fraCinize.lua create mode 100644 fraxinizator/fraxevice.lua create mode 100644 fraxinizator/freeform.lua create mode 100644 fraxinizator/string.lua create mode 100644 fraxinizator/ximplifier.lua diff --git a/device/rom.c b/device/rom.c index 1bcf29e..4630943 100644 --- a/device/rom.c +++ b/device/rom.c @@ -1,8 +1,8 @@ #define ROM vm->devices[2] void rom_write(struct VMinst* vm, void* data, uint64_t length) { - printf("rom_write was called. [%p, %p, %lu]", vm, data, length); - exit(-1); + if (length == 0) ((uint64_t*)ROM.buffer)[0] = (uint64_t)data; + else fwrite(data, sizeof(uint8_t), length, ((FILE**)(ROM.buffer))[1024 * 256 / 8 - 1 - ((uint64_t*)ROM.buffer)[0]]); } void rom_out(struct VMinst* vm) { @@ -11,10 +11,11 @@ void rom_out(struct VMinst* vm) { } void rom_read(struct VMinst* vm, void* buffer, uint64_t length, uint64_t where) { - + fread(buffer, sizeof(uint8_t), length, ((FILE**)(ROM.buffer))[1024 * 256 / 8 - 1 - ((uint64_t*)ROM.buffer)[0]]); } void rom_wait(struct VMinst* vm, uint64_t data) { + fseek(((FILE**)(ROM.buffer))[1024 * 256 / 8 - 1 - ((uint64_t*)ROM.buffer)[0]], data, SEEK_SET); } void rom_poweroff(struct VMinst* vm) { @@ -29,6 +30,7 @@ void rom_poweroff(struct VMinst* vm) { void setup_rom(struct VMinst* vm) { ROM.buffer = malloc(1024 * 256); + ((uint64_t*)ROM.buffer)[0] = 0; ROM.write = &rom_write; ROM.out = &rom_out; ROM.read = &rom_read; @@ -39,6 +41,6 @@ void setup_rom(struct VMinst* vm) { exit(-1); } for (int i = 0; i < DEV_ROM_COUNT; ++i) { - ((uint64_t**)ROM.buffer)[1024 * 32 - 8 + i] = (uint64_t*) fopen(dev_rom[i], "rb+"); + ((uint64_t**)ROM.buffer)[1024 * 256 / 8 - 1 - i] = (uint64_t*) fopen(dev_rom[i], "wb+"); } } diff --git a/faxm.lua b/faxm.lua index 3b286f1..3f2bc20 100644 --- a/faxm.lua +++ b/faxm.lua @@ -2,10 +2,10 @@ local date = require"date" local opcode = require"faxmopcode" local FX = { --require"faxm/fraCinize", - require"faxm/string", - require"faxm/ximplifier", - require"faxm/fraxevice", - require"faxm/freeform" + require"fraxinizator/string", + require"fraxinizator/ximplifier", + require"fraxinizator/fraxevice", + require"fraxinizator/freeform" } @@ -63,6 +63,7 @@ end function parseCode(source, code, data) for k, v in pairs(FX) do if v.source then source = v.source(source) end end + print(source) local dminsize, cminsize, xtype = -1, -1, "8u" local section, segment local objects = {} @@ -99,7 +100,6 @@ function parseCode(source, code, data) vdata = vdata:trim():gsub(",", " "):gsub("%s+", " ") for _, v in ipairs(vdata:split" ") do if v:sub(1, 1) == "|" then - for k, v_ in pairs(FX) do if v_.eval then v = v_.eval(v) end end v = v:sub(2) if v:sub(1, 1) == "x" then v = "0" .. v end v = load("return " .. v)() diff --git a/fraxinizator/fraCinize.lua b/fraxinizator/fraCinize.lua new file mode 100644 index 0000000..341051e --- /dev/null +++ b/fraxinizator/fraCinize.lua @@ -0,0 +1,5 @@ +return { + source = function(source) + return source + end +} \ No newline at end of file diff --git a/fraxinizator/fraxevice.lua b/fraxinizator/fraxevice.lua new file mode 100644 index 0000000..a293d85 --- /dev/null +++ b/fraxinizator/fraxevice.lua @@ -0,0 +1,14 @@ +return { + source = function(source) + source = source:gsub("(%s*)console%.print%s+(%S+%s+%S+);", "%1console.write %2;%1console.out;") + source = source:gsub("(%a+)%.write", "write ____%1") + source = source:gsub("(%a+)%.out", "out ____%1") + source = source:gsub("(%a+)%.wait", "wait ____%1") + source = source:gsub("(%a+)%.read", "read ____%1") + source = source:gsub("____clock", "|0") + source = source:gsub("____timer", "|0") + source = source:gsub("____console", "|1") + source = source:gsub("____rom", "|2") + return source + end +} \ No newline at end of file diff --git a/fraxinizator/freeform.lua b/fraxinizator/freeform.lua new file mode 100644 index 0000000..284353f --- /dev/null +++ b/fraxinizator/freeform.lua @@ -0,0 +1,11 @@ +return { + source = function(source) + return source:gsub("\n", "") + end, + any_line = function(line) + return line:trim():gsub("%s+", " "):gsub("%s+=%s+", "=") + end, + line = function(line) + return line:gsub(",", " "):gsub("%s+", " "):split" " + end +} \ No newline at end of file diff --git a/fraxinizator/string.lua b/fraxinizator/string.lua new file mode 100644 index 0000000..12777d9 --- /dev/null +++ b/fraxinizator/string.lua @@ -0,0 +1,36 @@ +return { + source = function(source) + local tl = {} + while source:match[[|"[^"]+"]] do + local s = source:match[[|"[^"]+"]] + local ss = s + s = s:sub(3, #s - 1) + local r = {} + for i = 0, math.floor(#s / 8) do + local t = s:sub(i * 8 + 1, (i + 1) * 8) + while #t < 8 do t = t .. "\0" end + t = {string.byte(t, 1, -1)} + local rt = {} + for i = 1, 8 do rt[9 - i] = t[i] end + for i = 1, 8 do rt[i] = string.format("%02x", rt[i]) end + if table.concat(rt, "") ~= "0000000000000000" then + r[#r + 1] = "|x" .. table.concat(rt, "") + end + end + if #(r[#r]:gsub("000", "")) == #(r[#r]) then + r[#r + 1] = "|x0000000000000000" + end + local function regexEscape(str) + return str:gsub("[%(%)%.%%%+%-%*%?%[%^%$%]]", "%%%1") + end + local tt = table.concat(r, ", ") + tl[tt] = #r + source = source:gsub(regexEscape(ss), tt) + end + source = source:gsub("(string%s+(%w+)%s?:(%s+)([|xa-f0-9, ]+)[^;])", function(found) + found = "object" .. found:sub(7) + return found .. " ? length=|" .. tostring(tl[found:gsub("object%s+%w+%s?:(%s+)", "")] * 8) + end) + return source + end +} \ No newline at end of file diff --git a/fraxinizator/ximplifier.lua b/fraxinizator/ximplifier.lua new file mode 100644 index 0000000..03b6ea3 --- /dev/null +++ b/fraxinizator/ximplifier.lua @@ -0,0 +1,9 @@ +return { + source = function(source) + source = source:gsub("%(([^)]+)%)", " %1") + source = source:gsub("([|%^#][%w.]+%s+)([a-z]+)", "%1;%2"):gsub(":", ":;") + source = source:gsub("object", ";object"):gsub("section", ";section"):gsub("%[", ";["):gsub("%]", "];") + source = source:gsub("(\n%s+);", ";%1"):gsub(";(%s+);", ";%1"):gsub("^;", "") + return source .. ";" + end +} \ No newline at end of file diff --git a/livm.c b/livm.c index fcb195b..fbedb52 100644 --- a/livm.c +++ b/livm.c @@ -30,7 +30,7 @@ struct VMinst { char* dev_rom[] = {"sda"}; #ifndef DEV_ROM_COUNT -# define DEV_ROM_COUNT 0 +# define DEV_ROM_COUNT 1 #endif #ifdef LIVMDEBUG diff --git a/main.c b/main.c index 3d54257..cac7c46 100644 --- a/main.c +++ b/main.c @@ -22,16 +22,27 @@ uint64_t str2u64(char* data) { int main() { + time_t t[5]; + t[0] = clock(); struct VMinst vm = createVM(512); // alloc 256 bytes uint64_t vmram[] = { // "proper" way to write out "Hello, LIVM!" #include "out.fx" }; + t[1] = clock(); loadRAM(&vm, vmram, sizeof vmram / sizeof(uint64_t)); + t[2] = clock(); //print_ullram(&vm); //uint64_t dt[] = {5485433203209299272, 7810728294139909705, 0}; //puts(((char*)dt)); runVM(&vm); + t[3] = clock(); //print_ullram(&vm); deleteVM(&vm); + t[4] = clock(); + printf("Full execution time: %d, %f\n", t[4] - t[0], (((double)t[4] - t[0])/((double)CLOCKS_PER_SEC))); + printf("Setup time: %d\n", t[1] - t[0]); + printf("Boot time: %d\n", t[2] - t[1]); + printf("Execution time: %d, %f\n", t[3] - t[2], (((double)t[3] - t[2])/((double)CLOCKS_PER_SEC))); + printf("Clean time: %d\n", t[4] - t[3]); return 0; } diff --git a/main.faxm b/main.faxm index 80574b8..e561842 100644 --- a/main.faxm +++ b/main.faxm @@ -5,4 +5,5 @@ string hellohell: |"hell-oh!"; section start: console.print(^helloworld, #helloworld.length) console.print(^hellohell, #hellohell.length) + rom.write ^hellohell, #hellohell.length poff \ No newline at end of file diff --git a/out.fx b/out.fx index 83a5fe5..2d8c44d 100644 --- a/out.fx +++ b/out.fx @@ -1 +1 @@ -8, 1, 6, 1, 1, 16, 8, 1004, 8031924123371070824, 6581362, 2407296241712784744, 0, 0, 0, 0, 0, 399, 3, 1, 0, 30, 400, 1, 1, 399, 3, 1, 2, 31, 400, 1, 1, 10, 0, 0, 0, 0, 0, 16, 16 \ No newline at end of file +8, 1, 6, 1, 1, 16, 8, 1004, 8031924123371070824, 6581362, 2407296241712784744, 0, 0, 0, 0, 0, 399, 3, 1, 0, 35, 400, 1, 1, 399, 3, 1, 2, 36, 400, 1, 1, 399, 3, 2, 2, 37, 10, 0, 0, 0, 0, 0, 16, 16, 16 \ No newline at end of file