]> code.bitgloo.com Git - bitgloo/alee-forth.git/commitdiff
fix execute; disable verify(); bench w/ standalone
authorClyne Sullivan <clyne@bitgloo.com>
Thu, 9 Nov 2023 13:08:38 +0000 (08:08 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Thu, 9 Nov 2023 13:08:38 +0000 (08:08 -0500)
alee-standalone.cpp
forth/fib.fth
libalee/corewords.cpp
libalee/state.hpp
splitmemdict.hpp

index 5681dbfea94d7455514e6d30ade92f31baa81307..0285701ece65271df37bb729e7dfbd263be54bcb 100644 (file)
@@ -20,6 +20,7 @@
 #include "splitmemdict.hpp"
 
 #include <charconv>
+#include <chrono>
 #include <fstream>
 #include <iostream>
 #include <vector>
@@ -83,6 +84,8 @@ static void load(State& state)
 
 void user_sys(State& state)
 {
+    static bool start = false;
+    static decltype(std::chrono::high_resolution_clock::now()) last;
     char buf[32] = {0};
 
     switch (state.pop()) {
@@ -103,6 +106,20 @@ void user_sys(State& state)
     case 4: // load
         load(state);
         break;
+    case 5: // time
+        if (!start) {
+            start = true;
+            last = std::chrono::high_resolution_clock::now();
+        } else {
+            start = false;
+            auto diff = std::chrono::duration_cast<std::chrono::microseconds>(
+                std::chrono::high_resolution_clock::now() - last);
+            state.push((Cell)diff.count());
+        }
+        break;
+    case 6: // double-add
+        { auto sum = state.popd() + state.popd(); state.pushd(sum); }
+        break;
     default:
         break;
     }
index 82c87cdb8d383149caf81e256c6b75a6f2d6e7e9..671528a486519f33125851e51715d45bf68c2056 100644 (file)
@@ -9,7 +9,7 @@
   5 sys fib 5 sys >r 2drop r> ;
 
 variable avg 0 avg !
-100 constant iters
+2000 constant iters
 
 : bench ( -- )
   iters 0 do 100 fibbench avg +! loop
index e323ed97b30965a89dfc0c31d4d16801ed48a21e..138ade4fb56e2c04c3c52bff0863ffdcd8a10d2e 100644 (file)
@@ -40,16 +40,17 @@ void find(State& state, Word word)
 void CoreWords::run(Cell ins, State& state)
 {
     DoubleCell dcell;
-    const Addr index = ins;
+    Addr index = ins;
     auto& ip = state.ip();
 
+execute:
     if (index >= Dictionary::Begin) {
         // must be calling a defined subroutine
         state.pushr(ip);
         ip = index;
         return;
     } else if (index >= WordCount) {
-        state.push(index - WordCount);
+        state.push(static_cast<Cell>(index - WordCount));
     } else switch (index) {
     case 0: // _lit
         state.push(state.beyondip());
@@ -148,11 +149,12 @@ void CoreWords::run(Cell ins, State& state)
         find(state, state.dict.input());
         break;
     case 24: // execute
-        ip = state.pop();
-        return;
+        index = state.pop();
+        goto execute;
     case 25: // exit
         ip = state.popr();
-        state.verify(ip != 0, Error::exit);
+        if (ip == 0)
+            state.exit();
         break;
     case 26: // semic
         state.dict.add(findi("exit"));
index 2e69463da0c41aadd66f9a217d0208232dbb494d..abf7a1e2944ef669be77ebb705ce4b88fa3f456d 100644 (file)
@@ -25,6 +25,8 @@
 #include <csetjmp>
 #include <cstddef>
 
+#define verify(C, E)
+
 constexpr unsigned DataStackSize = 64;
 constexpr unsigned ReturnStackSize = 64;
 
@@ -57,6 +59,10 @@ public:
      */
     void reset();
 
+    void exit() {
+        std::longjmp(context.jmpbuf, static_cast<int>(Error::exit));
+    }
+
     Addr& ip() noexcept {
         return context.ip;
     }
@@ -129,10 +135,10 @@ public:
         return dict.read(context.ip);
     }
 
-    inline void verify(bool condition, Error error) {
-        if (!condition)
-            std::longjmp(context.jmpbuf, static_cast<int>(error));
-    }
+//    inline void verify(bool condition, Error error) {
+//        if (!condition)
+//            std::longjmp(context.jmpbuf, static_cast<int>(error));
+//    }
 
 private:
     InputFunc inputfunc; // User-provided function to collect "stdin" input.
index 730d103ee44062d96f632b439feeeebaf8b8db87..73b20134af0295e4d0b7225a7ae6814dce1777ff 100644 (file)
@@ -36,7 +36,7 @@ class SplitMemDict : public Dictionary
     uint8_t extra[Dictionary::Begin];
 
     Addr convertAddress(Addr addr) const noexcept {
-        return addr < RON ? addr : static_cast<Addr>(addr - RON);
+        return static_cast<Addr>(addr - (addr >= RON) * RON);
     }
 
 public: