before stack
This commit is contained in:
parent
07c3d31d38
commit
51968d1f87
8 changed files with 328 additions and 458 deletions
10
Makefile
10
Makefile
|
|
@ -1,10 +1,10 @@
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CXX = g++
|
CXX = g++
|
||||||
|
|
||||||
CPPFLAGS = -g #-O3 -ffast-math
|
CPPFLAGS = -std=c++20 -g -Wall -Wextra -Wpedantic #-O3 -ffast-math
|
||||||
CFLAGS = -g #-O3 -ffast-math
|
CFLAGS = -g -Wall -Wextra -Wpedantic #-O3 -ffast-math
|
||||||
LDFLAGS = -g #-O3 -ffast-math
|
LDFLAGS = -g -Wall -Wextra -Wpedantic #-O3 -ffast-math
|
||||||
LDLIBS = -lfltk -lcurl -lfltk_images
|
LDLIBS =
|
||||||
|
|
||||||
|
|
||||||
SRC_DIR = src
|
SRC_DIR = src
|
||||||
|
|
@ -33,7 +33,7 @@ $(EXE): $(OBJ) | $(BIN_DIR)
|
||||||
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
|
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
|
||||||
|
|
||||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
|
||||||
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
|
||||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR)
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR)
|
||||||
|
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
#include <iostream>
|
|
||||||
#include "curlwrap.hpp"
|
|
||||||
|
|
||||||
#include <curl/curl.h>
|
|
||||||
#include <curl/easy.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
size_t writeback(char * ptr, size_t size, size_t nmemb, void * data) {
|
|
||||||
std::string* us = (std::string*) data;
|
|
||||||
|
|
||||||
us->append(ptr, nmemb);
|
|
||||||
|
|
||||||
return nmemb;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Curl::Curl() {
|
|
||||||
handle = curl_easy_init();
|
|
||||||
}
|
|
||||||
|
|
||||||
Curl::~Curl() {
|
|
||||||
if (handle) {
|
|
||||||
curl_easy_cleanup(handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Curl::seturl(std::string url) {
|
|
||||||
data = "";
|
|
||||||
curl_easy_setopt(handle, CURLOPT_URL, url.c_str());
|
|
||||||
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writeback);
|
|
||||||
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &data);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Curl::get() {
|
|
||||||
curl_easy_perform(handle);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
#ifndef CURLWRAP_HEADER
|
|
||||||
#define CURLWRAP_HEADER
|
|
||||||
|
|
||||||
|
|
||||||
#include <curl/curl.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
struct Curl {
|
|
||||||
CURL * handle;
|
|
||||||
std::string data;
|
|
||||||
Curl();
|
|
||||||
~Curl();
|
|
||||||
|
|
||||||
void seturl(std::string url);
|
|
||||||
|
|
||||||
std::string get();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
unsigned char icon_inspect_file_png[] = {
|
|
||||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
|
|
||||||
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30,
|
|
||||||
0x08, 0x03, 0x00, 0x00, 0x00, 0x60, 0xdc, 0x09, 0xb5, 0x00, 0x00, 0x00,
|
|
||||||
0x04, 0x67, 0x41, 0x4d, 0x41, 0x00, 0x00, 0xb1, 0x8f, 0x0b, 0xfc, 0x61,
|
|
||||||
0x05, 0x00, 0x00, 0x00, 0x20, 0x63, 0x48, 0x52, 0x4d, 0x00, 0x00, 0x7a,
|
|
||||||
0x26, 0x00, 0x00, 0x80, 0x84, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 0x80,
|
|
||||||
0xe8, 0x00, 0x00, 0x75, 0x30, 0x00, 0x00, 0xea, 0x60, 0x00, 0x00, 0x3a,
|
|
||||||
0x98, 0x00, 0x00, 0x17, 0x70, 0x9c, 0xba, 0x51, 0x3c, 0x00, 0x00, 0x00,
|
|
||||||
0x75, 0x50, 0x4c, 0x54, 0x45, 0x00, 0x00, 0x00, 0x77, 0x77, 0x77, 0x86,
|
|
||||||
0x86, 0x86, 0xff, 0xfb, 0xf0, 0x99, 0x99, 0x99, 0x55, 0x55, 0x55, 0xea,
|
|
||||||
0xea, 0xea, 0xcc, 0xcc, 0xcc, 0xd7, 0xd7, 0xd7, 0xe7, 0xe7, 0xd6, 0x99,
|
|
||||||
0xcc, 0xff, 0x99, 0x99, 0xcc, 0x5f, 0x5f, 0x5f, 0x99, 0xff, 0xff, 0xc0,
|
|
||||||
0xc0, 0xc0, 0xcc, 0xff, 0xff, 0xcc, 0xff, 0xcc, 0x66, 0xff, 0xff, 0x33,
|
|
||||||
0xff, 0xff, 0x4d, 0x4d, 0x4d, 0x33, 0x33, 0x33, 0xcc, 0xec, 0xff, 0x00,
|
|
||||||
0xff, 0xff, 0x11, 0x11, 0x11, 0x66, 0x66, 0x66, 0x1c, 0x1c, 0x1c, 0x22,
|
|
||||||
0x22, 0x22, 0xb2, 0xb2, 0xb2, 0x00, 0x66, 0xff, 0x00, 0x33, 0x99, 0x00,
|
|
||||||
0xcc, 0xff, 0x00, 0x99, 0xff, 0x00, 0x66, 0x99, 0x00, 0x33, 0xcc, 0x00,
|
|
||||||
0x00, 0x80, 0x00, 0x00, 0x66, 0x00, 0x00, 0xff, 0x00, 0x33, 0x66, 0xff,
|
|
||||||
0xff, 0xff, 0x1d, 0x20, 0xae, 0x06, 0x00, 0x00, 0x00, 0x01, 0x74, 0x52,
|
|
||||||
0x4e, 0x53, 0x00, 0x40, 0xe6, 0xd8, 0x66, 0x00, 0x00, 0x00, 0x01, 0x62,
|
|
||||||
0x4b, 0x47, 0x44, 0x26, 0x5a, 0x08, 0x98, 0xb5, 0x00, 0x00, 0x00, 0x07,
|
|
||||||
0x74, 0x49, 0x4d, 0x45, 0x07, 0xe2, 0x06, 0x1a, 0x00, 0x32, 0x12, 0x39,
|
|
||||||
0x75, 0x77, 0x4b, 0x00, 0x00, 0x01, 0x74, 0x49, 0x44, 0x41, 0x54, 0x48,
|
|
||||||
0xc7, 0xed, 0xd4, 0xcb, 0x56, 0x83, 0x30, 0x14, 0x05, 0xd0, 0x86, 0xbc,
|
|
||||||
0x9a, 0x94, 0x90, 0x04, 0x0a, 0x56, 0x05, 0x5b, 0xad, 0xfe, 0xff, 0x2f,
|
|
||||||
0x7a, 0x6f, 0x12, 0xa4, 0xba, 0xc2, 0xa3, 0x13, 0x97, 0x03, 0xcf, 0xa4,
|
|
||||||
0x0c, 0xd8, 0xdc, 0x93, 0x90, 0xb2, 0xdb, 0xfd, 0xe7, 0x4f, 0x86, 0x14,
|
|
||||||
0x3f, 0xb2, 0x0a, 0xe8, 0xf7, 0x30, 0x7e, 0x2f, 0x58, 0x13, 0x44, 0x40,
|
|
||||||
0x6e, 0x81, 0x5c, 0x12, 0x24, 0x66, 0x2f, 0xd4, 0x04, 0xd4, 0xbc, 0x20,
|
|
||||||
0x44, 0x63, 0x0e, 0x84, 0x97, 0xfb, 0xaf, 0x29, 0x8c, 0xce, 0x0a, 0xa2,
|
|
||||||
0x4d, 0xa5, 0xac, 0x71, 0xd6, 0xeb, 0xb2, 0x94, 0xe3, 0x10, 0x46, 0xe7,
|
|
||||||
0x04, 0xd1, 0xd6, 0x02, 0xb0, 0x35, 0x44, 0x97, 0x5c, 0x4a, 0xa5, 0xd0,
|
|
||||||
0xf0, 0xe6, 0x88, 0xc9, 0x01, 0xab, 0x00, 0x38, 0xcb, 0x30, 0x30, 0x83,
|
|
||||||
0xc3, 0x0f, 0x00, 0x21, 0x2b, 0xc6, 0x08, 0xcf, 0x0f, 0xa0, 0x38, 0xc1,
|
|
||||||
0x8a, 0xd6, 0xfb, 0x4e, 0x97, 0x4c, 0xc6, 0x75, 0x04, 0x91, 0x03, 0x86,
|
|
||||||
0x0a, 0x04, 0xae, 0x0e, 0xd1, 0x1c, 0x40, 0x5c, 0x05, 0x8a, 0x3c, 0xa0,
|
|
||||||
0x61, 0x42, 0xa8, 0xc4, 0x24, 0x4c, 0x50, 0x31, 0x28, 0xf2, 0x00, 0x2b,
|
|
||||||
0x39, 0x6b, 0x5b, 0x67, 0x3c, 0x6c, 0x14, 0x67, 0x29, 0x38, 0x23, 0x0b,
|
|
||||||
0x84, 0x15, 0xe3, 0x2e, 0xe1, 0x3e, 0xe1, 0x1a, 0x44, 0x7a, 0xed, 0x59,
|
|
||||||
0xe0, 0x8d, 0x68, 0x71, 0x0d, 0xa9, 0x52, 0x33, 0x55, 0x9a, 0x01, 0xda,
|
|
||||||
0xb7, 0x0e, 0x27, 0x38, 0x67, 0x3a, 0xd8, 0xa5, 0xa6, 0x99, 0x2a, 0x65,
|
|
||||||
0x01, 0x8c, 0xf0, 0xf8, 0x1e, 0x4c, 0x68, 0xd4, 0x15, 0x4d, 0xb5, 0x52,
|
|
||||||
0x09, 0x46, 0xd4, 0xbe, 0x52, 0xc6, 0x87, 0xa7, 0x16, 0x0f, 0xc5, 0xd8,
|
|
||||||
0x68, 0xae, 0x12, 0x0a, 0x5d, 0xa9, 0xda, 0x77, 0x90, 0x02, 0x0e, 0x43,
|
|
||||||
0x33, 0xfe, 0xf7, 0x66, 0x01, 0x9c, 0xd6, 0x43, 0x38, 0xae, 0x92, 0x1c,
|
|
||||||
0x19, 0x3b, 0x1d, 0x61, 0xc6, 0x62, 0xa5, 0x48, 0xc8, 0x23, 0xe4, 0x89,
|
|
||||||
0xd1, 0xe7, 0x53, 0x3f, 0xa4, 0x56, 0x4b, 0x00, 0x8d, 0x84, 0x10, 0x75,
|
|
||||||
0x7a, 0x39, 0xf7, 0x43, 0xb3, 0x52, 0x29, 0x82, 0xf0, 0xd4, 0x4b, 0xdf,
|
|
||||||
0xa1, 0x08, 0xad, 0xd6, 0x00, 0x0d, 0xc5, 0x2f, 0x67, 0x14, 0xaf, 0x20,
|
|
||||||
0xe8, 0x2a, 0x88, 0x89, 0x62, 0x88, 0x62, 0x0b, 0x48, 0xe2, 0x2d, 0x88,
|
|
||||||
0x4d, 0x20, 0x89, 0x2b, 0x8a, 0x6d, 0x60, 0x12, 0xeb, 0xdb, 0x9a, 0x32,
|
|
||||||
0x44, 0xc1, 0x16, 0xbf, 0x7e, 0x84, 0xdf, 0x04, 0x45, 0x7f, 0xc5, 0xab,
|
|
||||||
0xdd, 0xc6, 0x0c, 0xe7, 0xfe, 0xfd, 0x63, 0xeb, 0xcd, 0x51, 0x0c, 0xc3,
|
|
||||||
0x5d, 0xf7, 0xff, 0xe7, 0x97, 0xf2, 0x09, 0x81, 0xc5, 0x1c, 0x78, 0xc0,
|
|
||||||
0x82, 0x16, 0xc0, 0x00, 0x00, 0x00, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64,
|
|
||||||
0x61, 0x74, 0x65, 0x3a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x00, 0x32,
|
|
||||||
0x30, 0x31, 0x38, 0x2d, 0x30, 0x36, 0x2d, 0x32, 0x36, 0x54, 0x30, 0x30,
|
|
||||||
0x3a, 0x35, 0x30, 0x3a, 0x31, 0x38, 0x2d, 0x30, 0x34, 0x3a, 0x30, 0x30,
|
|
||||||
0x0e, 0x62, 0x1d, 0x0e, 0x00, 0x00, 0x00, 0x25, 0x74, 0x45, 0x58, 0x74,
|
|
||||||
0x64, 0x61, 0x74, 0x65, 0x3a, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x00,
|
|
||||||
0x32, 0x30, 0x31, 0x38, 0x2d, 0x30, 0x36, 0x2d, 0x32, 0x36, 0x54, 0x30,
|
|
||||||
0x30, 0x3a, 0x35, 0x30, 0x3a, 0x31, 0x38, 0x2d, 0x30, 0x34, 0x3a, 0x30,
|
|
||||||
0x30, 0x7f, 0x3f, 0xa5, 0xb2, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e,
|
|
||||||
0x44, 0xae, 0x42, 0x60, 0x82
|
|
||||||
};
|
|
||||||
unsigned int icon_inspect_file_png_len = 761;
|
|
||||||
11
src/images.h
11
src/images.h
|
|
@ -1,11 +0,0 @@
|
||||||
#ifndef IMAGES_H
|
|
||||||
#define IMAGES_H
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
extern unsigned char icon_inspect_file_png[];
|
|
||||||
extern size_t icon_inspect_file_png_len;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
578
src/main.cpp
578
src/main.cpp
|
|
@ -1,289 +1,365 @@
|
||||||
#include <FL/Enumerations.H>
|
#include <cassert>
|
||||||
#include <FL/Fl_Group.H>
|
|
||||||
#include <FL/Fl_Widget.H>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <istream>
|
||||||
#include "curlwrap.hpp"
|
|
||||||
#include "images.h"
|
|
||||||
#include "summarymanager.hpp"
|
|
||||||
#include "testcpp.hpp"
|
|
||||||
|
|
||||||
#include <FL/Fl.H>
|
|
||||||
#include <FL/Fl_Box.H>
|
|
||||||
#include <FL/Fl_Button.H>
|
|
||||||
#include <FL/Fl_Flex.H>
|
|
||||||
#include <FL/Fl_Multi_Browser.H>
|
|
||||||
#include <FL/Fl_PNG_Image.H>
|
|
||||||
#include <FL/Fl_Tile.H>
|
|
||||||
#include <FL/Fl_Window.H>
|
|
||||||
#include <FL/fl_ask.H>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
struct Data {
|
||||||
|
virtual ~Data() {}
|
||||||
|
};
|
||||||
|
|
||||||
struct Person {
|
struct SelfEval : Data {
|
||||||
std::string year;
|
virtual ~SelfEval() {}
|
||||||
std::string name;
|
};
|
||||||
|
|
||||||
Person(std::string &y, std::string &n) : year(y), name(n) {}
|
struct Applyable : Data {
|
||||||
std::string toString() const {
|
virtual ~Applyable() {}
|
||||||
return "{(Person): " + year + ", " + name + "}";
|
};
|
||||||
|
|
||||||
|
struct Cell {
|
||||||
|
Data *d;
|
||||||
|
size_t cdr = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Env {
|
||||||
|
std::unordered_set<std::string> builtin;
|
||||||
|
std::unordered_map<std::string, size_t> userdef;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Symbol : Data{
|
||||||
|
std::string data;
|
||||||
|
std::string Get() {
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, const Person &e) {
|
struct String : SelfEval {
|
||||||
// os << "{(Person): " << e.year << ", " << e.name << "}";
|
std::string data;
|
||||||
os << e.toString();
|
std::string Get() {
|
||||||
return os;
|
return data;
|
||||||
}
|
|
||||||
|
|
||||||
struct BasicEntry {
|
|
||||||
Person A;
|
|
||||||
Person B;
|
|
||||||
|
|
||||||
std::string matchlink;
|
|
||||||
|
|
||||||
int Apercent;
|
|
||||||
int Bpercent;
|
|
||||||
|
|
||||||
std::string toString() const {
|
|
||||||
return "{(BasicEntry): " + A.toString() + ", " + B.toString() + ", " + matchlink + +", " +
|
|
||||||
std::to_string(Apercent) + "%, " + std::to_string(Bpercent) + "%}";
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
std::ostream &operator<<(std::ostream &os, const BasicEntry &e) {
|
|
||||||
// os << "{(BasicEntry): " << e.A << ", " << e.B << ", " << e.matchlink << "}";
|
|
||||||
os << e.toString();
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Selected {
|
struct Number : SelfEval {
|
||||||
Fl_Multi_Browser &browser;
|
int data;
|
||||||
Selected(Fl_Multi_Browser &browser_in) : browser(browser_in) {}
|
int Get() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void show_callback(Fl_Widget *w, void *data) {
|
struct Fork : Data {
|
||||||
Selected *rdata = (Selected *)data;
|
size_t data;
|
||||||
|
size_t Get() {
|
||||||
auto s = rdata->browser.size() + 1;
|
return data;
|
||||||
|
|
||||||
for (size_t i = 0; i < s; i++) {
|
|
||||||
if (rdata->browser.selected(i)) {
|
|
||||||
fl_alert("%s", rdata->browser.text(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Lambda : Data {
|
||||||
|
Env env;
|
||||||
|
Cell args;
|
||||||
|
Cell f;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Registers {
|
||||||
|
std::variant<size_t, Data *, Cell> A;
|
||||||
|
std::variant<size_t, Data *, Cell> B;
|
||||||
|
std::variant<size_t, Data *, Cell> C;
|
||||||
|
Env E;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Machine {
|
||||||
|
size_t maxCells;
|
||||||
|
size_t freepos = 1;
|
||||||
|
std::vector<Cell> mem;
|
||||||
|
|
||||||
|
std::vector<Registers> stack;
|
||||||
|
|
||||||
|
Registers reg;
|
||||||
|
|
||||||
|
Machine(size_t max) : mem(max) {
|
||||||
|
maxCells = max;
|
||||||
|
reg.E.builtin.insert("+");
|
||||||
|
reg.E.builtin.insert("-");
|
||||||
|
reg.E.builtin.insert("lambda");
|
||||||
|
reg.E.builtin.insert("set");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<BasicEntry> MakeEntires(std::string filename) {
|
size_t Apply(Data * d, size_t cdr) {
|
||||||
|
if (Symbol * fname = dynamic_cast<Symbol*>(d)) {
|
||||||
std::vector<BasicEntry> out;
|
if (reg.E.builtin.contains(fname->data)) {
|
||||||
|
return ApplyBuiltin(fname->data, cdr);
|
||||||
std::ifstream matches(filename);
|
} else { //defined symbol.
|
||||||
|
return 0; //TODO
|
||||||
if (!matches.is_open()) {
|
|
||||||
std::cout << "Err reading " << filename << std::endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string line;
|
} else if (Lambda * f = dynamic_cast<Lambda*>(d)) {
|
||||||
|
reg.A = f->args;
|
||||||
|
reg.A = ((Fork *) (std::get<Cell>(reg.A)).d)->data;
|
||||||
|
|
||||||
std::string line1;
|
reg.B = cdr;
|
||||||
std::string line2;
|
auto tmp = reg.E;
|
||||||
|
//reg.E = f->env;
|
||||||
|
reg.E.userdef.merge(f->env.userdef);
|
||||||
|
while (std::get<size_t>(reg.A) != 0) {
|
||||||
|
reg.E.userdef[ ((Symbol *) mem[std::get<size_t>(reg.A)].d )->data] = std::get<size_t>(reg.B);
|
||||||
|
reg.A = mem[std::get<size_t>(reg.A)].cdr;
|
||||||
|
reg.B = mem[std::get<size_t>(reg.B)].cdr;
|
||||||
|
}
|
||||||
|
|
||||||
size_t linenum = 1; // One indexed like devtools
|
auto ret = Eval(f->f.d);
|
||||||
while (std::getline(matches, line)) {
|
reg.E = tmp;
|
||||||
if (linenum < 15) {
|
return newCell(ret);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ((linenum - 15) % 3 == 0) {
|
return 0;
|
||||||
line1 = line;
|
|
||||||
if (line == "</td></tr></tbody></table>" || line == "</TABLE>")
|
|
||||||
break;
|
|
||||||
} else if ((linenum - 15) % 3 == 1) {
|
|
||||||
line2 = line;
|
|
||||||
|
|
||||||
// std::cout << "Debug: L1: " << line1 << std::endl;
|
|
||||||
// std::cout << "Debug: L2: " << line2 << std::endl;
|
|
||||||
|
|
||||||
auto firstquote = line1.find("\"");
|
|
||||||
// printf("fq: %ld\n", firstquote);
|
|
||||||
auto secondquote = line1.find("\"", firstquote + 1);
|
|
||||||
// printf("sq: %ld\n", secondquote);
|
|
||||||
auto matchlink = line1.substr(firstquote + 1, secondquote - (firstquote + 1));
|
|
||||||
|
|
||||||
auto firstslash = line1.find("/", secondquote + 1);
|
|
||||||
auto secondslash = line1.find("/", firstslash + 1);
|
|
||||||
auto thirdslash = line1.find("/", secondslash + 1);
|
|
||||||
|
|
||||||
auto firstpar = line1.find("(", thirdslash + 1);
|
|
||||||
auto secondpar = line1.find(")", firstpar + 1);
|
|
||||||
|
|
||||||
auto p1class = line1.substr(firstslash + 1, secondslash - firstslash - 1);
|
|
||||||
auto p1name = line1.substr(secondslash + 1, thirdslash - secondslash - 1);
|
|
||||||
|
|
||||||
auto p1match = line1.substr(firstpar + 1, secondpar - firstpar - 2);
|
|
||||||
|
|
||||||
std::cout << p1match << std::endl;
|
|
||||||
|
|
||||||
firstquote = line2.find("\"");
|
|
||||||
secondquote = line2.find("\"", firstquote + 1);
|
|
||||||
firstslash = line2.find("/", secondquote + 1);
|
|
||||||
secondslash = line2.find("/", firstslash + 1);
|
|
||||||
thirdslash = line2.find("/", secondslash + 1);
|
|
||||||
firstpar = line2.find("(", thirdslash + 1);
|
|
||||||
secondpar = line2.find(")", firstpar + 1);
|
|
||||||
|
|
||||||
auto p2class = line2.substr(firstslash + 1, secondslash - (firstslash + 1));
|
|
||||||
auto p2name = line2.substr(secondslash + 1, thirdslash - (secondslash + 1));
|
|
||||||
|
|
||||||
auto p2match = line2.substr(firstpar + 1, secondpar - firstpar - 2);
|
|
||||||
std::cout << p2match << std::endl;
|
|
||||||
|
|
||||||
auto p1 = Person(p1class, p1name);
|
|
||||||
|
|
||||||
auto p2 = Person(p2class, p2name);
|
|
||||||
|
|
||||||
BasicEntry finent = {.A = p1,
|
|
||||||
.B = p2,
|
|
||||||
.matchlink = matchlink,
|
|
||||||
.Apercent = std::stoi(p1match),
|
|
||||||
.Bpercent = std::stoi(p2match)};
|
|
||||||
|
|
||||||
out.push_back(finent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
linenum++;
|
|
||||||
|
|
||||||
|
size_t ApplyBuiltin(std::string fname, size_t cdr) {
|
||||||
|
if (fname == "+") {
|
||||||
|
int base = 0;
|
||||||
|
while (cdr != 0) {
|
||||||
|
Number *a = dynamic_cast<Number *>(mem[cdr].d);
|
||||||
|
base += a->data;
|
||||||
|
cdr = mem[cdr].cdr;
|
||||||
}
|
}
|
||||||
return out;
|
Number *n = new Number;
|
||||||
|
n->data = base;
|
||||||
|
return newCell(n);
|
||||||
|
|
||||||
|
} else if (fname == "-") {
|
||||||
|
Number *s = dynamic_cast<Number *>(mem[cdr].d);
|
||||||
|
int base = s->data;
|
||||||
|
|
||||||
|
cdr = mem[cdr].cdr;
|
||||||
|
if (cdr == 0) {
|
||||||
|
Number *n = new Number;
|
||||||
|
n->data = -base;
|
||||||
|
return newCell(n);
|
||||||
|
} else {
|
||||||
|
while (cdr != 0) {
|
||||||
|
Number *a = dynamic_cast<Number *>(mem[cdr].d);
|
||||||
|
base -= a->data;
|
||||||
|
cdr = mem[cdr].cdr;
|
||||||
|
}
|
||||||
|
Number *n = new Number;
|
||||||
|
n->data = base;
|
||||||
|
return newCell(n);
|
||||||
|
}
|
||||||
|
} else if (fname == "lambda") {
|
||||||
|
Fork * args = dynamic_cast<Fork*>(mem[cdr].d);
|
||||||
|
Fork * f = dynamic_cast<Fork*>(mem[mem[cdr].cdr].d);
|
||||||
|
|
||||||
|
Lambda * l = new Lambda;
|
||||||
|
l->env = reg.E;
|
||||||
|
l->args = mem[cdr]; //mem[args->data];
|
||||||
|
l->f = mem[mem[cdr].cdr]; //mem[f->data];
|
||||||
|
//std::cout <<"got lambd" << std::endl;
|
||||||
|
return newCell(l);
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct State {
|
size_t newCell() {
|
||||||
std::vector<BasicEntry> entries;
|
if (freepos >= maxCells) {
|
||||||
};
|
|
||||||
|
|
||||||
void changelayout(Fl_Widget *w, void *meow) {
|
|
||||||
std::pair<Fl_Flex &, SummaryManager &> *in = (std::pair<Fl_Flex &, SummaryManager &> *)meow;
|
|
||||||
in->second.show();
|
|
||||||
// in->second.parent()->redraw();
|
|
||||||
// in->first.window()->redraw();
|
|
||||||
// in->first.init_sizes();
|
|
||||||
in->first.layout();
|
|
||||||
in->second.redraw();
|
|
||||||
// in->first.redraw();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Topbar : Fl_Group {
|
|
||||||
|
|
||||||
Fl_PNG_Image inspectIcon;
|
|
||||||
|
|
||||||
Fl_Box *titleText;
|
|
||||||
Fl_Button *inspect;
|
|
||||||
|
|
||||||
Topbar(int x, int y, int w, int h)
|
|
||||||
: Fl_Group(x, y, w, h),
|
|
||||||
inspectIcon("Inspect", icon_inspect_file_png, icon_inspect_file_png_len) {
|
|
||||||
|
|
||||||
titleText = new Fl_Box(0, 0, 100, 50, "MossMan");
|
|
||||||
titleText->labelsize(36);
|
|
||||||
titleText->labelfont(FL_TIMES | FL_BOLD);
|
|
||||||
titleText->align(FL_ALIGN_INSIDE | FL_ALIGN_TOP_LEFT);
|
|
||||||
inspect = new Fl_Button(950, 0, 50, 50);
|
|
||||||
resizable(titleText);
|
|
||||||
|
|
||||||
inspect->image(inspectIcon);
|
|
||||||
inspect->tooltip("Inspect Entr(ies)");
|
|
||||||
|
|
||||||
end();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MainGui : Fl_Window {
|
|
||||||
Topbar *topbar;
|
|
||||||
|
|
||||||
Fl_Tile *tilebox;
|
|
||||||
Fl_Multi_Browser *list;
|
|
||||||
SummaryManager *summaryEditor;
|
|
||||||
MainGui() : Fl_Window(0, 0, 1000, 750, "MossMan :3") {
|
|
||||||
topbar = new Topbar(0, 0, 1000, 50);
|
|
||||||
|
|
||||||
tilebox = new Fl_Tile(0, 50, 1000, 700); // parent is maingui, will be freed at decon
|
|
||||||
list = new Fl_Multi_Browser(0, 50, 150, 700);
|
|
||||||
summaryEditor = new SummaryManager(150, 50, 850, 700);
|
|
||||||
|
|
||||||
tilebox->end();
|
|
||||||
|
|
||||||
end();
|
|
||||||
|
|
||||||
resizable(tilebox);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
if (argc < 2) {
|
|
||||||
std::cout << "Not enough args" << std::endl;
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
auto nc = freepos;
|
||||||
State s;
|
freepos += 1;
|
||||||
s.entries = MakeEntires(argv[1]);
|
return nc;
|
||||||
|
|
||||||
for (auto e : s.entries) {
|
|
||||||
std::cout << e << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Fl::scheme("base");
|
size_t newCell(Data *d) {
|
||||||
// auto window = std::make_unique<Fl_Window>(300, 300, 300, 300, "MossMan :D");
|
auto t = newCell();
|
||||||
|
mem[t].d = d;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
// auto group = std::make_unique<Fl_Group>(0,0,300,300);
|
Data *Eval(Data *d) {
|
||||||
// auto group2 = std::make_unique<Fl_Group>(0, 0, 300, 50);
|
// std::cout << "Eval top" << std::endl;
|
||||||
// auto box = std::make_unique<Fl_Box>(0,0,100,50,"MossMan");
|
if (SelfEval *h = dynamic_cast<SelfEval *>(d)) {
|
||||||
// box->labelsize(36);
|
return h;
|
||||||
// box->labelfont(FL_TIMES | FL_BOLD);
|
} else if (Symbol *h = dynamic_cast<Symbol*>(d)) {
|
||||||
// box->align(FL_ALIGN_INSIDE | FL_ALIGN_TOP_LEFT);
|
if (reg.E.builtin.contains(h->data)) return h;
|
||||||
// auto button = std::make_unique<Fl_Button>(250, 0, 50, 50);
|
return mem[reg.E.userdef[h->data]].d;
|
||||||
// auto button2 = std::make_unique<Fl_Button>(200,0, 50, 50);
|
} else if (Fork *h = dynamic_cast<Fork *>(d)) {
|
||||||
// group2->resizable(*box);
|
// std::cout << "Eval callllled" << std::endl;
|
||||||
// group2->end();
|
// Symbol *car = dynamic_cast<Symbol *>(mem[h->data].d);
|
||||||
|
//new car:
|
||||||
|
auto car = mem[h->data].d;
|
||||||
|
|
||||||
// auto group3 = std::make_unique<Fl_Flex>(0,51,300, 250, Fl_Flex::HORIZONTAL);
|
// if (!car) {
|
||||||
// // auto browser = std::make_unique<Fl_Multi_Browser>(0,51,300,250);
|
// throw(100);
|
||||||
// // auto browser2 = std::make_unique<Fl_Multi_Browser>(0,51,300,250);
|
|
||||||
// auto browser = std::make_unique<Fl_Multi_Browser>(0,0,0,0);
|
|
||||||
// auto tabs = std::make_unique<SummaryManager>(0,0,300,300);
|
|
||||||
// //auto browser2 = std::make_unique<Fl_Multi_Browser>(0,0,0,0);
|
|
||||||
// tabs->hide();
|
|
||||||
// group3->end();
|
|
||||||
// std::pair<Fl_Flex&, SummaryManager&> saved(*group3, *tabs);
|
|
||||||
// button2->callback(changelayout,&saved);
|
|
||||||
|
|
||||||
// auto icon = std::make_unique<Fl_PNG_Image>("Inspect", icon_inspect_file_png,
|
|
||||||
// icon_inspect_file_png_len); button->image(*icon); button->tooltip("Inspect Entr(ies)");
|
|
||||||
|
|
||||||
// for (auto e : s.entries) {
|
|
||||||
// auto h = ((e.A.year + "/" + e.A.name) + " and " + (e.B.year + "/" + e.B.name) + " (" +
|
|
||||||
// std::to_string(e.Apercent) + "%, " + std::to_string(e.Bpercent) + "%)");
|
|
||||||
// browser->add(h.c_str());
|
|
||||||
// }
|
// }
|
||||||
|
size_t front = 0;
|
||||||
|
size_t current = 0;
|
||||||
|
size_t firstargleft = mem[h->data].cdr;
|
||||||
|
|
||||||
// group->resizable(*group3);
|
// std::cout << "Farg " << firstargleft << std::endl;
|
||||||
// group->end();
|
|
||||||
|
|
||||||
// window->resizable(*group);
|
while (firstargleft != 0) {
|
||||||
// window->end();
|
if (auto c = dynamic_cast<Symbol*>(car)) {
|
||||||
|
if(c->data == "lambda") {
|
||||||
// MainGui x;
|
front = mem[h->data].cdr;
|
||||||
|
break;
|
||||||
// Selected callbackdata(*browser);
|
}
|
||||||
|
}
|
||||||
// button->callback(show_callback, (void*) &callbackdata);
|
|
||||||
|
if (front == 0) {
|
||||||
// window->show();
|
front = newCell();
|
||||||
|
current = front;
|
||||||
MainGui x;
|
} else {
|
||||||
x.show();
|
auto temp = newCell();
|
||||||
|
mem[current].cdr = temp;
|
||||||
return Fl::run();
|
current = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// std::cout << "here" << std::endl;
|
||||||
|
mem[current].d = Eval(mem[firstargleft].d);
|
||||||
|
|
||||||
|
// std::cout << "there" << std::endl;
|
||||||
|
firstargleft = mem[firstargleft].cdr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mem[Apply(Eval(car), front)].d;
|
||||||
|
} else {
|
||||||
|
throw("err");
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ListPrint(Cell c) {
|
||||||
|
while (true) {
|
||||||
|
if (typeid(*(c.d)) == typeid(Number)) {
|
||||||
|
auto p = dynamic_cast<Number *>(c.d);
|
||||||
|
std::cout << p->Get() << " ";
|
||||||
|
} else if (typeid(*(c.d)) == typeid(Symbol)) {
|
||||||
|
auto p = dynamic_cast<Symbol *>(c.d);
|
||||||
|
std::cout << p->Get() << " ";
|
||||||
|
} else if (typeid(*(c.d)) == typeid(String)) {
|
||||||
|
auto p = dynamic_cast<String *>(c.d);
|
||||||
|
std::cout << "@\"" << p->Get() << "\"@ ";
|
||||||
|
} else if (typeid(*(c.d)) == typeid(Fork)) {
|
||||||
|
std::cout << "(";
|
||||||
|
auto p = dynamic_cast<Fork *>(c.d);
|
||||||
|
ListPrint(mem[p->Get()]);
|
||||||
|
std::cout << ")";
|
||||||
|
}
|
||||||
|
if (c.cdr == 0)
|
||||||
|
break;
|
||||||
|
c = mem[c.cdr];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Cell read_atom(std::istream &in) {
|
||||||
|
bool isnum = true;
|
||||||
|
|
||||||
|
std::string pass = "";
|
||||||
|
char ch;
|
||||||
|
|
||||||
|
if (in.peek() == '"') {
|
||||||
|
in.get(ch);
|
||||||
|
while (true) {
|
||||||
|
in.get(ch);
|
||||||
|
if (ch == '\\') {
|
||||||
|
in.get(ch);
|
||||||
|
pass += ch;
|
||||||
|
} else if (ch == '"') {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
pass += ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Cell c;
|
||||||
|
c.cdr = 0;
|
||||||
|
auto n = new String;
|
||||||
|
n->data = pass;
|
||||||
|
c.d = n;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (in.get(ch) && ch != '(' && ch != ' ' && ch != ')') {
|
||||||
|
if (ch != '0' && ch != '1' && ch != '2' && ch != '3' && ch != '4' && ch != '5' &&
|
||||||
|
ch != '6' && ch != '7' && ch != '8' && ch != '9') {
|
||||||
|
isnum = false;
|
||||||
|
}
|
||||||
|
pass += ch;
|
||||||
|
}
|
||||||
|
in.unget();
|
||||||
|
|
||||||
|
Cell c;
|
||||||
|
c.cdr = 0;
|
||||||
|
if (isnum) {
|
||||||
|
auto n = new Number;
|
||||||
|
n->data = std::stoi(pass);
|
||||||
|
c.d = n;
|
||||||
|
} else {
|
||||||
|
auto s = new Symbol;
|
||||||
|
s->data = pass;
|
||||||
|
c.d = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t read_expr(std::istream &in) {
|
||||||
|
size_t front = 0;
|
||||||
|
size_t current = 0;
|
||||||
|
|
||||||
|
char ch;
|
||||||
|
while (in.get(ch)) {
|
||||||
|
if (!std::isspace(ch)) {
|
||||||
|
if (ch == '(') {
|
||||||
|
auto temp = newCell();
|
||||||
|
mem[current].cdr = temp;
|
||||||
|
current = temp;
|
||||||
|
if (front == 0) {
|
||||||
|
front = current;
|
||||||
|
}
|
||||||
|
auto x = new Fork;
|
||||||
|
mem[current].d = x;
|
||||||
|
x->data = read_expr(in);
|
||||||
|
|
||||||
|
} else if (ch == ')') {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
auto temp = newCell();
|
||||||
|
mem[current].cdr = temp;
|
||||||
|
current = temp;
|
||||||
|
if (front == 0) {
|
||||||
|
front = current;
|
||||||
|
}
|
||||||
|
|
||||||
|
in.unget();
|
||||||
|
|
||||||
|
mem[current] = read_atom(in);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return front;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
auto m = Machine(1000);
|
||||||
|
|
||||||
|
auto exp = m.read_expr(std::cin);
|
||||||
|
|
||||||
|
m.ListPrint(m.mem[exp]);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
Cell c;
|
||||||
|
c.d = m.Eval(m.mem[exp].d);
|
||||||
|
|
||||||
|
m.ListPrint(c);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
#include "summarymanager.hpp"
|
|
||||||
#include <FL/Fl.H>
|
|
||||||
#include <FL/Fl_Button.H>
|
|
||||||
#include <FL/Fl_Tabs.H>
|
|
||||||
#include <FL/Fl_Window.H>
|
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
SummaryManager::SummaryManager(int x, int y, int w, int h)
|
|
||||||
: Fl_Group(x, y, w, h), tabs(x, y, w, h) {
|
|
||||||
|
|
||||||
Fl_Group *grp1 = new Fl_Group(x, y + 30, w, h - 30, "Tab1");
|
|
||||||
{
|
|
||||||
Fl_Window *win1 = new Fl_Window(x, y + 30, w, h - 30, "Tab1W");
|
|
||||||
std::cout << "here" << std::endl;
|
|
||||||
{
|
|
||||||
auto butt = new Fl_Button(0, 0, 100, 200, "test");
|
|
||||||
}
|
|
||||||
win1->end();
|
|
||||||
auto butt = new Fl_Button(0, 30, 100, 200, "nyaaa");
|
|
||||||
}
|
|
||||||
grp1->end();
|
|
||||||
// Fl_Group *grp2 = new Fl_Group(20, 30, 280, 170, "Tab2");
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
// grp2->end();
|
|
||||||
// Fl_Group *grp3 = new Fl_Group(20, 30, 280, 170, "Tab3");
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
// grp3->end();
|
|
||||||
// Fl_Group *grp4 = new Fl_Group(20, 30, 280, 170, "Tab4");
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
// grp4->end();
|
|
||||||
// Fl_Group *grp5 = new Fl_Group(20, 30, 280, 170, "Tab5");
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
// grp5->end();
|
|
||||||
tabs.end();
|
|
||||||
tabs.handle_overflow(Fl_Tabs::OVERFLOW_DRAG);
|
|
||||||
|
|
||||||
tabs.resizable(grp1);
|
|
||||||
|
|
||||||
end();
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
#ifndef SUMMARYMANAGER_HEADER
|
|
||||||
#define SUMMARYMANAGER_HEADER
|
|
||||||
|
|
||||||
#include <FL/Fl_Button.H>
|
|
||||||
#include <FL/Fl_Group.H>
|
|
||||||
#include <FL/Fl_Tabs.H>
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
struct SummaryManager : Fl_Group {
|
|
||||||
SummaryManager(int x, int y, int w, int h);
|
|
||||||
Fl_Tabs tabs;
|
|
||||||
std::vector<Fl_Button*> items;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue