diff --git a/Depfile b/Depfile index 8429365..801703a 100644 --- a/Depfile +++ b/Depfile @@ -3,6 +3,13 @@ Artifact=kernel TempDir=obj SourceDir=asm src AdditionalObjects=obj/main.o +AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o +AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o +AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o +AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o +AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o +AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o +AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o LexUseCpp YaccUseCpp @@ -14,14 +21,14 @@ CXX=g++ LD=g++ LEX=flex YACC=bison -TEMPLE=mono /home/felix/projects/temple/bin/Debug/temple.exe +#TEMPLE=mono /home/felix/projects/temple/bin/Debug/temple.exe # Flags -FLAGS=-m32 -Dnullptr=0 -D__cdecl="__attribute__((cdecl))" -mno-sse -mno-sse2 -mno-mmx +FLAGS=-m32 -DCONDUCTANCE_64BIT -DCIRCUIT_OS -Dnullptr=0 -D__cdecl="__attribute__((cdecl))" -mno-sse -mno-sse2 -mno-mmx -I/home/felix/projects/Electronics/Electronics/Conductance -I/home/felix/projects/Electronics/Electronics/Tools ASFLAGS=-masm=intel CCFLAGS=-g -std=c11 -Dnullptr=0 -Wall -g -fno-stack-protector -ffreestanding -Iinclude CXXFLAGS=-g -std=c++11 -Wall -g -fno-stack-protector -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wall -Wextra -ffreestanding -Wno-unused-function -Iinclude -LDFLAGS=-g -m32 -nostdlib -fno-builtin -Tkernel.ld +LDFLAGS=-g -m32 -nostdlib -fno-builtin -Tkernel.ld -L/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/ -lConductance -- obj/main.o: scripts/main.ts diff --git a/Makefile b/Makefile index ec089eb..f7b4a5c 100644 --- a/Makefile +++ b/Makefile @@ -13,24 +13,24 @@ YACC = bison SRCS_AS = asm/dynamic.S asm/intr_common_handler.S asm/multiboot.S asm/start.S SRCS_CC = src/console.c src/init.c src/interrupts.c src/malloc.c src/pmm.c src/serial.c src/stdlib.c src/timer.c src/vmm.c SRCS_CXX = src/cplusplus.cpp src/cpp-test.cpp src/vm.cpp -OBJS = obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o +OBJS = obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o # Flags -FLAGS = -m32 -Dnullptr=0 -D__cdecl="__attribute__((cdecl))" -mno-sse -mno-sse2 -mno-mmx +FLAGS = -m32 -DCONDUCTANCE_64BIT -DCIRCUIT_OS -Dnullptr=0 -D__cdecl="__attribute__((cdecl))" -mno-sse -mno-sse2 -mno-mmx -I/home/felix/projects/Electronics/Electronics/Conductance -I/home/felix/projects/Electronics/Electronics/Tools ASFLAGS = -masm=intel CCFLAGS = -g -std=c11 -Dnullptr=0 -Wall -g -fno-stack-protector -ffreestanding -Iinclude CXXFLAGS = -g -std=c++11 -Wall -g -fno-stack-protector -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wall -Wextra -ffreestanding -Wno-unused-function -Iinclude -LDFLAGS = -g -m32 -nostdlib -fno-builtin -Tkernel.ld +LDFLAGS = -g -m32 -nostdlib -fno-builtin -Tkernel.ld -L/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/ -lConductance # Targets all: kernel .PHONY: clean clean: - $(RM) obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o + $(RM) obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o -kernel: obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o - $(LD) $(FLAGS) $(LDFLAGS) -o $@ obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o +kernel: obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o + $(LD) $(FLAGS) $(LDFLAGS) -o $@ obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o # src/console.c obj/console.o: src/console.c include/console.h include/stdlib.h \ @@ -91,8 +91,8 @@ obj/cplusplus.o: src/cplusplus.cpp include/stdlib.h include/varargs.h \ # src/cpp-test.cpp obj/cpp-test.o: src/cpp-test.cpp include/console.h include/ker/string.hpp \ include/stdlib.h include/varargs.h include/config.h include/malloc.h \ - include/ker/vector.hpp include/ker/new.hpp include/ker/dictionary.hpp \ - include/kernel.h include/ker/pair.hpp + include/string.h include/ker/vector.hpp include/ker/new.hpp \ + include/ker/dictionary.hpp include/kernel.h include/ker/pair.hpp $(CXX) $(FLAGS) $(CXXFLAGS) -o $@ -c src/cpp-test.cpp # src/vm.cpp diff --git a/include/ker/dictionary.hpp b/include/ker/dictionary.hpp index 268b29a..f7d4d88 100644 --- a/include/ker/dictionary.hpp +++ b/include/ker/dictionary.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "pair.hpp" #include "vector.hpp" @@ -22,6 +23,13 @@ namespace ker } + Dictionary(const std::initializer_list &items) + { + for(const Entry &entry : items) { + this->contents.append(entry); + } + } + Dictionary(const Dictionary &other) : contents(other.contents) { @@ -40,6 +48,14 @@ namespace ker return *this; } + size_t length() const { + return this->contents.length(); + } + + void clear() { + this->contents.clear(); + } + Value &at(const Key &key) { for(auto &&pair : this->contents) @@ -47,9 +63,8 @@ namespace ker if(pair.first == key) { return pair.second; } - } - die("Key not found in dictionary."); - return _default; + } + return this->add(key, Value()); } const Value &at(const Key &key) const @@ -85,18 +100,19 @@ namespace ker return false; } - void add(const Key &key, const Value &value) + Value &add(const Key &key, const Value &value) { if(this->contains(key)) { for(auto &&pair : this->contents) { if(pair.first == key) { pair.second = value; - return; + return pair.second; } } + return _default; } else { - this->contents.append(Entry(key, value)); + return this->contents.append(Entry(key, value)).second; } } diff --git a/include/ker/new.hpp b/include/ker/new.hpp index a901a60..88af82d 100644 --- a/include/ker/new.hpp +++ b/include/ker/new.hpp @@ -2,6 +2,8 @@ #include +#if defined(CIRCUIT_OS) + inline void* operator new(size_t, void* __p) { return __p; @@ -14,3 +16,5 @@ inline void* operator new[](size_t, void* __p) inline void operator delete (void*, void*) { } inline void operator delete[](void*, void*) { } + +#endif diff --git a/include/ker/string.hpp b/include/ker/string.hpp index cc4661f..5f775de 100644 --- a/include/ker/string.hpp +++ b/include/ker/string.hpp @@ -2,6 +2,12 @@ #include #include +#if !defined(CIRCUIT_OS) + #include + #include +#endif + +#define KER_STRING_AVAILABLE namespace ker { @@ -170,15 +176,21 @@ namespace ker itoa(number, buffer, radix); return String(buffer); } + + template + static String from(const T &) + { + return "Not implemented yet"; + } }; - static String operator + (const char *lhs, const String &rhs) + static inline String operator + (const char *lhs, const String &rhs) { return String::concat(lhs, rhs); } - static String operator + (const String &lhs, const char *rhs) + static inline String operator + (const String &lhs, const char *rhs) { return String::concat(lhs, rhs); } diff --git a/include/ker/vector.hpp b/include/ker/vector.hpp index 8e9510d..58bb5d2 100644 --- a/include/ker/vector.hpp +++ b/include/ker/vector.hpp @@ -1,8 +1,15 @@ #pragma once #include +#include +#include #include "new.hpp" +#if !defined(CIRCUIT_OS) +#include +#include +#endif + namespace ker { template @@ -96,6 +103,46 @@ namespace ker return this->mData[this->mLength - 1]; } + /** + * @brief Removes the last element. + */ + void pop() + { + if(this->length() > 0) { + this->resize(this->length() - 1); + } + } + + void clear() + { + this->resize(0); + } + + T& insert(size_t index, const T& value) + { + if(this->mReserved < (this->mLength + 1)) { + this->resize(this->mLength + 1); + } + for(int32_t i = this->mLength - 1; i > static_cast(index); i--) { + // Move every item backwards + this->mData[i+1] = this->mData[i]; + } + // then override + this->mData[index] = value; + return this->mData[index]; + } + + void remove(size_t index) + { + for(uint32_t i = index; i < this->mLength; i++) { + // Move every item backwards + this->mData[i] = this->mData[i+1]; + } + // then override + this->mData[this->mLength - 1].~T(); + this->mLength -= 1; + } + void resize(size_t size) { size_t current = this->mLength; @@ -141,6 +188,14 @@ namespace ker return this->at(idx); } + const T &front() const { + return this->mData[0]; + } + + const T &back() const { + return this->mData[this->mLength - 1]; + } + T* begin() { return &this->mData[0]; @@ -160,5 +215,10 @@ namespace ker { return &this->mData[this->mLength]; } + + const T *data() const + { + return &this->mData[0]; + } }; } diff --git a/src/vm.cpp b/src/vm.cpp index 5fd1c74..f00f685 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -3,12 +3,48 @@ #include #include +#include +#include +#include + extern "C" { extern const char mainscript_start; extern const char mainscript_end; extern const char mainscript_size; } +void printVMValue(const VMValue &value) +{ + switch(value.type().type()) { + case VMTypeType::Void: + kprintf("void"); + break; + case VMTypeType::Compound: + kprintf("compound"); + break; + case VMTypeType::Pointer: + kprintf("pointer"); + break; + case VMTypeType::Primitive: + { + VMText str = static_cast(value.type()).toString(value); + kprintf("%s", str.str()); + break; + } + default: + kprintf("???"); + break; + } +} + +ExceptionCode printArguments(VMValue &, const VMArray &args) +{ + for(const VMValue &arg : args) { + printVMValue(arg); + } + return ExceptionCode::None; +} + extern "C" void vm_start() { struct { @@ -19,8 +55,15 @@ extern "C" void vm_start() (uint32_t)&mainscript_size }; - (void)mainfile; + VirtualMachine vm; + vm.import("print") = printArguments; - kprintf("No implementation of Conductance here yet.\n"); + + while(vm.step()) + { + kprintf("."); + } + + kprintf("\n"); }