Skip to content

Commit

Permalink
[mycpp refactor] Remove leaky_ prefixes on filenames
Browse files Browse the repository at this point in the history
We're going to use FUNC_NAME to track progress instead.

- Add comment about incorrect translation of 'del d[key]'
  • Loading branch information
Andy C committed Nov 13, 2022
1 parent 1db3239 commit eb74571
Show file tree
Hide file tree
Showing 17 changed files with 593 additions and 616 deletions.
2 changes: 1 addition & 1 deletion cpp/core_test.cc
Expand Up @@ -6,7 +6,7 @@
#include "cpp/leaky_core.h"
#include "cpp/leaky_core_error.h"
#include "cpp/leaky_stdlib.h" // posix::getcwd
#include "mycpp/builtins.h" // IOError_OSError
#include "mycpp/gc_builtins.h" // IOError_OSError
#include "vendor/greatest.h"

static_assert(offsetof(Obj, field_mask_) == offsetof(error::Usage, field_mask_),
Expand Down
2 changes: 1 addition & 1 deletion cpp/leaky_binding_test.cc
Expand Up @@ -7,7 +7,7 @@
#include "cpp/leaky_osh.h"
#include "cpp/leaky_pylib.h"
#include "cpp/leaky_stdlib.h"
#include "mycpp/builtins.h"
#include "mycpp/gc_builtins.h"
#include "vendor/greatest.h"

TEST show_sizeof() {
Expand Down
2 changes: 1 addition & 1 deletion cpp/leaky_frontend_flag_spec.cc
Expand Up @@ -3,7 +3,7 @@
#include "cpp/leaky_frontend_flag_spec.h"

#include "_gen/frontend/arg_types.h"
#include "mycpp/builtins.h"
#include "mycpp/gc_builtins.h"
// for definition of args::Reader, etc.
#include "prebuilt/frontend/args.mycpp.h"

Expand Down
2 changes: 1 addition & 1 deletion cpp/leaky_osh.cc
Expand Up @@ -8,7 +8,7 @@

#include "cpp/leaky_core_error.h"
#include "cpp/leaky_core_pyerror.h"
#include "mycpp/builtins.h"
#include "mycpp/gc_builtins.h"

namespace arith_parse {

Expand Down
13 changes: 5 additions & 8 deletions mycpp/NINJA_subgraph.py
Expand Up @@ -23,14 +23,11 @@ def DefineTargets(ru):
ru.cc_library(
'//mycpp/runtime',
srcs = [
'mycpp/gc_mylib.cc',
'mycpp/bump_leak_heap.cc',
'mycpp/gc_builtins.cc',
'mycpp/gc_mylib.cc',
'mycpp/gc_str.cc',
'mycpp/marksweep_heap.cc',

# files we haven't added StackRoots to
'mycpp/leaky_containers.cc',
'mycpp/leaky_builtins.cc',
'mycpp/leaky_mylib.cc',
]
)

Expand Down Expand Up @@ -62,8 +59,8 @@ def DefineTargets(ru):

for test_main in [
# TODO: make these 2 run under GC
'mycpp/leaky_containers_test.cc',
'mycpp/leaky_str_test.cc',
'mycpp/gc_containers_test.cc',
'mycpp/gc_str_test.cc',

'mycpp/demo/target_lang.cc',
'mycpp/demo/hash_table.cc',
Expand Down
9 changes: 1 addition & 8 deletions mycpp/comparators.h
Expand Up @@ -22,13 +22,6 @@ namespace id_kind_asdl {
enum class Kind;
};

inline bool are_equal(id_kind_asdl::Kind left, id_kind_asdl::Kind right);

// Only used by unit tests
bool str_equals0(const char* c_string, Str* s);

Str* str_concat(Str* a, Str* b); // a + b when a and b are strings
Str* str_concat3(Str* a, Str* b, Str* c); // for os_path::join()
Str* str_repeat(Str* s, int times); // e.g. ' ' * 3
bool are_equal(id_kind_asdl::Kind left, id_kind_asdl::Kind right);

#endif // MYCPP_COMPARATORS_H
10 changes: 7 additions & 3 deletions mycpp/cppgen_pass.py
Expand Up @@ -1889,20 +1889,24 @@ def visit_with_stmt(self, o: 'mypy.nodes.WithStmt') -> T:
self.write_ind('}\n')

def visit_del_stmt(self, o: 'mypy.nodes.DelStmt') -> T:
# TODO:
# del mylist[:] -> mylist->clear()
# del mydict[mykey] -> mydict->remove(key)

d = o.expr
if isinstance(d, IndexExpr):
self.write_ind('')
self.accept(d.base)

if isinstance(d.index, SliceExpr):
# del mylist[:] -> mylist->clear()

sl = d.index
assert sl.begin_index is None, sl
assert sl.end_index is None, sl
self.write('->clear()')
else:
# del mydict[mykey] -> mydict->remove(key)
# TODO: This is wrong because dict_remove() doesn't raise KeyError
# like del does!

self.write('->remove(')
self.accept(d.index)
self.write(')')
Expand Down
File renamed without changes.
9 changes: 8 additions & 1 deletion mycpp/builtins.h → mycpp/gc_builtins.h
@@ -1,4 +1,4 @@
// builtins.h: Statically typed Python builtins.
// gc_builtins.h: Statically typed Python builtins.
//
// Builtin types: tuples, NotImplementedError, AssertionError
// Builtin functions: print(), repr(), ord()
Expand Down Expand Up @@ -123,6 +123,13 @@ inline bool to_bool(int i) {

bool str_contains(Str* haystack, Str* needle);

// Only used by unit tests
bool str_equals0(const char* c_string, Str* s);

Str* str_concat(Str* a, Str* b); // a + b when a and b are strings
Str* str_concat3(Str* a, Str* b, Str* c); // for os_path::join()
Str* str_repeat(Str* s, int times); // e.g. ' ' * 3

extern Str* kEmptyString;

// Function that mycpp generates for non-constant format strings
Expand Down
File renamed without changes.

0 comments on commit eb74571

Please sign in to comment.