Skip to content

Commit

Permalink
New bytecode. Switch to more granular instructions to enable more opts
Browse files Browse the repository at this point in the history
 - add path_get, path_set, path_delete
 - Get rid of block_ref, not really needed
 - bug fix in string_length; strings can have NULL data
  • Loading branch information
andyfischer committed Jul 25, 2014
1 parent 97740d9 commit 89f77f8
Show file tree
Hide file tree
Showing 202 changed files with 5,258 additions and 5,525 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -27,6 +27,7 @@
*.o
*.trace
.gdb_history
.vagrant

# Windows build artifacts
*.opensdf
Expand Down
9 changes: 2 additions & 7 deletions tools/vagrant/Vagrantfile → Vagrantfile
Expand Up @@ -34,12 +34,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Default value: false
# config.ssh.forward_agent = true

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
config.vm.synced_folder "../..", "/circa_home"

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
Expand Down Expand Up @@ -116,5 +110,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
#
# chef.validation_client_name = "ORGNAME-validator"

config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.provision :shell, inline: "apt-get update"
config.vm.provision :shell, inline: "apt-get install -y build-essential valgrind python3"
end
16 changes: 1 addition & 15 deletions include/circa/circa.h
Expand Up @@ -102,7 +102,7 @@ struct Value
int asInt();
float asFloat();

Value* element(int i);
Value* index(int i);
int length();

// Assignment
Expand Down Expand Up @@ -521,20 +521,6 @@ caValue* circa_function_get_name(caBlock* func);

// -- Code Building --

// Install an evaluation function to the given named function. Returns the container Term.
// Returns NULL if the name was not found.
caTerm* circa_install_function(caBlock* block, const char* name, caEvaluateFunc func);

typedef struct caFunctionBinding
{
const char* name;
caEvaluateFunc func;
} caFunctionBinding;

// Install a series of C function bindings. This will treat 'bindingList' as an array
// that is terminanted with a NULL caFunctionBinding.
void circa_install_function_list(caBlock* block, const caFunctionBinding* bindingList);

// Create a new value() term with the given name. Returns the term's value. The value
// is deep-write-safe.
caValue* circa_declare_value(caBlock* block, const char* name);
Expand Down
21 changes: 0 additions & 21 deletions include/circa/internal/for_hosted_funcs.h

This file was deleted.

20 changes: 20 additions & 0 deletions notes/bytecode_06_05
@@ -0,0 +1,20 @@

Main goals
Don't copy input values unnecessarily

--

Bytecode changes
Single 'push_frame' opcode (with input count)
Pushes a new stack frame without a branch (yet)

New input bytecodes
copy_value
move_from_stack
etc

'enter' bytecodes now vary depending on block type
enter_frame_simple
enter_frame_closure_call
enter_frame_closure_apply
enter_frame_dynamic_method
9 changes: 3 additions & 6 deletions premake4.lua
Expand Up @@ -20,10 +20,7 @@ solution "Circa"
location "src"
files {
"src/*.cpp",
"src/ext/*.cpp",
"src/generated/all_builtin_functions.cpp",
"src/generated/all_builtin_types.cpp",
"src/generated/setup_builtin_functions.cpp",
"src/ext/read_tar.cpp",
"src/generated/stdlib_script_text.cpp",
"3rdparty/tinymt/tinymt64.cc",
"3rdparty/http-parser/http_parser.c"
Expand All @@ -45,7 +42,7 @@ solution "Circa"
"src/command_line/file_checker.cpp",
"3rdparty/linenoise/linenoise.c",
}
links {"static_lib","dl","uv"}
links {"static_lib","dl"}

configuration "Debug"
targetname "circa_d"
Expand All @@ -55,7 +52,7 @@ solution "Circa"
targetname "circa_test"
location "src"
files {"src/unit_tests/*.cpp"}
links {"static_lib","dl","uv"}
links {"static_lib","dl"}

configuration "Release"
targetname "circa_test_r"
21 changes: 9 additions & 12 deletions src/block.cpp
Expand Up @@ -357,6 +357,13 @@ Term* block_get_function_term(Block* block)
return block->owningTerm->function;
}

Value* block_name(Block* block)
{
if (block->owningTerm == NULL)
return NULL;
return term_name(block->owningTerm);
}

