first programs working
This commit is contained in:
parent
26d03201b0
commit
3178c19e43
|
@ -0,0 +1 @@
|
|||
{"draw_editor_panel":109,"fw_parent":117,"fw_app":"bf","draw_title":110,"Num_panels_horizontal":23,"on":1,"Num_panels_vertical":24,"on.text_input":118,"on.initialize":104,"draw_data":90,"panel_bounds":93,"Margin":27,"create_editor_panel":114,"Font_size":28,"on.draw":108,"Title_font":73,"create_editor":94,"Data":102,"Code":101,"on.keychord_press":65,"In":98,"Data_title_text":76,"Out":103,"Cursor":38,"on.mouse_press":112}
|
|
@ -0,0 +1,5 @@
|
|||
on.text_input = function(t)
|
||||
if Cursor then
|
||||
edit.text_input(Cursor.editor, t)
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"draw_editor_panel":109,"fw_parent":118,"fw_app":"bf","draw_title":110,"Num_panels_horizontal":23,"on":1,"Num_panels_vertical":24,"on.text_input":118,"on.initialize":104,"draw_data":90,"panel_bounds":93,"Margin":27,"create_editor_panel":114,"Font_size":28,"on.draw":108,"Title_font":73,"create_editor":94,"Data":102,"Code":101,"on.keychord_press":119,"In":98,"Data_title_text":76,"Out":103,"Cursor":38,"on.mouse_press":112}
|
|
@ -0,0 +1,5 @@
|
|||
on.keychord_press = function(chord, key)
|
||||
if Cursor then
|
||||
edit.keychord_press(Cursor.editor, chord, key)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,33 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[', cp)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
--print(string.char(data[dp]))
|
||||
print(data[dp])
|
||||
elseif inst == ',' then
|
||||
data[dp] = string.byte(io.read(1))
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"draw_editor_panel":109,"fw_parent":119,"fw_app":"bf","draw_title":110,"eval":120,"Num_panels_horizontal":23,"on":1,"Num_panels_vertical":24,"on.text_input":118,"on.initialize":104,"draw_data":90,"panel_bounds":93,"Margin":27,"create_editor_panel":114,"Font_size":28,"on.draw":108,"Title_font":73,"create_editor":94,"Data":102,"Code":101,"on.keychord_press":119,"In":98,"Data_title_text":76,"Out":103,"Cursor":38,"on.mouse_press":112}
|
|
@ -0,0 +1,3 @@
|
|||
editor_to_string = function(editor)
|
||||
return table.concat(map(editor.lines, function(line) return line.data end), '\n')
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"draw_editor_panel":109,"fw_parent":120,"fw_app":"bf","draw_title":110,"panel_bounds":93,"eval":120,"Num_panels_horizontal":23,"on":1,"Num_panels_vertical":24,"on.text_input":118,"on.initialize":104,"draw_data":90,"editor_to_string":121,"Margin":27,"create_editor_panel":114,"Font_size":28,"on.draw":108,"Title_font":73,"create_editor":94,"Data":102,"Code":101,"on.keychord_press":119,"In":98,"Data_title_text":76,"Out":103,"Cursor":38,"on.mouse_press":112}
|
|
@ -0,0 +1 @@
|
|||
{"draw_editor_panel":109,"fw_parent":121,"fw_app":"bf","draw_title":110,"panel_bounds":93,"eval":120,"Num_panels_horizontal":23,"on":1,"Num_panels_vertical":24,"on.text_input":118,"on.initialize":104,"draw_data":90,"editor_to_string":121,"Margin":27,"create_editor_panel":114,"Font_size":28,"on.draw":108,"Title_font":73,"create_editor":94,"Data":102,"Code":101,"on.keychord_press":122,"In":98,"Data_title_text":76,"Out":103,"Cursor":38,"on.mouse_press":112}
|
|
@ -0,0 +1,7 @@
|
|||
on.keychord_press = function(chord, key)
|
||||
if chord == 'f4' then
|
||||
eval(editor_to_string(Code.editor), Data)
|
||||
elseif Cursor then
|
||||
edit.keychord_press(Cursor.editor, chord, key)
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"draw_editor_panel":109,"fw_parent":122,"fw_app":"bf","map":123,"draw_title":110,"panel_bounds":93,"eval":120,"Num_panels_horizontal":23,"on":1,"Num_panels_vertical":24,"on.text_input":118,"on.initialize":104,"draw_data":90,"editor_to_string":121,"Margin":27,"create_editor_panel":114,"Font_size":28,"on.draw":108,"Title_font":73,"create_editor":94,"Data":102,"Code":101,"on.keychord_press":122,"In":98,"Data_title_text":76,"Out":103,"Cursor":38,"on.mouse_press":112}
|
|
@ -0,0 +1,7 @@
|
|||
map = function(arr, f)
|
||||
local result = {}
|
||||
for _, x in ipairs(arr) do
|
||||
table.insert(result, f(x))
|
||||
end
|
||||
return result
|
||||
end
|
|
@ -0,0 +1,33 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[', cp)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
--print(string.char(data[dp]))
|
||||
print(data[dp])
|
||||
elseif inst == ',' then
|
||||
data[dp] = string.byte(io.read(1))
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"draw_editor_panel":109,"fw_parent":123,"fw_app":"bf","map":123,"draw_title":110,"panel_bounds":93,"eval":124,"Num_panels_horizontal":23,"on":1,"Num_panels_vertical":24,"on.text_input":118,"on.initialize":104,"draw_data":90,"editor_to_string":121,"Margin":27,"create_editor_panel":114,"Font_size":28,"on.draw":108,"Title_font":73,"create_editor":94,"Data":102,"Code":101,"on.keychord_press":122,"In":98,"Data_title_text":76,"Out":103,"Cursor":38,"on.mouse_press":112}
|
|
@ -0,0 +1,33 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[' , cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
--print(string.char(data[dp]))
|
||||
print(data[dp])
|
||||
elseif inst == ',' then
|
||||
data[dp] = string.byte(io.read(1))
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"draw_editor_panel":109,"fw_parent":124,"fw_app":"bf","map":123,"draw_title":110,"panel_bounds":93,"eval":125,"Num_panels_horizontal":23,"on":1,"Num_panels_vertical":24,"on.text_input":118,"on.initialize":104,"draw_data":90,"editor_to_string":121,"Margin":27,"create_editor_panel":114,"Font_size":28,"on.draw":108,"Title_font":73,"create_editor":94,"Data":102,"Code":101,"on.keychord_press":122,"In":98,"Data_title_text":76,"Out":103,"Cursor":38,"on.mouse_press":112}
|
|
@ -0,0 +1,37 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[' , cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
Out.editor.lines[1].data = Out.editor.lines[1].data..string.char(data[dp])
|
||||
Text.redraw_all(Out.editor)
|
||||
--print(string.char(data[dp]))
|
||||
--print(data[dp])
|
||||
elseif inst == ',' then
|
||||
--data[dp] = string.byte(io.read(1))
|
||||
data[dp] = In.editor.lines[1].data[1]
|
||||
In.editor.lines[1].data = In.editor.lines[1].data:sub(2)
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"eval":126,"Num_panels_horizontal":23,"fw_parent":125,"draw_title":110,"fw_app":"bf","on":1,"draw_data":90,"Margin":27,"panel_bounds":93,"editor_to_string":121,"on.mouse_press":112,"create_editor":94,"map":123,"Code":101,"Cursor":38,"Title_font":73,"on.draw":108,"Out":103,"In":98,"Font_size":28,"on.keychord_press":122,"Data_title_text":76,"on.text_input":118,"Data":102,"Num_panels_vertical":24,"on.initialize":104,"draw_editor_panel":109,"create_editor_panel":114}
|
|
@ -0,0 +1,37 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[' , cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
Out.editor.lines[1].data = Out.editor.lines[1].data..string.char(data[dp])
|
||||
Text.redraw_all(Out.editor)
|
||||
--print(string.char(data[dp]))
|
||||
--print(data[dp])
|
||||
elseif inst == ',' then
|
||||
--data[dp] = string.byte(io.read(1))
|
||||
data[dp] = string.byte(In.editor.lines[1].data[1])
|
||||
In.editor.lines[1].data = In.editor.lines[1].data:sub(2)
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"eval":127,"Num_panels_horizontal":23,"fw_parent":126,"draw_title":110,"fw_app":"bf","on":1,"draw_data":90,"Margin":27,"panel_bounds":93,"editor_to_string":121,"on.mouse_press":112,"create_editor":94,"map":123,"Code":101,"Cursor":38,"Title_font":73,"on.draw":108,"Out":103,"In":98,"Font_size":28,"on.keychord_press":122,"Data_title_text":76,"on.text_input":118,"Data":102,"Num_panels_vertical":24,"on.initialize":104,"draw_editor_panel":109,"create_editor_panel":114}
|
|
@ -0,0 +1,40 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[' , cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
Out.editor.lines[1].data = Out.editor.lines[1].data..string.char(data[dp])
|
||||
Text.redraw_all(Out.editor)
|
||||
--print(string.char(data[dp]))
|
||||
--print(data[dp])
|
||||
elseif inst == ',' then
|
||||
--data[dp] = string.byte(io.read(1))
|
||||
print(In)
|
||||
print(In.editor)
|
||||
print(In.editor.lines[1].data)
|
||||
data[dp] = string.byte(In.editor.lines[1].data[1])
|
||||
In.editor.lines[1].data = In.editor.lines[1].data:sub(2)
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"eval":128,"Num_panels_horizontal":23,"fw_parent":127,"draw_title":110,"fw_app":"bf","on":1,"draw_data":90,"Margin":27,"panel_bounds":93,"editor_to_string":121,"on.mouse_press":112,"create_editor":94,"map":123,"Code":101,"Cursor":38,"Title_font":73,"on.draw":108,"Out":103,"In":98,"Font_size":28,"on.keychord_press":122,"Data_title_text":76,"on.text_input":118,"Data":102,"Num_panels_vertical":24,"on.initialize":104,"draw_editor_panel":109,"create_editor_panel":114}
|
|
@ -0,0 +1,41 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[' , cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
Out.editor.lines[1].data = Out.editor.lines[1].data..string.char(data[dp])
|
||||
Text.redraw_all(Out.editor)
|
||||
--print(string.char(data[dp]))
|
||||
--print(data[dp])
|
||||
elseif inst == ',' then
|
||||
--data[dp] = string.byte(io.read(1))
|
||||
print(In)
|
||||
print(In.editor)
|
||||
print(In.editor.lines[1].data)
|
||||
print(In.editor.lines[1].data[1])
|
||||
data[dp] = string.byte(In.editor.lines[1].data[1])
|
||||
In.editor.lines[1].data = In.editor.lines[1].data:sub(2)
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"eval":129,"Num_panels_horizontal":23,"fw_parent":128,"draw_title":110,"fw_app":"bf","on":1,"draw_data":90,"Margin":27,"panel_bounds":93,"editor_to_string":121,"on.mouse_press":112,"create_editor":94,"map":123,"Code":101,"Cursor":38,"Title_font":73,"on.draw":108,"Out":103,"In":98,"Font_size":28,"on.keychord_press":122,"Data_title_text":76,"on.text_input":118,"Data":102,"Num_panels_vertical":24,"on.initialize":104,"draw_editor_panel":109,"create_editor_panel":114}
|
|
@ -0,0 +1,41 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[' , cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
Out.editor.lines[1].data = Out.editor.lines[1].data..string.char(data[dp])
|
||||
Text.redraw_all(Out.editor)
|
||||
--print(string.char(data[dp]))
|
||||
--print(data[dp])
|
||||
elseif inst == ',' then
|
||||
--data[dp] = string.byte(io.read(1))
|
||||
print(In)
|
||||
print(In.editor)
|
||||
print(In.editor.lines[1].data)
|
||||
print(In.editor.lines[1].data[1])
|
||||
data[dp] = string.byte(In.editor.lines[1].data:sub(1,1))
|
||||
In.editor.lines[1].data = In.editor.lines[1].data:sub(2)
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"eval":130,"Num_panels_horizontal":23,"fw_parent":129,"draw_title":110,"fw_app":"bf","on":1,"draw_data":90,"Margin":27,"panel_bounds":93,"editor_to_string":121,"on.mouse_press":112,"create_editor":94,"map":123,"Code":101,"Cursor":38,"Title_font":73,"on.draw":108,"Out":103,"In":98,"Font_size":28,"on.keychord_press":122,"Data_title_text":76,"on.text_input":118,"Data":102,"Num_panels_vertical":24,"on.initialize":104,"draw_editor_panel":109,"create_editor_panel":114}
|
|
@ -0,0 +1,44 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[' , cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
print('out')
|
||||
print(dp, data[dp])
|
||||
Out.editor.lines[1].data = Out.editor.lines[1].data..string.char(data[dp])
|
||||
Text.redraw_all(Out.editor)
|
||||
--print(string.char(data[dp]))
|
||||
--print(data[dp])
|
||||
elseif inst == ',' then
|
||||
--data[dp] = string.byte(io.read(1))
|
||||
print('in')
|
||||
print(In)
|
||||
print(In.editor)
|
||||
print(In.editor.lines[1].data)
|
||||
print(In.editor.lines[1].data[1])
|
||||
data[dp] = string.byte(In.editor.lines[1].data:sub(1,1))
|
||||
In.editor.lines[1].data = In.editor.lines[1].data:sub(2)
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"eval":131,"Num_panels_horizontal":23,"fw_parent":130,"draw_title":110,"fw_app":"bf","on":1,"draw_data":90,"Margin":27,"panel_bounds":93,"editor_to_string":121,"on.mouse_press":112,"create_editor":94,"map":123,"Code":101,"Cursor":38,"Title_font":73,"on.draw":108,"Out":103,"In":98,"Font_size":28,"on.keychord_press":122,"Data_title_text":76,"on.text_input":118,"Data":102,"Num_panels_vertical":24,"on.initialize":104,"draw_editor_panel":109,"create_editor_panel":114}
|
|
@ -0,0 +1,45 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
print('== inst', cp)
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[' , cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
print('out')
|
||||
print(dp, data[dp])
|
||||
Out.editor.lines[1].data = Out.editor.lines[1].data..string.char(data[dp])
|
||||
Text.redraw_all(Out.editor)
|
||||
--print(string.char(data[dp]))
|
||||
--print(data[dp])
|
||||
elseif inst == ',' then
|
||||
--data[dp] = string.byte(io.read(1))
|
||||
print('in')
|
||||
print(In)
|
||||
print(In.editor)
|
||||
print(In.editor.lines[1].data)
|
||||
print(In.editor.lines[1].data[1])
|
||||
data[dp] = string.byte(In.editor.lines[1].data:sub(1,1))
|
||||
In.editor.lines[1].data = In.editor.lines[1].data:sub(2)
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"eval":132,"Num_panels_horizontal":23,"fw_parent":131,"draw_title":110,"fw_app":"bf","on":1,"draw_data":90,"Margin":27,"panel_bounds":93,"editor_to_string":121,"on.mouse_press":112,"create_editor":94,"map":123,"Code":101,"Cursor":38,"Title_font":73,"on.draw":108,"Out":103,"In":98,"Font_size":28,"on.keychord_press":122,"Data_title_text":76,"on.text_input":118,"Data":102,"Num_panels_vertical":24,"on.initialize":104,"draw_editor_panel":109,"create_editor_panel":114}
|
|
@ -0,0 +1,45 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
print('== inst', cp, #code)
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[' , cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
print('out')
|
||||
print(dp, data[dp])
|
||||
Out.editor.lines[1].data = Out.editor.lines[1].data..string.char(data[dp])
|
||||
Text.redraw_all(Out.editor)
|
||||
--print(string.char(data[dp]))
|
||||
--print(data[dp])
|
||||
elseif inst == ',' then
|
||||
--data[dp] = string.byte(io.read(1))
|
||||
print('in')
|
||||
print(In)
|
||||
print(In.editor)
|
||||
print(In.editor.lines[1].data)
|
||||
print(In.editor.lines[1].data[1])
|
||||
data[dp] = string.byte(In.editor.lines[1].data:sub(1,1))
|
||||
In.editor.lines[1].data = In.editor.lines[1].data:sub(2)
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"eval":133,"Num_panels_horizontal":23,"fw_parent":132,"draw_title":110,"fw_app":"bf","on":1,"draw_data":90,"Margin":27,"panel_bounds":93,"editor_to_string":121,"on.mouse_press":112,"create_editor":94,"map":123,"Code":101,"Cursor":38,"Title_font":73,"on.draw":108,"Out":103,"In":98,"Font_size":28,"on.keychord_press":122,"Data_title_text":76,"on.text_input":118,"Data":102,"Num_panels_vertical":24,"on.initialize":104,"draw_editor_panel":109,"create_editor_panel":114}
|
|
@ -0,0 +1,49 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
print('== inst', cp, #code)
|
||||
print('-- data')
|
||||
for i,d in ipairs(Data) do
|
||||
print(i,d)
|
||||
end
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[' , cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
print('out')
|
||||
print(dp, data[dp])
|
||||
Out.editor.lines[1].data = Out.editor.lines[1].data..string.char(data[dp])
|
||||
Text.redraw_all(Out.editor)
|
||||
--print(string.char(data[dp]))
|
||||
--print(data[dp])
|
||||
elseif inst == ',' then
|
||||
--data[dp] = string.byte(io.read(1))
|
||||
print('in')
|
||||
print(In)
|
||||
print(In.editor)
|
||||
print(In.editor.lines[1].data)
|
||||
print(In.editor.lines[1].data[1])
|
||||
data[dp] = string.byte(In.editor.lines[1].data:sub(1,1))
|
||||
In.editor.lines[1].data = In.editor.lines[1].data:sub(2)
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"eval":134,"Num_panels_horizontal":23,"fw_parent":133,"draw_title":110,"fw_app":"bf","on":1,"draw_data":90,"Margin":27,"panel_bounds":93,"editor_to_string":121,"on.mouse_press":112,"create_editor":94,"map":123,"Code":101,"Cursor":38,"Title_font":73,"on.draw":108,"Out":103,"In":98,"Font_size":28,"on.keychord_press":122,"Data_title_text":76,"on.text_input":118,"Data":102,"Num_panels_vertical":24,"on.initialize":104,"draw_editor_panel":109,"create_editor_panel":114}
|
|
@ -0,0 +1,53 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
print('== inst', cp, #code)
|
||||
print('-- data')
|
||||
for i,d in ipairs(Data) do
|
||||
print(i,d)
|
||||
end
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[' , cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
print('out')
|
||||
print(dp, data[dp])
|
||||
Out.editor.lines[1].data = Out.editor.lines[1].data..string.char(data[dp])
|
||||
Text.redraw_all(Out.editor)
|
||||
--print(string.char(data[dp]))
|
||||
--print(data[dp])
|
||||
elseif inst == ',' then
|
||||
--data[dp] = string.byte(io.read(1))
|
||||
print('in')
|
||||
print(In)
|
||||
print(In.editor)
|
||||
print(In.editor.lines[1].data)
|
||||
print(In.editor.lines[1].data[1])
|
||||
if #In.editor.lines[1].data > 0 then
|
||||
data[dp] = string.byte(In.editor.lines[1].data:sub(1,1))
|
||||
else
|
||||
data[dp] = 0
|
||||
end
|
||||
In.editor.lines[1].data = In.editor.lines[1].data:sub(2)
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"create_editor":94,"Title_font":73,"Code":101,"on.keychord_press":122,"In":98,"on.text_input":118,"Out":103,"Data_title_text":76,"create_editor_panel":114,"draw_editor_panel":109,"Cursor":38,"Num_panels_vertical":24,"eval":135,"Data":102,"on":1,"fw_parent":134,"draw_title":110,"Num_panels_horizontal":23,"fw_app":"bf","on.mouse_press":112,"on.draw":108,"on.initialize":104,"draw_data":90,"panel_bounds":93,"Margin":27,"editor_to_string":121,"Font_size":28,"map":123}
|
|
@ -0,0 +1,46 @@
|
|||
eval = function(code, data)
|
||||
local cp,dp = 1,1
|
||||
while cp <= #code do
|
||||
print('== inst', cp, #code)
|
||||
print('-- data')
|
||||
for i,d in ipairs(Data) do
|
||||
print(i,d)
|
||||
end
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[' , cp, --[[plain]] true)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
Out.editor.lines[1].data = Out.editor.lines[1].data..string.char(data[dp])
|
||||
Text.redraw_all(Out.editor)
|
||||
--print(string.char(data[dp]))
|
||||
--print(data[dp])
|
||||
elseif inst == ',' then
|
||||
--data[dp] = string.byte(io.read(1))
|
||||
if #In.editor.lines[1].data > 0 then
|
||||
data[dp] = string.byte(In.editor.lines[1].data:sub(1,1))
|
||||
else
|
||||
data[dp] = 0
|
||||
end
|
||||
In.editor.lines[1].data = In.editor.lines[1].data:sub(2)
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
{"fw_app":"bf","In":98,"draw_title":110,"Out":103,"on.keychord_press":122,"Num_panels_horizontal":23,"on.text_input":118,"Num_panels_vertical":24,"editor_to_string":121,"on.initialize":104,"create_editor_panel":114,"Margin":27,"Title_font":73,"Data":102,"map":123,"create_editor":94,"Font_size":28,"Code":101,"Data_title_text":76,"on":1,"panel_bounds":93,"draw_data":90,"on.mouse_press":112,"eval":136,"on.draw":108,"Cursor":38,"fw_parent":135,"draw_editor_panel":109}
|
77
bf.lua
77
bf.lua
|
@ -1,9 +1,11 @@
|
|||
local code = '[->+<]' -- add
|
||||
local code = '++>++++[<+>-] # now print result\n ++++ ++++ [<+++ +++ > -] < .' -- add 2 to 5
|
||||
local code = '++>++++[<+>-]<.'
|
||||
local cp = 1
|
||||
local data = {}
|
||||
local dp = 1
|
||||
local code = '[->+<]' -- add
|
||||
data[1] = 3
|
||||
data[2] = 4
|
||||
--? local code = '++>++++[<+>-] # now print result\n ++++ ++++ [<+++ +++ > -] < .' -- add 2 to 5
|
||||
--? local code = '++>++++[<+>-]<.'
|
||||
|
||||
function rfind(s, pat, i)
|
||||
if i == nil then i = #s end
|
||||
|
@ -16,35 +18,50 @@ function rfind(s, pat, i)
|
|||
return nil
|
||||
end
|
||||
|
||||
while cp <= #code do
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp)
|
||||
function eval()
|
||||
print(cp, #code)
|
||||
while cp <= #code do
|
||||
local inst = code:sub(cp,cp)
|
||||
if inst == '<' then
|
||||
dp = dp-1
|
||||
elseif inst == '>' then
|
||||
dp = dp+1
|
||||
elseif inst == '+' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]+1
|
||||
elseif inst == '-' then
|
||||
if data[dp] == nil then data[dp] = 0 end
|
||||
data[dp] = data[dp]-1
|
||||
elseif inst == '[' then
|
||||
if data[dp] == 0 then
|
||||
cp = code:find(']', cp)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[', cp)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
print(string.char(data[dp]))
|
||||
--? print(data[dp])
|
||||
elseif inst == ',' then
|
||||
data[dp] = string.byte(io.read(1))
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
end
|
||||
elseif inst == ']' then
|
||||
if data[dp] ~= 0 then
|
||||
cp = rfind(code, '[', cp)
|
||||
end
|
||||
elseif inst == '.' then
|
||||
--? print(string.char(data[dp]))
|
||||
print(data[dp])
|
||||
elseif inst == ',' then
|
||||
data[dp] = string.byte(io.read(1))
|
||||
elseif inst == '#' then
|
||||
cp = code:find('\n', cp)
|
||||
cp = cp+1
|
||||
end
|
||||
cp = cp+1
|
||||
end
|
||||
|
||||
print(#arg)
|
||||
if #arg > 0 then
|
||||
print(arg[1])
|
||||
local f = io.open(arg[1])
|
||||
if f == nil then
|
||||
print('could not open', arg[1])
|
||||
os.exit(1)
|
||||
end
|
||||
code = f:read('*a')
|
||||
eval()
|
||||
end
|
||||
|
||||
print('---')
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
[->+<]
|
|
@ -0,0 +1,5 @@
|
|||
, # read a byte
|
||||
[ # if it's null, exit
|
||||
. # otherwise emit it
|
||||
, # read next byte
|
||||
] # loop
|
Loading…
Reference in New Issue