fixed set map bug
This commit is contained in:
parent
5857726201
commit
bcd6922aef
|
@ -7,13 +7,6 @@
|
|||
#define UseInterfacesThatArePhasingOut 0
|
||||
#include "4coder_helper.h"
|
||||
|
||||
// NOTE(allen|a3.3): All of your custom ids should be enumerated
|
||||
// as shown here, they may start at 0, and you can only have
|
||||
// 2^24 of them so don't be wasteful!
|
||||
enum My_Maps{
|
||||
my_code_map
|
||||
};
|
||||
|
||||
static void
|
||||
write_string(Application_Links *app, String string){
|
||||
Buffer_Summary buffer = app->get_active_buffer(app);
|
||||
|
|
|
@ -3,6 +3,14 @@
|
|||
|
||||
unsigned char blink_t = 0;
|
||||
|
||||
// NOTE(allen|a3.3): All of your custom ids should be enumerated
|
||||
// as shown here, they may start at 0, and you can only have
|
||||
// 2^24 of them so don't be wasteful!
|
||||
enum My_Maps{
|
||||
my_code_map,
|
||||
my_html_map
|
||||
};
|
||||
|
||||
HOOK_SIG(my_start){
|
||||
exec_command(app, cmdid_open_panel_vsplit);
|
||||
exec_command(app, cmdid_change_active_panel);
|
||||
|
@ -101,6 +109,19 @@ CUSTOM_COMMAND_SIG(write_allen_note){
|
|||
write_string(app, make_lit_string("// NOTE(allen): "));
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(write_h){
|
||||
write_string(app, make_lit_string("<h1></h1>"));
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(write_div){
|
||||
write_string(app, make_lit_string("<div></div>"));
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(begin_html_mode){
|
||||
push_parameter(app, par_key_mapid, my_html_map);
|
||||
exec_command(app, cmdid_set_settings);
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(write_capital){
|
||||
User_Input command_in = app->get_command_input(app);
|
||||
char c = command_in.key.character_no_caps_lock;
|
||||
|
@ -291,7 +312,6 @@ void default_get_bindings(Bind_Helper *context){
|
|||
bind(context, 'o', MDFR_ALT, open_in_other);
|
||||
|
||||
bind(context, 'm', MDFR_ALT, build_search);
|
||||
bind(context, ',', MDFR_ALT, switch_to_compilation);
|
||||
bind(context, 'x', MDFR_ALT, execute_arbitrary_command);
|
||||
bind(context, 'z', MDFR_ALT, execute_any_cli);
|
||||
|
||||
|
@ -304,6 +324,13 @@ void default_get_bindings(Bind_Helper *context){
|
|||
bind(context, '~', MDFR_ALT, ruin_theme);
|
||||
|
||||
end_map(context);
|
||||
|
||||
|
||||
begin_map(context, my_html_map);
|
||||
inherit_map(context, mapid_file);
|
||||
bind(context, 'h', MDFR_ALT, write_h);
|
||||
bind(context, 'd', MDFR_ALT, write_div);
|
||||
end_map(context);
|
||||
|
||||
|
||||
begin_map(context, my_code_map);
|
||||
|
@ -411,7 +438,7 @@ void default_get_bindings(Bind_Helper *context){
|
|||
bind(context, 'O', MDFR_CTRL, cmdid_reopen);
|
||||
bind(context, 'w', MDFR_CTRL, cmdid_interactive_save_as);
|
||||
bind(context, 's', MDFR_CTRL, cmdid_save);
|
||||
|
||||
|
||||
bind(context, '\n', MDFR_SHIFT, write_and_auto_tab);
|
||||
bind(context, ' ', MDFR_SHIFT, cmdid_write_character);
|
||||
|
||||
|
@ -419,6 +446,7 @@ void default_get_bindings(Bind_Helper *context){
|
|||
bind(context, 'w', MDFR_ALT | MDFR_CTRL, write_capital);
|
||||
bind(context, 'e', MDFR_ALT | MDFR_CTRL, write_capital);
|
||||
|
||||
bind(context, 'T', MDFR_CTRL | MDFR_ALT, begin_html_mode);
|
||||
|
||||
end_map(context);
|
||||
}
|
||||
|
|
25
4ed.cpp
25
4ed.cpp
|
@ -120,7 +120,12 @@ app_get_map_index(Models *models, i32 mapid){
|
|||
internal Command_Map*
|
||||
app_get_map(Models *models, i32 mapid){
|
||||
Command_Map *map = 0;
|
||||
if (mapid < mapid_global) map = models->user_maps + mapid;
|
||||
if (mapid < mapid_global){
|
||||
mapid = app_get_map_index(models, mapid);
|
||||
if (mapid < models->user_map_count){
|
||||
map = models->user_maps + mapid;
|
||||
}
|
||||
}
|
||||
else if (mapid == mapid_global) map = &models->map_top;
|
||||
else if (mapid == mapid_file) map = &models->map_file;
|
||||
return map;
|
||||
|
@ -1596,7 +1601,10 @@ COMMAND_DECL(set_settings){
|
|||
REQ_READABLE_VIEW(view);
|
||||
REQ_FILE(file, view);
|
||||
USE_MODELS(models);
|
||||
|
||||
|
||||
b32 set_mapid = 0;
|
||||
i32 new_mapid = 0;
|
||||
|
||||
Command_Parameter *end = param_stack_end(&command->part);
|
||||
Command_Parameter *param = param_stack_first(&command->part, end);
|
||||
for (; param < end; param = param_next(param, end)){
|
||||
|
@ -1649,17 +1657,26 @@ COMMAND_DECL(set_settings){
|
|||
|
||||
case par_key_mapid:
|
||||
{
|
||||
set_mapid = 1;
|
||||
int v = dynamic_to_int(¶m->param.value);
|
||||
if (v == mapid_global) file->settings.base_map_id = mapid_global;
|
||||
else if (v == mapid_file) file->settings.base_map_id = mapid_file;
|
||||
else if (v < mapid_global){
|
||||
int index = app_get_map_index(models, v);
|
||||
if (index < models->user_map_count) file->settings.base_map_id = v;
|
||||
new_mapid = app_get_map_index(models, v);
|
||||
if (new_mapid < models->user_map_count) file->settings.base_map_id = v;
|
||||
else file->settings.base_map_id = mapid_file;
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
if (set_mapid){
|
||||
for (View_Iter iter = file_view_iter_init(&models->layout, file, 0);
|
||||
file_view_iter_good(iter);
|
||||
iter = file_view_iter_next(iter)){
|
||||
iter.view->map = app_get_map(models, file->settings.base_map_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
COMMAND_DECL(command_line){
|
||||
|
|
|
@ -1007,6 +1007,7 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
int max_token_i = token_stack_out->max_count;
|
||||
|
||||
Lex_FSM fsm = {0};
|
||||
Whitespace_FSM wfsm = {0};
|
||||
Pos_Update_Rule pos_update_rule = PUR_none;
|
||||
|
||||
char c = 0;
|
||||
|
@ -1028,7 +1029,16 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
for(;;){
|
||||
for (; S.wfsm.white_done == 0 && S.pos < end_pos;){
|
||||
c = chunk[S.pos++];
|
||||
S.wfsm = whitespace_skip_fsm(S.wfsm, c);
|
||||
wfsm = S.wfsm;
|
||||
{
|
||||
if (wfsm.pp_state != LSPP_default){
|
||||
if (c == '\n') wfsm.pp_state = LSPP_default;
|
||||
}
|
||||
if (!(c == ' ' || c == '\n' || c == '\t' || c == '\r' || c == '\f' || c == '\v')){
|
||||
wfsm.white_done = 1;
|
||||
}
|
||||
}
|
||||
S.wfsm = wfsm;
|
||||
}
|
||||
if (S.wfsm.white_done == 0){
|
||||
DrYield(4, 1);
|
||||
|
@ -1045,9 +1055,397 @@ cpp_lex_nonalloc(Lex_Data *S_ptr, char *chunk, int size, Cpp_Token_Stack *token_
|
|||
for (; S.fsm.emit_token == 0 && S.pos < end_pos;){
|
||||
c = chunk[S.pos++];
|
||||
S.tb[S.tb_pos++] = c;
|
||||
|
||||
|
||||
fsm = S.fsm;
|
||||
fsm = main_fsm(fsm, S.pp_state, c);
|
||||
|
||||
{
|
||||
if (c == 0) fsm.emit_token = 1;
|
||||
else
|
||||
switch (S.pp_state){
|
||||
case LSPP_error:
|
||||
fsm.state = LS_error_message;
|
||||
if (c == '\n') fsm.emit_token = 1;
|
||||
break;
|
||||
|
||||
case LSPP_include:
|
||||
switch (fsm.state){
|
||||
case LSINC_default:
|
||||
switch (c){
|
||||
case '"': fsm.state = LSINC_quotes; break;
|
||||
case '<': fsm.state = LSINC_pointy; break;
|
||||
default: fsm.state = LSINC_junk; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LSINC_quotes:
|
||||
if (c == '"') fsm.emit_token = 1;
|
||||
break;
|
||||
|
||||
case LSINC_pointy:
|
||||
if (c == '>') fsm.emit_token = 1;
|
||||
break;
|
||||
|
||||
case LSINC_junk:
|
||||
if (c == '\n') fsm.emit_token = 1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
switch (fsm.state){
|
||||
case LS_default:
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'){
|
||||
fsm.state = LS_identifier;
|
||||
}
|
||||
else if (c >= '1' && c <= '9'){
|
||||
fsm.state = LS_number;
|
||||
}
|
||||
else if (c == '0'){
|
||||
fsm.state = LS_number0;
|
||||
}
|
||||
else switch (c){
|
||||
case '\'': fsm.state = LS_char; break;
|
||||
case '"': fsm.state = LS_string; break;
|
||||
|
||||
case '/': fsm.state = LS_comment_pre; break;
|
||||
|
||||
case '.': fsm.state = LS_dot; break;
|
||||
|
||||
case '<': fsm.state = LS_less; break;
|
||||
case '>': fsm.state = LS_more; break;
|
||||
|
||||
case '-': fsm.state = LS_minus; break;
|
||||
|
||||
case '&': fsm.state = LS_and; break;
|
||||
case '|': fsm.state = LS_or; break;
|
||||
|
||||
case '+': fsm.state = LS_plus; break;
|
||||
|
||||
case ':': fsm.state = LS_colon; break;
|
||||
|
||||
case '*': fsm.state = LS_star; break;
|
||||
|
||||
case '%': fsm.state = LS_modulo; break;
|
||||
case '^': fsm.state = LS_caret; break;
|
||||
|
||||
case '=': fsm.state = LS_eq; break;
|
||||
case '!': fsm.state = LS_bang; break;
|
||||
|
||||
case '#': fsm.state = LS_pound; break;
|
||||
|
||||
#define OperCase(op,type) case op: fsm.emit_token = 1; break;
|
||||
OperCase('{', CPP_TOKEN_BRACE_OPEN);
|
||||
OperCase('}', CPP_TOKEN_BRACE_CLOSE);
|
||||
|
||||
OperCase('[', CPP_TOKEN_BRACKET_OPEN);
|
||||
OperCase(']', CPP_TOKEN_BRACKET_CLOSE);
|
||||
|
||||
OperCase('(', CPP_TOKEN_PARENTHESE_OPEN);
|
||||
OperCase(')', CPP_TOKEN_PARENTHESE_CLOSE);
|
||||
|
||||
OperCase('~', CPP_TOKEN_TILDE);
|
||||
OperCase(',', CPP_TOKEN_COMMA);
|
||||
OperCase(';', CPP_TOKEN_SEMICOLON);
|
||||
OperCase('?', CPP_TOKEN_TERNARY_QMARK);
|
||||
|
||||
OperCase('@', CPP_TOKEN_JUNK);
|
||||
OperCase('$', CPP_TOKEN_JUNK);
|
||||
OperCase('\\', CPP_TOKEN_JUNK);
|
||||
#undef OperCase
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_identifier:
|
||||
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_')){
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_pound:
|
||||
if (S.pp_state == LSPP_default){
|
||||
if (c == ' ' || c == '\t' || c == '\r' || c == '\f' || c == '\v'){
|
||||
fsm.state = LS_pound;
|
||||
}
|
||||
else if (c == '\n'){
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
else{
|
||||
fsm.state = LS_pp;
|
||||
}
|
||||
}
|
||||
else{
|
||||
switch (c){
|
||||
case '#': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_pp:
|
||||
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_')){
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_char:
|
||||
switch(c){
|
||||
case '\'': fsm.emit_token = 1; break;
|
||||
case '\\': fsm.state = LS_char_slashed; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_char_slashed:
|
||||
switch (c){
|
||||
case '\r': case '\f': case '\v': break;
|
||||
case '\n': fsm.state = LS_string; fsm.multi_line |= 1; break;
|
||||
default: fsm.state = LS_char; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_string:
|
||||
switch(c){
|
||||
case '\"': fsm.emit_token = 1; break;
|
||||
case '\\': fsm.state = LS_string_slashed; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_string_slashed:
|
||||
switch (c){
|
||||
case '\r': case '\f': case '\v': break;
|
||||
case '\n': fsm.state = LS_string; fsm.multi_line |= 1; break;
|
||||
default: fsm.state = LS_string; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_number:
|
||||
if (c >= '0' && c <= '9'){
|
||||
fsm.state = LS_number;
|
||||
}
|
||||
else{
|
||||
switch (c){
|
||||
case '.': fsm.state = LS_float; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_number0:
|
||||
if (c >= '0' && c <= '9'){
|
||||
fsm.state = LS_number;
|
||||
}
|
||||
else if (c == 'x'){
|
||||
fsm.state = LS_hex;
|
||||
}
|
||||
else if (c == '.'){
|
||||
fsm.state = LS_float;
|
||||
}
|
||||
else{
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_float:
|
||||
if (!(c >= '0' && c <= '9')){
|
||||
switch (c){
|
||||
case 'e': fsm.state = LS_crazy_float0; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_crazy_float0:
|
||||
{
|
||||
if ((c >= '0' && c <= '9') || c == '-'){
|
||||
fsm.state = LS_crazy_float1;
|
||||
}
|
||||
else{
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_crazy_float1:
|
||||
{
|
||||
if (!(c >= '0' && c <= '9')){
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_hex:
|
||||
if (!(c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F')){
|
||||
fsm.emit_token = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_dot:
|
||||
if (c >= '0' && c <= '9'){
|
||||
fsm.state = LS_float;
|
||||
}
|
||||
else
|
||||
switch (c){
|
||||
case '.': fsm.state = LS_ellipsis; break;
|
||||
case '*': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_ellipsis: fsm.emit_token = 1; break;
|
||||
|
||||
case LS_less:
|
||||
switch (c){
|
||||
case '<': fsm.state = LS_less_less; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_less_less:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_more:
|
||||
switch (c){
|
||||
case '>': fsm.state = LS_more_more; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_more_more:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_comment_pre:
|
||||
switch (c){
|
||||
case '/': fsm.state = LS_comment; break;
|
||||
case '*': fsm.state = LS_comment_block; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_comment:
|
||||
switch (c){
|
||||
case '\\': fsm.state = LS_comment_slashed; break;
|
||||
case '\n': fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_comment_slashed:
|
||||
switch (c){
|
||||
case '\r': case '\f': case '\v': break;
|
||||
default: fsm.state = LS_comment; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_comment_block:
|
||||
switch (c){
|
||||
case '*': fsm.state = LS_comment_block_ending; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_comment_block_ending:
|
||||
switch (c){
|
||||
case '*': fsm.state = LS_comment_block_ending; break;
|
||||
case '/': fsm.emit_token = 1; break;
|
||||
default: fsm.state = LS_comment_block; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_minus:
|
||||
switch (c){
|
||||
case '>': fsm.state = LS_arrow; break;
|
||||
case '-': fsm.emit_token = 1; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_arrow:
|
||||
switch (c){
|
||||
case '*': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_and:
|
||||
switch (c){
|
||||
case '&': fsm.emit_token = 1; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_or:
|
||||
switch (c){
|
||||
case '|': fsm.emit_token = 1; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_plus:
|
||||
switch (c){
|
||||
case '+': fsm.emit_token = 1; break;
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_colon:
|
||||
switch (c){
|
||||
case ':': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_star:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_modulo:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_caret:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_eq:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LS_bang:
|
||||
switch (c){
|
||||
case '=': fsm.emit_token = 1; break;
|
||||
default: fsm.emit_token = 1; break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//fsm = main_fsm(fsm, S.pp_state, c);
|
||||
S.fsm = fsm;
|
||||
}
|
||||
if (S.fsm.emit_token == 0){
|
||||
|
|
|
@ -317,7 +317,7 @@ run_experiment(Experiment *exp, char *filename, int verbose, int chunks){
|
|||
|
||||
void
|
||||
show_time(Times t, int repeats, char *type){
|
||||
f32 speed_up = ((f32)t.handcoded) / t.fsm;
|
||||
f32 speed_up = ((f32)t.handcoded) / (t.fsm);
|
||||
printf(
|
||||
"\n%s time for %d repeates\n"
|
||||
OUTLINE("%lld")
|
||||
|
@ -337,8 +337,8 @@ int main(){
|
|||
|
||||
int repeats = 100;
|
||||
int verbose_level = -1;
|
||||
int chunk_start = 0;
|
||||
int chunk_end = 1024;
|
||||
int chunk_start = 1;
|
||||
int chunk_end = 16;
|
||||
#define TEST_FILE "lexer_test.cpp"
|
||||
#define SINGLE_ITEM 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue