Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
brainfucker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
brainfucker
Commits
81955ca5
Commit
81955ca5
authored
Jan 10, 2015
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup
parent
f5c9feb6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
20 deletions
+23
-20
bf.ml
bf.ml
+19
-15
run.sh
run.sh
+4
-5
No files found.
bf.ml
View file @
81955ca5
...
@@ -159,7 +159,12 @@ let compile_c memsize program =
...
@@ -159,7 +159,12 @@ let compile_c memsize program =
let
rec
compile_commands
buf
=
function
let
rec
compile_commands
buf
=
function
|
[]
->
buf
|
[]
->
buf
|
cmd
::
tl
->
compile_commands
(
buf
^
compile_command
cmd
^
"
\n
"
)
tl
|
cmd
::
tl
->
compile_commands
(
buf
^
compile_command
cmd
^
"
\n
"
)
tl
and
compile_offset
o
=
function
and
compile_command
=
function
|
Loop
p
->
"while (*p) {
\n
"
^
indent
(
compile_commands
""
p
)
^
"}"
|
Offset
(
o
,
cmd
)
->
begin
match
cmd
with
|
Shift
n
->
"p"
^
add
n
|
Shift
n
->
"p"
^
add
n
|
Add
n
->
ptr
o
^
add
n
|
Add
n
->
ptr
o
^
add
n
|
Goto
0
->
"p = mem"
|
Goto
0
->
"p = mem"
...
@@ -170,11 +175,10 @@ let compile_c memsize program =
...
@@ -170,11 +175,10 @@ let compile_c memsize program =
|
Mul
(
x
,
1
)
->
ptr
o
^
" += "
^
ptr
(
o
+
x
)
|
Mul
(
x
,
1
)
->
ptr
o
^
" += "
^
ptr
(
o
+
x
)
|
Mul
(
x
,
-
1
)
->
ptr
o
^
" -= "
^
ptr
(
o
+
x
)
|
Mul
(
x
,
-
1
)
->
ptr
o
^
" -= "
^
ptr
(
o
+
x
)
|
Mul
(
x
,
y
)
->
ptr
o
^
" += "
^
ptr
(
o
+
x
)
^
" * "
^
string_of_int
y
|
Mul
(
x
,
y
)
->
ptr
o
^
" += "
^
ptr
(
o
+
x
)
^
" * "
^
string_of_int
y
|
cmd
->
failwith
"cannot offset command: "
^
string_of_command
cmd
|
_
->
failwith
"cannot compile: "
^
string_of_command
cmd
and
compile_command
=
function
end
^
";"
|
Loop
p
->
"while (*p != 0) {
\n
"
^
indent
(
compile_commands
""
p
)
^
"}"
|
cmd
->
|
Offset
(
o
,
cmd
)
->
compile_offset
o
cmd
^
";"
compile_command
(
Offset
(
0
,
cmd
))
|
cmd
->
compile_offset
0
cmd
^
";"
in
in
"#include <stdio.h>
\n
"
^
"#include <stdio.h>
\n
"
^
"#include <stdlib.h>
\n
"
^
"#include <stdlib.h>
\n
"
^
...
...
run.sh
View file @
81955ca5
#!/usr/bin/env bash
#!/usr/bin/env bash
set
-e
set
-e
make
-s
bf
cat
>
_tmp.b
./bf | opt
-O3
-o
prog.bc
make
-s
_tmp-opt
make
-s
prog
./_tmp-opt
./prog
rm
-f
_tmp
*
rm
-f
prog
{
,.bc,.o
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment