diff options
39 files changed, 352 insertions, 495 deletions
@@ -1 +1,3 @@ *.o +/delete_me_pls +/luma @@ -1,25 +1,25 @@ -CXX=clang++ -CXXFLAGS=-Iinclude -D_ATFILE_SOURCE -D_FORTIFY_SOURCE=2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_ISOC99_SOURCE -D_ISOC11_SOURCE -D_ISOC2X_SOURCE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED -D__STDC_WANT_IEC_60559_BFP_EXT__ -D__STDC_WANT_IEC_60559_FUNCS_EXT__ -D__STDC_WANT_IEC_60559_TYPES_EXT__ -D__STDC_WANT_LIB_EXT2__=0x1 -ifneq ($(DEBUG),1) -CXXFLAGS += -DNDEBUG -endif -ifeq ($(LUMA__X),1) -CXXFLAGS += -DLUMA__X=true -endif -CXXFLAGS += -std=c++20 -Wall -Wextra -Wpedantic -CXXFLAGS += -march=native -mtune=native -O3 -LDFLAGS = -lfmt -lgmp -lmpfr -lpthread -lvulkan -lwayland-client -lxcb -HDRS_CXX = \ - include/luma.hh -SRCS_CXX = \ - src/main.cc \ - src/luma/luma.cc \ - src/luma/arghandl.cc -SRCS=$(SRCS_CXX) -OBJS=$(SRCS:.cc=.o) +CC = clang +CFLAGS = -std=c2x -Wall -Wextra -Wpedantic -I include -march=native -mtune=native -O3 +LDFLAGS = +SRCS = \ + src/luma/print.c \ + src/luma/utf8dec.c \ + src/luma/utf8enc.c \ + src/main.c +HDRS = \ + include/luma/arch.h \ + include/luma/print.h \ + include/luma/utf8dec.h \ + include/luma/utf8enc.h +OBJS = $(SRCS:.c=.o) luma: $(OBJS) - $(CXX) $(LDFLAGS) -o $@ $(OBJS) -$(OBJS): $(HDRS_CXX) $(SRCS_CXX) + $(CC) $(LDFLAGS) $^ -o $@ +.PHONY: run +run: luma + ./luma .PHONY: clean clean: + rm $(OBJS) +.PHONT: purge +purge: rm luma $(OBJS) @@ -1,7 +1,19 @@ -pkgname="luma" -pkgver=12 +# Maintainer: Gabriel Jensen +pkgname=luma +pkgver=19.0.0 pkgrel=1 -arch=('any') -license=('AGPL3') -depends=('gmp' 'libxcb' 'mpfr' 'wayland') -makedepends=('vulkan-headers') +pkgdesc="luma programming language - runtime environment" +arch=("any") +url="https://mandelbrot.dk/luma/luma" +license=("AGPL3") +makedepends=("git") +source=("git+https://mandelbrot.dk/luma/luma.git") +sha512sums=("SKIP") +build() { + cd "$srcdir/$pkgname" + make -j$(nproc) +} +package() { + cd "$srcdir/$pkgname" + make DESTDIR="$pkgdir/usr" install +} @@ -1,7 +1,19 @@ +# luma + +[*luma*](https://mandelbrot.dk/luma/luma) is a free and open-source programming language. + +## Copyright & License + +Copyright (c) 2021 Gabriel Jensen. + +All rights reserved. + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. + If not, see <https://www.gnu.org/licenses/>. diff --git a/changelog.html b/changelog.html deleted file mode 100644 index ce72472..0000000 --- a/changelog.html +++ /dev/null @@ -1,41 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="utf-8"> - </head> - <body> - <h1>14</h1> - <ul> - Compile "luma" instead of "luma.bin". - Get input file via arguments passed to executable. - </ul> - <h1>13</h1> - <ul> - <li>Reformat README.html to Markdown.</li> - </ul> - <h1>12</h1> - <ul> - <li>Add "changelog.html" to keep track of changes.</li> - <li>Remove deprecated gfx library files.</li> - <li>Fix PGKBUILD version not considering version 0.</li> - <li>Add new language example.</li> - <li>Begin rewrite of entire codebase.<\li> - <li>Move old codebase into the "old" folder.</li> - <li>Begin creation Luma stdlib API.</li> - <li>Build "luma.bin" file instead of "luma.elf".</li> - </ul> - <h1>11</h1> - <h1>↋</h1> - <h1>↊</h1> - <h1>9</h1> - <h1>8</h1> - <h1>7</h1> - <h1>6</h1> - <h1>5</h1> - <h1>4</h1> - <h1>3</h1> - <h1>2</h1> - <h1>1</h1> - <h1>0</h1> - </body> -</html> diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..cb530ae --- /dev/null +++ b/changelog.md @@ -0,0 +1,125 @@ +# 17 + +* Reformat changelog to Markdown. +* Completely rework codebase (multiple times, in 3 languages). Finally decide on C. +* Split project into three projects: *libluma* (API), *luma* (interpreter), and *luma-docs* (documentation). +* Merge with *libluma*. +* Create language sample. +* Use STDC functions instead of POSIX where possible. +* Create functions for decoding and encoding UTF-8. +* Don't include entire changelog in commit message. + +# 16 + +* Remove build artifacts. + +# 15 + +* Compile "luma" instead of "luma.bin". +* Get input file via arguments passed to executable. + +# 14 + +* Reformat README.html to Markdown. + +# 13 + +* Add "changelog.html" to keep track of changes. +* Remove deprecated gfx library files. +* Fix PGKBUILD version not considering version 0. +* Add new language example. +* Begin rewrite of entire codebase.<\li> +* Move old codebase into the "old" folder. +* Begin creation Luma stdlib API. +* Build "luma.bin" file instead of "luma.elf". + +# 12 + +* revert .gitignore styling +* reorganize source code structure in filesystem +* remove gfxlib in favour of language-bindings to underlying libraries +* adjust compiler optimization flags +* improve c++ stdlib replacement +* create cmd argument handler +* unite core functions in class with app data (replaces luma::dat) for easier access (no friends needed, "this->" instead of "luma::dat.") +* reformat README into HTML (temporary change, will be reformated again in later commit) + +# 11 + +* create the arch_t and kernel_t types +* use char const * instead of std::string +* use custom function instead of std::cerr and std::cout +* replace as many stdlib function with custom-made ones + +# 10 + +* redo .gitignore ifle +* clean up Makefile +* create PKGBUILD file +* create dedicated folder for language examples +* try to avoid macros where possible +* remove C relics +* create semi-working Vulkan test + +# ↋ + +* readd x support but only for non-linux systems (may change in the future) +* fix makefile cxxflags + +# ↊ + +* drop x support +* move codebase to c++ +* rework makefile +* create simple wayland demo + +# 9 + +* quick commit before dropping x support + +# 8 + +* create license file +* makefile optimizations +* added readme +* added stdc version checking +* x connection handling to a different file + +# 7 + +* make Makefile check for Makefile changes when linking not compiling + +# 6 + +* make Makefile check for Makefile changes when making +* make a gamble and enable -O3 + +# 5 + +* fix error when compiling crtwin.c +* make makefile super nice +* update .gitignore + +# 4 + +* change compiler to clang +* improve makefile +* create luma example file +* expanded stdlib + +# 3 + +* readd .gitignore + +# 2 + +* create makefile +* create simple xcb demo + +# 1 + +* create foundation for stdlib socket + +# 0 + +* first diff --git a/examples/example0.luma b/examples/example0.luma deleted file mode 100644 index 4e72a9a..0000000 --- a/examples/example0.luma +++ /dev/null @@ -1,12 +0,0 @@ -def fn /std/void [/std/int28 argc | /std/arr /std/str args] -noret main - ifeq argc #3 args.#1 “Hello” args.#2 “there!” - call /std/fout [“General Kenobi?” | $000A] - else - def var /std/int28 iter - loop @iter - ifeq iter #10 - brk - call /std/fout [“Luma FTW!” | $000A] - call /std/fout [“"Luma FTW!" should have been written 10 times.” | $000A] - exit #0 -X diff --git a/include/luma.hh b/include/luma.hh deleted file mode 100644 index ba7ad27..0000000 --- a/include/luma.hh +++ /dev/null @@ -1,13 +0,0 @@ -#if !defined(LUMA__HEADER) -# define LUMA__HEADER -# include <string> -using namespace std::literals::string_literals; -class luma { -public: - [[noreturn]] luma(int const argc,char const * * argv); - ~luma(); -private: - void arghandl(int const argc, char const * * argv); - std::basic_string<char> lumafile = ""s; -}; -# endif diff --git a/include/luma/arch.h b/include/luma/arch.h new file mode 100644 index 0000000..b929ce4 --- /dev/null +++ b/include/luma/arch.h @@ -0,0 +1,37 @@ +# if !defined(LUMA_HDR_ARCH) +# define LUMA_HDR_ARCH +enum luma_arch { + // Null + luma_arch_null, + // Keywords + luma_arch_lab, + luma_arch_next, + // Instructions + luma_arch_add, + luma_arch_call, + luma_arch_cp, + luma_arch_div, + luma_arch_ex, + luma_arch_fac, + luma_arch_get, + luma_arch_hello, + luma_arch_luma, + luma_arch_mult, + luma_arch_pow, + luma_arch_root, + luma_arch_sub, + // Numbers + luma_arch_zero, + luma_arch_one, + luma_arch_two, + luma_arch_three, + luma_arch_four, + luma_arch_five, + luma_arch_six, + luma_arch_seven, + luma_arch_eight, + luma_arch_nine, + luma_arch_dek, + luma_arch_el, +}; +# endif diff --git a/include/luma/print.h b/include/luma/print.h new file mode 100644 index 0000000..0105940 --- /dev/null +++ b/include/luma/print.h @@ -0,0 +1,5 @@ +# if !defined(LUMA_HDR_PRINT) +# define LUMA_HDR_PRINT +# include <uchar.h> +extern void luma_print(char * str,...); +# endif diff --git a/include/luma/utf8dec.h b/include/luma/utf8dec.h new file mode 100644 index 0000000..56ef640 --- /dev/null +++ b/include/luma/utf8dec.h @@ -0,0 +1,5 @@ +# if !defined(LUMA_HDR_UTF8DEC) +# define LUMA_HDR_UTF8DEC +# include <stdint.h> +extern uint32_t * luma_utf8enc(char const * str); +# endif diff --git a/include/luma/utf8enc.h b/include/luma/utf8enc.h new file mode 100644 index 0000000..8b9aa25 --- /dev/null +++ b/include/luma/utf8enc.h @@ -0,0 +1,5 @@ +# if !defined(LUMA_HDR_UTF8ENC) +# define LUMA_HDR_UTF8ENC +# include <stdint.h> +extern uint8_t const * luma_utf8enc(uint32_t * codep); +# endif @@ -0,0 +1,5 @@ +luma #0 +fn “main” #0 + gæt “std:print” + cɑll “std:print” “Hællo ðære!” + æx #0 diff --git a/old/include/luma/main.hh b/old/include/luma/main.hh deleted file mode 100644 index 1061e10..0000000 --- a/old/include/luma/main.hh +++ /dev/null @@ -1,87 +0,0 @@ -# if !defined(LUMA__HEADER__MAIN) -# define LUMA__HEADER__MAIN -# include <cstddef> -// constexpr -> const -> normal -// typedef -> enum class -> class -> operator -> variable -> function -namespace luma { - typedef decltype(nullptr) nullptr_t; // Official way to define nullptr_t - enum class arch_t { - aarch64, - amd64, - ia64, - ppc64, - unknown, - }; - enum class kernel_t { - darwinos, - dragonflybsd, - freebsd, - hurd, - linux, - minix, - netbsd, - openbsd, - unknown, - }; - class app_t { - public: - app_t(int const argc, char const * * argv); - ~app_t(); - private: - bool constexpr static debug = -# if defined(NDEBUG) - false; -# else - true; -# endif - luma::arch_t constexpr static arch = luma::arch_t:: -# if defined(__aarch64__) - aarch64; -# elif (defined(_M_AMD64) || defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(x86_64__)) - amd64; -# elif (defined(_IA64) defined(_M_IA64) || defined(__IA64__) || defined(__ia64__) || defined(__itanium__)) - ia64; -# elif (defined(_ARCH_PPC64) || defined(__powerpc64__) || defined(__PPC64__) || defined(__ppc64__)) - ppc64; -# else - unknown; -# endif - luma::kernel_t constexpr static kernel = luma::kernel_t:: -# if defined(__APPLE__) - darwinos; -# elif defined(__DragonFly__) - dragonflybsd; -# elif defined(__FreeBSD__) - freebsd; -# elif (defined(__GNU__) || defined(__gnu_hurd__)) - hurd; -# elif defined(__linux__) - linux; -# elif defined(__minix) - minix; -# elif defined(__NetBSD__) - netbsd; -# elif defined(__OpenBSD__) - openbsd; -# else - unknown; -# endif - int stderr = 0x0; - int stdout = 0x0; - char const * archstr(luma::arch_t arch) noexcept; - char const * getenv(char const * envvar); - char const * kernelstr(luma::kernel_t kernel) noexcept; - char const * strcut(char const * str,int pos,int len); - int strcmp(char const * lstr,char const * rstr) noexcept; - int strlen(char const * str) noexcept; - void arghandl(char const * arg); - void dbgmsgf(char const * msg); - [[noreturn]] void exit() noexcept; - //template<typename T,typename ... Args> - //void msgf(char const * msg, Args const & ... args); - void msgf(int pipe,char const * buf,std::size_t count); - void msgferr(char const * buf); - void msgfout(char const * buf); - }; -} -# endif diff --git a/old/src/luma/app_t/app_t.cc b/old/src/luma/app_t/app_t.cc deleted file mode 100644 index c650071..0000000 --- a/old/src/luma/app_t/app_t.cc +++ /dev/null @@ -1,95 +0,0 @@ -# include <fcntl.h> -# include <iostream> -# include <luma/main.hh> -# include <unistd.h> -luma::app_t::app_t(int const argc,char const * * argv) { - this->stderr = ::open("/dev/stderr",O_WRONLY); - this->stdout = ::open("/dev/stdout",O_WRONLY); - if(argc < 0x2) { - this->msgferr("Missing argument \"file\".\n"); - this->msgferr("Use \"--help\" for help.\n"); - this->exit(); - } - //else { - // for(int i = 0x0;i < argc;++i) { - // this->arghandl(argv[i]); - // } - //} - this->msgfout(this->archstr(this->arch)); - this->msgfout(this->kernelstr(this->kernel)); - if(!::access(argv[0x1],R_OK)) { - int lumafile = ::open(argv[0x1],O_RDONLY); - for(int line = 0x0,pos = 0x0;;++pos) { - char * tok; - ::read(lumafile,&tok,0x1); - this->msgfout("Here?\n"); - std::cout << line << ":" << pos << "=" << "\u000A"; - int pipe = ::open("/dev/stdout",O_WRONLY); - this->msgf(pipe,tok,0x4); - if(this->strcmp(tok,"\u000A") == 0x0) { - ++line; - } - else if(this->strcmp(tok,"\u0061") == 0x0) { - this->msgfout("\'a\' detected!"); - } - } - /* - char const * toks[] = { - "\u0009", // Horizontal Tabulation - "\u000A", // New Line (Nl) - "\u0020", // Space - "\u0023", // Number Sign - "\u0028", // Left Parenthesis - "\u0029", // Right Parenthesis - "\u002B", // Plus Sign - "\u003C", // Less-Than Sign - "\u003D", // Equals Sign - "\u003E", // Greater-Than Sign - "\u0061", // Latin Small Letter a - "\u0062", // Latin Small Letter b - "\u0063", // Latin Small Letter c - "\u0064", // Latin Small Letter d - "\u0065", // Latin Small Letter e - "\u0066", // Latin Small Letter f - "\u0067", // Latin Small Letter g - "\u0068", // Latin Small Letter h - "\u0069", // Latin Small Letter i - "\u006a", // Latin Small Letter j - "\u006B", // Latin Small Letter k - "\u006C", // Latin Small Letter l - "\u006D", // Latin Small Letter m - "\u006E", // Latin Small Letter n - "\u006F", // Latin Small Letter o - "\u0070", // Latin Small Letter p - "\u0071", // Latin Small Letter q - "\u0072", // Latin Small Letter r - "\u0073", // Latin Small Letter s - "\u0074", // Latin Small Letter t - "\u0075", // Latin Small Letter u - "\u0076", // Latin Small Letter v - "\u0077", // Latin Small Letter w - "\u0078", // Latin Small Letter x - "\u0079", // Latin Small Letter y - "\u007A", // Latin Small Letter z - "\u00D7", // Multiplication Sign - "\u00F7", // Division Sign - "\u201C", // Left Double Quotation Mark - "\u201D", // Right Double Quotation Mark - "\u218A", // Turned Digit Two - "\u218B", // Turned Digit Three - "\u2212", // Minus Sign - "\u2217", // Asterisk Operator - "\u2260", // Not Equal To - "\u2264", // Less-Than or Equal To - "\u2265", // Greater-Than or Equal To - }; - */ - } - else { - this->msgferr("The file doesn\'t exist.\n"); - this->exit(); - } -} -luma::app_t::~app_t() { - this->exit(); -} diff --git a/old/src/luma/app_t/archstr.cc b/old/src/luma/app_t/archstr.cc deleted file mode 100644 index 57b32dc..0000000 --- a/old/src/luma/app_t/archstr.cc +++ /dev/null @@ -1,22 +0,0 @@ -# include <luma/main.hh> -char const * luma::app_t::archstr(luma::arch_t arch) noexcept { - char const * str = ""; - switch(arch) { - default: - str = "Unknown"; - break; - case luma::arch_t::aarch64: - str = "ARM64/AArch64"; - break; - case luma::arch_t::amd64: - str = "AMD64/x86-64"; - break; - case luma::arch_t::ia64: - str = "IA-64"; - break; - case luma::arch_t::ppc64: - str = "PPC64"; - break; - } - return str; -} diff --git a/old/src/luma/app_t/arghandl.cc b/old/src/luma/app_t/arghandl.cc deleted file mode 100644 index 74a63ed..0000000 --- a/old/src/luma/app_t/arghandl.cc +++ /dev/null @@ -1,12 +0,0 @@ -# include <luma/main.hh> -void luma::app_t::arghandl(char const * arg) { - char const * appinf = "Luma ()"; - if(this->strcmp(arg,"--help")) { - this->msgfout("\n"); - this->exit(); - } - else if(this->strcmp(arg,"--version")) { - this->msgfout("\n"); - this->exit(); - } -} diff --git a/old/src/luma/app_t/dbgmsgf.cc b/old/src/luma/app_t/dbgmsgf.cc deleted file mode 100644 index fe0631c..0000000 --- a/old/src/luma/app_t/dbgmsgf.cc +++ /dev/null @@ -1,6 +0,0 @@ -# include <luma/main.hh> -void luma::app_t::dbgmsgf(char const * msg) { - if constexpr(debug) { - this->msgferr(msg); - } -} diff --git a/old/src/luma/app_t/exit.cc b/old/src/luma/app_t/exit.cc deleted file mode 100644 index 8a975e6..0000000 --- a/old/src/luma/app_t/exit.cc +++ /dev/null @@ -1,5 +0,0 @@ -# include <luma/main.hh> -# include <unistd.h> -[[noreturn]] void luma::app_t::exit() noexcept { - ::_exit(0x0); -} diff --git a/old/src/luma/app_t/getenv.cc b/old/src/luma/app_t/getenv.cc deleted file mode 100644 index 2c1b3f4..0000000 --- a/old/src/luma/app_t/getenv.cc +++ /dev/null @@ -1,13 +0,0 @@ -# include <luma/main.hh> -# include <unistd.h> -char const * luma::app_t::getenv(char const * envvar) { - /* - strlen = this->strlen(envvar); - for(char const * var : ::environ) { - if(this->strcmp(this->strcut(envvar,0x0,this->strlen(envvar),envvar) == 0x0) { - - } - } - */ - return "wayland"; -} diff --git a/old/src/luma/app_t/kernelstr.cc b/old/src/luma/app_t/kernelstr.cc deleted file mode 100644 index 9b326bd..0000000 --- a/old/src/luma/app_t/kernelstr.cc +++ /dev/null @@ -1,34 +0,0 @@ -# include <luma/main.hh> -char const * luma::app_t::kernelstr(luma::kernel_t kernel) noexcept { - char const * str = ""; - switch(kernel) { - default: - str = "Unknown"; - break; - case luma::kernel_t::darwinos: - str = "Dawin OS"; - break; - case luma::kernel_t::dragonflybsd: - str = "DragonFly BSD"; - break; - case luma::kernel_t::freebsd: - str = "FreeBSD"; - break; - case luma::kernel_t::hurd: - str = "Hurd"; - break; - case luma::kernel_t::linux: - str = "Linux"; - break; - case luma::kernel_t::minix: - str = "MINIX"; - break; - case luma::kernel_t::netbsd: - str = "NetBSD"; - break; - case luma::kernel_t::openbsd: - str = "OpenBSD"; - break; - } - return str; -} diff --git a/old/src/luma/app_t/msgf.cc b/old/src/luma/app_t/msgf.cc deleted file mode 100644 index cf61c98..0000000 --- a/old/src/luma/app_t/msgf.cc +++ /dev/null @@ -1,8 +0,0 @@ -# include <cstddef> -# include <luma/main.hh> -# include <unistd.h> -void luma::app_t::msgf(int pipe,char const * msg,std::size_t count) { - if(::write(pipe,msg,count) < 0x0) { - // ??? - } -} diff --git a/old/src/luma/app_t/msgferr.cc b/old/src/luma/app_t/msgferr.cc deleted file mode 100644 index f5bf60c..0000000 --- a/old/src/luma/app_t/msgferr.cc +++ /dev/null @@ -1,4 +0,0 @@ -# include <luma/main.hh> -void luma::app_t::msgferr(char const * msg) { - this->msgf(this->stderr,msg,this->strlen(msg)); -} diff --git a/old/src/luma/app_t/msgfout.cc b/old/src/luma/app_t/msgfout.cc deleted file mode 100644 index 3373d51..0000000 --- a/old/src/luma/app_t/msgfout.cc +++ /dev/null @@ -1,4 +0,0 @@ -# include <luma/main.hh> -void luma::app_t::msgfout(char const * msg) { - this->msgf(this->stdout,msg,this->strlen(msg)); -} diff --git a/old/src/luma/app_t/strcmp.cc b/old/src/luma/app_t/strcmp.cc deleted file mode 100644 index ce8e082..0000000 --- a/old/src/luma/app_t/strcmp.cc +++ /dev/null @@ -1,11 +0,0 @@ -# include <luma/main.hh> -int luma::app_t::strcmp(char const * lstr,char const * rstr) noexcept { - for(int i = 0x0;;++i) { - if(lstr[i] != rstr[i]) { - return lstr[i] < rstr[i] ? -0x1 : 0x1; - } - if(lstr[i] == '\0') { - return 0x0; - } - } -} diff --git a/old/src/luma/app_t/strcut.cc b/old/src/luma/app_t/strcut.cc deleted file mode 100644 index 233c47f..0000000 --- a/old/src/luma/app_t/strcut.cc +++ /dev/null @@ -1,25 +0,0 @@ -# include <luma/main.hh> -char const * luma::app_t::strcut(char const * str,int pos,int len) { - /* - if((this->strlen(str) - pos - len - 0x1) < 0x0) { // 0x1 counts null as well - // string too short - this->msgerr("String too short!\n"); - return nullptr; - } - else { - char * outstr = nullptr; - int outstrpos = 0x0; - this->msg("boys"); - for(int pos = 0x0;(pos < len);++pos) { - this->msg("diers"); - char chr = str[pos]; - this->msg("hallo"); - outstr[outstrpos] = chr; - ++outstrpos; - } - outstr[++outstrpos] = '\0'; - return outstr; - } - */ - return nullptr; -} diff --git a/old/src/luma/app_t/strlen.cc b/old/src/luma/app_t/strlen.cc deleted file mode 100644 index a4c9ba6..0000000 --- a/old/src/luma/app_t/strlen.cc +++ /dev/null @@ -1,8 +0,0 @@ -# include <luma/main.hh> -int luma::app_t::strlen(char const * str) noexcept { - int len = 0x0; - while(str[len] != '\0') { - ++len; - } - return len; -} diff --git a/old/src/main.cc b/old/src/main.cc deleted file mode 100644 index 7bca331..0000000 --- a/old/src/main.cc +++ /dev/null @@ -1,6 +0,0 @@ -# include <fcntl.h> -# include <luma/main.hh> -# include <unistd.h> -int main(int const argc,char const * * argv) { - luma::app_t app(argc,argv); -} diff --git a/src/luma/arghandl.cc b/src/luma/arghandl.cc deleted file mode 100644 index f9f08c0..0000000 --- a/src/luma/arghandl.cc +++ /dev/null @@ -1,12 +0,0 @@ -# include <cstdio> -# include <luma.hh> -# include <string> -using namespace std::literals::string_literals; -void luma::arghandl(int const argc,char const * * argv) { - for(int pos = 0x1;pos < argc; ++pos) { - std::string arg = argv[pos]; - if(pos == 0x1) { - this->lumafile = arg; - } - } -} diff --git a/src/luma/luma.cc b/src/luma/luma.cc deleted file mode 100644 index 5b72788..0000000 --- a/src/luma/luma.cc +++ /dev/null @@ -1,37 +0,0 @@ -# include <cstdio> -# include <cstdlib> -# include <luma.hh> -# include <fcntl.h> -# include <sys/stat.h> -# include <unistd.h> -[[noreturn]] luma::luma(int const argc,char const * * argv) { - this->arghandl(argc,argv); - std::printf("Will open \"%s\".\u000A",this->lumafile.c_str()); - int file = ::open(this->lumafile.c_str(),O_RDONLY); - char tok = '\0'; - char word[0x1000]; - int wordpos = 0x0; - struct ::stat fst; - ::fstat(file,&fst); - printf("Size of file is %ld characters.\u000A",fst.st_size); - ::sleep(0x1); - for(int filepos = 0x0;filepos < fst.st_size;++filepos) { - if(::read(file,&tok,0x1) < 0x0) { - std::printf("Error reading file.\u000A"); - ::_exit(EXIT_FAILURE); - } - if(tok == '\u000A' || tok == '\u0020') { - if(wordpos == 0x0) continue; - word[wordpos] = '\0'; - std::printf("The word is \"%s\".\u000A",word); - word[0x0] = '\0'; - wordpos = 0x0; - } - else { - word[wordpos] = tok; - std::printf("Got character '%c' and set word[%d] to it.\u000A",tok,wordpos); - ++wordpos; - } - } - ::_exit(EXIT_SUCCESS); -} diff --git a/src/luma/print.c b/src/luma/print.c new file mode 100644 index 0000000..df53d8a --- /dev/null +++ b/src/luma/print.c @@ -0,0 +1,16 @@ +# include <luma/utf8enc.h> +# include <stdio.h> +# include <string.h> +void luma_print([[maybe_unused]] char * str,...) { + /*for(size_t n = 0x0;;++n) { + if(str[n] == 0x0) { + fwrite(&(char){0xA},0x1,0x1,stdout); + break; + } + if(!strcmp(&str[n],"\uFFFD")) { + fwrite(&(char){0x20},0x1,0x1,stdout); + continue; + } + fwrite(&str[n],0x1,0x1,stdout); + }*/ +} diff --git a/src/luma/utf8dec.c b/src/luma/utf8dec.c new file mode 100644 index 0000000..35ef07e --- /dev/null +++ b/src/luma/utf8dec.c @@ -0,0 +1,8 @@ +# include <luma/utf8dec.h> +# include <stdint.h> +# include <stdlib.h> +uint32_t * luma_utf8dec([[maybe_unused]] char const * str) { + uint32_t * utf = malloc(0x4); + utf[0x0] = (uint32_t){0x0}; + return utf; +} diff --git a/src/luma/utf8enc.c b/src/luma/utf8enc.c new file mode 100644 index 0000000..cd1edff --- /dev/null +++ b/src/luma/utf8enc.c @@ -0,0 +1,61 @@ +# include <luma/utf8enc.h> +# include <stdint.h> +# include <stdio.h> +# include <stdlib.h> +uint8_t const * luma_utf8enc(uint32_t * codeps) { + size_t sz = (size_t){0x0}; // Size of input array (bytes). + size_t outsz = (size_t){0x0}; // Size of output array /bytes). + for(size_t n = (size_t){0x0};;n += (size_t){0x1}) { // First pass: get size of input array, and determine size of output array. + uint32_t codep = codeps[n]; // Current Unicode codepoint. + if(codep == (uint32_t){0x0}) { // U+0000 is Null. + sz = n; + break; + } + if(codep > 0x10FFFF) { // Codepoint out of range. + return NULL; + } + if(codep > 0xFFFF) { // 4 bytes. + outsz += (size_t){0x2}; + continue; + } + if(codep > 0x7FF) { // 3 bytes. + outsz += (size_t){0x3}; + continue; + } + if(codep > 0x7F) { // 2 bytes. + outsz += (size_t){0x2}; + continue; + } + // 1 byte. + outsz += (size_t){0x1}; + } + outsz += (size_t){0x1}; // Add space for null-terminator. + printf("There are %zu element(s).\n",sz); + printf("The output will have %zu element(s).\n",outsz); + uint8_t * outstr = malloc(outsz); // Allocate space for output array. + outstr[outsz - (size_t){0x1}] = (uint8_t){0x0}; // Create null-terminator on output array. + size_t outn = (size_t){0x0}; // Keep track of position in output array. + for(size_t n = (size_t){0x0};n < sz;n += (size_t){0x1}) { + uint32_t codep = codeps[n]; // Current Unicode codepoint. + if(codep > 0xFFFF) { + outstr[outn] = (uint8_t){0x3F}; + outn += (size_t){0x1}; + continue; + } + if(codep > 0x7FF) { + outstr[outn] = (uint8_t){0x3F}; + outn += (size_t){0x1}; + continue; + } + if(codep > 0x7F) { + outstr[outn] = (uint8_t){0xC0 + (codep >> 0x6)}; + outn += (size_t){0x1}; + outstr[outn] = (uint8_t){0x80 + ((uint8_t){codep << 0x2} >> 0x2)}; + outn += (size_t){0x1}; + continue; + } + outstr[outn] = codep; + outn += (size_t){0x1}; + } + return (uint8_t const *){outstr}; +} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..8f55eec --- /dev/null +++ b/src/main.c @@ -0,0 +1,32 @@ +# include <locale.h> +# include <luma/arch.h> +# include <luma/print.h> +# include <luma/utf8enc.h> +# include <stdint.h> +# include <stdio.h> +# include <stdlib.h> +int main(void) { + setlocale(LC_ALL,"en_GB.UTF-8"); + enum luma_arch code[] = { + luma_arch_lab, + luma_arch_hello, + }; + for(size_t i = (size_t){0x0};i < sizeof code / sizeof code[0x0];++i) { + printf("Got code %d.\n",code[i]); + } + uint8_t const * msg = luma_utf8enc((uint32_t[]){0x00A2,0x2C,0x20Ac,0x2C,0x218A,0x2C,0x1F44B,0x0}); + printf("%u\n",msg[0x0]); + printf("%u\n",msg[0x1]); + printf("%s\n",msg); + //uint32_t * utf = luma_utf8dec(msg); + free((void *)msg); + /*for(size_t n = (size_t){0x0};;n += (size_t){0x1}) { + if(utf[n] == (uint32_t){0x0}) { + break; + } + printf("%d\n",utf[n]); + } + free((void *)utf);*/ + //luma_print("Hello world. �👋"); + exit(EXIT_SUCCESS); +} diff --git a/src/main.cc b/src/main.cc deleted file mode 100644 index 5de90c4..0000000 --- a/src/main.cc +++ /dev/null @@ -1,4 +0,0 @@ -# include <luma.hh> -int main(int const argc,char const * * argv) { - ::luma luma(argc,argv); -} diff --git a/stdlib/std/fopen.luma b/stdlib/std/fopen.luma deleted file mode 100644 index 18079c6..0000000 --- a/stdlib/std/fopen.luma +++ /dev/null @@ -1 +0,0 @@ -def fn /std/file_t [/std/str_t | /std/fmode_t] fopen diff --git a/stdlib/std/fwrite.luma b/stdlib/std/fwrite.luma deleted file mode 100644 index 53df1ec..0000000 --- a/stdlib/std/fwrite.luma +++ /dev/null @@ -1 +0,0 @@ -def fn /std/void_t [/std/file_t | /std/str_t] fwrite diff --git a/stdlib/std/msgfout.luma b/stdlib/std/msgfout.luma deleted file mode 100644 index 7491677..0000000 --- a/stdlib/std/msgfout.luma +++ /dev/null @@ -1,2 +0,0 @@ -def fn /std/void_t [/str_t msg] /std/msgfout - call /std/fopen [] diff --git a/test.luma b/test.luma deleted file mode 100644 index da5ef03..0000000 --- a/test.luma +++ /dev/null @@ -1,5 +0,0 @@ -def var ./std/int num -cpy #0 .num -inc .num -mult .num #2 -pow .num #4 |