Block* function_contents(Term* func)
{
return nested_contents(func);
Expand Down Expand Up @@ -468,7 +475,7 @@ void clear_block(Block* block)

// Iterate through the block and tear down any term references, so that we
// don't have to worry about stale pointers later.
for (BlockIterator it(block); it.unfinished(); ++it) {
for (BlockIterator it(block); it; ++it) {
if (*it == NULL)
continue;

Expand Down Expand Up @@ -525,11 +532,6 @@ void remove_nulls(Block* block)
block->_terms.resize(block->_terms.length() - numDeleted);
}

EvaluateFunc get_override_for_block(Block* block)
{
return block->overrides.evaluate;
}

Term* find_term_by_id(Block* block, int id)
{
for (BlockIterator it(block); !it.finished(); it.advance()) {
Expand Down Expand Up @@ -747,11 +749,6 @@ Type* get_output_type(Block* block, int index)
return placeholder->type;
}

void block_set_evaluate_func(Block* block, EvaluateFunc eval)
{
block->overrides.evaluate = eval;
}

void block_set_specialize_type_func(Block* block, SpecializeTypeFunc specializeFunc)
{
block->overrides.specializeType = specializeFunc;
Expand Down Expand Up @@ -833,7 +830,7 @@ bool block_check_invariants_print_result(Block* block, caValue* out)

void block_link_missing_functions(Block* block, Block* source)
{
for (BlockIterator it(block); it.unfinished(); it.advance()) {
for (BlockIterator it(block); it; ++it) {
Term* term = *it;
if (term->function == NULL || term->function == FUNCS.unknown_function) {
std::string funcName = term->stringProp(sym_Syntax_FunctionName, "");
Expand Down
7 changes: 1 addition & 6 deletions src/block.h
Expand Up @@ -9,12 +9,10 @@ namespace circa {

struct BlockOverrides
{
EvaluateFunc evaluate;
SpecializeTypeFunc specializeType;
PostCompileFunc postCompile;

BlockOverrides() :
evaluate(NULL),
specializeType(NULL),
postCompile(NULL)
{}
Expand Down Expand Up @@ -135,6 +133,7 @@ bool has_nested_contents(Term* term);
Block* make_nested_contents(Term* term);
Block* nested_contents(Term* term);
Term* block_get_function_term(Block* block);
Value* block_name(Block* block);

void remove_nested_contents(Term* term);

Expand Down Expand Up @@ -177,9 +176,6 @@ Block* load_script_term(Block* block, const char* filename);

void remove_nulls(Block* block);

// Return the block's override func. May be NULL.
EvaluateFunc get_override_for_block(Block* block);

Term* find_term_by_id(Block* block, int id);

std::string get_source_file_location(Block* block);
Expand All @@ -202,7 +198,6 @@ int block_locals_count(Block* block);
Type* get_input_type(Block* block, int index);
Type* get_output_type(Block* block, int index);

void block_set_evaluate_func(Block* block, EvaluateFunc eval);
void block_set_specialize_type_func(Block* block, SpecializeTypeFunc specializeFunc);
void block_set_post_compile_func(Block* block, PostCompileFunc postCompile);
void block_set_function_has_nested(Block* block, bool hasNestedContents);
Expand Down
6 changes: 3 additions & 3 deletions src/building.cpp
Expand Up @@ -32,6 +32,8 @@ void on_term_created(Term* term)

Term* apply(Block* block, Term* function, TermList const& inputs, caValue* name)
{
ca_assert(function != NULL);

block_start_changes(block);

// Figure out the term position; it should be placed before any output() terms.
Expand Down Expand Up @@ -929,8 +931,6 @@ void block_finish_changes(Block* block)
// Refresh for-loop zero block
if (is_for_loop(block))
for_loop_remake_zero_block(block);
if (is_while_loop(block))
while_loop_finish_changes(block);

dirty_bytecode(block);

Expand Down Expand Up @@ -1254,7 +1254,7 @@ void create_inputs_for_outer_references(Term* term)
Block* block = nested_contents(term);
TermMap outerToInnerMap;

for (BlockIterator it(block); it.unfinished(); it.advance()) {
for (BlockIterator it(block); it; ++it) {
Term* innerTerm = *it;
for (int inputIndex=0; inputIndex < innerTerm->numInputs(); inputIndex++) {
Term* input = innerTerm->input(inputIndex);
Expand Down

0 comments on commit 89f77f8

Please sign in to comment.