Verified Commit 158b02bf authored by Camil Staps's avatar Camil Staps 🚀

Add ABC instructions (#137)

parent a2c80b23
definition module BuiltinABCInstructions
from CloogleDB import :: ABCInstructionEntry
builtin_abc_instructions :: [ABCInstructionEntry]
implementation module BuiltinABCInstructions
import StdMisc
import StdOverloaded
import Cloogle
import CloogleDB
builtin_abc_instructions :: [ABCInstructionEntry]
builtin_abc_instructions =
[ i_ccall
, i_halt
, i_no_op
: [{zero & aie_instruction=i} \\ i <- other_instructions]
]
instance zero ABCInstructionEntry
where
zero =
{ aie_instruction = undef
, aie_arguments = []
, aie_description = "There is no documentation for this ABC instruction yet."
}
i_ccall :: ABCInstructionEntry
i_ccall =
{ zero
& aie_instruction = "ccall"
, aie_arguments = [ABCArgument ABCTypeLabel False, ABCArgument ABCTypeString False]
, aie_description = "Calls a C function."
}
i_halt :: ABCInstructionEntry
i_halt =
{ zero
& aie_instruction = "halt"
, aie_description = "Terminates the program immediately."
}
i_no_op :: ABCInstructionEntry
i_no_op =
{ zero
& aie_instruction = "no_op"
, aie_description = "Do nothing. This is for example useful in the `cast` function:\n\n```clean\ncast :: .a -> .b\ncast _ = code {\n\tno_op\n}\n```"
}
/**
* Instructions without documentation yet
*/
other_instructions :: [String]
other_instructions =
[ "absR"
, "acosR"
, "add_args"
, "addI"
, "addLU"
, "addR"
, "andB"
, "and%"
, "asinR"
, "atanR"
, "build"
, "buildB"
, "buildC"
, "buildI"
, "buildR"
, "buildAC"
, "buildB_b"
, "buildC_b"
, "buildF_b"
, "buildI_b"
, "buildR_b"
, "buildh"
, "build_r"
, "build_u"
, "catS"
, "call"
, "centry"
, "cmpS"
, "ceilingR"
, "CtoAC"
, "copy_graph"
, "cosR"
, "code_channelP"
, "create"
, "create_array"
, "create_array_"
, "create_channel"
, "currentP"
, "CtoI"
, "decI"
, "del_args"
, "divI"
, "divLU"
, "divR"
, "divU"
, "entierR"
, "eqB"
, "eqB_a"
, "eqB_b"
, "eqC"
, "eqC_a"
, "eqC_b"
, "eqD_b"
, "eqI"
, "eqI_a"
, "eqI_b"
, "eqR"
, "eqR_a"
, "eqR_b"
, "eqAC_a"
, "eq_desc"
, "eq_desc_b"
, "eq_nulldesc"
, "eq_symbol"
, "exit_false"
, "expR"
, "fill"
, "fill1"
, "fill2"
, "fill3"
, "fill1_r"
, "fill2_r"
, "fill3_r"
, "fillcaf"
, "fillcp"
, "fillcp_u"
, "fill_u"
, "fillh"
, "fillB"
, "fillB_b"
, "fillC"
, "fillC_b"
, "fillF_b"
, "fillI"
, "fillI_b"
, "fillR"
, "fillR_b"
, "fill_a"
, "fill_r"
, "floordivI"
, "getWL"
, "get_desc_arity"
, "get_desc_flags_b"
, "get_desc0_number"
, "get_node_arity"
, "gtC"
, "gtI"
, "gtR"
, "gtU"
, "in"
, "incI"
, "instruction"
, "is_record"
, "ItoC"
, "ItoP"
, "ItoR"
, "jmp"
, "jmp_ap"
, "jmp_ap_upd"
, "jmp_upd"
, "jmp_eval"
, "jmp_eval_upd"
, "jmp_false"
, "jmp_not_eqZ"
, "jmp_true"
, "jrsr"
, "jsr"
, "jsr_ap"
, "jsr_eval"
, "lnR"
, "load_i"
, "load_si16"
, "load_si32"
, "load_ui8"
, "log10R"
, "ltC"
, "ltI"
, "ltR"
, "ltU"
, "modI"
, "mulI"
, "mulR"
, "mulUUL"
, "negI"
, "negR"
, "new_ext_reducer"
, "new_int_reducer"
, "newP"
, "notB"
, "not%"
, "orB"
, "or%"
, "out"
, "pop_a"
, "pop_b"
, "powR"
, "print"
, "printD"
, "print_char"
, "print_int"
, "print_real"
, "print_r_arg"
, "print_sc"
, "print_symbol"
, "print_symbol_sc"
, "pushcaf"
, "push_finalizers"
, "pushA_a"
, "pushB"
, "pushB_a"
, "pushC"
, "pushC_a"
, "pushD"
, "pushD_a"
, "pushF_a"
, "pushI"
, "pushI_a"
, "pushL"
, "pushLc"
, "pushR"
, "pushR_a"
, "pushzs"
, "push_a"
, "push_b"
, "push_a_b"
, "push_arg"
, "push_arg_b"
, "push_args"
, "push_args_u"
, "push_array"
, "push_arraysize"
, "push_b_a"
, "push_node"
, "push_node_u"
, "push_a_r_args"
, "push_t_r_a"
, "push_t_r_args"
, "push_r_args"
, "push_r_args_a"
, "push_r_args_b"
, "push_r_args_u"
, "push_r_arg_D"
, "push_r_arg_t"
, "push_r_arg_u"
, "push_wl_args"
, "pushZ"
, "pushZR"
, "putWL"
, "randomP"
, "release"
, "remI"
, "remU"
, "replace"
, "repl_arg"
, "repl_args"
, "repl_args_b"
, "repl_r_args"
, "repl_r_args_a"
, "rotl%"
, "rotr%"
, "rtn"
, "RtoI"
, "select"
, "send_graph"
, "send_request"
, "set_continue"
, "set_defer"
, "set_entry"
, "set_finalizers"
, "setwait"
, "shiftl%"
, "shiftr%"
, "shiftrU"
, "sinR"
, "sincosR"
, "sliceS"
, "sqrtR"
, "stop_reducer"
, "subI"
, "subLU"
, "addIo"
, "mulIo"
, "subIo"
, "subR"
, "suspend"
, "tanR"
, "testcaf"
, "truncateR"
, "update_a"
, "updatepop_a"
, "update_b"
, "updatepop_b"
, "updateS"
, "update"
, "xor%"
, ".algtype"
, ".caf"
, ".code"
, ".comp"
, ".a"
, ".d"
, ".depend"
, ".desc"
, ".desc0"
, ".descn"
, ".descexp"
, ".descs"
, ".end"
, ".endinfo"
, ".export"
, ".keep"
, ".inline"
, ".impdesc"
, ".implab"
, ".implib"
, ".impmod"
, ".impobj"
, ".module"
, ".n"
, ".nu"
, ".newlocallabel"
, ".n_string"
, ".o"
, ".pb"
, ".pd"
, ".pe"
, ".pl"
, ".pld"
, ".pn"
, ".pt"
, ".record"
, ".start"
, ".string"
]
definition module BuiltinSyntax
from CloogleDB import :: SyntaxEntry
builtin_syntax :: [SyntaxEntry]
This diff is collapsed.
definition module Builtins definition module Builtins
from CloogleDB import :: FunctionEntry, :: ClassEntry, :: TypeDefEntry, from CloogleDB import :: FunctionEntry, :: ClassEntry, :: TypeDefEntry,
:: SyntaxEntry :: CleanLangReportLocation
CLR :: Int String String -> CleanLangReportLocation
builtin_functions :: [FunctionEntry] builtin_functions :: [FunctionEntry]
builtin_classes :: [ClassEntry] builtin_classes :: [ClassEntry]
builtin_types :: [TypeDefEntry] builtin_types :: [TypeDefEntry]
builtin_syntax :: [SyntaxEntry]
This diff is collapsed.
Subproject commit a5e772d13bdb09aea01536b501d64688ab68e0d1 Subproject commit 300a410e9231a36f7c28d5e16e207a96a0c21a7a
...@@ -28,6 +28,8 @@ from CloogleDBFactory import :: TemporaryDB, newTemporaryDB, finaliseDB, ...@@ -28,6 +28,8 @@ from CloogleDBFactory import :: TemporaryDB, newTemporaryDB, finaliseDB,
:: IndexItem, :: SourceURL, :: PathPattern :: IndexItem, :: SourceURL, :: PathPattern
import Builtins import Builtins
import BuiltinSyntax
import BuiltinABCInstructions
:: CLI = :: CLI =
{ help :: !Bool { help :: !Bool
...@@ -105,7 +107,8 @@ where ...@@ -105,7 +107,8 @@ where
map TypeDefEntry builtin_types ++ map TypeDefEntry builtin_types ++
map FunctionEntry (concatMap constructor_functions builtin_types) ++ map FunctionEntry (concatMap constructor_functions builtin_types) ++
map FunctionEntry (concatMap record_functions builtin_types) ++ map FunctionEntry (concatMap record_functions builtin_types) ++
map SyntaxEntry builtin_syntax map SyntaxEntry builtin_syntax ++
map ABCInstructionEntry builtin_abc_instructions
parseCLI :: [String] -> Either String CLI parseCLI :: [String] -> Either String CLI
parseCLI [] = Right zero parseCLI [] = Right zero
...@@ -132,7 +135,8 @@ where ...@@ -132,7 +135,8 @@ where
<< "Classes" <-- s.n_classes << "Classes" <-- s.n_classes
<< "Instances" <-- s.n_instances << "Instances" <-- s.n_instances
<< "Derivations" <-- s.n_derivations << "Derivations" <-- s.n_derivations
<< "Syntax constructs" <-- s.n_syntax_constructs) << "Syntax constructs" <-- s.n_syntax_constructs
<< "ABC instructions" <-- s.n_abc_instructions)
where where
(<<) infixl :: *File String -> *File (<<) infixl :: *File String -> *File
(<<) f s = f <<< "| " <<< rpad 17 s <<< " | " (<<) f s = f <<< "| " <<< rpad 17 s <<< " | "
......
...@@ -163,7 +163,7 @@ function mergeComments(code, comments) { ...@@ -163,7 +163,7 @@ function mergeComments(code, comments) {
String.prototype.markup = function() { String.prototype.markup = function() {
return this return this
.replace(/\n```[^\n]+\n/g, '<pre>') .replace(/\n```[^\n]+\n/g, '<pre>')
.replace(/\n```\n/g, '</pre>') .replace(/\n```(\n|$)/g, '</pre>')
.split(/\n\n/).join('<br class="parbreak"/>') .split(/\n\n/).join('<br class="parbreak"/>')
.split(/\n\s*-/).join('<br/>-') .split(/\n\s*-/).join('<br/>-')
.split(/\n\s*\*/).join('<br/>*') .split(/\n\s*\*/).join('<br/>*')
...@@ -628,13 +628,35 @@ function getResults(str, libs, include_builtins, include_core, include_apps, pag ...@@ -628,13 +628,35 @@ function getResults(str, libs, include_builtins, include_core, include_apps, pag
res.className = 'result'; res.className = 'result';
res.innerHTML = res.innerHTML =
'<div class="result-basic">Clean syntax: ' + extra['syntax_title'] + '</div>' + '<div class="result-basic">Clean syntax: ' + extra['syntax_title'] + '</div>' +
'<div class="result-extra">' + meta.join('<br/>') + '</div>' + '<div class="result-extra">' +
meta.join('<br/>') +
'<br class="parbreak"/>' +
'<a href="https://github.com/clean-cloogle/cloogle.org/blob/master/backend/BuiltinSyntax.icl" target="_blank">Edit this explanation on GitHub.</a>' +
'</div>' +
'<div class="result-extra toggle-container">' + '<div class="result-extra toggle-container">' +
toggler + toggler +
'<div class="togglee">' + makeExampleList(extra['syntax_examples']) + '</div></div>' + '<div class="togglee">' + makeExampleList(extra['syntax_examples']) + '</div></div>' +
'<pre class="result-code">' + code + '</pre>'; '<pre class="result-code">' + code + '</pre>';
return res; return res;
case 'ABCInstructionResult':
var parameters = extra['abc_arguments'].length > 0
? '<code>' + extra['abc_arguments'].join(' ') + '</code>'
: 'none';
meta.unshift('Parameters: ' + parameters + '.');
var res = document.createElement('div');
res.className = 'result';
res.innerHTML =
'<div class="result-basic">ABC ' + (extra['abc_instruction'][0] == '.' ? 'directive' : 'instruction') +
': <code>' + extra['abc_instruction'] + '</code></div>' +
'<div class="result-extra">' +
meta.join('<br/>') +
'<a class="parbreak" href="https://github.com/clean-cloogle/cloogle.org/blob/master/backend/BuiltinABCInstructions.icl" target="_blank">Edit this explanation on GitHub.</a>' +
'</div>' +
'<pre class="result-code"><span class="keyword">' + extra['abc_instruction'] + '</span></pre>';
return res;
case 'ProblemResult': case 'ProblemResult':
result = result[1]; result = result[1];
var solutions = '', examples = []; var solutions = '', examples = [];
...@@ -649,9 +671,9 @@ function getResults(str, libs, include_builtins, include_core, include_apps, pag ...@@ -649,9 +671,9 @@ function getResults(str, libs, include_builtins, include_core, include_apps, pag
'<div class="result-basic">Common problem: ' + result.problem_title + '</div>' + '<div class="result-basic">Common problem: ' + result.problem_title + '</div>' +
'<div class="result-extra">' + '<div class="result-extra">' +
result.problem_description + result.problem_description +
'<br/><br/>Possible solutions:<ul>' + solutions + '</ul>' + '<br class="parbreak"/>Possible solutions:<ul>' + solutions + '</ul>' +
'Examples:<ul>' + examples + '</ul>' + 'Examples:<ul>' + examples + '</ul>' +
'<a href="https://github.com/clean-cloogle/common-problems/blob/master/' + result.problem_key + '.md" target="_blank">Edit this explanation.</a><br/><br/>' + '<a href="https://github.com/clean-cloogle/common-problems/blob/master/' + result.problem_key + '.md" target="_blank">Edit this explanation on GitHub.</a>' +
'</div>' + '</div>' +
'<div class="result-code"></div>'; '<div class="result-code"></div>';
return res; return res;
......
...@@ -16,8 +16,11 @@ a { ...@@ -16,8 +16,11 @@ a {
color: #26c; color: #26c;
} }
br.parbreak { .parbreak:before {
margin-bottom: .5em; content: '';
display: block;
height: 0;
margin-top: .5em;
} }
#header { #header {
......
...@@ -76,7 +76,7 @@ else ...@@ -76,7 +76,7 @@ else
echo "Not clearing the cache." echo "Not clearing the cache."
fi fi
RESULTS="$(grep -A11 -F '| Table' /tmp/cloogle-build.log | sed 's/\x1b\[[0-9;]*m//g')" RESULTS="$(grep -A12 -F '| Table' /tmp/cloogle-build.log | sed 's/\x1b\[[0-9;]*m//g')"
if [[ "$HUGINN" != "" ]]; then if [[ "$HUGINN" != "" ]]; then
curl -s -d text="Cloogle build succeeded." "$HUGINN"; echo curl -s -d text="Cloogle build succeeded." "$HUGINN"; echo
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment